Skip to content

Commit 73f7f13

Browse files
rogerqPaolo Abeni
authored andcommitted
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 <[email protected]> Signed-off-by: MD Danish Anwar <[email protected]> Signed-off-by: Meghana Malladi <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 46eeb90 commit 73f7f13

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed

drivers/net/ethernet/ti/icssg/icssg_common.c

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ int emac_tx_complete_packets(struct prueth_emac *emac, int chn,
136136
struct net_device *ndev = emac->ndev;
137137
struct cppi5_host_desc_t *desc_tx;
138138
struct netdev_queue *netif_txq;
139+
struct prueth_swdata *swdata;
139140
struct prueth_tx_chn *tx_chn;
140141
unsigned int total_bytes = 0;
141142
struct sk_buff *skb;
142143
dma_addr_t desc_dma;
143144
int res, num_tx = 0;
144-
void **swdata;
145145

146146
tx_chn = &emac->tx_chns[chn];
147147

@@ -161,16 +161,11 @@ int emac_tx_complete_packets(struct prueth_emac *emac, int chn,
161161
desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool,
162162
desc_dma);
163163
swdata = cppi5_hdesc_get_swdata(desc_tx);
164-
165-
/* was this command's TX complete? */
166-
if (emac->is_sr1 && *(swdata) == emac->cmd_data) {
167-
prueth_xmit_free(tx_chn, desc_tx);
168-
continue;
169-
}
170-
171-
skb = *(swdata);
172164
prueth_xmit_free(tx_chn, desc_tx);
165+
if (swdata->type != PRUETH_SWDATA_SKB)
166+
continue;
173167

168+
skb = swdata->data.skb;
174169
ndev = skb->dev;
175170
ndev->stats.tx_packets++;
176171
ndev->stats.tx_bytes += skb->len;
@@ -472,9 +467,9 @@ int prueth_dma_rx_push_mapped(struct prueth_emac *emac,
472467
{
473468
struct net_device *ndev = emac->ndev;
474469
struct cppi5_host_desc_t *desc_rx;
470+
struct prueth_swdata *swdata;
475471
dma_addr_t desc_dma;
476472
dma_addr_t buf_dma;
477-
void **swdata;
478473

479474
buf_dma = page_pool_get_dma_addr(page) + PRUETH_HEADROOM;
480475
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,
490485
cppi5_hdesc_attach_buf(desc_rx, buf_dma, buf_len, buf_dma, buf_len);
491486

492487
swdata = cppi5_hdesc_get_swdata(desc_rx);
493-
*swdata = page;
488+
swdata->type = PRUETH_SWDATA_PAGE;
489+
swdata->data.page = page;
494490

495491
return k3_udma_glue_push_rx_chn(rx_chn->rx_chn, PRUETH_RX_FLOW_DATA,
496492
desc_rx, desc_dma);
@@ -539,11 +535,11 @@ static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id)
539535
u32 buf_dma_len, pkt_len, port_id = 0;
540536
struct net_device *ndev = emac->ndev;
541537
struct cppi5_host_desc_t *desc_rx;
538+
struct prueth_swdata *swdata;
542539
dma_addr_t desc_dma, buf_dma;
543540
struct page *page, *new_page;
544541
struct page_pool *pool;
545542
struct sk_buff *skb;
546-
void **swdata;
547543
u32 *psdata;
548544
void *pa;
549545
int ret;
@@ -561,7 +557,13 @@ static int emac_rx_packet(struct prueth_emac *emac, u32 flow_id)
561557

562558
desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma);
563559
swdata = cppi5_hdesc_get_swdata(desc_rx);
564-
page = *swdata;
560+
if (swdata->type != PRUETH_SWDATA_PAGE) {
561+
netdev_err(ndev, "rx_pkt: invalid swdata->type %d\n", swdata->type);
562+
k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
563+
return 0;
564+
}
565+
566+
page = swdata->data.page;
565567
page_pool_dma_sync_for_cpu(pool, page, 0, PAGE_SIZE);
566568
cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len);
567569
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)
626628
{
627629
struct prueth_rx_chn *rx_chn = data;
628630
struct cppi5_host_desc_t *desc_rx;
631+
struct prueth_swdata *swdata;
629632
struct page_pool *pool;
630633
struct page *page;
631-
void **swdata;
632634

633635
pool = rx_chn->pg_pool;
634636
desc_rx = k3_cppi_desc_pool_dma2virt(rx_chn->desc_pool, desc_dma);
635637
swdata = cppi5_hdesc_get_swdata(desc_rx);
636-
page = *swdata;
637-
page_pool_recycle_direct(pool, page);
638+
if (swdata->type == PRUETH_SWDATA_PAGE) {
639+
page = swdata->data.page;
640+
page_pool_recycle_direct(pool, page);
641+
}
642+
638643
k3_cppi_desc_pool_free(rx_chn->desc_pool, desc_rx);
639644
}
640645

