Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: ethernet: ti am65_cpsw: Drop separate TX completion functions

Drop separate TX completion functions for SKB and XDP. To do that
use the SW_DATA mechanism to store ndev and skb/xdpf for TX packets.

Use BUILD_BUG_ON_MSG() to fail build if SW_DATA size exceeds whats
available. i.e. AM65_CPSW_NAV_SW_DATA_SIZE.

Signed-off-by: Roger Quadros <rogerq@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Roger Quadros and committed by
David S. Miller
ce643fa6 6d6c7933

+32 -58
+24 -58
drivers/net/ethernet/ti/am65-cpsw-nuss.c
··· 830 830 { 831 831 struct am65_cpsw_tx_chn *tx_chn = data; 832 832 enum am65_cpsw_tx_buf_type buf_type; 833 + struct am65_cpsw_tx_swdata *swdata; 833 834 struct cppi5_host_desc_t *desc_tx; 834 835 struct xdp_frame *xdpf; 835 836 struct sk_buff *skb; 836 - void **swdata; 837 837 838 838 desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, desc_dma); 839 839 swdata = cppi5_hdesc_get_swdata(desc_tx); 840 840 buf_type = am65_cpsw_nuss_buf_type(tx_chn, desc_dma); 841 841 if (buf_type == AM65_CPSW_TX_BUF_TYPE_SKB) { 842 - skb = *(swdata); 842 + skb = swdata->skb; 843 843 dev_kfree_skb_any(skb); 844 844 } else { 845 - xdpf = *(swdata); 845 + xdpf = swdata->xdpf; 846 846 xdp_return_frame(xdpf); 847 847 } 848 848 ··· 1099 1099 struct am65_cpsw_common *common = am65_ndev_to_common(ndev); 1100 1100 struct am65_cpsw_port *port = am65_ndev_to_port(ndev); 1101 1101 struct cppi5_host_desc_t *host_desc; 1102 + struct am65_cpsw_tx_swdata *swdata; 1102 1103 struct netdev_queue *netif_txq; 1103 1104 dma_addr_t dma_desc, dma_buf; 1104 1105 u32 pkt_len = xdpf->len; 1105 - void **swdata; 1106 1106 int ret; 1107 1107 1108 1108 host_desc = k3_cppi_desc_pool_alloc(tx_chn->desc_pool); ··· 1132 1132 cppi5_hdesc_attach_buf(host_desc, dma_buf, pkt_len, dma_buf, pkt_len); 1133 1133 1134 1134 swdata = cppi5_hdesc_get_swdata(host_desc); 1135 - *(swdata) = xdpf; 1135 + swdata->ndev = ndev; 1136 + swdata->xdpf = xdpf; 1136 1137 1137 1138 /* Report BQL before sending the packet */ 1138 1139 netif_txq = netdev_get_tx_queue(ndev, tx_chn->id); ··· 1436 1435 return num_rx; 1437 1436 } 1438 1437 1439 - static struct sk_buff * 1440 - am65_cpsw_nuss_tx_compl_packet_skb(struct am65_cpsw_tx_chn *tx_chn, 1441 - dma_addr_t desc_dma) 1442 - { 1443 - struct cppi5_host_desc_t *desc_tx; 1444 - struct sk_buff *skb; 1445 - void **swdata; 1446 - 1447 - desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, 1448 - desc_dma); 1449 - swdata = cppi5_hdesc_get_swdata(desc_tx); 1450 - skb = *(swdata); 1451 - am65_cpsw_nuss_xmit_free(tx_chn, desc_tx); 1452 - 1453 - am65_cpts_tx_timestamp(tx_chn->common->cpts, skb); 1454 - 1455 - dev_sw_netstats_tx_add(skb->dev, 1, skb->len); 1456 - 1457 - return skb; 1458 - } 1459 - 1460 - static struct xdp_frame * 1461 - am65_cpsw_nuss_tx_compl_packet_xdp(struct am65_cpsw_common *common, 1462 - struct am65_cpsw_tx_chn *tx_chn, 1463 - dma_addr_t desc_dma, 1464 - struct net_device **ndev) 1465 - { 1466 - struct cppi5_host_desc_t *desc_tx; 1467 - struct am65_cpsw_port *port; 1468 - struct xdp_frame *xdpf; 1469 - u32 port_id = 0; 1470 - void **swdata; 1471 - 1472 - desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, desc_dma); 1473 - cppi5_desc_get_tags_ids(&desc_tx->hdr, NULL, &port_id); 1474 - swdata = cppi5_hdesc_get_swdata(desc_tx); 1475 - xdpf = *(swdata); 1476 - am65_cpsw_nuss_xmit_free(tx_chn, desc_tx); 1477 - 1478 - port = am65_common_get_port(common, port_id); 1479 - dev_sw_netstats_tx_add(port->ndev, 1, xdpf->len); 1480 - *ndev = port->ndev; 1481 - 1482 - return xdpf; 1483 - } 1484 - 1485 1438 static void am65_cpsw_nuss_tx_wake(struct am65_cpsw_tx_chn *tx_chn, struct net_device *ndev, 1486 1439 struct netdev_queue *netif_txq) 1487 1440 { ··· 1458 1503 { 1459 1504 bool single_port = AM65_CPSW_IS_CPSW2G(common); 1460 1505 enum am65_cpsw_tx_buf_type buf_type; 1506 + struct am65_cpsw_tx_swdata *swdata; 1507 + struct cppi5_host_desc_t *desc_tx; 1461 1508 struct device *dev = common->dev; 1462 1509 struct am65_cpsw_tx_chn *tx_chn; 1463 1510 struct netdev_queue *netif_txq; ··· 1490 1533 break; 1491 1534 } 1492 1535 1536 + desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, 1537 + desc_dma); 1538 + swdata = cppi5_hdesc_get_swdata(desc_tx); 1539 + ndev = swdata->ndev; 1493 1540 buf_type = am65_cpsw_nuss_buf_type(tx_chn, desc_dma); 1494 1541 if (buf_type == AM65_CPSW_TX_BUF_TYPE_SKB) { 1495 - skb = am65_cpsw_nuss_tx_compl_packet_skb(tx_chn, desc_dma); 1496 - ndev = skb->dev; 1542 + skb = swdata->skb; 1543 + am65_cpts_tx_timestamp(tx_chn->common->cpts, skb); 1497 1544 pkt_len = skb->len; 1498 1545 napi_consume_skb(skb, budget); 1499 1546 } else { 1500 - xdpf = am65_cpsw_nuss_tx_compl_packet_xdp(common, tx_chn, 1501 - desc_dma, &ndev); 1547 + xdpf = swdata->xdpf; 1502 1548 pkt_len = xdpf->len; 1503 1549 if (buf_type == AM65_CPSW_TX_BUF_TYPE_XDP_TX) 1504 1550 xdp_return_frame_rx_napi(xdpf); ··· 1511 1551 1512 1552 total_bytes += pkt_len; 1513 1553 num_tx++; 1514 - 1554 + am65_cpsw_nuss_xmit_free(tx_chn, desc_tx); 1555 + dev_sw_netstats_tx_add(ndev, 1, pkt_len); 1515 1556 if (!single_port) { 1516 1557 /* as packets from multi ports can be interleaved 1517 1558 * on the same channel, we have to figure out the ··· 1595 1634 struct am65_cpsw_common *common = am65_ndev_to_common(ndev); 1596 1635 struct cppi5_host_desc_t *first_desc, *next_desc, *cur_desc; 1597 1636 struct am65_cpsw_port *port = am65_ndev_to_port(ndev); 1637 + struct am65_cpsw_tx_swdata *swdata; 1598 1638 struct device *dev = common->dev; 1599 1639 struct am65_cpsw_tx_chn *tx_chn; 1600 1640 struct netdev_queue *netif_txq; 1601 1641 dma_addr_t desc_dma, buf_dma; 1602 1642 int ret, q_idx, i; 1603 - void **swdata; 1604 1643 u32 *psdata; 1605 1644 u32 pkt_len; 1606 1645 ··· 1646 1685 k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &buf_dma); 1647 1686 cppi5_hdesc_attach_buf(first_desc, buf_dma, pkt_len, buf_dma, pkt_len); 1648 1687 swdata = cppi5_hdesc_get_swdata(first_desc); 1649 - *(swdata) = skb; 1688 + swdata->ndev = ndev; 1689 + swdata->skb = skb; 1650 1690 psdata = cppi5_hdesc_get_psdata(first_desc); 1651 1691 1652 1692 /* HW csum offload if enabled */ ··· 3489 3527 __be64 id_temp; 3490 3528 int ret, i; 3491 3529 3530 + BUILD_BUG_ON_MSG(sizeof(struct am65_cpsw_tx_swdata) > AM65_CPSW_NAV_SW_DATA_SIZE, 3531 + "TX SW_DATA size exceeds AM65_CPSW_NAV_SW_DATA_SIZE"); 3532 + BUILD_BUG_ON_MSG(sizeof(struct am65_cpsw_swdata) > AM65_CPSW_NAV_SW_DATA_SIZE, 3533 + "SW_DATA size exceeds AM65_CPSW_NAV_SW_DATA_SIZE"); 3492 3534 common = devm_kzalloc(dev, sizeof(struct am65_cpsw_common), GFP_KERNEL); 3493 3535 if (!common) 3494 3536 return -ENOMEM;
+8
drivers/net/ethernet/ti/am65-cpsw-nuss.h
··· 104 104 char name[32]; 105 105 }; 106 106 107 + struct am65_cpsw_tx_swdata { 108 + struct net_device *ndev; 109 + union { 110 + struct sk_buff *skb; 111 + struct xdp_frame *xdpf; 112 + }; 113 + }; 114 + 107 115 struct am65_cpsw_swdata { 108 116 u32 flow_id; 109 117 struct page *page;