Skip to contentSkip to conversation

NET: Implement a standard ndev_printk family

RFC PATCH In review Auke Kok 4 participants 10 messages Jun 11, 2007

Subsystems (2)
lore
Share & tools
lore

Auke Kok

author
#0 lore raw

RFC PATCH 1/2 NET: Implement a standard ndev_printk family

A lot of netdevices implement their own variant of printk and use use variations of dev_printk, printk or others that use msg_enable, which has been an eyesore with countless variations across drivers.

This patch implements a standard ndev_printk and derivatives such as ndev_err, ndev_info, ndev_warn that allows drivers to transparently use both the msg_enable and a generic netdevice message layout. It moves the msg_enable over to the net_device struct and allows drivers to obsolete ethtool handling code of the msg_enable value.

The current code has each driver contain a copy of msg_enable and handle the setting/changing through ethtool that way. Since the netdev name is stored in the net_device struct, those two are not coherently available in a uniform way across all drivers (a single macro or function would not work since all drivers name their net_device members differently). This makes netdevice driver writes reinvent the wheel over and over again.

It thus makes sense to move msg_enable to the net_device. This gives us the opportunity to (1) initialize it by default with a globally sane value, (2) remove msg_enable handling code w/r ethtool for drivers that know and use the msg_enable member of the net_device struct. (3) Ethtool code can just modify the net_device msg_enable for drivers that do not have custom msg_enable get/set handlers so converted drivers lose some code for that as well.

---

 include/linux/netdevice.h |   38 ++++++++++++++++++++++++++++++++++++++
 net/core/dev.c            |    5 +++++
 net/core/ethtool.c        |   14 +++++++-------
 3 files changed, 50 insertions(+), 7 deletions(-)
include/linux/netdevice.h +38 -0
index 3a70f55..d185f41 100644
@@ -540,6 +540,8 @@ struct net_device
 	struct device		dev;
 	/* space for optional statistics and wireless sysfs groups */
 	struct attribute_group  *sysfs_groups[3];
+
+	int			msg_enable;
 };
 #define to_net_dev(d) container_of(d, struct net_device, dev)
 
@@ -838,6 +840,42 @@ enum {
 	NETIF_MSG_WOL		= 0x4000,
 };
 
