Message ID | 20230104194132.24637-9-gerhard@engleder-embedded.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | tsnep: XDP support | expand |
From: Gerhard Engleder <gerhard@engleder-embedded.com> Date: Wed Jan 04 2023 20:41:31 GMT+0100 > Register xdp_rxq_info with page_pool memory model. This is needed for > XDP buffer handling. > > Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com> > Reviewed-by: Saeed Mahameed <saeed@kernel.org> > --- > drivers/net/ethernet/engleder/tsnep.h | 6 ++-- > drivers/net/ethernet/engleder/tsnep_main.c | 34 +++++++++++++++++----- > 2 files changed, 31 insertions(+), 9 deletions(-) > > diff --git a/drivers/net/ethernet/engleder/tsnep.h b/drivers/net/ethernet/engleder/tsnep.h > index 0e7fc36a64e1..0210dab90f71 100644 > --- a/drivers/net/ethernet/engleder/tsnep.h > +++ b/drivers/net/ethernet/engleder/tsnep.h > @@ -133,17 +133,19 @@ struct tsnep_rx { > u32 dropped; > u32 multicast; > u32 alloc_failed; > + > + struct xdp_rxq_info xdp_rxq; > }; > > struct tsnep_queue { > struct tsnep_adapter *adapter; > char name[IFNAMSIZ + 9]; > > + struct napi_struct napi; > + > struct tsnep_tx *tx; > struct tsnep_rx *rx; > > - struct napi_struct napi; > - I'd leave a word in the commit message that you're moving ::napi to improve structure cacheline span. Or even do that in a separate commit with some pahole output to make it clear why you do that. > int irq; > u32 irq_mask; > void __iomem *irq_delay_addr; [...] > @@ -1253,6 +1266,7 @@ int tsnep_netdev_open(struct net_device *netdev) > { > struct tsnep_adapter *adapter = netdev_priv(netdev); > int i; > + unsigned int napi_id; Reverse Christmas Tree variable style is already messed up here, maybe you could fix it inplace while at it or at least not make it worse? :D > void __iomem *addr; > int tx_queue_index = 0; > int rx_queue_index = 0; [...] Thanks, Olek
On 05.01.23 18:35, Alexander Lobakin wrote: > From: Gerhard Engleder <gerhard@engleder-embedded.com> > Date: Wed Jan 04 2023 20:41:31 GMT+0100 > >> Register xdp_rxq_info with page_pool memory model. This is needed for >> XDP buffer handling. >> >> Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com> >> Reviewed-by: Saeed Mahameed <saeed@kernel.org> >> --- >> drivers/net/ethernet/engleder/tsnep.h | 6 ++-- >> drivers/net/ethernet/engleder/tsnep_main.c | 34 +++++++++++++++++----- >> 2 files changed, 31 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/net/ethernet/engleder/tsnep.h b/drivers/net/ethernet/engleder/tsnep.h >> index 0e7fc36a64e1..0210dab90f71 100644 >> --- a/drivers/net/ethernet/engleder/tsnep.h >> +++ b/drivers/net/ethernet/engleder/tsnep.h >> @@ -133,17 +133,19 @@ struct tsnep_rx { >> u32 dropped; >> u32 multicast; >> u32 alloc_failed; >> + >> + struct xdp_rxq_info xdp_rxq; >> }; >> >> struct tsnep_queue { >> struct tsnep_adapter *adapter; >> char name[IFNAMSIZ + 9]; >> >> + struct napi_struct napi; >> + >> struct tsnep_tx *tx; >> struct tsnep_rx *rx; >> >> - struct napi_struct napi; >> - > > I'd leave a word in the commit message that you're moving ::napi to > improve structure cacheline span. Or even do that in a separate commit > with some pahole output to make it clear why you do that. I only reordered based on access order during initialization. But I understand that this not a valid reason. I will remove that reordering. >> int irq; >> u32 irq_mask; >> void __iomem *irq_delay_addr; > > [...] > >> @@ -1253,6 +1266,7 @@ int tsnep_netdev_open(struct net_device *netdev) >> { >> struct tsnep_adapter *adapter = netdev_priv(netdev); >> int i; >> + unsigned int napi_id; > > Reverse Christmas Tree variable style is already messed up here, maybe > you could fix it inplace while at it or at least not make it worse? :D I forgot to do that here. Will be fixed. Gerhard
diff --git a/drivers/net/ethernet/engleder/tsnep.h b/drivers/net/ethernet/engleder/tsnep.h index 0e7fc36a64e1..0210dab90f71 100644 --- a/drivers/net/ethernet/engleder/tsnep.h +++ b/drivers/net/ethernet/engleder/tsnep.h @@ -133,17 +133,19 @@ struct tsnep_rx { u32 dropped; u32 multicast; u32 alloc_failed; + + struct xdp_rxq_info xdp_rxq; }; struct tsnep_queue { struct tsnep_adapter *adapter; char name[IFNAMSIZ + 9]; + struct napi_struct napi; + struct tsnep_tx *tx; struct tsnep_rx *rx; - struct napi_struct napi; - int irq; u32 irq_mask; void __iomem *irq_delay_addr; diff --git a/drivers/net/ethernet/engleder/tsnep_main.c b/drivers/net/ethernet/engleder/tsnep_main.c index b24a00782f27..6a30f3bf73a6 100644 --- a/drivers/net/ethernet/engleder/tsnep_main.c +++ b/drivers/net/ethernet/engleder/tsnep_main.c @@ -802,6 +802,9 @@ static void tsnep_rx_ring_cleanup(struct tsnep_rx *rx) entry->page = NULL; } + if (xdp_rxq_info_is_reg(&rx->xdp_rxq)) + xdp_rxq_info_unreg(&rx->xdp_rxq); + if (rx->page_pool) page_pool_destroy(rx->page_pool); @@ -817,7 +820,7 @@ static void tsnep_rx_ring_cleanup(struct tsnep_rx *rx) } } -static int tsnep_rx_ring_init(struct tsnep_rx *rx) +static int tsnep_rx_ring_init(struct tsnep_rx *rx, unsigned int napi_id) { struct device *dmadev = rx->adapter->dmadev; struct tsnep_rx_entry *entry; @@ -860,6 +863,15 @@ static int tsnep_rx_ring_init(struct tsnep_rx *rx) goto failed; } + retval = xdp_rxq_info_reg(&rx->xdp_rxq, rx->adapter->netdev, + rx->queue_index, napi_id); + if (retval) + goto failed; + retval = xdp_rxq_info_reg_mem_model(&rx->xdp_rxq, MEM_TYPE_PAGE_POOL, + rx->page_pool); + if (retval) + goto failed; + for (i = 0; i < TSNEP_RING_SIZE; i++) { entry = &rx->entry[i]; next_entry = &rx->entry[(i + 1) % TSNEP_RING_SIZE]; @@ -1115,7 +1127,8 @@ static bool tsnep_rx_pending(struct tsnep_rx *rx) } static int tsnep_rx_open(struct tsnep_adapter *adapter, void __iomem *addr, - int queue_index, struct tsnep_rx *rx) + unsigned int napi_id, int queue_index, + struct tsnep_rx *rx) { dma_addr_t dma; int retval; @@ -1125,7 +1138,7 @@ static int tsnep_rx_open(struct tsnep_adapter *adapter, void __iomem *addr, rx->addr = addr; rx->queue_index = queue_index; - retval = tsnep_rx_ring_init(rx); + retval = tsnep_rx_ring_init(rx, napi_id); if (retval) return retval; @@ -1253,6 +1266,7 @@ int tsnep_netdev_open(struct net_device *netdev) { struct tsnep_adapter *adapter = netdev_priv(netdev); int i; + unsigned int napi_id; void __iomem *addr; int tx_queue_index = 0; int rx_queue_index = 0; @@ -1260,6 +1274,11 @@ int tsnep_netdev_open(struct net_device *netdev) for (i = 0; i < adapter->num_queues; i++) { adapter->queue[i].adapter = adapter; + + netif_napi_add(adapter->netdev, &adapter->queue[i].napi, + tsnep_poll); + napi_id = adapter->queue[i].napi.napi_id; + if (adapter->queue[i].tx) { addr = adapter->addr + TSNEP_QUEUE(tx_queue_index); retval = tsnep_tx_open(adapter, addr, tx_queue_index, @@ -1270,7 +1289,7 @@ int tsnep_netdev_open(struct net_device *netdev) } if (adapter->queue[i].rx) { addr = adapter->addr + TSNEP_QUEUE(rx_queue_index); - retval = tsnep_rx_open(adapter, addr, + retval = tsnep_rx_open(adapter, addr, napi_id, rx_queue_index, adapter->queue[i].rx); if (retval) @@ -1302,8 +1321,6 @@ int tsnep_netdev_open(struct net_device *netdev) goto phy_failed; for (i = 0; i < adapter->num_queues; i++) { - netif_napi_add(adapter->netdev, &adapter->queue[i].napi, - tsnep_poll); napi_enable(&adapter->queue[i].napi); tsnep_enable_irq(adapter, adapter->queue[i].irq_mask); @@ -1326,6 +1343,8 @@ int tsnep_netdev_open(struct net_device *netdev) tsnep_rx_close(adapter->queue[i].rx); if (adapter->queue[i].tx) tsnep_tx_close(adapter->queue[i].tx); + + netif_napi_del(&adapter->queue[i].napi); } return retval; } @@ -1348,7 +1367,6 @@ int tsnep_netdev_close(struct net_device *netdev) tsnep_disable_irq(adapter, adapter->queue[i].irq_mask); napi_disable(&adapter->queue[i].napi); - netif_napi_del(&adapter->queue[i].napi); tsnep_free_irq(&adapter->queue[i], i == 0); @@ -1356,6 +1374,8 @@ int tsnep_netdev_close(struct net_device *netdev) tsnep_rx_close(adapter->queue[i].rx); if (adapter->queue[i].tx) tsnep_tx_close(adapter->queue[i].tx); + + netif_napi_del(&adapter->queue[i].napi); } return 0;