Changeset 3d135e9 in mainline for uspace/drv/nic/virtio-net/virtio-net.c
- Timestamp:
- 2018-06-16T16:05:39Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b8ef198b
- Parents:
- fe96085
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/virtio-net/virtio-net.c
rfe96085 r3d135e9 112 112 { 113 113 for (unsigned i = 0; i < size; i++) { 114 virtio_virtq_ set_desc(vdev, num, i, 0, 0,114 virtio_virtq_desc_set(vdev, num, i, 0, 0, 115 115 VIRTQ_DESC_F_NEXT, (i + 1 == size) ? -1U : i + 1); 116 116 } 117 117 *head = 0; 118 } 119 120 static uint16_t virtio_net_alloc_buf(virtio_dev_t *vdev, uint16_t num, 121 uint16_t *head) 122 { 123 uint16_t descno = *head; 124 if (descno != (uint16_t) -1U) 125 *head = virtio_virtq_desc_get_next(vdev, num, descno); 126 return descno; 118 127 } 119 128 … … 261 270 * flags. 262 271 */ 263 virtio_virtq_ set_desc(vdev, RX_QUEUE_1, i,272 virtio_virtq_desc_set(vdev, RX_QUEUE_1, i, 264 273 virtio_net->rx_buf_p[i], RX_BUF_SIZE, VIRTQ_DESC_F_WRITE, 265 274 0); … … 335 344 static void virtio_net_send(nic_t *nic, void *data, size_t size) 336 345 { 337 // TODO 346 virtio_net_t *virtio_net = nic_get_specific(nic); 347 virtio_dev_t *vdev = &virtio_net->virtio_dev; 348 349 if (size > sizeof(virtio_net) + TX_BUF_SIZE) { 350 ddf_msg(LVL_WARN, "TX data too big, frame dropped"); 351 return; 352 } 353 354 uint16_t descno = virtio_net_alloc_buf(vdev, TX_QUEUE_1, 355 &virtio_net->tx_free_head); 356 if (descno == (uint16_t) -1U) { 357 ddf_msg(LVL_WARN, "No TX buffers available, frame dropped"); 358 return; 359 } 360 assert(descno < TX_BUFFERS); 361 362 /* Setup the packed header */ 363 virtio_net_hdr_t *hdr = (virtio_net_hdr_t *) virtio_net->tx_buf[descno]; 364 memset(hdr, 0, sizeof(virtio_net_hdr_t)); 365 hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE; 366 367 /* Copy packet data into the buffer just past the header */ 368 memcpy(&hdr[1], data, size); 369 370 /* 371 * Set the descriptor, put it into the virtqueue and notify the device 372 */ 373 virtio_virtq_desc_set(vdev, TX_QUEUE_1, descno, 374 virtio_net->tx_buf_p[descno], TX_BUF_SIZE, 0, 0); 375 virtio_virtq_produce_available(vdev, TX_QUEUE_1, descno); 338 376 } 339 377
Note:
See TracChangeset
for help on using the changeset viewer.