ibmvnic: define map_rxpool_buf_to_ltb()
authorSukadev Bhattiprolu <sukadev@linux.ibm.com>
Wed, 13 Apr 2022 17:10:22 +0000 (13:10 -0400)
committerJakub Kicinski <kuba@kernel.org>
Fri, 15 Apr 2022 21:02:04 +0000 (14:02 -0700)
Define a helper to map a given rx pool buffer into its corresponding long
term buffer (LTB) and offset. Currently there is just one LTB per pool so
the mapping is trivial. When we add support for multiple LTBs per pool,
this helper will be more useful.

Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.ibm.com>
Signed-off-by: Dany Madden <drt@linux.ibm.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/ibm/ibmvnic.c

index 7fd9dd3..753afda 100644 (file)
@@ -345,6 +345,25 @@ static void free_long_term_buff(struct ibmvnic_adapter *adapter,
        ltb->map_id = 0;
 }
 
+/**
+ * map_rxpool_buf_to_ltb - Map given rxpool buffer to offset in an LTB.
+ * @rxpool: The receive buffer pool containing buffer
+ * @bufidx: Index of buffer in rxpool
+ * @ltbp: (Output) pointer to the long term buffer containing the buffer
+ * @offset: (Output) offset of buffer in the LTB from @ltbp
+ *
+ * Map the given buffer identified by [rxpool, bufidx] to an LTB in the
+ * pool and its corresponding offset.
+ */
+static void map_rxpool_buf_to_ltb(struct ibmvnic_rx_pool *rxpool,
+                                 unsigned int bufidx,
+                                 struct ibmvnic_long_term_buff **ltbp,
+                                 unsigned int *offset)
+{
+       *ltbp = &rxpool->long_term_buff;
+       *offset = bufidx * rxpool->buff_size;
+}
+
 static void deactivate_rx_pools(struct ibmvnic_adapter *adapter)
 {
        int i;
@@ -361,6 +380,7 @@ static void replenish_rx_pool(struct ibmvnic_adapter *adapter,
        struct device *dev = &adapter->vdev->dev;
        struct ibmvnic_ind_xmit_queue *ind_bufp;
        struct ibmvnic_sub_crq_queue *rx_scrq;
+       struct ibmvnic_long_term_buff *ltb;
        union sub_crq *sub_crq;
        int buffers_added = 0;
        unsigned long lpar_rc;
@@ -407,10 +427,10 @@ static void replenish_rx_pool(struct ibmvnic_adapter *adapter,
                pool->next_free = (pool->next_free + 1) % pool->size;
 
                /* Copy the skb to the long term mapped DMA buffer */
-               offset = bufidx * pool->buff_size;
-               dst = pool->long_term_buff.buff + offset;
+               map_rxpool_buf_to_ltb(pool, bufidx, &ltb, &offset);
+               dst = ltb->buff + offset;
                memset(dst, 0, pool->buff_size);
-               dma_addr = pool->long_term_buff.addr + offset;
+               dma_addr = ltb->addr + offset;
 
                /* add the skb to an rx_buff in the pool */
                pool->rx_buff[bufidx].data = dst;
@@ -426,7 +446,7 @@ static void replenish_rx_pool(struct ibmvnic_adapter *adapter,
                sub_crq->rx_add.correlator =
                    cpu_to_be64((u64)&pool->rx_buff[bufidx]);
                sub_crq->rx_add.ioba = cpu_to_be32(dma_addr);
-               sub_crq->rx_add.map_id = pool->long_term_buff.map_id;
+               sub_crq->rx_add.map_id = ltb->map_id;
 
                /* The length field of the sCRQ is defined to be 24 bits so the
                 * buffer size needs to be left shifted by a byte before it is