net: lan966x: Introduce helper functions
authorHoratiu Vultur <horatiu.vultur@microchip.com>
Wed, 23 Nov 2022 20:31:34 +0000 (21:31 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 25 Nov 2022 10:38:10 +0000 (10:38 +0000)
Introduce lan966x_fdma_tx_setup_dcb and lan966x_fdma_tx_start functions
and use of them inside lan966x_fdma_xmit. There is no functional change
in here.
They are introduced to be used when XDP_TX/REDIRECT actions are
introduced.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c

index 3055124b4dd7918e98be5696540336360fbe17a9..94c720e59caee37e65e07d41ce27d5341354a049 100644 (file)
@@ -612,14 +612,53 @@ static int lan966x_fdma_get_next_dcb(struct lan966x_tx *tx)
        return -1;
 }
 
+static void lan966x_fdma_tx_setup_dcb(struct lan966x_tx *tx,
+                                     int next_to_use, int len,
+                                     dma_addr_t dma_addr)
+{
+       struct lan966x_tx_dcb *next_dcb;
+       struct lan966x_db *next_db;
+
+       next_dcb = &tx->dcbs[next_to_use];
+       next_dcb->nextptr = FDMA_DCB_INVALID_DATA;
+
+       next_db = &next_dcb->db[0];
+       next_db->dataptr = dma_addr;
+       next_db->status = FDMA_DCB_STATUS_SOF |
+                         FDMA_DCB_STATUS_EOF |
+                         FDMA_DCB_STATUS_INTR |
+                         FDMA_DCB_STATUS_BLOCKO(0) |
+                         FDMA_DCB_STATUS_BLOCKL(len);
+}
+
+static void lan966x_fdma_tx_start(struct lan966x_tx *tx, int next_to_use)
+{
+       struct lan966x *lan966x = tx->lan966x;
+       struct lan966x_tx_dcb *dcb;
+
+       if (likely(lan966x->tx.activated)) {
+               /* Connect current dcb to the next db */
+               dcb = &tx->dcbs[tx->last_in_use];
+               dcb->nextptr = tx->dma + (next_to_use *
+                                         sizeof(struct lan966x_tx_dcb));
+
+               lan966x_fdma_tx_reload(tx);
+       } else {
+               /* Because it is first time, then just activate */
+               lan966x->tx.activated = true;
+               lan966x_fdma_tx_activate(tx);
+       }
+
+       /* Move to next dcb because this last in use */
+       tx->last_in_use = next_to_use;
+}
+
 int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev)
 {
        struct lan966x_port *port = netdev_priv(dev);
        struct lan966x *lan966x = port->lan966x;
        struct lan966x_tx_dcb_buf *next_dcb_buf;
-       struct lan966x_tx_dcb *next_dcb, *dcb;
        struct lan966x_tx *tx = &lan966x->tx;
-       struct lan966x_db *next_db;
        int needed_headroom;
        int needed_tailroom;
        dma_addr_t dma_addr;
@@ -665,16 +704,7 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev)
        }
 
        /* Setup next dcb */
-       next_dcb = &tx->dcbs[next_to_use];
-       next_dcb->nextptr = FDMA_DCB_INVALID_DATA;
-
-       next_db = &next_dcb->db[0];
-       next_db->dataptr = dma_addr;
-       next_db->status = FDMA_DCB_STATUS_SOF |
-                         FDMA_DCB_STATUS_EOF |
-                         FDMA_DCB_STATUS_INTR |
-                         FDMA_DCB_STATUS_BLOCKO(0) |
-                         FDMA_DCB_STATUS_BLOCKL(skb->len);
+       lan966x_fdma_tx_setup_dcb(tx, next_to_use, skb->len, dma_addr);
 
        /* Fill up the buffer */
        next_dcb_buf = &tx->dcbs_buf[next_to_use];
@@ -688,21 +718,8 @@ int lan966x_fdma_xmit(struct sk_buff *skb, __be32 *ifh, struct net_device *dev)
            LAN966X_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP)
                next_dcb_buf->ptp = true;
 
-       if (likely(lan966x->tx.activated)) {
-               /* Connect current dcb to the next db */
-               dcb = &tx->dcbs[tx->last_in_use];
-               dcb->nextptr = tx->dma + (next_to_use *
-                                         sizeof(struct lan966x_tx_dcb));
-
-               lan966x_fdma_tx_reload(tx);
-       } else {
-               /* Because it is first time, then just activate */
-               lan966x->tx.activated = true;
-               lan966x_fdma_tx_activate(tx);
-       }
-
-       /* Move to next dcb because this last in use */
-       tx->last_in_use = next_to_use;
+       /* Start the transmission */
+       lan966x_fdma_tx_start(tx, next_to_use);
 
        return NETDEV_TX_OK;