Changeset 331d024 in mainline


Ignore:
Timestamp:
2018-06-28T18:57:36Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1e472ee
Parents:
96c30c8
Message:

Move desc free list functions to libvirtio

Location:
uspace
Files:
3 edited

Legend:

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

    r96c30c8 r331d024  
    122122                buf[0] = NULL;
    123123        }
    124 }
    125 
    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,
    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 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,
    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 list
    167  *
    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);
    182124}
    183125
     
    214156
    215157        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);
    218160        }
    219161        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);
    222164        }
    223165}
     
    379321         * Put all TX and CT buffers on a free list
    380322         */
    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,
    382324            &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,
    384326            &virtio_net->ct_free_head);
    385327
     
    446388        }
    447389
    448         uint16_t descno = virtio_net_alloc_desc(vdev, TX_QUEUE_1,
     390        uint16_t descno = virtio_alloc_desc(vdev, TX_QUEUE_1,
    449391            &virtio_net->tx_free_head);
    450392        if (descno == (uint16_t) -1U) {
  • uspace/lib/virtio/virtio-pci.h

    r96c30c8 r331d024  
    186186    uint16_t);
    187187
     188extern void virtio_create_desc_free_list(virtio_dev_t *, uint16_t, uint16_t,
     189    uint16_t *);
     190extern uint16_t virtio_alloc_desc(virtio_dev_t *, uint16_t, uint16_t *);
     191extern void virtio_free_desc(virtio_dev_t *, uint16_t, uint16_t *, uint16_t);
     192
    188193extern void virtio_virtq_produce_available(virtio_dev_t *, uint16_t, uint16_t);
    189194extern bool virtio_virtq_consume_used(virtio_dev_t *, uint16_t, uint16_t *,
  • uspace/lib/virtio/virtio.c

    r96c30c8 r331d024  
    5757        return pio_read_le16(&d->next);
    5858}
     59
     60/** Create free descriptor list from the unused VIRTIO descriptors
     61 *
     62 * @param vdev[in]   VIRTIO device for which the free list will be created.
     63 * @param num[in]    Index of the virtqueue for which the free list will be
     64 *                   created.
     65 * @param size[in]   Number of descriptors on the free list. The free list will
     66 *                   contain descriptors starting from 0 to \a size - 1.
     67 * @param head[out]  Variable that will hold the VIRTIO descriptor at the head
     68 *                   of the free list.
     69 */
     70void virtio_create_desc_free_list(virtio_dev_t *vdev, uint16_t num,
     71    uint16_t size, uint16_t *head)
     72{
     73        for (unsigned i = 0; i < size; i++) {
     74                virtio_virtq_desc_set(vdev, num, i, 0, 0,
     75                    VIRTQ_DESC_F_NEXT, (i + 1 == size) ? -1U : i + 1);
     76        }
     77        *head = 0;
     78}
     79
     80/** Allocate a descriptor from the free list
     81 *
     82 * @param vdev[in]      VIRTIO device with the free list.
     83 * @param num[in]       Index of the virtqueue with free list.
     84 * @param head[in,out]  Head of the free list.
     85 *
     86 * @return  Allocated descriptor or 0xFFFF if the list is empty.
     87 */
     88uint16_t virtio_alloc_desc(virtio_dev_t *vdev, uint16_t num, uint16_t *head)
     89{
     90        virtq_t *q = &vdev->queues[num];
     91        fibril_mutex_lock(&q->lock);
     92        uint16_t descno = *head;
     93        if (descno != (uint16_t) -1U)
     94                *head = virtio_virtq_desc_get_next(vdev, num, descno);
     95        fibril_mutex_unlock(&q->lock);
     96        return descno;
     97}
     98
     99/** Free a descriptor into the free list
     100 *
     101 * @param vdev[in]      VIRTIO device with the free list.
     102 * @param num[in]       Index of the virtqueue with free list.
     103 * @param head[in,out]  Head of the free list.
     104 * @param descno[in]    The freed descriptor.
     105 */
     106void virtio_free_desc(virtio_dev_t *vdev, uint16_t num, uint16_t *head,
     107    uint16_t descno)
     108{
     109        virtq_t *q = &vdev->queues[num];
     110        fibril_mutex_lock(&q->lock);
     111        virtio_virtq_desc_set(vdev, num, descno, 0, 0, VIRTQ_DESC_F_NEXT,
     112            *head);
     113        *head = descno;
     114        fibril_mutex_unlock(&q->lock);
     115}
     116
    59117
    60118void virtio_virtq_produce_available(virtio_dev_t *vdev, uint16_t num,
Note: See TracChangeset for help on using the changeset viewer.