Ignore:
Timestamp:
2018-05-22T19:06:50Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
341df5f
Parents:
1c53d93
git-author:
Jakub Jermar <jakub@…> (2018-05-05 14:43:51)
git-committer:
Jakub Jermar <jakub@…> (2018-05-22 19:06:50)
Message:

Configure the virtqueues

File:
1 edited

Legend:

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

    r1c53d93 rcbcb34c  
    4343#define NAME    "virtio-net"
    4444
     45#define VIRTIO_NET_NUM_QUEUES   3
     46
     47#define RECVQ1          0
     48#define TRANSQ1         1
     49#define CTRLQ1          2
     50
     51#define RECVQ_SIZE      8
     52#define TRANSQ_SIZE     8
     53#define CTRLQ_SIZE      4
     54
    4555static errno_t virtio_net_initialize(ddf_dev_t *dev)
    4656{
     
    6171                return rc;
    6272
     73        virtio_dev_t *vdev = &virtio_net->virtio_dev;
    6374        virtio_pci_common_cfg_t *cfg = virtio_net->virtio_dev.common_cfg;
    6475        virtio_net_cfg_t *netcfg = virtio_net->virtio_dev.device_cfg;
     
    8697
    8798        ddf_msg(LVL_NOTE, "offered features %x", features);
    88         features &= (1U << VIRTIO_NET_F_MAC);
     99        features &= (1U << VIRTIO_NET_F_MAC) | (1U << VIRTIO_NET_F_CTRL_VQ);
    89100
    90101        if (!features) {
     
    96107        pio_write_32(&cfg->driver_feature_select, VIRTIO_NET_F_SELECT_PAGE_0);
    97108        pio_write_32(&cfg->driver_feature, features);
     109
     110        ddf_msg(LVL_NOTE, "accepted features %x", features);
    98111
    99112        /* 5. Set FEATURES_OK */
     
    109122
    110123        /* 7. Perform device-specific setup */
     124
     125        /*
     126         * Discover and configure the virtqueues
     127         */
     128        uint16_t num_queues = pio_read_16(&cfg->num_queues);
     129        if (num_queues != VIRTIO_NET_NUM_QUEUES) {
     130                ddf_msg(LVL_NOTE, "Unsupported number of virtqueues: %u",
     131                    num_queues);
     132                goto fail;
     133        }
     134
     135        vdev->queues = calloc(sizeof(virtq_t), num_queues);
     136        if (!vdev->queues) {
     137                rc = ENOMEM;
     138                goto fail;
     139        }
     140
     141        rc = virtio_virtq_setup(vdev, RECVQ1, RECVQ_SIZE, 1500,
     142            VIRTQ_DESC_F_WRITE);
     143        if (rc != EOK)
     144                goto fail;
     145        rc = virtio_virtq_setup(vdev, TRANSQ1, TRANSQ_SIZE, 1500, 0);
     146        if (rc != EOK)
     147                goto fail;
     148        rc = virtio_virtq_setup(vdev, CTRLQ1, CTRLQ_SIZE, 512, 0);
     149        if (rc != EOK)
     150                goto fail;
     151
     152        /*
     153         * Read the MAC address
     154         */
    111155        nic_address_t nic_addr;
    112156        for (unsigned i = 0; i < 6; i++)
    113                 nic_addr.address[i] = netcfg->mac[i];
     157                nic_addr.address[i] = pio_read_8(&netcfg->mac[i]);
    114158        rc = nic_report_address(nic_data, &nic_addr);
    115159        if (rc != EOK)
Note: See TracChangeset for help on using the changeset viewer.