+#define ndev_err(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_ERR "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+
+#define ndev_warn(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_WARNING "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+
+#define ndev_notice(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_NOTICE "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+
+#define ndev_info(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_INFO "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+
+#ifdef DEBUG
+#define ndev_debug(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_DEBUG "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+#else
+/* Force type-checking on ndev_dbg() when DEBUG is not set */
+static inline int __attribute__ ((format (printf, 3, 4)))
+__ndev_dbg(struct net_device * netdev, u32 level, const char *format, ...)
+{
+	return 0;
+}
+#define ndev_dbg(netdev, level, fmt, args...) \
+	__ndev_dbg(netdev, NETIF_MSG_##level, fmt, ##args)
+#endif
+
 #define netif_msg_drv(p)	((p)->msg_enable & NETIF_MSG_DRV)
 #define netif_msg_probe(p)	((p)->msg_enable & NETIF_MSG_PROBE)
 #define netif_msg_link(p)	((p)->msg_enable & NETIF_MSG_LINK)
net/core/dev.c +5 -0
index 2609062..316f250 100644
@@ -3378,6 +3378,11 @@ struct net_device *alloc_netdev(int sizeof_priv, const char *name,
 		dev->priv = netdev_priv(dev);
 
 	dev->get_stats = internal_stats;
+	dev->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK;
+#ifdef DEBUG
+	/* put these to good use: */
+	dev->msg_enable |= NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR;
+#endif
 	setup(dev);
 	strcpy(dev->name, name);
 	return dev;
net/core/ethtool.c +7 -7
index 8d5e5a0..ff8d52f 100644
@@ -234,9 +234,9 @@ static int ethtool_get_msglevel(struct net_device *dev, char __user *useraddr)
 	struct ethtool_value edata = { ETHTOOL_GMSGLVL };
 
 	if (!dev->ethtool_ops->get_msglevel)
-		return -EOPNOTSUPP;
-
-	edata.data = dev->ethtool_ops->get_msglevel(dev);
+		edata.data = dev->msg_enable;
+	else
+		edata.data = dev->ethtool_ops->get_msglevel(dev);
 
 	if (copy_to_user(useraddr, &edata, sizeof(edata)))
 		return -EFAULT;
@@ -247,13 +247,13 @@ static int ethtool_set_msglevel(struct net_device *dev, char __user *useraddr)
 {
 	struct ethtool_value edata;
 
-	if (!dev->ethtool_ops->set_msglevel)
-		return -EOPNOTSUPP;
-
 	if (copy_from_user(&edata, useraddr, sizeof(edata)))
 		return -EFAULT;
 
-	dev->ethtool_ops->set_msglevel(dev, edata.data);
+	if (!dev->ethtool_ops->set_msglevel)
+		dev->msg_enable = edata.data;
+	else
+		dev->ethtool_ops->set_msglevel(dev, edata.data);
 	return 0;
 }
 
author
#1 lore raw

RFC PATCH 2/2 NET: Convert several drivers to ndev_printk

With the generic ndev_printk macros, we can now convert network drivers to use this generic printk family for netdevices.

---

 drivers/net/e100.c                |  135 ++++++++++++++++---------------------
 drivers/net/e1000/e1000.h         |   15 ----
 drivers/net/e1000/e1000_ethtool.c |   39 +++--------
 drivers/net/e1000/e1000_main.c    |  110 +++++++++++++++---------------
 drivers/net/e1000/e1000_param.c   |   67 +++++++++---------
 drivers/net/ixgb/ixgb.h           |   14 ----
 drivers/net/ixgb/ixgb_ethtool.c   |   15 ----
 drivers/net/ixgb/ixgb_main.c      |   50 ++++++--------
 8 files changed, 184 insertions(+), 261 deletions(-)
drivers/net/e100.c +60 -75
index 6169663..8c09c9e 100644
@@ -172,19 +172,12 @@ MODULE_AUTHOR(DRV_COPYRIGHT);
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
 
-static int debug = 3;
 static int eeprom_bad_csum_allow = 0;
 static int use_io = 0;
-module_param(debug, int, 0);
 module_param(eeprom_bad_csum_allow, int, 0);
 module_param(use_io, int, 0);
-MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
 MODULE_PARM_DESC(eeprom_bad_csum_allow, "Allow bad eeprom checksums");
 MODULE_PARM_DESC(use_io, "Force use of i/o access mode");
-#define DPRINTK(nlevel, klevel, fmt, args...) \
-	(void)((NETIF_MSG_##nlevel & nic->msg_enable) && \
-	printk(KERN_##klevel PFX "%s: %s: " fmt, nic->netdev->name, \
-		__FUNCTION__ , ## args))
 
 #define INTEL_8255X_ETHERNET_DEVICE(device_id, ich) {\
 	PCI_VENDOR_ID_INTEL, device_id, PCI_ANY_ID, PCI_ANY_ID, \
@@ -645,12 +638,12 @@ static int e100_self_test(struct nic *nic)
 
 	/* Check results of self-test */
 	if(nic->mem->selftest.result != 0) {
-		DPRINTK(HW, ERR, "Self-test failed: result=0x%08X\n",
+		ndev_err(nic->netdev, HW, "Self-test failed: result=0x%08X\n",
 			nic->mem->selftest.result);
 		return -ETIMEDOUT;
 	}
 	if(nic->mem->selftest.signature == 0) {
-		DPRINTK(HW, ERR, "Self-test failed: timed out\n");
+		ndev_err(nic->netdev, HW, "Self-test failed: timed out\n");
 		return -ETIMEDOUT;
 	}
 
@@ -754,7 +747,7 @@ static int e100_eeprom_load(struct nic *nic)
 	 * the sum of words should be 0xBABA */
 	checksum = le16_to_cpu(0xBABA - checksum);
 	if(checksum != nic->eeprom[nic->eeprom_wc - 1]) {
-		DPRINTK(PROBE, ERR, "EEPROM corrupted\n");
+		ndev_err(nic->netdev, PROBE, "EEPROM corrupted\n");
 		if (!eeprom_bad_csum_allow)
 			return -EAGAIN;
 	}
@@ -896,8 +889,7 @@ static u16 mdio_ctrl(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data)
 		udelay(20);
 	}
 	if (unlikely(!i)) {
-		printk("e100.mdio_ctrl(%s) won't go Ready\n",
-			nic->netdev->name );
+		dev_err(&nic->pdev->dev, "mdio_ctrl won't go Ready\n");
 		spin_unlock_irqrestore(&nic->mdio_lock, flags);
 		return 0;		/* No way to indicate timeout error */
 	}
@@ -909,7 +901,7 @@ static u16 mdio_ctrl(struct nic *nic, u32 addr, u32 dir, u32 reg, u16 data)
 			break;
 	}
 	spin_unlock_irqrestore(&nic->mdio_lock, flags);
-	DPRINTK(HW, DEBUG,
+	ndev_dbg(nic->netdev, HW,
 		"%s:addr=%d, reg=%d, data_in=0x%04X, data_out=0x%04X\n",
 		dir == mdi_read ? "READ" : "WRITE", addr, reg, data, data_out);
 	return (u16)data_out;
@@ -962,8 +954,8 @@ static void e100_get_defaults(struct nic *nic)
 static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
 {
 	struct config *config = &cb->u.config;
-	u8 *c = (u8 *)config;
-
+	u8 *c;
+	
 	cb->command = cpu_to_le16(cb_config);
 
 	memset(config, 0, sizeof(struct config));
@@ -1023,12 +1015,16 @@ static void e100_configure(struct nic *nic, struct cb *cb, struct sk_buff *skb)
 			config->standard_stat_counter = 0x0;
 	}
 
-	DPRINTK(HW, DEBUG, "[00-07]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
-		c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
-	DPRINTK(HW, DEBUG, "[08-15]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
-		c[8], c[9], c[10], c[11], c[12], c[13], c[14], c[15]);
-	DPRINTK(HW, DEBUG, "[16-23]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
-		c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23]);
+	c = (u8 *)config;
+	ndev_dbg(nic->netdev, HW,
+	         "[00-07]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
+	         c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
+	ndev_dbg(nic->netdev, HW,
+	         "[08-15]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
+	         c[8], c[9], c[10], c[11], c[12], c[13], c[14], c[15]);
+	ndev_dbg(nic->netdev, HW,
+	         "[16-23]=%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
+	         c[16], c[17], c[18], c[19], c[20], c[21], c[22], c[23]);
 }
 
 /********************************************************/
@@ -1298,7 +1294,7 @@ static inline int e100_exec_cb_wait(struct nic *nic, struct sk_buff *skb,
 	struct cb *cb = nic->cb_to_clean;
 
 	if ((err = e100_exec_cb(nic, NULL, e100_setup_ucode)))
-		DPRINTK(PROBE,ERR, "ucode cmd failed with error %d\n", err);
+		ndev_err(nic->netdev, PROBE, "ucode cmd failed with error %d\n", err);
 
 	/* must restart cuc */
 	nic->cuc_cmd = cuc_start;
@@ -1318,7 +1314,7 @@ static inline int e100_exec_cb_wait(struct nic *nic, struct sk_buff *skb,
 
 	/* if the command failed, or is not OK, notify and return */
 	if (!counter || !(cb->status & cpu_to_le16(cb_ok))) {
-		DPRINTK(PROBE,ERR, "ucode load failed\n");
+		ndev_err(nic->netdev, PROBE, "ucode load failed\n");
 		err = -EPERM;
 	}
 
@@ -1359,7 +1355,7 @@ static int e100_phy_init(struct nic *nic)
 		if(!((bmcr == 0xFFFF) || ((stat == 0) && (bmcr == 0))))
 			break;
 	}
-	DPRINTK(HW, DEBUG, "phy_addr = %d\n", nic->mii.phy_id);
+	ndev_dbg(nic->netdev, HW, "phy_addr = %d\n", nic->mii.phy_id);
 	if(addr == 32)
 		return -EAGAIN;
 
@@ -1378,7 +1374,7 @@ static int e100_phy_init(struct nic *nic)
 	id_lo = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID1);
 	id_hi = mdio_read(netdev, nic->mii.phy_id, MII_PHYSID2);
 	nic->phy = (u32)id_hi << 16 | (u32)id_lo;
-	DPRINTK(HW, DEBUG, "phy ID = 0x%08X\n", nic->phy);
+	ndev_dbg(nic->netdev, HW, "phy ID = 0x%08X\n", nic->phy);
 
 	/* Handle National tx phys */
 #define NCS_PHY_MODEL_MASK	0xFFF0FFFF
@@ -1407,7 +1403,7 @@ static int e100_hw_init(struct nic *nic)
 
 	e100_hw_reset(nic);
 
-	DPRINTK(HW, ERR, "e100_hw_init\n");
+	ndev_err(nic->netdev, HW, "e100_hw_init\n");
 	if(!in_interrupt() && (err = e100_self_test(nic)))
 		return err;
 
@@ -1451,7 +1447,7 @@ static void e100_set_multicast_list(struct net_device *netdev)
 {
 	struct nic *nic = netdev_priv(netdev);
 
-	DPRINTK(HW, DEBUG, "mc_count=%d, flags=0x%04X\n",
+	ndev_dbg(nic->netdev, HW, "mc_count=%d, flags=0x%04X\n",
 		netdev->mc_count, netdev->flags);
 
 	if(netdev->flags & IFF_PROMISC)
@@ -1524,7 +1520,7 @@ static void e100_update_stats(struct nic *nic)
 
 
 	if(e100_exec_cmd(nic, cuc_dump_reset, 0))
-		DPRINTK(TX_ERR, DEBUG, "exec cuc_dump_reset failed\n");
+		ndev_dbg(nic->netdev, TX_ERR, "exec cuc_dump_reset failed\n");
 }
 
 static void e100_adjust_adaptive_ifs(struct nic *nic, int speed, int duplex)
@@ -1554,18 +1550,18 @@ static void e100_watchdog(unsigned long data)
 	struct nic *nic = (struct nic *)data;
 	struct ethtool_cmd cmd;
 
-	DPRINTK(TIMER, DEBUG, "right now = %ld\n", jiffies);
+	ndev_dbg(nic->netdev, TIMER, "right now = %ld\n", jiffies);
 
 	/* mii library handles link maintenance tasks */
 
 	mii_ethtool_gset(&nic->mii, &cmd);
 
 	if(mii_link_ok(&nic->mii) && !netif_carrier_ok(nic->netdev)) {
-		DPRINTK(LINK, INFO, "link up, %sMbps, %s-duplex\n",
+		ndev_info(nic->netdev, LINK, "link up, %sMbps, %s-duplex\n",
 			cmd.speed == SPEED_100 ? "100" : "10",
 			cmd.duplex == DUPLEX_FULL ? "full" : "half");
 	} else if(!mii_link_ok(&nic->mii) && netif_carrier_ok(nic->netdev)) {
-		DPRINTK(LINK, INFO, "link down\n");
+		ndev_info(nic->netdev, LINK, "link down\n");
 	}
 
 	mii_check_link(&nic->mii);
@@ -1623,7 +1619,7 @@ static int e100_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 		   Issue a NOP command followed by a 1us delay before
 		   issuing the Tx command. */
 		if(e100_exec_cmd(nic, cuc_nop, 0))
-			DPRINTK(TX_ERR, DEBUG, "exec cuc_nop failed\n");
+			ndev_dbg(nic->netdev, TX_ERR, "exec cuc_nop failed\n");
 		udelay(1);
 	}
 
@@ -1632,12 +1628,12 @@ static int e100_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 	switch(err) {
 	case -ENOSPC:
 		/* We queued the skb, but now we're out of space. */
-		DPRINTK(TX_ERR, DEBUG, "No space for CB\n");
+		ndev_dbg(nic->netdev, TX_ERR, "No space for CB\n");
 		netif_stop_queue(netdev);
 		break;
 	case -ENOMEM:
 		/* This is a hard error - log it. */
-		DPRINTK(TX_ERR, DEBUG, "Out of Tx resources, returning skb\n");
+		ndev_dbg(nic->netdev, TX_ERR, "Out of Tx resources, returning skb\n");
 		netif_stop_queue(netdev);
 		return 1;
 	}
@@ -1657,7 +1653,7 @@ static int e100_tx_clean(struct nic *nic)
 	for(cb = nic->cb_to_clean;
 	    cb->status & cpu_to_le16(cb_complete);
 	    cb = nic->cb_to_clean = cb->next) {
-		DPRINTK(TX_DONE, DEBUG, "cb[%d]->status = 0x%04X\n",
+		ndev_dbg(nic->netdev, TX_DONE, "cb[%d]->status = 0x%04X\n",
 		        (int)(((void*)cb - (void*)nic->cbs)/sizeof(struct cb)),
 		        cb->status);
 
@@ -1798,7 +1794,7 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
 		sizeof(struct rfd), PCI_DMA_FROMDEVICE);
 	rfd_status = le16_to_cpu(rfd->status);
 
-	DPRINTK(RX_STATUS, DEBUG, "status=0x%04X\n", rfd_status);
+	ndev_dbg(nic->netdev, RX_STATUS, "status=0x%04X\n", rfd_status);
 
 	/* If data isn't ready, nothing to indicate */
 	if(unlikely(!(rfd_status & cb_complete)))
@@ -1907,7 +1903,7 @@ static irqreturn_t e100_intr(int irq, void *dev_id)
 	struct nic *nic = netdev_priv(netdev);
 	u8 stat_ack = ioread8(&nic->csr->scb.stat_ack);
 
-	DPRINTK(INTR, DEBUG, "stat_ack = 0x%02X\n", stat_ack);
+	ndev_dbg(nic->netdev, INTR, "stat_ack = 0x%02X\n", stat_ack);
 
 	if(stat_ack == stat_ack_not_ours ||	/* Not our interrupt */
 	   stat_ack == stat_ack_not_present)	/* Hardware is ejected */
@@ -2055,7 +2051,7 @@ static void e100_tx_timeout_task(struct work_struct *work)
 	struct nic *nic = container_of(work, struct nic, tx_timeout_task);
 	struct net_device *netdev = nic->netdev;
 
-	DPRINTK(TX_ERR, DEBUG, "scb.status=0x%02X\n",
+	ndev_dbg(nic->netdev, TX_ERR, "scb.status=0x%02X\n",
 		ioread8(&nic->csr->scb.status));
 	e100_down(netdev_priv(netdev));
 	e100_up(netdev_priv(netdev));
@@ -2216,18 +2212,6 @@ static int e100_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
 	return 0;
 }
 
-static u32 e100_get_msglevel(struct net_device *netdev)
-{
-	struct nic *nic = netdev_priv(netdev);
-	return nic->msg_enable;
-}
-
-static void e100_set_msglevel(struct net_device *netdev, u32 value)
-{
-	struct nic *nic = netdev_priv(netdev);
-	nic->msg_enable = value;
-}
-
 static int e100_nway_reset(struct net_device *netdev)
 {
 	struct nic *nic = netdev_priv(netdev);
@@ -2305,7 +2289,7 @@ static int e100_set_ringparam(struct net_device *netdev,
 	rfds->count = min(rfds->count, rfds->max);
 	cbs->count = max(ring->tx_pending, cbs->min);
 	cbs->count = min(cbs->count, cbs->max);
-	DPRINTK(DRV, INFO, "Ring Param settings: rx: %d, tx %d\n",
+	ndev_info(nic->netdev, DRV, "Ring Param settings: rx: %d, tx %d\n",
 	        rfds->count, cbs->count);
 	if(netif_running(netdev))
 		e100_up(nic);
@@ -2433,8 +2417,6 @@ static const struct ethtool_ops e100_ethtool_ops = {
 	.get_regs		= e100_get_regs,
 	.get_wol		= e100_get_wol,
 	.set_wol		= e100_set_wol,
-	.get_msglevel		= e100_get_msglevel,
-	.set_msglevel		= e100_set_msglevel,
 	.nway_reset		= e100_nway_reset,
 	.get_link		= e100_get_link,
 	.get_eeprom_len		= e100_get_eeprom_len,
@@ -2481,7 +2463,7 @@ static int e100_open(struct net_device *netdev)
 
 	netif_carrier_off(netdev);
 	if((err = e100_up(nic)))
-		DPRINTK(IFUP, ERR, "Cannot open interface, aborting.\n");
+		ndev_err(nic->netdev, IFUP, "Cannot open interface, aborting.\n");
 	return err;
 }
 
@@ -2499,8 +2481,7 @@ static int __devinit e100_probe(struct pci_dev *pdev,
 	int err;
 
 	if(!(netdev = alloc_etherdev(sizeof(struct nic)))) {
-		if(((1 << debug) - 1) & NETIF_MSG_PROBE)
-			printk(KERN_ERR PFX "Etherdev alloc failed, abort.\n");
+		dev_err(&pdev->dev, "Etherdev alloc failed, abort.\n");
 		return -ENOMEM;
 	}
 
@@ -2525,28 +2506,30 @@ static int __devinit e100_probe(struct pci_dev *pdev,
 	nic = netdev_priv(netdev);
 	nic->netdev = netdev;
 	nic->pdev = pdev;
-	nic->msg_enable = (1 << debug) - 1;
 	pci_set_drvdata(pdev, netdev);
 
 	if((err = pci_enable_device(pdev))) {
-		DPRINTK(PROBE, ERR, "Cannot enable PCI device, aborting.\n");
+		dev_err(&pdev->dev,
+		        "Cannot enable PCI device, aborting.\n");
 		goto err_out_free_dev;
 	}
 
 	if(!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
-		DPRINTK(PROBE, ERR, "Cannot find proper PCI device "
+		dev_err(&pdev->dev, "Cannot find proper PCI device "
 			"base address, aborting.\n");
 		err = -ENODEV;
 		goto err_out_disable_pdev;
 	}
 
 	if((err = pci_request_regions(pdev, DRV_NAME))) {
-		DPRINTK(PROBE, ERR, "Cannot obtain PCI resources, aborting.\n");
+		dev_err(&pdev->dev,
+		        "Cannot obtain PCI resources, aborting.\n");
 		goto err_out_disable_pdev;
 	}
 
 	if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
-		DPRINTK(PROBE, ERR, "No usable DMA configuration, aborting.\n");
+		dev_err(&pdev->dev,
+		        "No usable DMA configuration, aborting.\n");
 		goto err_out_free_res;
 	}
 
@@ -2554,11 +2537,12 @@ static int __devinit e100_probe(struct pci_dev *pdev,
 	SET_NETDEV_DEV(netdev, &pdev->dev);
 
 	if (use_io)
-		DPRINTK(PROBE, INFO, "using i/o access mode\n");
+		dev_info(&pdev->dev, "using i/o access mode\n");
 
 	nic->csr = pci_iomap(pdev, (use_io ? 1 : 0), sizeof(struct csr));
 	if(!nic->csr) {
-		DPRINTK(PROBE, ERR, "Cannot map device registers, aborting.\n");
+		dev_err(&pdev->dev,
+		        "Cannot map device registers, aborting.\n");
 		err = -ENOMEM;
 		goto err_out_free_res;
 	}
@@ -2592,7 +2576,7 @@ static int __devinit e100_probe(struct pci_dev *pdev,
 	INIT_WORK(&nic->tx_timeout_task, e100_tx_timeout_task);
 
 	if((err = e100_alloc(nic))) {
-		DPRINTK(PROBE, ERR, "Cannot alloc driver memory, aborting.\n");
+		ndev_err(nic->netdev, PROBE, "Cannot alloc driver memory, aborting.\n");
 		goto err_out_iounmap;
 	}
 
@@ -2605,13 +2589,13 @@ static int __devinit e100_probe(struct pci_dev *pdev,
 	memcpy(netdev->perm_addr, nic->eeprom, ETH_ALEN);
 	if (!is_valid_ether_addr(netdev->perm_addr)) {
 		if (!eeprom_bad_csum_allow) {
-			DPRINTK(PROBE, ERR, "Invalid MAC address from "
+			dev_err(&pdev->dev, "Invalid MAC address from "
 			        "EEPROM, aborting.\n");
 			err = -EAGAIN;
 			goto err_out_free;
 		} else {
-			DPRINTK(PROBE, ERR, "Invalid MAC address from EEPROM, "
-			        "you MUST configure one.\n");
+			dev_err(&pdev->dev, "Invalid MAC address from "
+			        "EEPROM, you MUST configure one.\n");
 		}
 	}
 
@@ -2623,15 +2607,17 @@ static int __devinit e100_probe(struct pci_dev *pdev,
 	/* ack any pending wake events, disable PME */
 	err = pci_enable_wake(pdev, 0, 0);
 	if (err)
-		DPRINTK(PROBE, ERR, "Error clearing wake event\n");
+		dev_err(&pdev->dev,
+		        "Error clearing wake event\n");
 
 	strcpy(netdev->name, "eth%d");
 	if((err = register_netdev(netdev))) {
-		DPRINTK(PROBE, ERR, "Cannot register net device, aborting.\n");
+		dev_err(&pdev->dev,
+		        "Cannot register net device, aborting.\n");
 		goto err_out_free;
 	}
 
-	DPRINTK(PROBE, INFO, "addr 0x%llx, irq %d, "
+	ndev_info(nic->netdev, PROBE, "addr 0x%llx, irq %d, "
 		"MAC addr %02X:%02X:%02X:%02X:%02X:%02X\n",
 		(unsigned long long)pci_resource_start(pdev, use_io ? 1 : 0), pdev->irq,
 		netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
@@ -2772,7 +2758,8 @@ static pci_ers_result_t e100_io_slot_reset(struct pci_dev *pdev)
 	struct nic *nic = netdev_priv(netdev);
 
 	if (pci_enable_device(pdev)) {
-		printk(KERN_ERR "e100: Cannot re-enable PCI device after reset.\n");
+		dev_err(&pdev->dev,
+		        "Cannot re-enable PCI device after reset.\n");
 		return PCI_ERS_RESULT_DISCONNECT;
 	}
 	pci_set_master(pdev);
@@ -2830,10 +2817,8 @@ static struct pci_driver e100_driver = {
 
 static int __init e100_init_module(void)
 {
-	if(((1 << debug) - 1) & NETIF_MSG_DRV) {
-		printk(KERN_INFO PFX "%s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
-		printk(KERN_INFO PFX "%s\n", DRV_COPYRIGHT);
-	}
+	printk(KERN_INFO PFX "%s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
+	printk(KERN_INFO PFX "%s\n", DRV_COPYRIGHT);
 	return pci_register_driver(&e100_driver);
 }
 
drivers/net/e1000/e1000.h +0 -15
index 16a6edf..a232f0e 100644
@@ -81,20 +81,6 @@ struct e1000_adapter;
 
 #include "e1000_hw.h"
 
-#ifdef DBG
-#define E1000_DBG(args...) printk(KERN_DEBUG "e1000: " args)
-#else
-#define E1000_DBG(args...)
-#endif
-
-#define E1000_ERR(args...) printk(KERN_ERR "e1000: " args)
-
-#define PFX "e1000: "
-#define DPRINTK(nlevel, klevel, fmt, args...) \
-	(void)((NETIF_MSG_##nlevel & adapter->msg_enable) && \
-	printk(KERN_##klevel PFX "%s: %s: " fmt, adapter->netdev->name, \
-		__FUNCTION__ , ## args))
-
 #define E1000_MAX_INTR 10
 
 /* TX/RX descriptor defines */
@@ -333,7 +319,6 @@ struct e1000_adapter {
 	struct e1000_tx_ring test_tx_ring;
 	struct e1000_rx_ring test_rx_ring;
 
-	int msg_enable;
 	boolean_t have_msi;
 
 	/* to not mess up cache alignment, always add to the bottom */
drivers/net/e1000/e1000_ethtool.c +12 -27
index bb08375..e5ba5ac 100644
@@ -198,7 +198,7 @@ e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
 	/* When SoL/IDER sessions are active, autoneg/speed/duplex
 	 * cannot be changed */
 	if (e1000_check_phy_reset_block(hw)) {
-		DPRINTK(DRV, ERR, "Cannot change link characteristics "
+		ndev_err(adapter->netdev, DRV, "Cannot change link characteristics "
 		        "when SoL/IDER is active.\n");
 		return -EINVAL;
 	}
@@ -356,25 +356,12 @@ e1000_set_tso(struct net_device *netdev, uint32_t data)
 	else
 		netdev->features &= ~NETIF_F_TSO6;
 
-	DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
+	ndev_info(adapter->netdev, PROBE,
+	          "TSO is %s\n", data ? "Enabled" : "Disabled");
 	adapter->tso_force = TRUE;
 	return 0;
 }
 
-static uint32_t
-e1000_get_msglevel(struct net_device *netdev)
-{
-	struct e1000_adapter *adapter = netdev_priv(netdev);
-	return adapter->msg_enable;
-}
-
-static void
-e1000_set_msglevel(struct net_device *netdev, uint32_t data)
-{
-	struct e1000_adapter *adapter = netdev_priv(netdev);
-	adapter->msg_enable = data;
-}
-
 static int
 e1000_get_regs_len(struct net_device *netdev)
 {
@@ -743,7 +730,7 @@ err_setup:
 		E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W));             \
 		value = E1000_READ_REG(&adapter->hw, R);                       \
 		if (value != (test[pat] & W & M)) {                             \
-			DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \
+			ndev_err(adapter->netdev, DRV, "pattern test reg %04X failed: got " \
 			        "0x%08X expected 0x%08X\n",                    \
 			        E1000_##R, value, (test[pat] & W & M));        \
 			*data = (adapter->hw.mac_type < e1000_82543) ?         \
@@ -759,7 +746,7 @@ err_setup:
 	E1000_WRITE_REG(&adapter->hw, R, W & M);                               \
 	value = E1000_READ_REG(&adapter->hw, R);                               \
 	if ((W & M) != (value & M)) {                                          \
-		DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\
+		ndev_err(adapter->netdev, DRV, "set/check reg %04X test failed: got 0x%08X "\
 		        "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \
 		*data = (adapter->hw.mac_type < e1000_82543) ?                 \
 			E1000_82542_##R : E1000_##R;                           \
@@ -797,7 +784,7 @@ e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
 	E1000_WRITE_REG(&adapter->hw, STATUS, toggle);
 	after = E1000_READ_REG(&adapter->hw, STATUS) & toggle;
 	if (value != after) {
-		DPRINTK(DRV, ERR, "failed STATUS register test got: "
+		ndev_err(adapter->netdev, DRV, "failed STATUS register test got: "
 		        "0x%08X expected: 0x%08X\n", after, value);
 		*data = 1;
 		return 1;
@@ -917,7 +904,7 @@ e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
 		*data = 1;
 		return -1;
 	}
-	DPRINTK(HW, INFO, "testing %s interrupt\n",
+	ndev_info(adapter->netdev, HW, "testing %s interrupt\n",
 	        (shared_int ? "shared" : "unshared"));
 
 	/* Disable all the interrupts */
@@ -1562,7 +1549,7 @@ e1000_loopback_test(struct e1000_adapter *adapter, uint64_t *data)
 	/* PHY loopback cannot be performed if SoL/IDER
 	 * sessions are active */
 	if (e1000_check_phy_reset_block(&adapter->hw)) {
-		DPRINTK(DRV, ERR, "Cannot do PHY loopback test "
+		ndev_err(adapter->netdev, DRV, "Cannot do PHY loopback test "
 		        "when SoL/IDER is active.\n");
 		*data = 0;
 		goto out;
@@ -1635,7 +1622,7 @@ e1000_diag_test(struct net_device *netdev,
 		uint8_t forced_speed_duplex = adapter->hw.forced_speed_duplex;
 		uint8_t autoneg = adapter->hw.autoneg;
 
-		DPRINTK(HW, INFO, "offline testing starting\n");
+		ndev_info(adapter->netdev, HW, "offline testing starting\n");
 
 		/* Link test performed before hardware reset so autoneg doesn't
 		 * interfere with test result */
@@ -1675,7 +1662,7 @@ e1000_diag_test(struct net_device *netdev,
 		if (if_running)
 			dev_open(netdev);
 	} else {
-		DPRINTK(HW, INFO, "online testing starting\n");
+		ndev_info(adapter->netdev, HW, "online testing starting\n");
 		/* Online tests */
 		if (e1000_link_test(adapter, &data[4]))
 			eth_test->flags |= ETH_TEST_FL_FAILED;
@@ -1770,7 +1757,7 @@ e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
 		wol->supported &= ~WAKE_UCAST;
 
 		if (adapter->wol & E1000_WUFC_EX)
-			DPRINTK(DRV, ERR, "Interface does not support "
+			ndev_err(adapter->netdev, DRV, "Interface does not support "
 		        "directed (unicast) frame wake-up packets\n");
 		break;
 	default:
@@ -1804,7 +1791,7 @@ e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
 	switch (hw->device_id) {
 	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
 		if (wol->wolopts & WAKE_UCAST) {
-			DPRINTK(DRV, ERR, "Interface does not support "
+			ndev_err(adapter->netdev, DRV, "Interface does not support "
 		        "directed (unicast) frame wake-up packets\n");
 			return -EOPNOTSUPP;
 		}
@@ -1948,8 +1935,6 @@ static const struct ethtool_ops e1000_ethtool_ops = {
 	.get_regs               = e1000_get_regs,
 	.get_wol                = e1000_get_wol,
 	.set_wol                = e1000_set_wol,
-	.get_msglevel           = e1000_get_msglevel,
-	.set_msglevel           = e1000_set_msglevel,
 	.nway_reset             = e1000_nway_reset,
 	.get_link               = ethtool_op_get_link,
 	.get_eeprom_len         = e1000_get_eeprom_len,
drivers/net/e1000/e1000_main.c +56 -54

396 lines not on this page · raw message

drivers/net/e1000/e1000_param.c +34 -33

205 lines not on this page · raw message

drivers/net/ixgb/ixgb.h +0 -14
index 3569d5b..d65cbea 100644
@@ -75,19 +75,6 @@ struct ixgb_adapter;
 #include "ixgb_ee.h"
 #include "ixgb_ids.h"
 
-#ifdef _DEBUG_DRIVER_
-#define IXGB_DBG(args...) printk(KERN_DEBUG "ixgb: " args)
-#else
-#define IXGB_DBG(args...)
-#endif
-
-#define PFX "ixgb: "
-#define DPRINTK(nlevel, klevel, fmt, args...) \
-	(void)((NETIF_MSG_##nlevel & adapter->msg_enable) && \
-	printk(KERN_##klevel PFX "%s: %s: " fmt, adapter->netdev->name, \
-		__FUNCTION__ , ## args))
-
-
 /* TX/RX descriptor defines */
 #define DEFAULT_TXD	 256
 #define MAX_TXD   	4096
@@ -190,7 +177,6 @@ struct ixgb_adapter {
 
 	/* structs defined in ixgb_hw.h */
 	struct ixgb_hw hw;
-	u16 msg_enable;
 	struct ixgb_hw_stats stats;
 	uint32_t alloc_rx_buff_failed;
 	boolean_t have_msi;
drivers/net/ixgb/ixgb_ethtool.c +0 -15
index afde848..b68b30e 100644
@@ -248,19 +248,6 @@ ixgb_set_tso(struct net_device *netdev, uint32_t data)
 	return 0;
 } 
 
-static uint32_t
-ixgb_get_msglevel(struct net_device *netdev)
-{
-	struct ixgb_adapter *adapter = netdev_priv(netdev);
-	return adapter->msg_enable;
-}
-
-static void
-ixgb_set_msglevel(struct net_device *netdev, uint32_t data)
-{
-	struct ixgb_adapter *adapter = netdev_priv(netdev);
-	adapter->msg_enable = data;
-}
 #define IXGB_GET_STAT(_A_, _R_) _A_->stats._R_
 
 static int 
@@ -716,8 +703,6 @@ static const struct ethtool_ops ixgb_ethtool_ops = {
 	.set_tx_csum = ixgb_set_tx_csum,
 	.get_sg	= ethtool_op_get_sg,
 	.set_sg	= ethtool_op_set_sg,
-	.get_msglevel = ixgb_get_msglevel,
-	.set_msglevel = ixgb_set_msglevel,
 	.get_tso = ethtool_op_get_tso,
 	.set_tso = ixgb_set_tso,
 	.get_strings = ixgb_get_strings,
drivers/net/ixgb/ixgb_main.c +22 -28

176 lines not on this page · raw message

author
#2 lore raw
In reply to Auke Kok
Quoted 3 lines · Auke Kok

A lot of netdevices implement their own variant of printk and use use variations of dev_printk, printk or others that use msg_enable, which has been an eyesore with countless variations across drivers.

<snip>

include/linux/netdevice.h enum { · line 846

Quoted 4 lines
include/linux/netdevice.h +4 -0
+#define ndev_err(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_ERR "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)

so now the only question is whether we want the ndev_printk() stuff to format as much as possible like dev_printk. dev_printk also prints dev_driver_string(dev), which is what above macro omits. To make this as much similar as possible, we could do:

Review

Quoted 5 lines
(quoted diff) +5 -0
+#define ndev_err(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_ERR "%s: %s %s: " format, (netdev)->name, \
+		dev_driver_string(netdev)-dev), (netdev)->dev.parent->bus_id, \
+             ## arg); } } while (0)

it would (e.g. e1000) change the output from:
eth1: 0000:00:19.0: NIC Link is Down

To:
eth1: e1000 0000:00:19.0: NIC Link is Down

But I am unsure whether the addition of the driver name is useful at this point - most drivers already printk some sort of association out that can be used to track the bus_id/netdev name back to the driver easily.

So, hence I omitted doing this in this patch.

Auke

#3 lore raw
In reply to Auke Kok

include/linux/netdevice.h struct net_device · line 547

Quoted 13 lines · Auke Kok
include/linux/netdevice.h +2 -0
index 3a70f55..d185f41 100644
@@ -540,6 +540,8 @@ struct net_device
 	struct device		dev;
 	/* space for optional statistics and wireless sysfs groups */
 	struct attribute_group  *sysfs_groups[3];
+
+	int			msg_enable;
 };
 #define to_net_dev(d) container_of(d, struct net_device, dev)
 

msg_enable is more frequently defined in drivers/net as u32 not int.

egrep -r -w --include=*.[ch] "u32[[:space:]]+msg_enable" drivers/net | wc -l egrep -r -w --include=*.[ch] "int[[:space:]]+msg_enable" drivers/net | wc -l

29 to 5

cheers, Joe

#6 lore raw
In reply to Auke Kok
Quoted 19 lines · On Mon, 11 Jun 2007 14:37:21 -0700 Auke Kok wrote:
 include/linux/netdevice.h |   38 ++++++++++++++++++++++++++++++++++++++
 net/core/dev.c            |    5 +++++
 net/core/ethtool.c        |   14 +++++++-------
 3 files changed, 50 insertions(+), 7 deletions(-)
include/linux/netdevice.h +2 -0
index 3a70f55..d185f41 100644
@@ -540,6 +540,8 @@ struct net_device
 	struct device		dev;
 	/* space for optional statistics and wireless sysfs groups */
 	struct attribute_group  *sysfs_groups[3];
+
+	int			msg_enable;
 };
 #define to_net_dev(d) container_of(d, struct net_device, dev)
 

include/linux/netdevice.h enum { · line 847

Quoted 8 lines
include/linux/netdevice.h +5 -0
@@ -838,6 +840,42 @@ enum {
 	NETIF_MSG_WOL		= 0x4000,
 };
 
+#define ndev_err(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_ERR "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+

I would still do what Steve H. suggested, i.e., only evaluate macro args one time. E.g. (not tested & reformatted :)

+#define ndev_err(netdev, level, format, arg...) \
+ do { \
+ struct net_device *__nd = netdev; \
+ if ((__nd)->msg_enable & NETIF_MSG_##level) \
+ printk(KERN_ERR "%s: %s: " format, (__nd)->name, \
+ (__nd)->dev.parent->bus_id, ## arg); \
+ } while (0)
+

Dropping the braces around the printk() too.

etc...

Quoted 24 lines
include/linux/netdevice.h +24 -0
+#define ndev_warn(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_WARNING "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+
+#define ndev_notice(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_NOTICE "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+
+#define ndev_info(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_INFO "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+
+#ifdef DEBUG
+#define ndev_debug(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_DEBUG "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+#else
+/* Force type-checking on ndev_dbg() when DEBUG is not set */
+static inline int __attribute__ ((format (printf, 3, 4)))
+__ndev_dbg(struct net_device * netdev, u32 level, const char *format, ...)

include/linux/netdevice.h enum { · line 881

Quoted 10 lines
include/linux/netdevice.h +7 -0
+{
+	return 0;
+}
+#define ndev_dbg(netdev, level, fmt, args...) \
+	__ndev_dbg(netdev, NETIF_MSG_##level, fmt, ##args)
+#endif
+
 #define netif_msg_drv(p)	((p)->msg_enable & NETIF_MSG_DRV)
 #define netif_msg_probe(p)	((p)->msg_enable & NETIF_MSG_PROBE)
 #define netif_msg_link(p)	((p)->msg_enable & NETIF_MSG_LINK)

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

author
#4 lore raw
In reply to Joe Perches
Quoted 17 lines · Joe Perches

include/linux/netdevice.h struct net_device · line 547

Quoted 13 lines · Auke Kok
include/linux/netdevice.h +2 -0
index 3a70f55..d185f41 100644
@@ -540,6 +540,8 @@ struct net_device
 	struct device		dev;
 	/* space for optional statistics and wireless sysfs groups */
 	struct attribute_group  *sysfs_groups[3];
+
+	int			msg_enable;
 };
 #define to_net_dev(d) container_of(d, struct net_device, dev)
 

msg_enable is more frequently defined in drivers/net as u32 not int.

Quoted 4 lines

egrep -r -w --include=*.[ch] "u32[[:space:]]+msg_enable" drivers/net | wc -l egrep -r -w --include=*.[ch] "int[[:space:]]+msg_enable" drivers/net | wc -l

29 to 5

yes, we're only using the bottom 15 bits anyway, but the net_device struct consistently uses 'int' style members, leaving it up to the compiler to pick an appropriate size for each arch. That was the reason I chose int here.

Auke

author
#7 lore raw
In reply to Randy Dunlap
Quoted 42 lines · Randy Dunlap
Quoted 19 lines · On Mon, 11 Jun 2007 14:37:21 -0700 Auke Kok wrote:
 include/linux/netdevice.h |   38 ++++++++++++++++++++++++++++++++++++++
 net/core/dev.c            |    5 +++++
 net/core/ethtool.c        |   14 +++++++-------
 3 files changed, 50 insertions(+), 7 deletions(-)
include/linux/netdevice.h +2 -0
index 3a70f55..d185f41 100644
@@ -540,6 +540,8 @@ struct net_device
 	struct device		dev;
 	/* space for optional statistics and wireless sysfs groups */
 	struct attribute_group  *sysfs_groups[3];
+
+	int			msg_enable;
 };
 #define to_net_dev(d) container_of(d, struct net_device, dev)
 

include/linux/netdevice.h enum { · line 847

Quoted 8 lines
include/linux/netdevice.h +5 -0
@@ -838,6 +840,42 @@ enum {
 	NETIF_MSG_WOL		= 0x4000,
 };
 
+#define ndev_err(netdev, level, format, arg...) \
+	do { if ((netdev)->msg_enable & NETIF_MSG_##level) { \
+		printk(KERN_ERR "%s: %s: " format, (netdev)->name, \
+		(netdev)->dev.parent->bus_id, ## arg); } } while (0)
+

I would still do what Steve H. suggested, i.e., only evaluate macro args one time. E.g. (not tested & reformatted :)

(quoted diff) +8 -0
+#define ndev_err(netdev, level, format, arg...) \
+	do { \
+		struct net_device *__nd = netdev; \
+		if ((__nd)->msg_enable & NETIF_MSG_##level) \
+			printk(KERN_ERR "%s: %s: " format, (__nd)->name, \
+				(__nd)->dev.parent->bus_id, ## arg); \
+	} while (0)
+
Quoted 1 line

Dropping the braces around the printk() too.

ahh, *now* I get it... :)

Auke

#8 lore raw
In reply to Auke Kok
Quoted 41 lines · On Mon, 11 Jun 2007 14:37:21 -0700 Auke Kok <[email protected]> wrote:

A lot of netdevices implement their own variant of printk and use use variations of dev_printk, printk or others that use msg_enable, which has been an eyesore with countless variations across drivers.

This patch implements a standard ndev_printk and derivatives such as ndev_err, ndev_info, ndev_warn that allows drivers to transparently use both the msg_enable and a generic netdevice message layout. It moves the msg_enable over to the net_device struct and allows drivers to obsolete ethtool handling code of the msg_enable value.

The current code has each driver contain a copy of msg_enable and handle the setting/changing through ethtool that way. Since the netdev name is stored in the net_device struct, those two are not coherently available in a uniform way across all drivers (a single macro or function would not work since all drivers name their net_device members differently). This makes netdevice driver writes reinvent the wheel over and over again.

It thus makes sense to move msg_enable to the net_device. This gives us the opportunity to (1) initialize it by default with a globally sane value, (2) remove msg_enable handling code w/r ethtool for drivers that know and use the msg_enable member of the net_device struct. (3) Ethtool code can just modify the net_device msg_enable for drivers that do not have custom msg_enable get/set handlers so converted drivers lose some code for that as well.

---

 include/linux/netdevice.h |   38 ++++++++++++++++++++++++++++++++++++++
 net/core/dev.c            |    5 +++++
 net/core/ethtool.c        |   14 +++++++-------
 3 files changed, 50 insertions(+), 7 deletions(-)
include/linux/netdevice.h +0 -0
index 3a70f55..d185f41 100644

include/linux/netdevice.h struct net_device · line 545

Quoted 6 lines
include/linux/netdevice.h +2 -0
@@ -540,6 +540,8 @@ struct net_device
 	struct device		dev;
 	/* space for optional statistics and wireless sysfs groups */
 	struct attribute_group  *sysfs_groups[3];
+
+	int			msg_enable;
 };

Since msg_enable is used as bits, it should be unsigned (probably unsigned long).

#5 lore raw
In reply to Kok, Auke
Quoted 4 lines · Auke
Quoted 1 line

msg_enable is more frequently defined in drivers/net as u32 not int.

yes, we're only using the bottom 15 bits anyway, but the net_device struct consistently uses 'int' style members, leaving it up to the compiler to pick an appropriate size for each arch. That was the reason I chose int here.

I guess I'm from a "don't be larger than necessary" school.

As it's a bitfield and not a boolean, it should be unsigned. Perhaps it could also be a good time to rename it to something like netif_enabled_msgs?

author
#9 lore raw
In reply to Stephen Hemminger
Quoted 39 lines · Stephen Hemminger
Quoted 36 lines · On Mon, 11 Jun 2007 14:37:21 -0700 Auke Kok <[email protected]> wrote:

A lot of netdevices implement their own variant of printk and use use variations of dev_printk, printk or others that use msg_enable, which has been an eyesore with countless variations across drivers.

This patch implements a standard ndev_printk and derivatives such as ndev_err, ndev_info, ndev_warn that allows drivers to transparently use both the msg_enable and a generic netdevice message layout. It moves the msg_enable over to the net_device struct and allows drivers to obsolete ethtool handling code of the msg_enable value.

The current code has each driver contain a copy of msg_enable and handle the setting/changing through ethtool that way. Since the netdev name is stored in the net_device struct, those two are not coherently available in a uniform way across all drivers (a single macro or function would not work since all drivers name their net_device members differently). This makes netdevice driver writes reinvent the wheel over and over again.

It thus makes sense to move msg_enable to the net_device. This gives us the opportunity to (1) initialize it by default with a globally sane value, (2) remove msg_enable handling code w/r ethtool for drivers that know and use the msg_enable member of the net_device struct. (3) Ethtool code can just modify the net_device msg_enable for drivers that do not have custom msg_enable get/set handlers so converted drivers lose some code for that as well.

---

 include/linux/netdevice.h |   38 ++++++++++++++++++++++++++++++++++++++
 net/core/dev.c            |    5 +++++
 net/core/ethtool.c        |   14 +++++++-------
 3 files changed, 50 insertions(+), 7 deletions(-)
Quoted 13 lines

include/linux/netdevice.h struct net_device · line 545

Quoted 11 lines
include/linux/netdevice.h +2 -0
index 3a70f55..d185f41 100644
@@ -540,6 +540,8 @@ struct net_device
 	struct device		dev;
 	/* space for optional statistics and wireless sysfs groups */
 	struct attribute_group  *sysfs_groups[3];
+
+	int			msg_enable;
 };

Since msg_enable is used as bits, it should be unsigned (probably unsigned long).

ack, but the long is really not needed here I think - we're only using the first 15.

Auke