Skip to content

Commit db7159c

Browse files
committed
eth: fbnic: store NAPIs in an array instead of the list
We will need an array for storing NAPIs in the upcoming IRQ handler reuse rework. Replace the current list we have, so that we are able to reuse it later. In a few places replace i as the iterator with t when we iterate over triads, this seems slightly less confusing than having i, j, k variables. Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent c23a146 commit db7159c

File tree

4 files changed

+71
-60
lines changed

4 files changed

+71
-60
lines changed

drivers/net/ethernet/meta/fbnic/fbnic_netdev.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,6 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev *fbd)
615615

616616
fbn->netdev = netdev;
617617
fbn->fbd = fbd;
618-
INIT_LIST_HEAD(&fbn->napis);
619618

620619
fbn->txq_size = FBNIC_TXQ_SIZE_DEFAULT;
621620
fbn->hpq_size = FBNIC_HPQ_SIZE_DEFAULT;

drivers/net/ethernet/meta/fbnic/fbnic_netdev.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
#include "fbnic_rpc.h"
1212
#include "fbnic_txrx.h"
1313

14+
#define FBNIC_MAX_NAPI_VECTORS 128u
15+
1416
struct fbnic_net {
1517
struct fbnic_ring *tx[FBNIC_MAX_TXQS];
1618
struct fbnic_ring *rx[FBNIC_MAX_RXQS];
1719

20+
struct fbnic_napi_vector *napi[FBNIC_MAX_NAPI_VECTORS];
21+
1822
struct net_device *netdev;
1923
struct fbnic_dev *fbd;
2024

@@ -56,8 +60,6 @@ struct fbnic_net {
5660

5761
/* Time stampinn filter config */
5862
struct kernel_hwtstamp_config hwtstamp_config;
59-
60-
struct list_head napis;
6163
};
6264

6365
int __fbnic_open(struct fbnic_net *fbn);

drivers/net/ethernet/meta/fbnic/fbnic_txrx.c

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,16 +1116,17 @@ static void fbnic_free_napi_vector(struct fbnic_net *fbn,
11161116
fbnic_free_irq(fbd, v_idx, nv);
11171117
page_pool_destroy(nv->page_pool);
11181118
netif_napi_del(&nv->napi);
1119-
list_del(&nv->napis);
1119+
fbn->napi[fbnic_napi_idx(nv)] = NULL;
11201120
kfree(nv);
11211121
}
11221122

11231123
void fbnic_free_napi_vectors(struct fbnic_net *fbn)
11241124
{
1125-
struct fbnic_napi_vector *nv, *temp;
1125+
int i;
11261126

1127-
list_for_each_entry_safe(nv, temp, &fbn->napis, napis)
1128-
fbnic_free_napi_vector(fbn, nv);
1127+
for (i = 0; i < fbn->num_napi; i++)
1128+
if (fbn->napi[i])
1129+
fbnic_free_napi_vector(fbn, fbn->napi[i]);
11291130
}
11301131

11311132
static void fbnic_name_napi_vector(struct fbnic_napi_vector *nv)
@@ -1222,7 +1223,7 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn,
12221223
nv->v_idx = v_idx;
12231224

12241225
/* Tie napi to netdev */
1225-
list_add(&nv->napis, &fbn->napis);
1226+
fbn->napi[fbnic_napi_idx(nv)] = nv;
12261227
netif_napi_add(fbn->netdev, &nv->napi, fbnic_poll);
12271228

12281229
/* Record IRQ to NAPI struct */
@@ -1307,7 +1308,7 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn,
13071308
page_pool_destroy(nv->page_pool);
13081309
napi_del:
13091310
netif_napi_del(&nv->napi);
1310-
list_del(&nv->napis);
1311+
fbn->napi[fbnic_napi_idx(nv)] = NULL;
13111312
kfree(nv);
13121313
return err;
13131314
}
@@ -1612,28 +1613,27 @@ static int fbnic_alloc_nv_resources(struct fbnic_net *fbn,
16121613

16131614
void fbnic_free_resources(struct fbnic_net *fbn)
16141615
{
1615-
struct fbnic_napi_vector *nv;
1616+
int i;
16161617

1617-
list_for_each_entry(nv, &fbn->napis, napis)
1618-
fbnic_free_nv_resources(fbn, nv);
1618+
for (i = 0; i < fbn->num_napi; i++)
1619+
fbnic_free_nv_resources(fbn, fbn->napi[i]);
16191620
}
16201621

16211622
int fbnic_alloc_resources(struct fbnic_net *fbn)
16221623
{
1623-
struct fbnic_napi_vector *nv;
1624-
int err = -ENODEV;
1624+
int i, err = -ENODEV;
16251625

1626-
list_for_each_entry(nv, &fbn->napis, napis) {
1627-
err = fbnic_alloc_nv_resources(fbn, nv);
1626+
for (i = 0; i < fbn->num_napi; i++) {
1627+
err = fbnic_alloc_nv_resources(fbn, fbn->napi[i]);
16281628
if (err)
16291629
goto free_resources;
16301630
}
16311631

16321632
return 0;
16331633

16341634
free_resources:
1635-
list_for_each_entry_continue_reverse(nv, &fbn->napis, napis)
1636-
fbnic_free_nv_resources(fbn, nv);
1635+
while (i--)
1636+
fbnic_free_nv_resources(fbn, fbn->napi[i]);
16371637

16381638
return err;
16391639
}
@@ -1670,33 +1670,34 @@ static void fbnic_disable_rcq(struct fbnic_ring *rxr)
16701670

16711671
void fbnic_napi_disable(struct fbnic_net *fbn)
16721672
{
1673-
struct fbnic_napi_vector *nv;
1673+
int i;
16741674

1675-
list_for_each_entry(nv, &fbn->napis, napis) {
1676-
napi_disable(&nv->napi);
1675+
for (i = 0; i < fbn->num_napi; i++) {
1676+
napi_disable(&fbn->napi[i]->napi);
16771677

1678-
fbnic_nv_irq_disable(nv);
1678+
fbnic_nv_irq_disable(fbn->napi[i]);
16791679
}
16801680
}
16811681

16821682
void fbnic_disable(struct fbnic_net *fbn)
16831683
{
16841684
struct fbnic_dev *fbd = fbn->fbd;
1685-
struct fbnic_napi_vector *nv;
1686-
int i, j;
1685+
int i, j, t;
1686+
1687+
for (i = 0; i < fbn->num_napi; i++) {
1688+
struct fbnic_napi_vector *nv = fbn->napi[i];
16871689

1688-
list_for_each_entry(nv, &fbn->napis, napis) {
16891690
/* Disable Tx queue triads */
1690-
for (i = 0; i < nv->txt_count; i++) {
1691-
struct fbnic_q_triad *qt = &nv->qt[i];
1691+
for (t = 0; t < nv->txt_count; t++) {
1692+
struct fbnic_q_triad *qt = &nv->qt[t];
16921693

16931694
fbnic_disable_twq0(&qt->sub0);
16941695
fbnic_disable_tcq(&qt->cmpl);
16951696
}
16961697

16971698
/* Disable Rx queue triads */
1698-
for (j = 0; j < nv->rxt_count; j++, i++) {
1699-
struct fbnic_q_triad *qt = &nv->qt[i];
1699+
for (j = 0; j < nv->rxt_count; j++, t++) {
1700+
struct fbnic_q_triad *qt = &nv->qt[t];
17001701

17011702
fbnic_disable_bdq(&qt->sub0, &qt->sub1);
17021703
fbnic_disable_rcq(&qt->cmpl);
@@ -1792,14 +1793,15 @@ int fbnic_wait_all_queues_idle(struct fbnic_dev *fbd, bool may_fail)
17921793

17931794
void fbnic_flush(struct fbnic_net *fbn)
17941795
{
1795-
struct fbnic_napi_vector *nv;
1796+
int i;
17961797

1797-
list_for_each_entry(nv, &fbn->napis, napis) {
1798-
int i, j;
1798+
for (i = 0; i < fbn->num_napi; i++) {
1799+
struct fbnic_napi_vector *nv = fbn->napi[i];
1800+
int j, t;
17991801

18001802
/* Flush any processed Tx Queue Triads and drop the rest */
1801-
for (i = 0; i < nv->txt_count; i++) {
1802-
struct fbnic_q_triad *qt = &nv->qt[i];
1803+
for (t = 0; t < nv->txt_count; t++) {
1804+
struct fbnic_q_triad *qt = &nv->qt[t];
18031805
struct netdev_queue *tx_queue;
18041806

18051807
/* Clean the work queues of unprocessed work */
@@ -1823,8 +1825,8 @@ void fbnic_flush(struct fbnic_net *fbn)
18231825
}
18241826

18251827
/* Flush any processed Rx Queue Triads and drop the rest */
1826-
for (j = 0; j < nv->rxt_count; j++, i++) {
1827-
struct fbnic_q_triad *qt = &nv->qt[i];
1828+
for (j = 0; j < nv->rxt_count; j++, t++) {
1829+
struct fbnic_q_triad *qt = &nv->qt[t];
18281830

18291831
/* Clean the work queues of unprocessed work */
18301832
fbnic_clean_bdq(nv, 0, &qt->sub0, qt->sub0.tail);
@@ -1845,14 +1847,15 @@ void fbnic_flush(struct fbnic_net *fbn)
18451847

18461848
void fbnic_fill(struct fbnic_net *fbn)
18471849
{
1848-
struct fbnic_napi_vector *nv;
1850+
int i;
18491851

1850-
list_for_each_entry(nv, &fbn->napis, napis) {
1851-
int i, j;
1852+
for (i = 0; i < fbn->num_napi; i++) {
1853+
struct fbnic_napi_vector *nv = fbn->napi[i];
1854+
int j, t;
18521855

18531856
/* Configure NAPI mapping for Tx */
1854-
for (i = 0; i < nv->txt_count; i++) {
1855-
struct fbnic_q_triad *qt = &nv->qt[i];
1857+
for (t = 0; t < nv->txt_count; t++) {
1858+
struct fbnic_q_triad *qt = &nv->qt[t];
18561859

18571860
/* Nothing to do if Tx queue is disabled */
18581861
if (qt->sub0.flags & FBNIC_RING_F_DISABLED)
@@ -1866,8 +1869,8 @@ void fbnic_fill(struct fbnic_net *fbn)
18661869
/* Configure NAPI mapping and populate pages
18671870
* in the BDQ rings to use for Rx
18681871
*/
1869-
for (j = 0; j < nv->rxt_count; j++, i++) {
1870-
struct fbnic_q_triad *qt = &nv->qt[i];
1872+
for (j = 0; j < nv->rxt_count; j++, t++) {
1873+
struct fbnic_q_triad *qt = &nv->qt[t];
18711874

18721875
/* Associate Rx queue with NAPI */
18731876
netif_queue_set_napi(nv->napi.dev, qt->cmpl.q_idx,
@@ -2025,21 +2028,23 @@ static void fbnic_enable_rcq(struct fbnic_napi_vector *nv,
20252028
void fbnic_enable(struct fbnic_net *fbn)
20262029
{
20272030
struct fbnic_dev *fbd = fbn->fbd;
2028-
struct fbnic_napi_vector *nv;
2029-
int i, j;
2031+
int i;
2032+
2033+
for (i = 0; i < fbn->num_napi; i++) {
2034+
struct fbnic_napi_vector *nv = fbn->napi[i];
2035+
int j, t;
20302036

2031-
list_for_each_entry(nv, &fbn->napis, napis) {
20322037
/* Setup Tx Queue Triads */
2033-
for (i = 0; i < nv->txt_count; i++) {
2034-
struct fbnic_q_triad *qt = &nv->qt[i];
2038+
for (t = 0; t < nv->txt_count; t++) {
2039+
struct fbnic_q_triad *qt = &nv->qt[t];
20352040

20362041
fbnic_enable_twq0(&qt->sub0);
20372042
fbnic_enable_tcq(nv, &qt->cmpl);
20382043
}
20392044

20402045
/* Setup Rx Queue Triads */
2041-
for (j = 0; j < nv->rxt_count; j++, i++) {
2042-
struct fbnic_q_triad *qt = &nv->qt[i];
2046+
for (j = 0; j < nv->rxt_count; j++, t++) {
2047+
struct fbnic_q_triad *qt = &nv->qt[t];
20432048

20442049
fbnic_enable_bdq(&qt->sub0, &qt->sub1);
20452050
fbnic_config_drop_mode_rcq(nv, &qt->cmpl);
@@ -2064,10 +2069,11 @@ void fbnic_napi_enable(struct fbnic_net *fbn)
20642069
{
20652070
u32 irqs[FBNIC_MAX_MSIX_VECS / 32] = {};
20662071
struct fbnic_dev *fbd = fbn->fbd;
2067-
struct fbnic_napi_vector *nv;
20682072
int i;
20692073

2070-
list_for_each_entry(nv, &fbn->napis, napis) {
2074+
for (i = 0; i < fbn->num_napi; i++) {
2075+
struct fbnic_napi_vector *nv = fbn->napi[i];
2076+
20712077
napi_enable(&nv->napi);
20722078

20732079
fbnic_nv_irq_enable(nv);
@@ -2096,17 +2102,18 @@ void fbnic_napi_depletion_check(struct net_device *netdev)
20962102
struct fbnic_net *fbn = netdev_priv(netdev);
20972103
u32 irqs[FBNIC_MAX_MSIX_VECS / 32] = {};
20982104
struct fbnic_dev *fbd = fbn->fbd;
2099-
struct fbnic_napi_vector *nv;
2100-
int i, j;
2105+
int i, j, t;
2106+
2107+
for (i = 0; i < fbn->num_napi; i++) {
2108+
struct fbnic_napi_vector *nv = fbn->napi[i];
21012109

2102-
list_for_each_entry(nv, &fbn->napis, napis) {
21032110
/* Find RQs which are completely out of pages */
2104-
for (i = nv->txt_count, j = 0; j < nv->rxt_count; j++, i++) {
2111+
for (t = nv->txt_count, j = 0; j < nv->rxt_count; j++, t++) {
21052112
/* Assume 4 pages is always enough to fit a packet
21062113
* and therefore generate a completion and an IRQ.
21072114
*/
2108-
if (fbnic_desc_used(&nv->qt[i].sub0) < 4 ||
2109-
fbnic_desc_used(&nv->qt[i].sub1) < 4)
2115+
if (fbnic_desc_used(&nv->qt[t].sub0) < 4 ||
2116+
fbnic_desc_used(&nv->qt[t].sub1) < 4)
21102117
irqs[nv->v_idx / 32] |= BIT(nv->v_idx % 32);
21112118
}
21122119
}

drivers/net/ethernet/meta/fbnic/fbnic_txrx.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ struct fbnic_napi_vector {
110110
u8 txt_count;
111111
u8 rxt_count;
112112

113-
struct list_head napis;
114-
115113
struct fbnic_q_triad qt[];
116114
};
117115

@@ -137,4 +135,9 @@ void fbnic_fill(struct fbnic_net *fbn);
137135
void fbnic_napi_depletion_check(struct net_device *netdev);
138136
int fbnic_wait_all_queues_idle(struct fbnic_dev *fbd, bool may_fail);
139137

138+
static inline int fbnic_napi_idx(const struct fbnic_napi_vector *nv)
139+
{
140+
return nv->v_idx - FBNIC_NON_NAPI_VECTORS;
141+
}
142+
140143
#endif /* _FBNIC_TXRX_H_ */

0 commit comments

Comments
 (0)