Ignore:
Timestamp:
2018-05-22T19:06:50Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2d4faf7
Parents:
cbcb34c
git-author:
Jakub Jermar <jakub@…> (2018-05-05 20:07:00)
git-committer:
Jakub Jermar <jakub@…> (2018-05-22 19:06:50)
Message:

Factor our generic virtio device initialization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/virtio-net/virtio-net.c

    rcbcb34c r341df5f  
    7575        virtio_net_cfg_t *netcfg = virtio_net->virtio_dev.device_cfg;
    7676
    77         /*
    78          * Perform device initialization as described in section 3.1.1 of the
    79          * specification.
    80          */
     77        /* Reset the device and negotiate the feature bits */
     78        rc = virtio_device_setup_start(vdev,
     79            VIRTIO_NET_F_MAC | VIRTIO_NET_F_CTRL_VQ);
     80        if (rc != EOK)
     81                goto fail;
    8182
    82         /* 1. Reset the device */
    83         uint8_t status = VIRTIO_DEV_STATUS_RESET;
    84         pio_write_8(&cfg->device_status, status);
    85 
    86         /* 2. Acknowledge we found the device */
    87         status |= VIRTIO_DEV_STATUS_ACKNOWLEDGE;
    88         pio_write_8(&cfg->device_status, status);
    89 
    90         /* 3. We know how to drive the device */
    91         status |= VIRTIO_DEV_STATUS_DRIVER;
    92         pio_write_8(&cfg->device_status, status);
    93 
    94         /* 4. Read the offered feature flags */
    95         pio_write_32(&cfg->device_feature_select, VIRTIO_NET_F_SELECT_PAGE_0);
    96         uint32_t features = pio_read_32(&cfg->device_feature);
    97 
    98         ddf_msg(LVL_NOTE, "offered features %x", features);
    99         features &= (1U << VIRTIO_NET_F_MAC) | (1U << VIRTIO_NET_F_CTRL_VQ);
    100 
    101         if (!features) {
    102                 rc = ENOTSUP;
    103                 goto fail;
    104         }
    105 
    106         /* 4. Write the accepted feature flags */
    107         pio_write_32(&cfg->driver_feature_select, VIRTIO_NET_F_SELECT_PAGE_0);
    108         pio_write_32(&cfg->driver_feature, features);
    109 
    110         ddf_msg(LVL_NOTE, "accepted features %x", features);
    111 
    112         /* 5. Set FEATURES_OK */
    113         status |= VIRTIO_DEV_STATUS_FEATURES_OK;
    114         pio_write_8(&cfg->device_status, status);
    115 
    116         /* 6. Test if the device supports our feature subset */
    117         status = pio_read_8(&cfg->device_status);
    118         if (!(status & VIRTIO_DEV_STATUS_FEATURES_OK)) {
    119                 rc = ENOTSUP;
    120                 goto fail;
    121         }
    122 
    123         /* 7. Perform device-specific setup */
     83        /* Perform device-specific setup */
    12484
    12585        /*
     
    164124            nic_addr.address[3], nic_addr.address[4], nic_addr.address[5]);
    165125
    166         /* 8. Go live */
    167         status |= VIRTIO_DEV_STATUS_DRIVER_OK;
    168         pio_write_8(&cfg->device_status, status);
     126        /* Go live */
     127        virtio_device_setup_finalize(vdev);
    169128
    170129        return EOK;
    171130
    172131fail:
    173         status |= VIRTIO_DEV_STATUS_FAILED;
    174         pio_write_8(&cfg->device_status, status);
    175         virtio_pci_dev_cleanup(&virtio_net->virtio_dev);
     132        virtio_device_setup_fail(vdev);
     133        virtio_pci_dev_cleanup(vdev);
    176134        return rc;
    177135}
Note: See TracChangeset for help on using the changeset viewer.