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
3551static int mana_open (struct net_device * ndev )
@@ -721,6 +737,13 @@ static const struct net_device_ops mana_devops = {
721737
722738static 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+
12431282static 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+
18921961static 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+
23112406static 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)
25182615static 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
25482651reset_apc :
0 commit comments