Changeset 8b3cb67 in mainline


Ignore:
Timestamp:
2018-06-24T10:39:55Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ea6840d
Parents:
6a0f1309
Message:

Add comments and rename functions for consitency

File:
1 edited

Legend:

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

    r6a0f1309 r8b3cb67  
    7070};
    7171
     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 */
    7287static errno_t virtio_net_setup_bufs(unsigned int buffers, size_t size,
    7388    bool write, void *buf[], uintptr_t buf_p[])
    7489{
    7590        /*
    76          * Allocate all buffers at once in one large chung.
     91         * Allocate all buffers at once in one large chunk.
    7792         */
    7893        void *virt = AS_AREA_ANY;
     
    96111}
    97112
     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 */
    98118static void virtio_net_teardown_bufs(void *buf[])
    99119{
     
    104124}
    105125
    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 */
     136static void virtio_net_create_desc_free_list(virtio_dev_t *vdev, uint16_t num,
    107137    uint16_t size, uint16_t *head)
    108138{
     
    114144}
    115145
    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 */
     154static uint16_t virtio_net_alloc_desc(virtio_dev_t *vdev, uint16_t num,
    117155    uint16_t *head)
    118156{
     
    123161}
    124162
    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 */
     170static void virtio_net_free_desc(virtio_dev_t *vdev, uint16_t num,
    126171    uint16_t *head, uint16_t descno)
    127172{
     
    163208
    164209        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);
    167212        }
    168213        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);
    171216        }
    172217}
     
    328373         * Put all TX and CT buffers on a free list
    329374         */
    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,
    331376            &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,
    333378            &virtio_net->ct_free_head);
    334379
     
    397442        }
    398443
    399         uint16_t descno = virtio_net_alloc_buf(vdev, TX_QUEUE_1,
     444        uint16_t descno = virtio_net_alloc_desc(vdev, TX_QUEUE_1,
    400445            &virtio_net->tx_free_head);
    401446        if (descno == (uint16_t) -1U) {
Note: See TracChangeset for help on using the changeset viewer.