Add printk statements in mt76 driver

I want to add a few printk statements in mac80211.c file in mt76 driver for some research project.
I have the following files in my build directory. But when I add them and make bin files we cant see them.

./build_dir/toolchain-mipsel_24kc_gcc-11.2.0_musl/linux-5.10.138/drivers/net/wireless/mediatek/mt76/mac80211.c

./build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/linux-5.10.138/drivers/net/wireless/mediatek/mt76/mac80211.c

Those are transient directories that get wiped on every rebuild. You should be adding them under package/kernel/mt76/patches/ in your buildroot.

May I ask you what you are trying to change? I added a dev_info() call because I faced the same issue. I did add them, though as a patch to the current driver; see below:

--- a/mt7615/dma.c
+++ b/mt7615/dma.c
@@ -218,6 +218,7 @@ void mt7615_dma_start(struct mt7615_dev

 int mt7615_dma_init(struct mt7615_dev *dev)
 {
+	struct mt76_dev *mdev = &dev->mt76;
 	int rx_ring_size = MT7615_RX_RING_SIZE;
 	u32 mask;
 	int ret;
@@ -281,6 +282,7 @@ int mt7615_dma_init(struct mt7615_dev *d
 	if (ret < 0)
 		return ret;

+	dev_info(mdev->dev, "NAPI poll weight value set to %d\n", NAPI_POLL_WEIGHT);
 	netif_tx_napi_add(&dev->mt76.tx_napi_dev, &dev->mt76.tx_napi,
 			  mt7615_poll_tx, NAPI_POLL_WEIGHT);
 	napi_enable(&dev->mt76.tx_napi);

Not sure if this is a good example, though.

@Borromini, when I tried a similar approach to @kamran-nishat with a quilt patch, it didn't work.

@kamran-nishat Unles you are using an SDK, you are looking at the wrong files. OpenWrt relies on kernel backports to have the most recent wireless stack available, even on older kernels. Currently those are 5.15.58 backports:

$ find build_dir/target-mipsel* -name mt76
build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-5.10.145/drivers/net/wireless/mediatek/mt76
build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/backports-5.15.58-1/drivers/net/wireless/mediatek/mt76
build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/linux-5.10.145/drivers/net/wireless/mediatek/mt76
build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/backports-5.15.58-1/drivers/net/wireless/mediatek/mt76
build_dir/target-mipsel_24kc_musl/linux-ramips_mt76x8/linux-5.10.145/drivers/net/wireless/mediatek/mt76
build_dir/target-mipsel_24kc_musl/linux-ramips_mt76x8/backports-5.15.58-1/drivers/net/wireless/mediatek/mt76

@amteza My MO is this:

  • Copy file you want to edit in place.
$ cd build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/backports-5.15.58-1/drivers/net/wireless/mediatek/mt76/
$ cp mt7615/dma.c{,.new}
  • Modify code and diff against old file. Make sure to keep the path relative to the root of your package, ie your paths in this case would be a/mt7615/dma.c and b/mt7615/dma.c.
$ diff -Naur mt7615/dma.c{,.new}
--- mt7615/dma.c	2022-07-31 15:16:25.554442200 +0200
+++ mt7615/dma.c.new	2022-09-27 22:22:08.164177969 +0200
@@ -11,6 +11,9 @@
 #include "../dma.h"
 #include "mac.h"
 
+
+// Silly comment
+
 static int
 mt7622_init_tx_queues_multi(struct mt7615_dev *dev)
 {

Now you got a diff, redirect that into a file and adjust the paths with the a/b prefix like you see in the other patches in the OpenWrt tree. Then dump your new patch in the patches/ subdir like I said earlier. If the subdir isn't there, create it and the OpenWrt buildroot will pick its contents up when you recompile mt76.

I did a poor job explaining myself. What I posted is appropriately managed by quilt. It's in the right patches directory and works. My question was more on the line: why, when correctly applying a patch, printk() didn't work?

Ah! Sorry. I misinterpreted. Cannot comment on that unfortunately.

1 Like

Hey @amteza did you get an answer to that?

printk() is working if I boot from tftp into the initramfs but not if I flash OpenWrt using the sysupgrade binary.

I ended ditching printk() for dev_info(), see following:

--- a/mt7615/dma.c
+++ b/mt7615/dma.c
@@ -218,6 +218,7 @@ void mt7615_dma_start(struct mt7615_dev

 int mt7615_dma_init(struct mt7615_dev *dev)
 {
+	struct mt76_dev *mdev = &dev->mt76;
 	int rx_ring_size = MT7615_RX_RING_SIZE;
 	u32 mask;
 	int ret;
@@ -281,6 +282,7 @@ int mt7615_dma_init(struct mt7615_dev *d
 	if (ret < 0)
 		return ret;

+	dev_info(mdev->dev, "NAPI poll weight value set to %d\n", NAPI_POLL_WEIGHT);
 	netif_tx_napi_add(&dev->mt76.tx_napi_dev, &dev->mt76.tx_napi,
 			  mt7615_poll_tx, NAPI_POLL_WEIGHT);
 	napi_enable(&dev->mt76.tx_napi);

Thank you, I'll check if that works. It's a bit confusing since according to the internet dev_*() are like pr_*() with device informations. And are all based on printk().

But, if it works :slight_smile:

I can assure you I tried with printk() and pr_info() without much success, why it works with dev_info()? It beats me. :smiley:

I don't get it to work :frowning:

No idea, the patches are still working on my latest build. See the following:

@reaper$ ➜  ~ ssh root@nanohd-upstairs.lan


BusyBox v1.35.0 (2022-11-10 13:47:07 UTC) built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt SNAPSHOT, r21271-6f729163b1
 -----------------------------------------------------
root@nanohd-upstairs:~# logread | grep NAPI
Sun Nov 13 07:06:01 2022 kern.info kernel: [   48.153102] mt7615e 0000:02:00.0: NAPI poll weight value set to 8
root@nanohd-upstairs:~#

Thank you @amteza for the confirmation, I have no doubt :)... I just got a bit frustrated and needed to vent, Sorry.

Maybe it is an issue with the layer it is in. In the drivers/net/dsa/mt7530.c there are several dev_dbg() already in there and none of them show up in dmesg.

dev_dbg() will only get printed if you increase the log level as debug prints are not printed on the default console level

1 Like

But did you try dev_info()? I reckon yes will be the answer. See @robimarko's comment about dev_dbg().

@robimarko @amteza I did start with dev_info() and then tried dev_dbg() since there were already existing entries in .../dsa/mt7530.c. And for dev_dbg() I set the level to 15 (echo 15 > /proc/sys/kernel/printk` I think it was).

It does work if I boot into initramfs but not if flashed. Does that generally work with files in the net/dsa/ for you @robimarko. Not sure if there's something wrong with the image creation, I'll have to dig deeper.

But thanks for your help!

But you are setting the new level after the switch driver has already probed

You're right of course, I didn't think very far. But I did assume my first go with dev_info() should have worked.