Changeset 331d024 in mainline for uspace/drv/nic/virtio-net/virtio-net.c
- Timestamp:
- 2018-06-28T18:57:36Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1e472ee
- Parents:
- 96c30c8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/virtio-net/virtio-net.c
r96c30c8 r331d024 122 122 buf[0] = NULL; 123 123 } 124 }125 126 /** Create free descriptor list from the unused VIRTIO descriptors127 *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 be130 * created.131 * @param size[in] Number of descriptors on the free list. The free list will132 * contain descriptors starting from 0 to \a size - 1.133 * @param head[out] Variable that will hold the VIRTIO descriptor at the head134 * of the free list.135 */136 static void virtio_net_create_desc_free_list(virtio_dev_t *vdev, uint16_t num,137 uint16_t size, uint16_t *head)138 {139 for (unsigned i = 0; i < size; i++) {140 virtio_virtq_desc_set(vdev, num, i, 0, 0,141 VIRTQ_DESC_F_NEXT, (i + 1 == size) ? -1U : i + 1);142 }143 *head = 0;144 }145 146 /** Allocate a descriptor from the free list147 *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,155 uint16_t *head)156 {157 virtq_t *q = &vdev->queues[num];158 fibril_mutex_lock(&q->lock);159 uint16_t descno = *head;160 if (descno != (uint16_t) -1U)161 *head = virtio_virtq_desc_get_next(vdev, num, descno);162 fibril_mutex_unlock(&q->lock);163 return descno;164 }165 166 /** Free a descriptor into the free list167 *168 * @param vdev[in] VIRTIO device with the free list.169 * @param num[in] Index of the virtqueue with free list.170 * @param head[in,out] Head of the free list.171 * @param descno[in] The freed descriptor.172 */173 static void virtio_net_free_desc(virtio_dev_t *vdev, uint16_t num,174 uint16_t *head, uint16_t descno)175 {176 virtq_t *q = &vdev->queues[num];177 fibril_mutex_lock(&q->lock);178 virtio_virtq_desc_set(vdev, num, descno, 0, 0, VIRTQ_DESC_F_NEXT,179 *head);180 *head = descno;181 fibril_mutex_unlock(&q->lock);182 124 } 183 125 … … 214 156 215 157 while (virtio_virtq_consume_used(vdev, TX_QUEUE_1, &descno, &len)) { 216 virtio_ net_free_desc(vdev, TX_QUEUE_1,217 &virtio_net->tx_free_head,descno);158 virtio_free_desc(vdev, TX_QUEUE_1, &virtio_net->tx_free_head, 159 descno); 218 160 } 219 161 while (virtio_virtq_consume_used(vdev, CT_QUEUE_1, &descno, &len)) { 220 virtio_ net_free_desc(vdev, CT_QUEUE_1,221 &virtio_net->ct_free_head,descno);162 virtio_free_desc(vdev, CT_QUEUE_1, &virtio_net->ct_free_head, 163 descno); 222 164 } 223 165 } … … 379 321 * Put all TX and CT buffers on a free list 380 322 */ 381 virtio_ net_create_desc_free_list(vdev, TX_QUEUE_1, TX_BUFFERS,323 virtio_create_desc_free_list(vdev, TX_QUEUE_1, TX_BUFFERS, 382 324 &virtio_net->tx_free_head); 383 virtio_ net_create_desc_free_list(vdev, CT_QUEUE_1, CT_BUFFERS,325 virtio_create_desc_free_list(vdev, CT_QUEUE_1, CT_BUFFERS, 384 326 &virtio_net->ct_free_head); 385 327 … … 446 388 } 447 389 448 uint16_t descno = virtio_ net_alloc_desc(vdev, TX_QUEUE_1,390 uint16_t descno = virtio_alloc_desc(vdev, TX_QUEUE_1, 449 391 &virtio_net->tx_free_head); 450 392 if (descno == (uint16_t) -1U) {
Note:
See TracChangeset
for help on using the changeset viewer.