Skip to content

Commit 6607c17

Browse files
Shradha Guptadavem330
Shradha Gupta
authored andcommitted
net: mana: Enable debugfs files for MANA device
Implement debugfs in MANA driver to be able to view RX,TX,EQ queue specific attributes and dump their gdma queues. These dumps can be used by other userspace utilities to improve debuggability and troubleshooting Following files are added in debugfs: /sys/kernel/debug/mana/ |-------------- 1 |--------------- EQs | |------- eq0 | | |---head | | |---tail | | |---eq_dump | |------- eq1 | . | . | |--------------- adapter-MTU |--------------- vport0 |------- RX-0 | |---cq_budget | |---cq_dump | |---cq_head | |---cq_tail | |---rq_head | |---rq_nbuf | |---rq_tail | |---rxq_dump |------- RX-1 . . |------- TX-0 | |---cq_budget | |---cq_dump | |---cq_head | |---cq_tail | |---sq_head | |---sq_pend_skb_qlen | |---sq_tail | |---txq_dump |------- TX-1 . . Signed-off-by: Shradha Gupta <shradhagupta@linux.microsoft.com> Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1ffcc8d commit 6607c17

File tree

4 files changed

+159
-3
lines changed

4 files changed

+159
-3
lines changed

drivers/net/ethernet/microsoft/mana/gdma_main.c

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
22
/* Copyright (c) 2021, Microsoft Corporation. */
33

4+
#include <linux/debugfs.h>
45
#include <linux/module.h>
56
#include <linux/pci.h>
67
#include <linux/utsname.h>
78
#include <linux/version.h>
89

910
#include <net/mana/mana.h>
1011

12+
struct dentry *mana_debugfs_root;
13+
1114
static u32 mana_gd_r32(struct gdma_context *g, u64 offset)
1215
{
1316
return readl(g->bar0_va + offset);
@@ -1516,6 +1519,12 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
15161519
gc->bar0_va = bar0_va;
15171520
gc->dev = &pdev->dev;
15181521

1522+
if (gc->is_pf)
1523+
gc->mana_pci_debugfs = debugfs_create_dir("0", mana_debugfs_root);
1524+
else
1525+
gc->mana_pci_debugfs = debugfs_create_dir(pci_slot_name(pdev->slot),
1526+
mana_debugfs_root);
1527+
15191528
err = mana_gd_setup(pdev);
15201529
if (err)
15211530
goto unmap_bar;
@@ -1529,6 +1538,13 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
15291538
cleanup_gd:
15301539
mana_gd_cleanup(pdev);
15311540
unmap_bar:
1541+
/*
1542+
* at this point we know that the other debugfs child dir/files
1543+
* are either not yet created or are already cleaned up.
1544+
* The pci debugfs folder clean-up now, will only be cleaning up
1545+
* adapter-MTU file and apc->mana_pci_debugfs folder.
1546+
*/
1547+
debugfs_remove_recursive(gc->mana_pci_debugfs);
15321548
pci_iounmap(pdev, bar0_va);
15331549
free_gc:
15341550
pci_set_drvdata(pdev, NULL);
@@ -1549,6 +1565,8 @@ static void mana_gd_remove(struct pci_dev *pdev)
15491565

15501566
mana_gd_cleanup(pdev);
15511567

1568+
debugfs_remove_recursive(gc->mana_pci_debugfs);
1569+
15521570
pci_iounmap(pdev, gc->bar0_va);
15531571

15541572
vfree(gc);
@@ -1600,6 +1618,8 @@ static void mana_gd_shutdown(struct pci_dev *pdev)
16001618

16011619
mana_gd_cleanup(pdev);
16021620

1621+
debugfs_remove_recursive(gc->mana_pci_debugfs);
1622+
16031623
pci_disable_device(pdev);
16041624
}
16051625

@@ -1619,7 +1639,28 @@ static struct pci_driver mana_driver = {
16191639
.shutdown = mana_gd_shutdown,
16201640
};
16211641

1622-
module_pci_driver(mana_driver);
1642+
static int __init mana_driver_init(void)
1643+
{
1644+
int err;
1645+
1646+
mana_debugfs_root = debugfs_create_dir("mana", NULL);
1647+
1648+
err = pci_register_driver(&mana_driver);
1649+
if (err)
1650+
debugfs_remove(mana_debugfs_root);
1651+
1652+
return err;
1653+
}
1654+
1655+
static void __exit mana_driver_exit(void)
1656+
{
1657+
debugfs_remove(mana_debugfs_root);
1658+
1659+
pci_unregister_driver(&mana_driver);
1660+
}
1661+
1662+
module_init(mana_driver_init);
1663+
module_exit(mana_driver_exit);
16231664

16241665
MODULE_DEVICE_TABLE(pci, mana_id_table);
16251666

