Changeset 3d135e9 in mainline
- 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
- Location:
- uspace
- Files:
-
- 4 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 -
uspace/drv/nic/virtio-net/virtio-net.h
rfe96085 r3d135e9 46 46 #define VIRTIO_NET_F_CTRL_VQ (1U << 17) 47 47 48 #define VIRTIO_NET_HDR_GSO_NONE 0 49 typedef struct { 50 uint8_t flags; 51 uint8_t gso_type; 52 uint16_t hdr_len; 53 uint16_t gso_size; 54 uint16_t csum_start; 55 uint16_t csum_offset; 56 uint16_t num_buffers; 57 } virtio_net_hdr_t; 58 48 59 typedef struct { 49 60 uint8_t mac[6]; -
uspace/lib/virtio/virtio-pci.h
rfe96085 r3d135e9 176 176 } virtio_dev_t; 177 177 178 extern void virtio_virtq_ set_desc(virtio_dev_t *vdev, uint16_t, uint16_t,178 extern void virtio_virtq_desc_set(virtio_dev_t *vdev, uint16_t, uint16_t, 179 179 uint64_t, uint32_t, uint16_t, uint16_t); 180 extern uint16_t virtio_virtq_desc_get_next(virtio_dev_t *vdev, uint16_t, 181 uint16_t); 180 182 181 183 extern void virtio_virtq_produce_available(virtio_dev_t *, uint16_t, uint16_t); -
uspace/lib/virtio/virtio.c
rfe96085 r3d135e9 39 39 #include <libarch/barrier.h> 40 40 41 void virtio_virtq_ set_desc(virtio_dev_t *vdev, uint16_t num, uint16_t descno,41 void virtio_virtq_desc_set(virtio_dev_t *vdev, uint16_t num, uint16_t descno, 42 42 uint64_t addr, uint32_t len, uint16_t flags, uint16_t next) 43 43 { … … 47 47 pio_write_le16(&d->flags, flags); 48 48 pio_write_le16(&d->next, next); 49 } 50 51 uint16_t virtio_virtq_desc_get_next(virtio_dev_t *vdev, uint16_t num, 52 uint16_t descno) 53 { 54 virtq_desc_t *d = &vdev->queues[num].desc[descno]; 55 if (!(pio_read_le16(&d->flags) & VIRTQ_DESC_F_NEXT)) 56 return (uint16_t) -1U; 57 return pio_read_le16(&d->next); 49 58 } 50 59
Note:
See TracChangeset
for help on using the changeset viewer.