Changeset 8b3cb67 in mainline for uspace/drv/nic/virtio-net/virtio-net.c
- Timestamp:
- 2018-06-24T10:39:55Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ea6840d
- Parents:
- 6a0f1309
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/virtio-net/virtio-net.c
r6a0f1309 r8b3cb67 70 70 }; 71 71 72 /** Allocate DMA buffers 73 * 74 * @param buffers[in] Number of buffers to allocate. 75 * @param size[in] Size of each buffer. 76 * @param write[in] True if the buffers are writable by the driver, false 77 * otherwise. 78 * @param buf[out] Output array holding virtual addresses of the allocated 79 * buffers. 80 * @param buf_p[out] Output array holding physical addresses of the allocated 81 * buffers. 82 * 83 * The buffers can be deallocated by virtio_net_teardown_bufs(). 84 * 85 * @return EOK on success or error code. 86 */ 72 87 static errno_t virtio_net_setup_bufs(unsigned int buffers, size_t size, 73 88 bool write, void *buf[], uintptr_t buf_p[]) 74 89 { 75 90 /* 76 * Allocate all buffers at once in one large chun g.91 * Allocate all buffers at once in one large chunk. 77 92 */ 78 93 void *virt = AS_AREA_ANY; … … 96 111 } 97 112 113 /** Deallocate DMA buffers 114 * 115 * @param buf[in] Array holding the virtual addresses of the DMA buffers 116 * previously allocated by virtio_net_setup_bufs(). 117 */ 98 118 static void virtio_net_teardown_bufs(void *buf[]) 99 119 { … … 104 124 } 105 125 106 static void virtio_net_create_buf_free_list(virtio_dev_t *vdev, uint16_t num, 126 /** Create free descriptor list from the unused VIRTIO descriptors 127 * 128 * @param vdev[in] VIRTIO device for which the free list will be created. 129 * @param num[in] Index of the virtqueue for which the free list will be 130 * created. 131 * @param size[in] Number of descriptors on the free list. The free list will 132 * contain descriptors starting from 0 to \a size - 1. 133 * @param head[out] Variable that will hold the VIRTIO descriptor at the head 134 * of the free list. 135 */ 136 static void virtio_net_create_desc_free_list(virtio_dev_t *vdev, uint16_t num, 107 137 uint16_t size, uint16_t *head) 108 138 { … … 114 144 } 115 145 116 static uint16_t virtio_net_alloc_buf(virtio_dev_t *vdev, uint16_t num, 146 /** Allocate a descriptor from the free list 147 * 148 * @param vdev[in] VIRTIO device with the free list. 149 * @param num[in] Index of the virtqueue with free list. 150 * @param head[in,out] Head of the free list. 151 * 152 * @return Allocated descriptor or 0xFFFF if the list is empty. 153 */ 154 static uint16_t virtio_net_alloc_desc(virtio_dev_t *vdev, uint16_t num, 117 155 uint16_t *head) 118 156 { … … 123 161 } 124 162 125 static void virtio_net_free_buf(virtio_dev_t *vdev, uint16_t num, 163 /** Free a descriptor into the free list 164 * 165 * @param vdev[in] VIRTIO device with the free list. 166 * @param num[in] Index of the virtqueue with free list. 167 * @param head[in,out] Head of the free list. 168 * @param descno[in] The freed descriptor. 169 */ 170 static void virtio_net_free_desc(virtio_dev_t *vdev, uint16_t num, 126 171 uint16_t *head, uint16_t descno) 127 172 { … … 163 208 164 209 while (virtio_virtq_consume_used(vdev, TX_QUEUE_1, &descno, &len)) { 165 virtio_net_free_ buf(vdev, TX_QUEUE_1, &virtio_net->tx_free_head,166 descno);210 virtio_net_free_desc(vdev, TX_QUEUE_1, 211 &virtio_net->tx_free_head, descno); 167 212 } 168 213 while (virtio_virtq_consume_used(vdev, CT_QUEUE_1, &descno, &len)) { 169 virtio_net_free_ buf(vdev, CT_QUEUE_1, &virtio_net->ct_free_head,170 descno);214 virtio_net_free_desc(vdev, CT_QUEUE_1, 215 &virtio_net->ct_free_head, descno); 171 216 } 172 217 } … … 328 373 * Put all TX and CT buffers on a free list 329 374 */ 330 virtio_net_create_ buf_free_list(vdev, TX_QUEUE_1, TX_BUFFERS,375 virtio_net_create_desc_free_list(vdev, TX_QUEUE_1, TX_BUFFERS, 331 376 &virtio_net->tx_free_head); 332 virtio_net_create_ buf_free_list(vdev, CT_QUEUE_1, CT_BUFFERS,377 virtio_net_create_desc_free_list(vdev, CT_QUEUE_1, CT_BUFFERS, 333 378 &virtio_net->ct_free_head); 334 379 … … 397 442 } 398 443 399 uint16_t descno = virtio_net_alloc_ buf(vdev, TX_QUEUE_1,444 uint16_t descno = virtio_net_alloc_desc(vdev, TX_QUEUE_1, 400 445 &virtio_net->tx_free_head); 401 446 if (descno == (uint16_t) -1U) {
Note:
See TracChangeset
for help on using the changeset viewer.