drivers/net/ethernet/microsoft/mana/mana_en.c

+104-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <uapi/linux/bpf.h>
55

6+
#include <linux/debugfs.h>
67
#include <linux/inetdevice.h>
78
#include <linux/etherdevice.h>
89
#include <linux/ethtool.h>
@@ -30,6 +31,21 @@ static void mana_adev_idx_free(int idx)
3031
ida_free(&mana_adev_ida, idx);
3132
}
3233

34+
static ssize_t mana_dbg_q_read(struct file *filp, char __user *buf, size_t count,
35+
loff_t *pos)
36+
{
37+
struct gdma_queue *gdma_q = filp->private_data;
38+
39+
return simple_read_from_buffer(buf, count, pos, gdma_q->queue_mem_ptr,
40+
gdma_q->queue_size);
41+
}
42+
43+
static const struct file_operations mana_dbg_q_fops = {
44+
.owner = THIS_MODULE,
45+
.open = simple_open,
46+
.read = mana_dbg_q_read,
47+
};
48+
3349
/* Microsoft Azure Network Adapter (MANA) functions */
3450

3551
static int mana_open(struct net_device *ndev)
@@ -721,6 +737,13 @@ static const struct net_device_ops mana_devops = {
721737

722738
static void mana_cleanup_port_context(struct mana_port_context *apc)
723739
{
740+
/*
741+
* at this point all dir/files under the vport directory
742+
* are already cleaned up.
743+
* We are sure the apc->mana_port_debugfs remove will not
744+
* cause any freed memory access issues
745+
*/
746+
debugfs_remove(apc->mana_port_debugfs);
724747
kfree(apc->rxqs);
725748
apc->rxqs = NULL;
726749
}
@@ -943,6 +966,8 @@ static int mana_query_device_cfg(struct mana_context *ac, u32 proto_major_ver,
943966
else
944967
gc->adapter_mtu = ETH_FRAME_LEN;
945968

969+
debugfs_create_u16("adapter-MTU", 0400, gc->mana_pci_debugfs, &gc->adapter_mtu);
970+
946971
return 0;
947972
}
948973

@@ -1228,6 +1253,8 @@ static void mana_destroy_eq(struct mana_context *ac)
12281253
if (!ac->eqs)
12291254
return;
12301255

1256+
debugfs_remove_recursive(ac->mana_eqs_debugfs);
1257+
12311258
for (i = 0; i < gc->max_num_queues; i++) {
12321259
eq = ac->eqs[i].eq;
12331260
if (!eq)
@@ -1240,6 +1267,18 @@ static void mana_destroy_eq(struct mana_context *ac)
12401267
ac->eqs = NULL;
12411268
}
12421269

1270+
static void mana_create_eq_debugfs(struct mana_context *ac, int i)
1271+
{
1272+
struct mana_eq eq = ac->eqs[i];
1273+
char eqnum[32];
1274+
1275+
sprintf(eqnum, "eq%d", i);
1276+
eq.mana_eq_debugfs = debugfs_create_dir(eqnum, ac->mana_eqs_debugfs);
1277+
debugfs_create_u32("head", 0400, eq.mana_eq_debugfs, &eq.eq->head);
1278+
debugfs_create_u32("tail", 0400, eq.mana_eq_debugfs, &eq.eq->tail);
1279+
debugfs_create_file("eq_dump", 0400, eq.mana_eq_debugfs, eq.eq, &mana_dbg_q_fops);
1280+
}
1281+
12431282
static int mana_create_eq(struct mana_context *ac)
12441283
{
12451284
struct gdma_dev *gd = ac->gdma_dev;
@@ -1260,11 +1299,14 @@ static int mana_create_eq(struct mana_context *ac)
12601299
spec.eq.context = ac->eqs;
12611300
spec.eq.log2_throttle_limit = LOG2_EQ_THROTTLE;
12621301

1302+
ac->mana_eqs_debugfs = debugfs_create_dir("EQs", gc->mana_pci_debugfs);
1303+
12631304
for (i = 0; i < gc->max_num_queues; i++) {
12641305
spec.eq.msix_index = (i + 1) % gc->num_msix_usable;
12651306
err = mana_gd_create_mana_eq(gd, &spec, &ac->eqs[i].eq);
12661307
if (err)
12671308
goto out;
1309+
mana_create_eq_debugfs(ac, i);
12681310
}
12691311

12701312
return 0;
@@ -1871,6 +1913,8 @@ static void mana_destroy_txq(struct mana_port_context *apc)
18711913
return;
18721914

18731915
for (i = 0; i < apc->num_queues; i++) {
1916+
debugfs_remove_recursive(apc->tx_qp[i].mana_tx_debugfs);
1917+
18741918
napi = &apc->tx_qp[i].tx_cq.napi;
18751919
if (apc->tx_qp[i].txq.napi_initialized) {
18761920
napi_synchronize(napi);
@@ -1889,6 +1933,31 @@ static void mana_destroy_txq(struct mana_port_context *apc)
18891933
apc->tx_qp = NULL;
18901934
}
18911935

1936+
static void mana_create_txq_debugfs(struct mana_port_context *apc, int idx)
1937+
{
1938+
struct mana_tx_qp *tx_qp = &apc->tx_qp[idx];
1939+
char qnum[32];
1940+
1941+
sprintf(qnum, "TX-%d", idx);
1942+
tx_qp->mana_tx_debugfs = debugfs_create_dir(qnum, apc->mana_port_debugfs);
1943+
debugfs_create_u32("sq_head", 0400, tx_qp->mana_tx_debugfs,
1944+
&tx_qp->txq.gdma_sq->head);
1945+
debugfs_create_u32("sq_tail", 0400, tx_qp->mana_tx_debugfs,
1946+
&tx_qp->txq.gdma_sq->tail);
1947+
debugfs_create_u32("sq_pend_skb_qlen", 0400, tx_qp->mana_tx_debugfs,
1948+
&tx_qp->txq.pending_skbs.qlen);
1949+
debugfs_create_u32("cq_head", 0400, tx_qp->mana_tx_debugfs,
1950+
&tx_qp->tx_cq.gdma_cq->head);
1951+
debugfs_create_u32("cq_tail", 0400, tx_qp->mana_tx_debugfs,
1952+
&tx_qp->tx_cq.gdma_cq->tail);
1953+
debugfs_create_u32("cq_budget", 0400, tx_qp->mana_tx_debugfs,
1954+
&tx_qp->tx_cq.budget);
1955+
debugfs_create_file("txq_dump", 0400, tx_qp->mana_tx_debugfs,
1956+
tx_qp->txq.gdma_sq, &mana_dbg_q_fops);
1957+
debugfs_create_file("cq_dump", 0400, tx_qp->mana_tx_debugfs,
1958+
tx_qp->tx_cq.gdma_cq, &mana_dbg_q_fops);
1959+
}
1960+
18921961
static int mana_create_txq(struct mana_port_context *apc,
18931962
struct net_device *net)
18941963
{
@@ -2000,6 +2069,8 @@ static int mana_create_txq(struct mana_port_context *apc,
20002069

20012070
gc->cq_table[cq->gdma_id] = cq->gdma_cq;
20022071

2072+
mana_create_txq_debugfs(apc, i);
2073+
20032074
netif_napi_add_tx(net, &cq->napi, mana_poll);
20042075
napi_enable(&cq->napi);
20052076
txq->napi_initialized = true;
@@ -2027,6 +2098,8 @@ static void mana_destroy_rxq(struct mana_port_context *apc,
20272098
if (!rxq)
20282099
return;
20292100

2101+
debugfs_remove_recursive(rxq->mana_rx_debugfs);
2102+
20302103
napi = &rxq->rx_cq.napi;
20312104

20322105
if (napi_initialized) {
@@ -2308,6 +2381,28 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
23082381
return NULL;
23092382
}
23102383

2384+
static void mana_create_rxq_debugfs(struct mana_port_context *apc, int idx)
2385+
{
2386+
struct mana_rxq *rxq;
2387+
char qnum[32];
2388+
2389+
rxq = apc->rxqs[idx];
2390+
2391+
sprintf(qnum, "RX-%d", idx);
2392+
rxq->mana_rx_debugfs = debugfs_create_dir(qnum, apc->mana_port_debugfs);
2393+
debugfs_create_u32("rq_head", 0400, rxq->mana_rx_debugfs, &rxq->gdma_rq->head);
2394+
debugfs_create_u32("rq_tail", 0400, rxq->mana_rx_debugfs, &rxq->gdma_rq->tail);
2395+
debugfs_create_u32("rq_nbuf", 0400, rxq->mana_rx_debugfs, &rxq->num_rx_buf);
2396+
debugfs_create_u32("cq_head", 0400, rxq->mana_rx_debugfs,
2397+
&rxq->rx_cq.gdma_cq->head);
2398+
debugfs_create_u32("cq_tail", 0400, rxq->mana_rx_debugfs,
2399+
&rxq->rx_cq.gdma_cq->tail);
2400+
debugfs_create_u32("cq_budget", 0400, rxq->mana_rx_debugfs, &rxq->rx_cq.budget);
2401+
debugfs_create_file("rxq_dump", 0400, rxq->mana_rx_debugfs, rxq->gdma_rq, &mana_dbg_q_fops);
2402+
debugfs_create_file("cq_dump", 0400, rxq->mana_rx_debugfs, rxq->rx_cq.gdma_cq,
2403+
&mana_dbg_q_fops);
2404+
}
2405+
23112406
static int mana_add_rx_queues(struct mana_port_context *apc,
23122407
struct net_device *ndev)
23132408
{
@@ -2326,6 +2421,8 @@ static int mana_add_rx_queues(struct mana_port_context *apc,
23262421
u64_stats_init(&rxq->stats.syncp);
23272422

23282423
apc->rxqs[i] = rxq;
2424+
2425+
mana_create_rxq_debugfs(apc, i);
23292426
}
23302427

23312428
apc->default_rxobj = apc->rxqs[0]->rxobj;
@@ -2518,14 +2615,19 @@ void mana_query_gf_stats(struct mana_port_context *apc)
25182615
static int mana_init_port(struct net_device *ndev)
25192616
{
25202617
struct mana_port_context *apc = netdev_priv(ndev);
2618+
struct gdma_dev *gd = apc->ac->gdma_dev;
25212619
u32 max_txq, max_rxq, max_queues;
25222620
int port_idx = apc->port_idx;
2621+
struct gdma_context *gc;
2622+
char vport[32];
25232623
int err;
25242624

25252625
err = mana_init_port_context(apc);
25262626
if (err)
25272627
return err;
25282628

2629+
gc = gd->gdma_context;
2630+
25292631
err = mana_query_vport_cfg(apc, port_idx, &max_txq, &max_rxq,
25302632
&apc->indir_table_sz);
25312633
if (err) {
@@ -2542,7 +2644,8 @@ static int mana_init_port(struct net_device *ndev)
25422644
apc->num_queues = apc->max_queues;
25432645

25442646
eth_hw_addr_set(ndev, apc->mac_addr);
2545-
2647+
sprintf(vport, "vport%d", port_idx);
2648+
apc->mana_port_debugfs = debugfs_create_dir(vport, gc->mana_pci_debugfs);
25462649
return 0;
25472650

25482651
reset_apc:

include/net/mana/gdma.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ struct gdma_event {
267267
struct gdma_queue;
268268

269269
struct mana_eq {
270-
struct gdma_queue *eq;
270+
struct gdma_queue *eq;
271+
struct dentry *mana_eq_debugfs;
271272
};
272273

273274
typedef void gdma_eq_callback(void *context, struct gdma_queue *q,
@@ -365,6 +366,7 @@ struct gdma_irq_context {
365366

366367
struct gdma_context {
367368
struct device *dev;
369+
struct dentry *mana_pci_debugfs;
368370

369371
/* Per-vPort max number of queues */
370372
unsigned int max_num_queues;
@@ -878,5 +880,7 @@ int mana_gd_send_request(struct gdma_context *gc, u32 req_len, const void *req,
878880
u32 resp_len, void *resp);
879881

880882
int mana_gd_destroy_dma_region(struct gdma_context *gc, u64 dma_region_handle);
883+
void mana_register_debugfs(void);
884+
void mana_unregister_debugfs(void);
881885

882886
#endif /* _GDMA_H */

include/net/mana/mana.h

+8
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ struct mana_rxq {
350350
int xdp_rc; /* XDP redirect return code */
351351

352352
struct page_pool *page_pool;
353+
struct dentry *mana_rx_debugfs;
353354

354355
/* MUST BE THE LAST MEMBER:
355356
* Each receive buffer has an associated mana_recv_buf_oob.
@@ -363,6 +364,8 @@ struct mana_tx_qp {
363364
struct mana_cq tx_cq;
364365

365366
mana_handle_t tx_object;
367+
368+
struct dentry *mana_tx_debugfs;
366369
};
367370

368371
struct mana_ethtool_stats {
@@ -407,6 +410,7 @@ struct mana_context {
407410
u16 num_ports;
408411

409412
struct mana_eq *eqs;
413+
struct dentry *mana_eqs_debugfs;
410414

411415
struct net_device *ports[MAX_PORTS_IN_MANA_DEV];
412416
};
@@ -468,6 +472,9 @@ struct mana_port_context {
468472
bool port_st_save; /* Saved port state */
469473

470474
struct mana_ethtool_stats eth_stats;
475+
476+
/* Debugfs */
477+
struct dentry *mana_port_debugfs;
471478
};
472479

473480
netdev_tx_t mana_start_xmit(struct sk_buff *skb, struct net_device *ndev);
@@ -494,6 +501,7 @@ int mana_pre_alloc_rxbufs(struct mana_port_context *apc, int mtu, int num_queues
494501
void mana_pre_dealloc_rxbufs(struct mana_port_context *apc);
495502

496503
extern const struct ethtool_ops mana_ethtool_ops;
504+
extern struct dentry *mana_debugfs_root;
497505

498506
/* A CQ can be created not associated with any EQ */
499507
#define GDMA_CQ_NO_EQ 0xffff

0 commit comments

Comments
 (0)