net: ti: icssg-prueth: introduce and use prueth_swdata struct for SWDATA
We have different cases for SWDATA (skb, page, cmd, etc) so it is better to have a dedicated data structure for that. We can embed the type field inside the struct and use it to interpret the data in completion handlers. Signed-off-by: Roger Quadros <rogerq@kernel.org> Signed-off-by: MD Danish Anwar <danishanwar@ti.com> Signed-off-by: Meghana Malladi <m-malladi@ti.com> Link: https://patch.msgid.link/20250305101422.1908370-3-m-malladi@ti.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
committed by
Paolo Abeni
parent
46eeb90f03
commit
73f7f13118
@@ -136,12 +136,12 @@ int emac_tx_complete_packets(struct prueth_emac *emac, int chn,
|
||||
struct net_device *ndev = emac->ndev;
|
||||
struct cppi5_host_desc_t *desc_tx;
|
||||
struct netdev_queue *netif_txq;
|
||||
struct prueth_swdata *swdata;
|
||||
struct prueth_tx_chn *tx_chn;
|
||||
unsigned int total_bytes = 0;
|
||||
struct sk_buff *skb;
|
||||
dma_addr_t desc_dma;
|
||||
int res, num_tx = 0;
|
||||
void **swdata;
|
||||
|
||||
tx_chn = &emac->tx_chns[chn];
|
||||
|
||||
@@ -161,16 +161,11 @@ int emac_tx_complete_packets(struct prueth_emac *emac, int chn,
|
||||
desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool,
|
||||
desc_dma);
|
||||
swdata = cppi5_hdesc_get_swdata(desc_tx);
|
||||
|
||||
/* was this command's TX complete? */
|
||||
if (emac->is_sr1 && *(swdata) == emac->cmd_data) {
|
||||
prueth_xmit_free(tx_chn, desc_tx);
|
||||
continue;
|
||||
}
|
||||
|
||||
skb = *(swdata);
|
||||
prueth_xmit_free(tx_chn, desc_tx);
|
||||
if (swdata->type != PRUETH_SWDATA_SKB)
|
||||
continue;
|
||||
|
||||
skb = swdata->data.skb;
|
||||
ndev = skb->dev;
|
||||
ndev->stats.tx_packets++;
|
||||
ndev->stats.tx_bytes += skb->len;
|
||||
@@ -472,9 +467,9 @@ int prueth_dma_rx_push_mapped(struct prueth_emac *emac,
|
||||
{
|
||||
struct net_device *ndev = emac->ndev;
|
||||
struct cppi5_host_desc_t *desc_rx;
|
||||
struct prueth_swdata *swdata;
|
||||
dma_addr_t desc_dma;
|
||||
dma_addr_t buf_dma;
|
||||
void **swdata;
|
||||
|
||||
buf_dma = page_pool_get_dma_addr(page) + PRUETH_HEADROOM;
|
||||
desc_rx = k3_cppi_desc_pool_alloc(rx_chn->desc_pool);
|
||||
@@ -490,7 +485,8 @@ int prueth_dma_rx_push_mapped(struct prueth_emac *emac,
|
||||
cppi5_hdesc_attach_buf(desc_rx, buf_dma, buf_len, buf_dma, buf_len);
|
||||
|
||||
swdata = cppi5_hdesc_get_swdata(desc_rx);
|
||||
*swdata = page;
|
||||
swdata->type = PRUETH_SWDATA_PAGE;
|
||||
swdata->data.page = page;
|
||||
|
||||
return k3_udma_glue_push_rx_chn(rx_chn->rx_chn, PRUETH_RX_FLOW_DATA,
|
||||
desc_rx, desc_dma);
|
||||
@@ -539,11 +535,11 @@ static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id)
|
||||
u32 buf_dma_len, pkt_len, port_id = 0;
|
||||
struct net_device *ndev = emac->ndev;
|
||||
struct cppi5_host_desc_t *desc_rx;
|
||||
struct prueth_swdata *swdata;
|
||||
dma_addr_t desc_dma, buf_dma;
|
||||
struct page *page, *new_page;
|
||||
struct page_pool *pool;
|
||||
struct sk_buff *skb;
|
||||
void **swdata;
|
||||
u32 *psdata;
|
||||
void *pa;
|
||||
int ret;
|
||||
@@ -561,7 +557,13 @@ static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id)
|
||||
|
||||
desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma);
|
||||
swdata = cppi5_hdesc_get_swdata(desc_rx);
|
||||
page = *swdata;
|
||||
if (swdata->type != PRUETH_SWDATA_PAGE) {
|
||||
netdev_err(ndev, "rx_pkt: invalid swdata->type %d\n", swdata->type);
|
||||
k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
page = swdata->data.page;
|
||||
page_pool_dma_sync_for_cpu(pool, page, 0, PAGE_SIZE);
|
||||
cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len);
|
||||
k3_udma_glue_rx_cppi5_to_dma_addr(rx_chn->rx_chn, &buf_dma);
|
||||
@@ -626,15 +628,18 @@ static void prueth_rx_cleanup(void *data, dma_addr_t desc_dma)
|
||||
{
|
||||
struct prueth_rx_chn *rx_chn = data;
|
||||
struct cppi5_host_desc_t *desc_rx;
|
||||
struct prueth_swdata *swdata;
|
||||
struct page_pool *pool;
|
||||
struct page *page;
|
||||
void **swdata;
|
||||
|
||||
pool = rx_chn->pg_pool;
|
||||
desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma);
|
||||
swdata = cppi5_hdesc_get_swdata(desc_rx);
|
||||
page = *swdata;
|
||||
page_pool_recycle_direct(pool, page);
|
||||
if (swdata->type == PRUETH_SWDATA_PAGE) {
|
||||
page = swdata->data.page;
|
||||
page_pool_recycle_direct(pool, page);
|
||||
}
|
||||
|
||||
k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
|
||||
}
|
||||
|
||||
@@ -671,13 +676,13 @@ enum netdev_tx icssg_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev
|
||||
struct prueth_emac *emac = netdev_priv(ndev);
|
||||
struct prueth *prueth = emac->prueth;
|
||||
struct netdev_queue *netif_txq;
|
||||
struct prueth_swdata *swdata;
|
||||
struct prueth_tx_chn *tx_chn;
|
||||
dma_addr_t desc_dma, buf_dma;
|
||||
u32 pkt_len, dst_tag_id;
|
||||
int i, ret = 0, q_idx;
|
||||
bool in_tx_ts = 0;
|
||||
int tx_ts_cookie;
|
||||
void **swdata;
|
||||
u32 *epib;
|
||||
|
||||
pkt_len = skb_headlen(skb);
|
||||
@@ -739,7 +744,8 @@ enum netdev_tx icssg_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev
|
||||
k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &buf_dma);
|
||||
cppi5_hdesc_attach_buf(first_desc, buf_dma, pkt_len, buf_dma, pkt_len);
|
||||
swdata = cppi5_hdesc_get_swdata(first_desc);
|
||||
*swdata = skb;
|
||||
swdata->type = PRUETH_SWDATA_SKB;
|
||||
swdata->data.skb = skb;
|
||||
|
||||
/* Handle the case where skb is fragmented in pages */
|
||||
cur_desc = first_desc;
|
||||
@@ -842,15 +848,17 @@ static void prueth_tx_cleanup(void *data, dma_addr_t desc_dma)
|
||||
{
|
||||
struct prueth_tx_chn *tx_chn = data;
|
||||
struct cppi5_host_desc_t *desc_tx;
|
||||
struct prueth_swdata *swdata;
|
||||
struct sk_buff *skb;
|
||||
void **swdata;
|
||||
|
||||
desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, desc_dma);
|
||||
swdata = cppi5_hdesc_get_swdata(desc_tx);
|
||||
skb = *(swdata);
|
||||
prueth_xmit_free(tx_chn, desc_tx);
|
||||
if (swdata->type == PRUETH_SWDATA_SKB) {
|
||||
skb = swdata->data.skb;
|
||||
dev_kfree_skb_any(skb);
|
||||
}
|
||||
|
||||
dev_kfree_skb_any(skb);
|
||||
prueth_xmit_free(tx_chn, desc_tx);
|
||||
}
|
||||
|
||||
irqreturn_t prueth_rx_irq(int irq, void *dev_id)
|
||||
|
||||
@@ -1522,6 +1522,9 @@ static int prueth_probe(struct platform_device *pdev)
|
||||
|
||||
np = dev->of_node;
|
||||
|
||||
BUILD_BUG_ON_MSG((sizeof(struct prueth_swdata) > PRUETH_NAV_SW_DATA_SIZE),
|
||||
"insufficient SW_DATA size");
|
||||
|
||||
prueth = devm_kzalloc(dev, sizeof(*prueth), GFP_KERNEL);
|
||||
if (!prueth)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -136,6 +136,22 @@ struct prueth_rx_chn {
|
||||
struct page_pool *pg_pool;
|
||||
};
|
||||
|
||||
enum prueth_swdata_type {
|
||||
PRUETH_SWDATA_INVALID = 0,
|
||||
PRUETH_SWDATA_SKB,
|
||||
PRUETH_SWDATA_PAGE,
|
||||
PRUETH_SWDATA_CMD,
|
||||
};
|
||||
|
||||
struct prueth_swdata {
|
||||
enum prueth_swdata_type type;
|
||||
union prueth_data {
|
||||
struct sk_buff *skb;
|
||||
struct page *page;
|
||||
u32 cmd;
|
||||
} data;
|
||||
};
|
||||
|
||||
/* There are 4 Tx DMA channels, but the highest priority is CH3 (thread 3)
|
||||
* and lower three are lower priority channels or threads.
|
||||
*/
|
||||
|
||||
@@ -84,7 +84,7 @@ static int emac_send_command_sr1(struct prueth_emac *emac, u32 cmd)
|
||||
__le32 *data = emac->cmd_data;
|
||||
dma_addr_t desc_dma, buf_dma;
|
||||
struct prueth_tx_chn *tx_chn;
|
||||
void **swdata;
|
||||
struct prueth_swdata *swdata;
|
||||
int ret = 0;
|
||||
u32 *epib;
|
||||
|
||||
@@ -122,7 +122,8 @@ static int emac_send_command_sr1(struct prueth_emac *emac, u32 cmd)
|
||||
|
||||
cppi5_hdesc_attach_buf(first_desc, buf_dma, pkt_len, buf_dma, pkt_len);
|
||||
swdata = cppi5_hdesc_get_swdata(first_desc);
|
||||
*swdata = data;
|
||||
swdata->type = PRUETH_SWDATA_CMD;
|
||||
swdata->data.cmd = le32_to_cpu(data[0]);
|
||||
|
||||
cppi5_hdesc_set_pktlen(first_desc, pkt_len);
|
||||
desc_dma = k3_cppi_desc_pool_virt2dma(tx_chn->desc_pool, first_desc);
|
||||
@@ -275,9 +276,9 @@ static struct page *prueth_process_rx_mgm(struct prueth_emac *emac,
|
||||
struct net_device *ndev = emac->ndev;
|
||||
struct cppi5_host_desc_t *desc_rx;
|
||||
struct page *page, *new_page;
|
||||
struct prueth_swdata *swdata;
|
||||
dma_addr_t desc_dma, buf_dma;
|
||||
u32 buf_dma_len;
|
||||
void **swdata;
|
||||
int ret;
|
||||
|
||||
ret = k3_udma_glue_pop_rx_chn(rx_chn->rx_chn, flow_id, &desc_dma);
|
||||
@@ -299,7 +300,7 @@ static struct page *prueth_process_rx_mgm(struct prueth_emac *emac,
|
||||
}
|
||||
|
||||
swdata = cppi5_hdesc_get_swdata(desc_rx);
|
||||
page = *swdata;
|
||||
page = swdata->data.page;
|
||||
cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len);
|
||||
|
||||
dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE);
|
||||
|
||||
Reference in New Issue
Block a user