@@ -671,13 +676,13 @@ enum netdev_tx icssg_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev
671676
struct prueth_emac *emac = netdev_priv(ndev);
672677
struct prueth *prueth = emac->prueth;
673678
struct netdev_queue *netif_txq;
679+
struct prueth_swdata *swdata;
674680
struct prueth_tx_chn *tx_chn;
675681
dma_addr_t desc_dma, buf_dma;
676682
u32 pkt_len, dst_tag_id;
677683
int i, ret = 0, q_idx;
678684
bool in_tx_ts = 0;
679685
int tx_ts_cookie;
680-
void **swdata;
681686
u32 *epib;
682687

683688
pkt_len = skb_headlen(skb);
@@ -739,7 +744,8 @@ enum netdev_tx icssg_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev
739744
k3_udma_glue_tx_dma_to_cppi5_addr(tx_chn->tx_chn, &buf_dma);
740745
cppi5_hdesc_attach_buf(first_desc, buf_dma, pkt_len, buf_dma, pkt_len);
741746
swdata = cppi5_hdesc_get_swdata(first_desc);
742-
*swdata = skb;
747+
swdata->type = PRUETH_SWDATA_SKB;
748+
swdata->data.skb = skb;
743749

744750
/* Handle the case where skb is fragmented in pages */
745751
cur_desc = first_desc;
@@ -842,15 +848,17 @@ static void prueth_tx_cleanup(void *data, dma_addr_t desc_dma)
842848
{
843849
struct prueth_tx_chn *tx_chn = data;
844850
struct cppi5_host_desc_t *desc_tx;
851+
struct prueth_swdata *swdata;
845852
struct sk_buff *skb;
846-
void **swdata;
847853

848854
desc_tx = k3_cppi_desc_pool_dma2virt(tx_chn->desc_pool, desc_dma);
849855
swdata = cppi5_hdesc_get_swdata(desc_tx);
850-
skb = *(swdata);
851-
prueth_xmit_free(tx_chn, desc_tx);
856+
if (swdata->type == PRUETH_SWDATA_SKB) {
857+
skb = swdata->data.skb;
858+
dev_kfree_skb_any(skb);
859+
}
852860

853-
dev_kfree_skb_any(skb);
861+
prueth_xmit_free(tx_chn, desc_tx);
854862
}
855863

856864
irqreturn_t prueth_rx_irq(int irq, void *dev_id)

drivers/net/ethernet/ti/icssg/icssg_prueth.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,9 @@ static int prueth_probe(struct platform_device *pdev)
15221522

15231523
np = dev->of_node;
15241524

1525+
BUILD_BUG_ON_MSG((sizeof(struct prueth_swdata) > PRUETH_NAV_SW_DATA_SIZE),
1526+
"insufficient SW_DATA size");
1527+
15251528
prueth = devm_kzalloc(dev, sizeof(*prueth), GFP_KERNEL);
15261529
if (!prueth)
15271530
return -ENOMEM;

drivers/net/ethernet/ti/icssg/icssg_prueth.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ struct prueth_rx_chn {
136136
struct page_pool *pg_pool;
137137
};
138138

139+
enum prueth_swdata_type {
140+
PRUETH_SWDATA_INVALID = 0,
141+
PRUETH_SWDATA_SKB,
142+
PRUETH_SWDATA_PAGE,
143+
PRUETH_SWDATA_CMD,
144+
};
145+
146+
struct prueth_swdata {
147+
enum prueth_swdata_type type;
148+
union prueth_data {
149+
struct sk_buff *skb;
150+
struct page *page;
151+
u32 cmd;
152+
} data;
153+
};
154+
139155
/* There are 4 Tx DMA channels, but the highest priority is CH3 (thread 3)
140156
* and lower three are lower priority channels or threads.
141157
*/

drivers/net/ethernet/ti/icssg/icssg_prueth_sr1.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int emac_send_command_sr1(struct prueth_emac *emac, u32 cmd)
8484
__le32 *data = emac->cmd_data;
8585
dma_addr_t desc_dma, buf_dma;
8686
struct prueth_tx_chn *tx_chn;
87-
void **swdata;
87+
struct prueth_swdata *swdata;
8888
int ret = 0;
8989
u32 *epib;
9090

@@ -122,7 +122,8 @@ static int emac_send_command_sr1(struct prueth_emac *emac, u32 cmd)
122122

123123
cppi5_hdesc_attach_buf(first_desc, buf_dma, pkt_len, buf_dma, pkt_len);
124124
swdata = cppi5_hdesc_get_swdata(first_desc);
125-
*swdata = data;
125+
swdata->type = PRUETH_SWDATA_CMD;
126+
swdata->data.cmd = le32_to_cpu(data[0]);
126127

127128
cppi5_hdesc_set_pktlen(first_desc, pkt_len);
128129
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,
275276
struct net_device *ndev = emac->ndev;
276277
struct cppi5_host_desc_t *desc_rx;
277278
struct page *page, *new_page;
279+
struct prueth_swdata *swdata;
278280
dma_addr_t desc_dma, buf_dma;
279281
u32 buf_dma_len;
280-
void **swdata;
281282
int ret;
282283

283284
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,
299300
}
300301

301302
swdata = cppi5_hdesc_get_swdata(desc_rx);
302-
page = *swdata;
303+
page = swdata->data.page;
303304
cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len);
304305

305306
dma_unmap_single(rx_chn->dma_dev, buf_dma, buf_dma_len, DMA_FROM_DEVICE);

0 commit comments

Comments
 (0)