Skip to contentSkip to conversation

: Third (final?) release of Sun Neptune driver

PATCH In review David Miller 7 participants 40 messages Oct 5, 2007 – Oct 8, 2007 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

PATCH 1/1 : Third (final?) release of Sun Neptune driver

I just checked the following into net-2.6.24, besides minor tweaks and bug fixes, this is probably what is going to Linus.

I verified it builds no just on sparc64 but also even on 32-bit platforms such as x86. :-)

Thanks!

commit 147fd2f057af893f63df5bad497bb60ac3abbaab

Author: David S. Miller <[email protected]>
Date:   Fri Oct 5 02:48:00 2007 -0700

[NIU]: Add Sun Neptune ethernet driver.

drivers/net/Kconfig +7 -0
index 0e48b29..9c635a2 100644
@@ -2594,6 +2594,13 @@ config NETXEN_NIC
 	help
 	  This enables the support for NetXen's Gigabit Ethernet card.
 
+config NIU
+	tristate "Sun Neptune 10Gbit Ethernet support"
+	depends on PCI
+	help
+	  This enables support for cards based upon Sun's
+	  Neptune chipset.
+
 config PASEMI_MAC
 	tristate "PA Semi 1/10Gbit MAC"
 	depends on PPC64 && PCI
drivers/net/Makefile +1 -0
index eb5c655..d2e0f35 100644
@@ -241,3 +241,4 @@ obj-$(CONFIG_NETCONSOLE) += netconsole.o
 obj-$(CONFIG_FS_ENET) += fs_enet/
 
 obj-$(CONFIG_NETXEN_NIC) += netxen/
+obj-$(CONFIG_NIU) += niu.o
drivers/net/niu.c new file +7940 -0

2,983 lines not on this page · raw message

drivers/net/niu.h new file +3222 -0

3,222 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 8 lines · On Fri, 05 Oct 2007 03:12:09 -0700 (PDT) David Miller <[email protected]>…

I just checked the following into net-2.6.24, besides minor tweaks and bug fixes, this is probably what is going to Linus.

I verified it builds no just on sparc64 but also even on 32-bit platforms such as x86. :-)

Thanks!

Looks good, minor stuff...
Surprisingly low number of comments. Which is okay by me, but others might find it harder. Perhaps some explanation of the queue stuff and other hardware surprises would be useful.

Quoted 129 lines

commit 147fd2f057af893f63df5bad497bb60ac3abbaab

Author: David S. Miller <[email protected]>
Date:   Fri Oct 5 02:48:00 2007 -0700

[NIU]: Add Sun Neptune ethernet driver.

drivers/net/Kconfig +7 -0
index 0e48b29..9c635a2 100644
@@ -2594,6 +2594,13 @@ config NETXEN_NIC
 	help
 	  This enables the support for NetXen's Gigabit Ethernet card.
 
+config NIU
+	tristate "Sun Neptune 10Gbit Ethernet support"
+	depends on PCI
+	help
+	  This enables support for cards based upon Sun's
+	  Neptune chipset.
+
 config PASEMI_MAC
 	tristate "PA Semi 1/10Gbit MAC"
 	depends on PPC64 && PCI
drivers/net/Makefile +1 -0
index eb5c655..d2e0f35 100644
@@ -241,3 +241,4 @@ obj-$(CONFIG_NETCONSOLE) += netconsole.o
 obj-$(CONFIG_FS_ENET) += fs_enet/
 
 obj-$(CONFIG_NETXEN_NIC) += netxen/
+obj-$(CONFIG_NIU) += niu.o
drivers/net/niu.c new file +88 -0
new file mode 100644
index 0000000..0dfabbe
@@ -0,0 +1,7940 @@
+/* niu.c: Neptune ethernet driver.
+ *
+ * Copyright (C) 2007 David S. Miller ([email protected])
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/dma-mapping.h>
+#include <linux/netdevice.h>
+#include <linux/ethtool.h>
+#include <linux/etherdevice.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/bitops.h>
+#include <linux/mii.h>
+#include <linux/if_ether.h>
+#include <linux/if_vlan.h>
+#include <linux/ip.h>
+#include <linux/in.h>
+#include <linux/ipv6.h>
+#include <linux/log2.h>
+#include <linux/jiffies.h>
+#include <linux/crc32.h>
+
+#include <asm/io.h>
+
+#ifdef CONFIG_SPARC64
+#include <linux/of_device.h>
+#endif
+
+#include "niu.h"
+
+#define DRV_MODULE_NAME		"niu"
+#define PFX DRV_MODULE_NAME	": "
+#define DRV_MODULE_VERSION	"0.5"
+#define DRV_MODULE_RELDATE	"October 5, 2007"
+
+static char version[] __devinitdata =
+	DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
+
+MODULE_AUTHOR("David S. Miller ([email protected])");
+MODULE_DESCRIPTION("NIU ethernet driver");
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRV_MODULE_VERSION);
+
+#ifndef DMA_44BIT_MASK
+#define DMA_44BIT_MASK	0x00000fffffffffffULL
+#endif
+
+#ifndef readq
+static u64 readq(void __iomem *reg)
+{
+	return (((u64)readl(reg + 0x4UL) << 32) |
+		(u64)readl(reg));
+}
+
+static void writeq(u64 val, void __iomem *reg)
+{
+	writel(val & 0xffffffff, reg);
+	writel(val >> 32, reg + 0x4UL);
+}
+#endif
+
+static struct pci_device_id niu_pci_tbl[] = {
+	{PCI_DEVICE(PCI_VENDOR_ID_SUN, 0xabcd)},
+	{}
+};
+
+MODULE_DEVICE_TABLE(pci, niu_pci_tbl);
+
+#define NIU_TX_TIMEOUT			(5 * HZ)
+
+#define nr64(reg)		readq(np->regs + (reg))
+#define nw64(reg, val)		writeq((val), np->regs + (reg))
+
+#define nr64_mac(reg)		readq(np->mac_regs + (reg))
+#define nw64_mac(reg, val)	writeq((val), np->mac_regs + (reg))
+
+#define nr64_ipp(reg)		readq(np->regs + np->ipp_off + (reg))
+#define nw64_ipp(reg, val)	writeq((val), np->regs + np->ipp_off + (reg))
+
+#define nr64_pcs(reg)		readq(np->regs + np->pcs_off + (reg))
+#define nw64_pcs(reg, val)	writeq((val), np->regs + np->pcs_off + (reg))
+
+#define nr64_xpcs(reg)		readq(np->regs + np->xpcs_off + (reg))
+#define nw64_xpcs(reg, val)	writeq((val), np->regs + np->xpcs_off + (reg))
+

drivers/net/niu.c line 98

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+static unsigned int niu_debug;
+#define NIU_DEBUG_INTERRUPT	0x00000001
+#define NIU_DEBUG_TX_WORK	0x00000002
+#define NIU_DEBUG_RX_WORK	0x00000004
+#define NIU_DEBUG_POLL		0x00000008
+#define NIU_DEBUG_PROBE		0x00010000
+#define NIU_DEBUG_MDIO		0x00020000
+#define NIU_DEBUG_MII		0x00040000
+#define NIU_DEBUG_INIT_HW	0x00080000
+#define NIU_DEBUG_STOP_HW	0x00100000

These match with existing netif_msg_XXX and your
driver already has msglvl ethtool hook.

Quoted 8 lines
drivers/net/niu.c new file +8 -0
+
+module_param(niu_debug, int, 0);
+MODULE_PARM_DESC(niu_debug,
+"NIU bitmapped debugging message enable value:\n"
+"	0x00000001	Log interrupt events\n"
+"	0x00000002	Log TX work\n"
+"	0x00000004	Log RX work\n"
+"	0x00000008	Log NAPI poll\n"

drivers/net/niu.c line 116

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+"	0x00010000	Log device probe events\n"
+"	0x00020000	Log MDIO reads and writes\n"
+"	0x00040000	Log MII reads and writes\n"
+"	0x00080000	Log HW initialization\n"
+"	0x00100000	Log HW shutdown\n"
+);
+
+#define niudbg(TYPE, f, a...) \
+do {	if (niu_debug & NIU_DEBUG_##TYPE) \
+		printk(KERN_ERR PFX f, ## a); \

Do you really want to print all these at KERN_ERR level?

Quoted 77 lines
drivers/net/niu.c new file +77 -0
+} while (0)
+
+#define niu_lock_parent(np, flags) \
+	spin_lock_irqsave(&np->parent->lock, flags)
+#define niu_unlock_parent(np, flags) \
+	spin_unlock_irqrestore(&np->parent->lock, flags)
+
+static int __niu_wait_bits_clear_mac(struct niu *np, unsigned long reg,
+				     u64 bits, int limit, int delay)
+{
+	while (--limit >= 0) {
+		u64 val = nr64_mac(reg);
+
+		if (!(val & bits))
+			break;
+		udelay(delay);
+	}
+	if (limit < 0)
+		return -ENODEV;
+	return 0;
+}
+
+static int __niu_set_and_wait_clear_mac(struct niu *np, unsigned long reg,
+					u64 bits, int limit, int delay,
+					const char *reg_name)
+{
+	int err;
+
+	nw64_mac(reg, bits);
+	err = __niu_wait_bits_clear_mac(np, reg, bits, limit, delay);
+	if (err)
+		printk(KERN_ERR PFX "%s: bits (%llx) of register %s "
+		       "would not clear, val[%llx]\n",
+		       np->dev->name, (unsigned long long) bits, reg_name,
+		       (unsigned long long) nr64_mac(reg));
+	return err;
+}
+
+#define niu_set_and_wait_clear_mac(NP, REG, BITS, LIMIT, DELAY, REG_NAME) \
+({	BUILD_BUG_ON(LIMIT <= 0 || DELAY < 0); \
+	__niu_set_and_wait_clear_mac(NP, REG, BITS, LIMIT, DELAY, REG_NAME); \
+})
+
+static int __niu_wait_bits_clear_ipp(struct niu *np, unsigned long reg,
+				     u64 bits, int limit, int delay)
+{
+	while (--limit >= 0) {
+		u64 val = nr64_ipp(reg);
+
+		if (!(val & bits))
+			break;
+		udelay(delay);
+	}
+	if (limit < 0)
+		return -ENODEV;
+	return 0;
+}
+
+static int __niu_set_and_wait_clear_ipp(struct niu *np, unsigned long reg,
+					u64 bits, int limit, int delay,
+					const char *reg_name)
+{
+	int err;
+	u64 val;
+
+	val = nr64_ipp(reg);
+	val |= bits;
+	nw64_ipp(reg, val);
+
+	err = __niu_wait_bits_clear_ipp(np, reg, bits, limit, delay);
+	if (err)
+		printk(KERN_ERR PFX "%s: bits (%llx) of register %s "
+		       "would not clear, val[%llx]\n",
+		       np->dev->name, (unsigned long long) bits, reg_name,
+		       (unsigned long long) nr64_ipp(reg));
+	return err;
+}

drivers/net/niu.c line 203

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+
+#define niu_set_and_wait_clear_ipp(NP, REG, BITS, LIMIT, DELAY, REG_NAME) \
+({	BUILD_BUG_ON(LIMIT <= 0 || DELAY < 0); \
+	__niu_set_and_wait_clear_ipp(NP, REG, BITS, LIMIT, DELAY, REG_NAME); \
+})
+
+static int __niu_wait_bits_clear(struct niu *np, unsigned long reg,
+				 u64 bits, int limit, int delay)
+{
+	BUILD_BUG_ON(limit <= 0 || delay < 0);

redundant you already checked

Quoted 644 lines
drivers/net/niu.c new file +644 -0
+	while (--limit >= 0) {
+		u64 val = nr64(reg);
+
+		if (!(val & bits))
+			break;
+		udelay(delay);
+	}
+	if (limit < 0)
+		return -ENODEV;
+	return 0;
+}
+
+#define niu_wait_bits_clear(NP, REG, BITS, LIMIT, DELAY) \
+({	BUILD_BUG_ON(LIMIT <= 0 || DELAY < 0); \
+	__niu_wait_bits_clear(NP, REG, BITS, LIMIT, DELAY); \
+})
+
+static int __niu_set_and_wait_clear(struct niu *np, unsigned long reg,
+				    u64 bits, int limit, int delay,
+				    const char *reg_name)
+{
+	int err;
+
+	nw64(reg, bits);
+	err = __niu_wait_bits_clear(np, reg, bits, limit, delay);
+	if (err)
+		printk(KERN_ERR PFX "%s: bits (%llx) of register %s "
+		       "would not clear, val[%llx]\n",
+		       np->dev->name, (unsigned long long) bits, reg_name,
+		       (unsigned long long) nr64(reg));
+	return err;
+}
+
+#define niu_set_and_wait_clear(NP, REG, BITS, LIMIT, DELAY, REG_NAME) \
+({	BUILD_BUG_ON(LIMIT <= 0 || DELAY < 0); \
+	__niu_set_and_wait_clear(NP, REG, BITS, LIMIT, DELAY, REG_NAME); \
+})
+
+static void niu_ldg_rearm(struct niu *np, struct niu_ldg *lp, int on)
+{
+	u64 val = (u64) lp->timer;
+
+	if (on)
+		val |= LDG_IMGMT_ARM;
+
+	nw64(LDG_IMGMT(lp->ldg_num), val);
+}
+
+static int niu_ldn_irq_enable(struct niu *np, int ldn, int on)
+{
+	unsigned long mask_reg, bits;
+	u64 val;
+
+	if (ldn < 0 || ldn > LDN_MAX)
+		return -EINVAL;
+
+	if (ldn < 64) {
+		mask_reg = LD_IM0(ldn);
+		bits = LD_IM0_MASK;
+	} else {
+		mask_reg = LD_IM1(ldn - 64);
+		bits = LD_IM1_MASK;
+	}
+
+	val = nr64(mask_reg);
+	if (on)
+		val &= ~bits;
+	else
+		val |= bits;
+	nw64(mask_reg, val);
+
+	return 0;
+}
+
+static int niu_enable_ldn_in_ldg(struct niu *np, struct niu_ldg *lp, int on)
+{
+	struct niu_parent *parent = np->parent;
+	int i;
+
+	for (i = 0; i <= LDN_MAX; i++) {
+		int err;
+
+		if (parent->ldg_map[i] != lp->ldg_num)
+			continue;
+
+		err = niu_ldn_irq_enable(np, i, on);
+		if (err)
+			return err;
+	}
+	return 0;
+}
+
+static int niu_enable_interrupts(struct niu *np, int on)
+{
+	int i;
+
+	for (i = 0; i < np->num_ldg; i++) {
+		struct niu_ldg *lp = &np->ldg[i];
+		int err;
+
+		err = niu_enable_ldn_in_ldg(np, lp, on);
+		if (err)
+			return err;
+	}
+	for (i = 0; i < np->num_ldg; i++)
+		niu_ldg_rearm(np, &np->ldg[i], on);
+
+	return 0;
+}
+
+static u32 phy_encode(u32 type, int port)
+{
+	return (type << (port * 2));
+}
+
+static u32 phy_decode(u32 val, int port)
+{
+	return (val >> (port * 2)) & PORT_TYPE_MASK;
+}
+
+static int mdio_wait(struct niu *np)
+{
+	int limit = 1000;
+	u64 val;
+
+	while (--limit > 0) {
+		val = nr64(MIF_FRAME_OUTPUT);
+		if ((val >> MIF_FRAME_OUTPUT_TA_SHIFT) & 0x1)
+			return val & MIF_FRAME_OUTPUT_DATA;
+
+		udelay(10);
+	}
+
+	return -ENODEV;
+}
+
+static int mdio_read(struct niu *np, int port, int dev, int reg)
+{
+	int err;
+
+	nw64(MIF_FRAME_OUTPUT, MDIO_ADDR_OP(port, dev, reg));
+	err = mdio_wait(np);
+	if (err < 0)
+		return err;
+
+	nw64(MIF_FRAME_OUTPUT, MDIO_READ_OP(port, dev));
+	return mdio_wait(np);
+}
+
+static int mdio_write(struct niu *np, int port, int dev, int reg, int data)
+{
+	int err;
+
+	nw64(MIF_FRAME_OUTPUT, MDIO_ADDR_OP(port, dev, reg));
+	err = mdio_wait(np);
+	if (err < 0)
+		return err;
+
+	nw64(MIF_FRAME_OUTPUT, MDIO_WRITE_OP(port, dev, data));
+	err = mdio_wait(np);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
+static int mii_read(struct niu *np, int port, int reg)
+{
+	nw64(MIF_FRAME_OUTPUT, MII_READ_OP(port, reg));
+	return mdio_wait(np);
+}
+
+static int mii_write(struct niu *np, int port, int reg, int data)
+{
+	int err;
+
+	nw64(MIF_FRAME_OUTPUT, MII_WRITE_OP(port, reg, data));
+	err = mdio_wait(np);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
+static int esr2_set_tx_cfg(struct niu *np, unsigned long channel, u32 val)
+{
+	int err;
+
+	err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+			 ESR2_TI_PLL_TX_CFG_L(channel),
+			 val & 0xffff);
+	if (!err)
+		err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+				 ESR2_TI_PLL_TX_CFG_H(channel),
+				 val >> 16);
+	return err;
+}
+
+static int esr2_set_rx_cfg(struct niu *np, unsigned long channel, u32 val)
+{
+	int err;
+
+	err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+			 ESR2_TI_PLL_RX_CFG_L(channel),
+			 val & 0xffff);
+	if (!err)
+		err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+				 ESR2_TI_PLL_RX_CFG_H(channel),
+				 val >> 16);
+	return err;
+}
+
+/* Mode is always 10G fiber.  */
+static int serdes_init_niu(struct niu *np)
+{
+	struct niu_link_config *lp = &np->link_config;
+	u32 tx_cfg, rx_cfg;
+	unsigned long i;
+
+	tx_cfg = (PLL_TX_CFG_ENTX | PLL_TX_CFG_SWING_1375MV);
+	rx_cfg = (PLL_RX_CFG_ENRX | PLL_RX_CFG_TERM_0P8VDDT |
+		  PLL_RX_CFG_ALIGN_ENA | PLL_RX_CFG_LOS_LTHRESH |
+		  PLL_RX_CFG_EQ_LP_ADAPTIVE);
+
+	if (lp->loopback_mode == LOOPBACK_PHY) {
+		u16 test_cfg = PLL_TEST_CFG_LOOPBACK_CML_DIS;
+
+		mdio_write(np, np->port, NIU_ESR2_DEV_ADDR,
+			   ESR2_TI_PLL_TEST_CFG_L, test_cfg);
+
+		tx_cfg |= PLL_TX_CFG_ENTEST;
+		rx_cfg |= PLL_RX_CFG_ENTEST;
+	}
+
+	for (i = 0; i < 4; i++) {
+		int err = esr2_set_tx_cfg(np, i, tx_cfg);
+		if (err)
+			return err;
+	}
+
+	for (i = 0; i < 4; i++) {
+		int err = esr2_set_rx_cfg(np, i, rx_cfg);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
+static int esr_read_rxtx_ctrl(struct niu *np, unsigned long chan, u32 *val)
+{
+	int err;
+
+	err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR, ESR_RXTX_CTRL_L(chan));
+	if (err >= 0) {
+		*val = (err & 0xffff);
+		err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR,
+				ESR_RXTX_CTRL_H(chan));
+		if (err >= 0)
+			*val |= ((err & 0xffff) << 16);
+		err = 0;
+	}
+	return err;
+}
+
+static int esr_read_glue0(struct niu *np, unsigned long chan, u32 *val)
+{
+	int err;
+
+	err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR,
+			ESR_GLUE_CTRL0_L(chan));
+	if (err >= 0) {
+		*val = (err & 0xffff);
+		err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR,
+				ESR_GLUE_CTRL0_H(chan));
+		if (err >= 0) {
+			*val |= ((err & 0xffff) << 16);
+			err = 0;
+		}
+	}
+	return err;
+}
+
+static int esr_read_reset(struct niu *np, u32 *val)
+{
+	int err;
+
+	err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR,
+			ESR_RXTX_RESET_CTRL_L);
+	if (err >= 0) {
+		*val = (err & 0xffff);
+		err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR,
+				ESR_RXTX_RESET_CTRL_H);
+		if (err >= 0) {
+			*val |= ((err & 0xffff) << 16);
+			err = 0;
+		}
+	}
+	return err;
+}
+
+static int esr_write_rxtx_ctrl(struct niu *np, unsigned long chan, u32 val)
+{
+	int err;
+
+	err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR,
+			 ESR_RXTX_CTRL_L(chan), val & 0xffff);
+	if (!err)
+		err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR,
+				 ESR_RXTX_CTRL_H(chan), (val >> 16));
+	return err;
+}
+
+static int esr_write_glue0(struct niu *np, unsigned long chan, u32 val)
+{
+	int err;
+
+	err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR,
+			ESR_GLUE_CTRL0_L(chan), val & 0xffff);
+	if (!err)
+		err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR,
+				 ESR_GLUE_CTRL0_H(chan), (val >> 16));
+	return err;
+}
+
+static int esr_reset(struct niu *np)
+{
+	u32 reset;
+	int err;
+
+	err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR,
+			 ESR_RXTX_RESET_CTRL_L, 0x0000);
+	if (err)
+		return err;
+	err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR,
+			 ESR_RXTX_RESET_CTRL_H, 0xffff);
+	if (err)
+		return err;
+	udelay(200);
+
+	
+	err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR,
+			 ESR_RXTX_RESET_CTRL_L, 0xffff);
+	if (err)
+		return err;
+	udelay(200);
+
+	err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR,
+			 ESR_RXTX_RESET_CTRL_H, 0x0000);
+	if (err)
+		return err;
+	udelay(200);
+
+	err = esr_read_reset(np, &reset);
+	if (err)
+		return err;
+	if (reset != 0) {
+		printk(KERN_ERR PFX "Port %u ESR_RESET did not clear [%08x]\n",
+		       np->port, reset);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+static int serdes_init_10g(struct niu *np)
+{
+	struct niu_link_config *lp = &np->link_config;
+	unsigned long ctrl_reg, test_cfg_reg, i;
+	u64 ctrl_val, test_cfg_val, sig, mask, val;
+	int err;
+
+	switch (np->port) {
+	case 0:
+		ctrl_reg = ENET_SERDES_0_CTRL_CFG;
+		test_cfg_reg = ENET_SERDES_0_TEST_CFG;
+		break;
+	case 1:
+		ctrl_reg = ENET_SERDES_1_CTRL_CFG;
+		test_cfg_reg = ENET_SERDES_1_TEST_CFG;
+		break;
+
+	default:
+		return -EINVAL;
+	}
+	ctrl_val = (ENET_SERDES_CTRL_SDET_0 |
+		    ENET_SERDES_CTRL_SDET_1 |
+		    ENET_SERDES_CTRL_SDET_2 |
+		    ENET_SERDES_CTRL_SDET_3 |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT));
+	test_cfg_val = 0;
+
+	if (lp->loopback_mode == LOOPBACK_PHY) {
+		test_cfg_val |= ((ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_0_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_1_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_2_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_3_SHIFT));
+	}
+
+	nw64(ctrl_reg, ctrl_val);
+	nw64(test_cfg_reg, test_cfg_val);
+
+	for (i = 0; i < 4; i++) {
+		u32 rxtx_ctrl, glue0;
+		int err;
+
+		err = esr_read_rxtx_ctrl(np, i, &rxtx_ctrl);
+		if (err)
+			return err;
+		err = esr_read_glue0(np, i, &glue0);
+		if (err)
+			return err;
+
+		rxtx_ctrl &= ~(ESR_RXTX_CTRL_VMUXLO);
+		rxtx_ctrl |= (ESR_RXTX_CTRL_ENSTRETCH |
+			      (2 << ESR_RXTX_CTRL_VMUXLO_SHIFT));
+
+		glue0 &= ~(ESR_GLUE_CTRL0_SRATE |
+			   ESR_GLUE_CTRL0_THCNT |
+			   ESR_GLUE_CTRL0_BLTIME);
+		glue0 |= (ESR_GLUE_CTRL0_RXLOSENAB |
+			  (0xf << ESR_GLUE_CTRL0_SRATE_SHIFT) |
+			  (0xff << ESR_GLUE_CTRL0_THCNT_SHIFT) |
+			  (BLTIME_300_CYCLES <<
+			   ESR_GLUE_CTRL0_BLTIME_SHIFT));
+
+		err = esr_write_rxtx_ctrl(np, i, rxtx_ctrl);
+		if (err)
+			return err;
+		err = esr_write_glue0(np, i, glue0);
+		if (err)
+			return err;
+	}
+
+	err = esr_reset(np);
+	if (err)
+		return err;
+
+	sig = nr64(ESR_INT_SIGNALS);
+	switch (np->port) {
+	case 0:
+		mask = ESR_INT_SIGNALS_P0_BITS;
+		val = (ESR_INT_SRDY0_P0 |
+		       ESR_INT_DET0_P0 |
+		       ESR_INT_XSRDY_P0 |
+		       ESR_INT_XDP_P0_CH3 |
+		       ESR_INT_XDP_P0_CH2 |
+		       ESR_INT_XDP_P0_CH1 |
+		       ESR_INT_XDP_P0_CH0);
+		break;
+
+	case 1:
+		mask = ESR_INT_SIGNALS_P1_BITS;
+		val = (ESR_INT_SRDY0_P1 |
+		       ESR_INT_DET0_P1 |
+		       ESR_INT_XSRDY_P1 |
+		       ESR_INT_XDP_P1_CH3 |
+		       ESR_INT_XDP_P1_CH2 |
+		       ESR_INT_XDP_P1_CH1 |
+		       ESR_INT_XDP_P1_CH0);
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	if ((sig & mask) != val) {
+		printk(KERN_ERR PFX "Port %u signal bits [%08x] are not "
+		       "[%08x]\n", np->port, (int) (sig & mask), (int) val);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+static int serdes_init_1g(struct niu *np)
+{
+	u64 val;
+
+	val = nr64(ENET_SERDES_1_PLL_CFG);
+	val &= ~ENET_SERDES_PLL_FBDIV2;
+	switch (np->port) {
+	case 0:
+		val |= ENET_SERDES_PLL_HRATE0;
+		break;
+	case 1:
+		val |= ENET_SERDES_PLL_HRATE1;
+		break;
+	case 2:
+		val |= ENET_SERDES_PLL_HRATE2;
+		break;
+	case 3:
+		val |= ENET_SERDES_PLL_HRATE3;
+		break;
+	default:
+		return -EINVAL;
+	}
+	nw64(ENET_SERDES_1_PLL_CFG, val);
+
+	return 0;
+}
+
+static int bcm8704_reset(struct niu *np)
+{
+	int err, limit;
+
+	err = mdio_read(np, np->phy_addr,
+			BCM8704_PHYXS_DEV_ADDR, MII_BMCR);
+	if (err < 0)
+		return err;
+	err |= BMCR_RESET;
+	err = mdio_write(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
+			 MII_BMCR, err);
+	if (err)
+		return err;
+
+	limit = 1000;
+	while (--limit >= 0) {
+		err = mdio_read(np, np->phy_addr,
+				BCM8704_PHYXS_DEV_ADDR, MII_BMCR);
+		if (err < 0)
+			return err;
+		if (!(err & BMCR_RESET))
+			break;
+	}
+	if (limit < 0) {
+		printk(KERN_ERR PFX "Port %u PHY will not reset "
+		       "(bmcr=%04x)\n", np->port, (err & 0xffff));
+		return -ENODEV;
+	}
+	return 0;
+}
+
+/* When written, certain PHY registers need to be read back twice
+ * in order for the bits to settle properly.
+ */
+static int bcm8704_user_dev3_readback(struct niu *np, int reg)
+{
+	int err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, reg);
+	if (err < 0)
+		return err;
+	err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, reg);
+	if (err < 0)
+		return err;
+	return 0;
+}
+
+static int bcm8704_init_user_dev3(struct niu *np)
+{
+	int err;
+
+	err = mdio_write(np, np->phy_addr,
+			 BCM8704_USER_DEV3_ADDR, BCM8704_USER_CONTROL,
+			 (USER_CONTROL_OPTXRST_LVL |
+			  USER_CONTROL_OPBIASFLT_LVL |
+			  USER_CONTROL_OBTMPFLT_LVL |
+			  USER_CONTROL_OPPRFLT_LVL |
+			  USER_CONTROL_OPTXFLT_LVL |
+			  USER_CONTROL_OPRXLOS_LVL |
+			  USER_CONTROL_OPRXFLT_LVL |
+			  USER_CONTROL_OPTXON_LVL |
+			  (0x3f << USER_CONTROL_RES1_SHIFT)));
+	if (err)
+		return err;
+
+	err = mdio_write(np, np->phy_addr,
+			 BCM8704_USER_DEV3_ADDR, BCM8704_USER_PMD_TX_CONTROL,
+			 (USER_PMD_TX_CTL_XFP_CLKEN |
+			  (1 << USER_PMD_TX_CTL_TX_DAC_TXD_SH) |
+			  (2 << USER_PMD_TX_CTL_TX_DAC_TXCK_SH) |
+			  USER_PMD_TX_CTL_TSCK_LPWREN));
+	if (err)
+		return err;
+
+	err = bcm8704_user_dev3_readback(np, BCM8704_USER_CONTROL);
+	if (err)
+		return err;
+	err = bcm8704_user_dev3_readback(np, BCM8704_USER_PMD_TX_CONTROL);
+	if (err)
+		return err;
+
+	err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
+			BCM8704_USER_OPT_DIGITAL_CTRL);
+	if (err < 0)
+		return err;
+	err &= ~USER_ODIG_CTRL_GPIOS;
+	err |= (0x3 << USER_ODIG_CTRL_GPIOS_SHIFT);
+	err = mdio_write(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
+			 BCM8704_USER_OPT_DIGITAL_CTRL, err);
+	if (err)
+		return err;
+
+	udelay(1000000);
+
+	return 0;
+}
+
+static int xcvr_init_10g(struct niu *np)
+{
+	struct niu_link_config *lp = &np->link_config;
+	u16 analog_stat0, tx_alarm_status;
+	int err;
+	u64 val;
+
+	val = nr64_mac(XMAC_CONFIG);
+	val &= ~XMAC_CONFIG_LED_POLARITY;
+	val |= XMAC_CONFIG_FORCE_LED_ON;
+	nw64_mac(XMAC_CONFIG, val);
+
+	/* XXX shared resource, lock parent XXX */
+	val = nr64(MIF_CONFIG);
+	val |= MIF_CONFIG_INDIRECT_MODE;
+	nw64(MIF_CONFIG, val);
+
+	err = bcm8704_reset(np);
+	if (err)
+		return err;
+
+	err = bcm8704_init_user_dev3(np);
+	if (err)
+		return err;
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
+			MII_BMCR);
+	if (err < 0)
+		return err;
+	err &= ~BMCR_LOOPBACK;
+
+	if (lp->loopback_mode == LOOPBACK_MAC)
+		err |= BMCR_LOOPBACK;
+
+	err = mdio_write(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
+			 MII_BMCR, err);

drivers/net/niu.c line 857

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+	if (err)
+		return err;
+
+#if 1
+	err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
+			MII_STAT1000);
+	if (err < 0)
+		return err;
+	printk(KERN_INFO PFX "Port %u PMA_PMD(MII_STAT1000) [%04x]\n",
+	       np->port, err);

pr_info() ?

drivers/net/niu.c line 863

Quoted 6 lines
drivers/net/niu.c new file +6 -0
+
+	err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, 0x20);
+	if (err < 0)
+		return err;
+	printk(KERN_INFO PFX "Port %u USER_DEV3(0x20) [%04x]\n",
+	       np->port, err);

pr_info() ?

Quoted 24 lines
drivers/net/niu.c new file +24 -0
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
+			MII_NWAYTEST);
+	if (err < 0)
+		return err;
+	printk(KERN_INFO PFX "Port %u PHYXS(MII_NWAYTEST) [%04x]\n",
+	       np->port, err);
+#endif
+
+	/* XXX dig this out it might not be so useful XXX */
+	err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
+			BCM8704_USER_ANALOG_STATUS0);
+	if (err < 0)
+		return err;
+	err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
+			BCM8704_USER_ANALOG_STATUS0);
+	if (err < 0)
+		return err;
+	analog_stat0 = err;
+
+	err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
+			BCM8704_USER_TX_ALARM_STATUS);
+	if (err < 0)
+		return err;

drivers/net/niu.c line 897

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+	err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
+			BCM8704_USER_TX_ALARM_STATUS);
+	if (err < 0)
+		return err;
+	tx_alarm_status = err;
+
+	if (analog_stat0 != 0x03fc) {
+		if ((analog_stat0 == 0x43bc) && (tx_alarm_status != 0)) {
+			printk(KERN_INFO PFX "Port %u cable not connected "
+			       "or bad cable.\n", np->port);

pr_info() ?

drivers/net/niu.c line 900

Quoted 3 lines
drivers/net/niu.c new file +3 -0
+		} else if (analog_stat0 == 0x639c) {
+			printk(KERN_INFO PFX "Port %u optical module is bad "
+			       "or missing.\n", np->port);

pr_info() ?

Quoted 173 lines
drivers/net/niu.c new file +173 -0
+		}
+	}
+
+	return 0;
+}
+
+static int mii_reset(struct niu *np)
+{
+	int limit, err;
+
+	err = mii_write(np, np->phy_addr, MII_BMCR, BMCR_RESET);
+
+	limit = 1000;
+	while (--limit >= 0) {
+		err = mii_read(np, np->phy_addr, MII_BMCR);
+		if (err < 0)
+			return err;
+		if (!(err & BMCR_RESET))
+			break;
+	}
+	if (limit < 0) {
+		printk(KERN_ERR PFX "Port %u MII would not reset, "
+		       "bmcr[%04x]\n", np->port, err);
+		return -ENODEV;
+	}
+
+	err = mii_write(np, np->phy_addr, MII_BMCR, 0);
+	if (err)
+		return err;
+
+	return 0;
+}
+
+static int mii_init_common(struct niu *np)
+{
+	struct niu_link_config *lp = &np->link_config;
+	u16 bmcr, bmsr, adv, estat;
+	int err;
+
+	err = mii_reset(np);
+	if (err)
+		return err;
+
+	err = mii_read(np, np->phy_addr, MII_BMSR);
+	if (err < 0)
+		return err;
+	bmsr = err;
+
+	estat = 0;
+	if (bmsr & BMSR_ESTATEN) {
+		err = mii_read(np, np->phy_addr, MII_ESTATUS);
+		if (err < 0)
+			return err;
+		estat = err;
+	}
+
+	bmcr = 0;
+
+	if (lp->loopback_mode == LOOPBACK_MAC) {
+		bmcr |= BMCR_LOOPBACK;
+		bmcr &= ~BMCR_ANENABLE;
+		if (lp->active_speed == SPEED_1000)
+			bmcr |= BMCR_SPEED1000;
+		if (lp->active_duplex == DUPLEX_FULL)
+			bmcr |= BMCR_FULLDPLX;
+	} else {
+		bmcr &= ~BMCR_LOOPBACK;
+	}
+	if (lp->loopback_mode == LOOPBACK_PHY) {
+		u16 aux;
+
+		aux = (BCM5464R_AUX_CTL_EXT_LB |
+		       BCM5464R_AUX_CTL_WRITE_1);
+		err = mii_write(np, np->phy_addr, BCM5464R_AUX_CTL, aux);
+		if (err)
+			return err;
+	}
+
+	/* XXX configurable XXX */
+	adv = 0;
+	if (bmsr & BMSR_10HALF)
+		adv |= ADVERTISE_10HALF;
+	if (bmsr & BMSR_10FULL)
+		adv |= ADVERTISE_10FULL;
+	if (bmsr & BMSR_100HALF)
+		adv |= ADVERTISE_100HALF;
+	if (bmsr & BMSR_100FULL)
+		adv |= ADVERTISE_100FULL;
+	if (bmsr & BMSR_100BASE4)
+		adv |= ADVERTISE_100BASE4;
+	adv |= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
+	err = mii_write(np, np->phy_addr, MII_ADVERTISE, adv);
+	if (err)
+		return err;
+
+	if (bmsr & BMSR_ESTATEN) {
+		u16 ctrl1000;
+
+		ctrl1000 = (BCM5464R_CTRL1000_AS_MASTER |
+			    BCM5464R_CTRL1000_ENABLE_AS_MASTER);
+		if (estat & ESTATUS_1000_TFULL)
+			ctrl1000 |= ADVERTISE_1000FULL;
+		if (estat & ESTATUS_1000_THALF)
+			ctrl1000 |= ADVERTISE_1000HALF;
+		err = mii_write(np, np->phy_addr, MII_CTRL1000, ctrl1000);
+		if (err)
+			return err;
+	}
+	bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
+
+	err = mii_write(np, np->phy_addr, MII_BMCR, bmcr);
+	if (err)
+		return err;
+
+	err = mii_read(np, np->phy_addr, MII_BMCR);
+	if (err < 0)
+		return err;
+	err = mii_read(np, np->phy_addr, MII_BMSR);
+	if (err < 0)
+		return err;
+#if 0
+	printk(KERN_ERR PFX "Port %u after MII init bmcr[%04x] bmsr[%04x]\n",
+	       np->port, bmcr, bmsr);
+#endif
+
+	return 0;
+}
+
+static int xcvr_init_1g(struct niu *np)
+{
+	u64 val;
+
+	/* XXX shared resource, lock parent XXX */
+	val = nr64(MIF_CONFIG);
+	val &= ~MIF_CONFIG_INDIRECT_MODE;
+	nw64(MIF_CONFIG, val);
+
+	return mii_init_common(np);
+}
+
+static int niu_xcvr_init(struct niu *np)
+{
+	const struct niu_phy_ops *ops = np->phy_ops;
+	int err;
+
+	err = 0;
+	if (ops->xcvr_init)
+		err = ops->xcvr_init(np);
+
+	return err;
+}
+
+static int niu_serdes_init(struct niu *np)
+{
+	const struct niu_phy_ops *ops = np->phy_ops;
+	int err;
+
+	err = 0;
+	if (ops->serdes_init)
+		err = ops->serdes_init(np);
+
+	return err;
+}
+
+static void niu_init_xif(struct niu *);
+
+static int niu_link_status_common(struct niu *np, int link_up)
+{
+	struct niu_link_config *lp = &np->link_config;
+	struct net_device *dev = np->dev;
+	unsigned long flags;
+
+	if (!netif_carrier_ok(dev) && link_up) {

drivers/net/niu.c line 1083

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+		printk(KERN_INFO PFX "%s: Link is up at %s, %s duplex\n",
+		       dev->name,
+		       (lp->active_speed == SPEED_10000 ?
+			"10Gb/sec" :
+			(lp->active_speed == SPEED_1000 ?
+			 "1Gb/sec" :
+			 (lp->active_speed == SPEED_100 ?
+			  "100Mbit/sec" : "10Mbit/sec"))),
+		       (lp->active_duplex == DUPLEX_FULL ?
+			"full" : "half"));

pr_info() ?

Quoted 1,053 lines
drivers/net/niu.c new file +1053 -0
+
+		spin_lock_irqsave(&np->lock, flags);
+		niu_init_xif(np);
+		spin_unlock_irqrestore(&np->lock, flags);
+
+		netif_carrier_on(dev);
+	} else if (netif_carrier_ok(dev) && !link_up) {
+		printk(KERN_WARNING PFX "%s: Link is down\n", dev->name);
+		netif_carrier_off(dev);
+	}
+
+	return 0;
+}
+
+static int link_status_10g(struct niu *np, int *link_up_p)
+{
+	unsigned long flags;
+	int err, link_up;
+
+	if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
+		return -EINVAL;
+
+	link_up = 0;
+
+	spin_lock_irqsave(&np->lock, flags);
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
+			BCM8704_PMD_RCV_SIGDET);
+	if (err < 0)
+		return err;
+	if (!(err & PMD_RCV_SIGDET_GLOBAL))
+		goto out;
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
+			BCM8704_PCS_10G_R_STATUS);
+	if (err < 0)
+		return err;
+	if (!(err & PCS_10G_R_STATUS_BLK_LOCK))
+		goto out;
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
+			BCM8704_PHYXS_XGXS_LANE_STAT);
+	if (err < 0)
+		return err;
+
+	if (err != (PHYXS_XGXS_LANE_STAT_ALINGED |
+		    PHYXS_XGXS_LANE_STAT_MAGIC |
+		    PHYXS_XGXS_LANE_STAT_LANE3 |
+		    PHYXS_XGXS_LANE_STAT_LANE2 |
+		    PHYXS_XGXS_LANE_STAT_LANE1 |
+		    PHYXS_XGXS_LANE_STAT_LANE0))
+		goto out;
+
+	link_up = 1;
+	np->link_config.active_speed = SPEED_10000;
+	np->link_config.active_duplex = DUPLEX_FULL;
+
+out:
+	spin_unlock_irqrestore(&np->lock, flags);
+
+	*link_up_p = link_up;
+	return 0;
+}
+
+static int link_status_1g(struct niu *np, int *link_up_p)
+{
+	u16 current_speed, bmsr;
+	unsigned long flags;
+	u8 current_duplex;
+	int err, link_up;
+
+	if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
+		return -EINVAL;
+
+	link_up = 0;
+	current_speed = SPEED_INVALID;
+	current_duplex = DUPLEX_INVALID;
+
+	spin_lock_irqsave(&np->lock, flags);
+
+	err = mii_read(np, np->phy_addr, MII_BMSR);
+	if (err < 0)
+		goto out;
+
+	bmsr = err;
+	if (bmsr & BMSR_LSTATUS) {
+		u16 adv, lpa, common, estat;
+
+		err = mii_read(np, np->phy_addr, MII_ADVERTISE);
+		if (err < 0)
+			goto out;
+		adv = err;
+
+		err = mii_read(np, np->phy_addr, MII_LPA);
+		if (err < 0)
+			goto out;
+		lpa = err;
+
+		common = adv & lpa;
+
+		err = mii_read(np, np->phy_addr, MII_ESTATUS);
+		if (err < 0)
+			goto out;
+		estat = err;
+
+		if (estat & (ESTATUS_1000_TFULL | ESTATUS_1000_THALF)) {
+			current_speed = SPEED_1000;
+			if (estat == ESTATUS_1000_TFULL)
+				current_duplex = DUPLEX_FULL;
+			else
+				current_duplex = DUPLEX_HALF;
+		} else {
+			if (common & ADVERTISE_100BASE4) {
+				current_speed = SPEED_100;
+				current_duplex = DUPLEX_HALF;
+			} else if (common & ADVERTISE_100FULL) {
+				current_speed = SPEED_100;
+				current_duplex = DUPLEX_FULL;
+			} else if (common & ADVERTISE_100HALF) {
+				current_speed = SPEED_100;
+				current_duplex = DUPLEX_HALF;
+			} else if (common & ADVERTISE_10FULL) {
+				current_speed = SPEED_10;
+				current_duplex = DUPLEX_FULL;
+			} else if (common & ADVERTISE_10HALF) {
+				current_speed = SPEED_10;
+				current_duplex = DUPLEX_HALF;
+			} else
+				goto out;
+		}
+		link_up = 1;
+	}
+
+out:
+	spin_unlock_irqrestore(&np->lock, flags);
+
+	*link_up_p = link_up;
+	return 0;
+}
+
+static int niu_link_status(struct niu *np, int *link_up_p)
+{
+	const struct niu_phy_ops *ops = np->phy_ops;
+	int err;
+
+	err = 0;
+	if (ops->link_status)
+		err = ops->link_status(np, link_up_p);
+
+	return err;
+}
+
+static void niu_timer(unsigned long __opaque)
+{
+	struct niu *np = (struct niu *) __opaque;
+	unsigned long off;
+	int err, link_up;
+
+	err = niu_link_status(np, &link_up);
+	if (!err)
+		niu_link_status_common(np, link_up);
+
+	if (netif_carrier_ok(np->dev))
+		off = 5 * HZ;
+	else
+		off = 1 * HZ;
+	np->timer.expires = jiffies + off;
+
+	add_timer(&np->timer);
+}
+
+static const struct niu_phy_ops phy_ops_10g_fiber_niu = {
+	.serdes_init		= serdes_init_niu,
+	.xcvr_init		= xcvr_init_10g,
+	.link_status		= link_status_10g,
+};
+
+static const struct niu_phy_ops phy_ops_10g_fiber = {
+	.serdes_init		= serdes_init_10g,
+	.xcvr_init		= xcvr_init_10g,
+	.link_status		= link_status_10g,
+};
+
+static const struct niu_phy_ops phy_ops_10g_copper = {
+	.serdes_init		= serdes_init_10g,
+	.link_status		= link_status_10g, /* XXX */
+};
+
+static const struct niu_phy_ops phy_ops_1g_fiber = {
+	.serdes_init		= serdes_init_1g,
+	.xcvr_init		= xcvr_init_1g,
+	.link_status		= link_status_1g,
+};
+
+static const struct niu_phy_ops phy_ops_1g_copper = {
+	.xcvr_init		= xcvr_init_1g,
+	.link_status		= link_status_1g,
+};
+
+struct niu_phy_template {
+	const struct niu_phy_ops	*ops;
+	u32				phy_addr_base;
+};
+
+static const struct niu_phy_template phy_template_niu = {
+	.ops		= &phy_ops_10g_fiber_niu,
+	.phy_addr_base	= 16,
+};
+
+static const struct niu_phy_template phy_template_10g_fiber = {
+	.ops		= &phy_ops_10g_fiber,
+	.phy_addr_base	= 8,
+};
+
+static const struct niu_phy_template phy_template_10g_copper = {
+	.ops		= &phy_ops_10g_copper,
+	.phy_addr_base	= 10,
+};
+
+static const struct niu_phy_template phy_template_1g_fiber = {
+	.ops		= &phy_ops_1g_fiber,
+	.phy_addr_base	= 0,
+};
+
+static const struct niu_phy_template phy_template_1g_copper = {
+	.ops		= &phy_ops_1g_copper,
+	.phy_addr_base	= 0,
+};
+
+static int niu_determine_phy_disposition(struct niu *np)
+{
+	struct niu_parent *parent = np->parent;
+	u8 plat_type = parent->plat_type;
+	const struct niu_phy_template *tp;
+	u32 phy_addr_off = 0;
+
+	if (plat_type == PLAT_TYPE_NIU) {
+		tp = &phy_template_niu;
+		phy_addr_off += np->port;
+	} else {
+		switch (np->flags & (NIU_FLAGS_10G | NIU_FLAGS_FIBER)) {
+		case 0:
+			/* 1G copper */
+			tp = &phy_template_1g_copper;
+			if (plat_type == PLAT_TYPE_VF_P0)
+				phy_addr_off = 10;
+			else if (plat_type == PLAT_TYPE_VF_P1)
+				phy_addr_off = 26;
+
+			phy_addr_off += (np->port ^ 0x3);
+			break;
+
+		case NIU_FLAGS_10G:
+			/* 10G copper */
+			tp = &phy_template_1g_copper;
+			break;
+
+		case NIU_FLAGS_FIBER:
+			/* 1G fiber */
+			tp = &phy_template_1g_fiber;
+			break;
+
+		case NIU_FLAGS_10G | NIU_FLAGS_FIBER:
+			/* 10G fiber */
+			tp = &phy_template_10g_fiber;
+			if (plat_type == PLAT_TYPE_VF_P0 ||
+			    plat_type == PLAT_TYPE_VF_P1)
+				phy_addr_off = 8;
+			phy_addr_off += np->port;
+			break;
+
+		default:
+			return -EINVAL;
+		}
+	}
+
+	np->phy_ops = tp->ops;
+	np->phy_addr = tp->phy_addr_base + phy_addr_off;
+
+	return 0;
+}
+
+static int niu_init_link(struct niu *np)
+{
+	struct niu_parent *parent = np->parent;
+	int err, ignore;
+
+	if (parent->plat_type == PLAT_TYPE_NIU) {
+		err = niu_xcvr_init(np);
+		if (err)
+			return err;
+		msleep(200);
+	}
+	err = niu_serdes_init(np);
+	if (err)
+		return err;
+	msleep(200);
+	err = niu_xcvr_init(np);
+	if (!err)
+		niu_link_status(np, &ignore);
+	return 0;
+}
+
+static void niu_set_primary_mac(struct niu *np, unsigned char *addr)
+{
+	u16 reg0 = addr[4] << 8 | addr[5];
+	u16 reg1 = addr[2] << 8 | addr[3];
+	u16 reg2 = addr[0] << 8 | addr[1];
+
+	if (np->flags & NIU_FLAGS_XMAC) {
+		nw64_mac(XMAC_ADDR0, reg0);
+		nw64_mac(XMAC_ADDR1, reg1);
+		nw64_mac(XMAC_ADDR2, reg2);
+	} else {
+		nw64_mac(BMAC_ADDR0, reg0);
+		nw64_mac(BMAC_ADDR1, reg1);
+		nw64_mac(BMAC_ADDR2, reg2);
+	}
+}
+
+static int niu_num_alt_addr(struct niu *np)
+{
+	if (np->flags & NIU_FLAGS_XMAC)
+		return XMAC_NUM_ALT_ADDR;
+	else
+		return BMAC_NUM_ALT_ADDR;
+}
+
+static int niu_set_alt_mac(struct niu *np, int index, unsigned char *addr)
+{
+	u16 reg0 = addr[4] << 8 | addr[5];
+	u16 reg1 = addr[2] << 8 | addr[3];
+	u16 reg2 = addr[0] << 8 | addr[1];
+
+	if (index >= niu_num_alt_addr(np))
+		return -EINVAL;
+
+	if (np->flags & NIU_FLAGS_XMAC) {
+		nw64_mac(XMAC_ALT_ADDR0(index), reg0);
+		nw64_mac(XMAC_ALT_ADDR1(index), reg1);
+		nw64_mac(XMAC_ALT_ADDR2(index), reg2);
+	} else {
+		nw64_mac(BMAC_ALT_ADDR0(index), reg0);
+		nw64_mac(BMAC_ALT_ADDR1(index), reg1);
+		nw64_mac(BMAC_ALT_ADDR2(index), reg2);
+	}
+
+	return 0;
+}
+
+static int niu_enable_alt_mac(struct niu *np, int index, int on)
+{
+	unsigned long reg;
+	u64 val, mask;
+
+	if (index >= niu_num_alt_addr(np))
+		return -EINVAL;
+
+	if (np->flags & NIU_FLAGS_XMAC)
+		reg = XMAC_ADDR_CMPEN;
+	else
+		reg = BMAC_ADDR_CMPEN;
+
+	mask = 1 << index;
+
+	val = nr64_mac(reg);
+	if (on)
+		val |= mask;
+	else
+		val &= ~mask;
+	nw64_mac(reg, val);
+
+	return 0;
+}
+
+static void __set_rdc_table_num_hw(struct niu *np, unsigned long reg,
+				   int num, int mac_pref)
+{
+	u64 val = nr64_mac(reg);
+	val &= ~(HOST_INFO_MACRDCTBLN | HOST_INFO_MPR);
+	val |= num;
+	if (mac_pref)
+		val |= HOST_INFO_MPR;
+	nw64_mac(reg, val);
+}
+
+static int __set_rdc_table_num(struct niu *np,
+			       int xmac_index, int bmac_index,
+			       int rdc_table_num, int mac_pref)
+{
+	unsigned long reg;
+
+	if (rdc_table_num & ~HOST_INFO_MACRDCTBLN)
+		return -EINVAL;
+	if (np->flags & NIU_FLAGS_XMAC)
+		reg = XMAC_HOST_INFO(xmac_index);
+	else
+		reg = BMAC_HOST_INFO(bmac_index);
+	__set_rdc_table_num_hw(np, reg, rdc_table_num, mac_pref);
+	return 0;
+}
+
+static int niu_set_primary_mac_rdc_table(struct niu *np, int table_num,
+					 int mac_pref)
+{
+	return __set_rdc_table_num(np, 17, 0, table_num, mac_pref);
+}
+
+static int niu_set_multicast_mac_rdc_table(struct niu *np, int table_num,
+					   int mac_pref)
+{
+	return __set_rdc_table_num(np, 16, 8, table_num, mac_pref);
+}
+
+static int niu_set_alt_mac_rdc_table(struct niu *np, int idx,
+				     int table_num, int mac_pref)
+{
+	if (idx >= niu_num_alt_addr(np))
+		return -EINVAL;
+	return __set_rdc_table_num(np, idx, idx + 1, table_num, mac_pref);
+}
+
+static u64 vlan_entry_set_parity(u64 reg_val)
+{
+	u64 port01_mask;
+	u64 port23_mask;
+
+	port01_mask = 0x00ff;
+	port23_mask = 0xff00;
+
+	if (hweight64(reg_val & port01_mask) & 1)
+		reg_val |= ENET_VLAN_TBL_PARITY0;
+	else
+		reg_val &= ~ENET_VLAN_TBL_PARITY0;
+
+	if (hweight64(reg_val & port23_mask) & 1)
+		reg_val |= ENET_VLAN_TBL_PARITY1;
+	else
+		reg_val &= ~ENET_VLAN_TBL_PARITY1;
+
+	return reg_val;
+}
+
+static void vlan_tbl_write(struct niu *np, unsigned long index,
+			   int port, int vpr, int rdc_table)
+{
+	u64 reg_val = nr64(ENET_VLAN_TBL(index));
+
+	reg_val &= ~((ENET_VLAN_TBL_VPR |
+		      ENET_VLAN_TBL_VLANRDCTBLN) <<
+		     ENET_VLAN_TBL_SHIFT(port));
+	if (vpr)
+		reg_val |= (ENET_VLAN_TBL_VPR <<
+			    ENET_VLAN_TBL_SHIFT(port));
+	reg_val |= (rdc_table << ENET_VLAN_TBL_SHIFT(port));
+
+	reg_val = vlan_entry_set_parity(reg_val);
+
+	nw64(ENET_VLAN_TBL(index), reg_val);
+}
+
+static void vlan_tbl_clear(struct niu *np)
+{
+	int i;
+
+	for (i = 0; i < ENET_VLAN_TBL_NUM_ENTRIES; i++)
+		nw64(ENET_VLAN_TBL(i), 0);
+}
+
+static int tcam_wait_bit(struct niu *np, u64 bit)
+{
+	int limit = 1000;
+
+	while (--limit > 0) {
+		if (nr64(TCAM_CTL) & bit)
+			break;
+		udelay(1);
+	}
+	if (limit < 0)
+		return -ENODEV;
+
+	return 0;
+}
+
+static int tcam_flush(struct niu *np, int index)
+{
+	nw64(TCAM_KEY_0, 0x00);
+	nw64(TCAM_KEY_MASK_0, 0xff);
+	nw64(TCAM_CTL, (TCAM_CTL_RWC_TCAM_WRITE | index));
+
+	return tcam_wait_bit(np, TCAM_CTL_STAT);
+}
+
+#if 0
+static int tcam_read(struct niu *np, int index,
+		     u64 *key, u64 *mask)
+{
+	int err;
+
+	nw64(TCAM_CTL, (TCAM_CTL_RWC_TCAM_READ | index));
+	err = tcam_wait_bit(np, TCAM_CTL_STAT);
+	if (!err) {
+		key[0] = nr64(TCAM_KEY_0);
+		key[1] = nr64(TCAM_KEY_1);
+		key[2] = nr64(TCAM_KEY_2);
+		key[3] = nr64(TCAM_KEY_3);
+		mask[0] = nr64(TCAM_KEY_MASK_0);
+		mask[1] = nr64(TCAM_KEY_MASK_1);
+		mask[2] = nr64(TCAM_KEY_MASK_2);
+		mask[3] = nr64(TCAM_KEY_MASK_3);
+	}
+	return err;
+}
+#endif
+
+static int tcam_write(struct niu *np, int index,
+		      u64 *key, u64 *mask)
+{
+	nw64(TCAM_KEY_0, key[0]);
+	nw64(TCAM_KEY_1, key[1]);
+	nw64(TCAM_KEY_2, key[2]);
+	nw64(TCAM_KEY_3, key[3]);
+	nw64(TCAM_KEY_MASK_0, mask[0]);
+	nw64(TCAM_KEY_MASK_1, mask[1]);
+	nw64(TCAM_KEY_MASK_2, mask[2]);
+	nw64(TCAM_KEY_MASK_3, mask[3]);
+	nw64(TCAM_CTL, (TCAM_CTL_RWC_TCAM_WRITE | index));
+
+	return tcam_wait_bit(np, TCAM_CTL_STAT);
+}
+
+#if 0
+static int tcam_assoc_read(struct niu *np, int index, u64 *data)
+{
+	int err;
+
+	nw64(TCAM_CTL, (TCAM_CTL_RWC_RAM_READ | index));
+	err = tcam_wait_bit(np, TCAM_CTL_STAT);
+	if (!err)
+		*data = nr64(TCAM_KEY_1);
+
+	return err;
+}
+#endif
+
+static int tcam_assoc_write(struct niu *np, int index, u64 assoc_data)
+{
+	nw64(TCAM_KEY_1, assoc_data);
+	nw64(TCAM_CTL, (TCAM_CTL_RWC_RAM_WRITE | index));
+
+	return tcam_wait_bit(np, TCAM_CTL_STAT);
+}
+
+static void tcam_enable(struct niu *np, int on)
+{
+	u64 val = nr64(FFLP_CFG_1);
+
+	if (on)
+		val &= ~FFLP_CFG_1_TCAM_DIS;
+	else
+		val |= FFLP_CFG_1_TCAM_DIS;
+	nw64(FFLP_CFG_1, val);
+}
+
+static void tcam_set_lat_and_ratio(struct niu *np, u64 latency, u64 ratio)
+{
+	u64 val = nr64(FFLP_CFG_1);
+
+	val &= ~(FFLP_CFG_1_FFLPINITDONE |
+		 FFLP_CFG_1_CAMLAT |
+		 FFLP_CFG_1_CAMRATIO);
+	val |= (latency << FFLP_CFG_1_CAMLAT_SHIFT);
+	val |= (ratio << FFLP_CFG_1_CAMRATIO_SHIFT);
+	nw64(FFLP_CFG_1, val);
+
+	val = nr64(FFLP_CFG_1);
+	val |= FFLP_CFG_1_FFLPINITDONE;
+	nw64(FFLP_CFG_1, val);
+}
+
+static int tcam_user_eth_class_enable(struct niu *np, unsigned long class,
+				      int on)
+{
+	unsigned long reg;
+	u64 val;
+
+	if (class < CLASS_CODE_ETHERTYPE1 ||
+	    class > CLASS_CODE_ETHERTYPE2)
+		return -EINVAL;
+
+	reg = L2_CLS(class - CLASS_CODE_ETHERTYPE1);
+	val = nr64(reg);
+	if (on)
+		val |= L2_CLS_VLD;
+	else
+		val &= ~L2_CLS_VLD;
+	nw64(reg, val);
+
+	return 0;
+}
+
+#if 0
+static int tcam_user_eth_class_set(struct niu *np, unsigned long class,
+				   u64 ether_type)
+{
+	unsigned long reg;
+	u64 val;
+
+	if (class < CLASS_CODE_ETHERTYPE1 ||
+	    class > CLASS_CODE_ETHERTYPE2 ||
+	    (ether_type & ~(u64)0xffff) != 0)
+		return -EINVAL;
+
+	reg = L2_CLS(class - CLASS_CODE_ETHERTYPE1);
+	val = nr64(reg);
+	val &= ~L2_CLS_ETYPE;
+	val |= (ether_type << L2_CLS_ETYPE_SHIFT);
+	nw64(reg, val);
+
+	return 0;
+}
+#endif
+
+static int tcam_user_ip_class_enable(struct niu *np, unsigned long class,
+				     int on)
+{
+	unsigned long reg;
+	u64 val;
+
+	if (class < CLASS_CODE_USER_PROG1 ||
+	    class > CLASS_CODE_USER_PROG4)
+		return -EINVAL;
+
+	reg = L3_CLS(class - CLASS_CODE_USER_PROG1);
+	val = nr64(reg);
+	if (on)
+		val |= L3_CLS_VALID;
+	else
+		val &= ~L3_CLS_VALID;
+	nw64(reg, val);
+
+	return 0;
+}
+
+#if 0
+static int tcam_user_ip_class_set(struct niu *np, unsigned long class,
+				  int ipv6, u64 protocol_id,
+				  u64 tos_mask, u64 tos_val)
+{
+	unsigned long reg;
+	u64 val;
+
+	if (class < CLASS_CODE_USER_PROG1 ||
+	    class > CLASS_CODE_USER_PROG4 ||
+	    (protocol_id & ~(u64)0xff) != 0 ||
+	    (tos_mask & ~(u64)0xff) != 0 ||
+	    (tos_val & ~(u64)0xff) != 0)
+		return -EINVAL;
+
+	reg = L3_CLS(class - CLASS_CODE_USER_PROG1);
+	val = nr64(reg);
+	val &= ~(L3_CLS_IPVER | L3_CLS_PID |
+		 L3_CLS_TOSMASK | L3_CLS_TOS);
+	if (ipv6)
+		val |= L3_CLS_IPVER;
+	val |= (protocol_id << L3_CLS_PID_SHIFT);
+	val |= (tos_mask << L3_CLS_TOSMASK_SHIFT);
+	val |= (tos_val << L3_CLS_TOS_SHIFT);
+	nw64(reg, val);
+
+	return 0;
+}
+#endif
+
+static int tcam_early_init(struct niu *np)
+{
+	unsigned long i;
+	int err;
+
+	tcam_enable(np, 0);
+	tcam_set_lat_and_ratio(np,
+			       DEFAULT_TCAM_LATENCY,
+			       DEFAULT_TCAM_ACCESS_RATIO);
+	for (i = CLASS_CODE_ETHERTYPE1; i <= CLASS_CODE_ETHERTYPE2; i++) {
+		err = tcam_user_eth_class_enable(np, i, 0);
+		if (err)
+			return err;
+	}
+	for (i = CLASS_CODE_USER_PROG1; i <= CLASS_CODE_USER_PROG4; i++) {
+		err = tcam_user_ip_class_enable(np, i, 0);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
+static int tcam_flush_all(struct niu *np)
+{
+	unsigned long i;
+
+	for (i = 0; i < np->parent->tcam_num_entries; i++) {
+		int err = tcam_flush(np, i);
+		if (err)
+			return err;
+	}
+	return 0;
+}
+
+static u64 hash_addr_regval(unsigned long index, unsigned long num_entries)
+{
+	return ((u64)index | (num_entries == 1 ?
+			      HASH_TBL_ADDR_AUTOINC : 0));
+}
+
+#if 0
+static int hash_read(struct niu *np, unsigned long partition,
+		     unsigned long index, unsigned long num_entries,
+		     u64 *data)
+{
+	u64 val = hash_addr_regval(index, num_entries);
+	unsigned long i;
+
+	if (partition >= FCRAM_NUM_PARTITIONS ||
+	    index + num_entries > FCRAM_SIZE)
+		return -EINVAL;
+
+	nw64(HASH_TBL_ADDR(partition), val);
+	for (i = 0; i < num_entries; i++)
+		data[i] = nr64(HASH_TBL_DATA(partition));
+
+	return 0;
+}
+#endif
+
+static int hash_write(struct niu *np, unsigned long partition,
+		      unsigned long index, unsigned long num_entries,
+		      u64 *data)
+{
+	u64 val = hash_addr_regval(index, num_entries);
+	unsigned long i;
+
+	if (partition >= FCRAM_NUM_PARTITIONS ||
+	    index + (num_entries * 8) > FCRAM_SIZE)
+		return -EINVAL;
+
+	nw64(HASH_TBL_ADDR(partition), val);
+	for (i = 0; i < num_entries; i++)
+		nw64(HASH_TBL_DATA(partition), data[i]);
+
+	return 0;
+}
+		       
+static void fflp_reset(struct niu *np)
+{
+	u64 val;
+
+	nw64(FFLP_CFG_1, FFLP_CFG_1_PIO_FIO_RST);
+	udelay(10);
+	nw64(FFLP_CFG_1, 0);
+
+	val = FFLP_CFG_1_FCRAMOUTDR_NORMAL | FFLP_CFG_1_FFLPINITDONE;
+	nw64(FFLP_CFG_1, val);
+}
+
+static void fflp_set_timings(struct niu *np)
+{
+	u64 val = nr64(FFLP_CFG_1);
+
+	val &= ~FFLP_CFG_1_FFLPINITDONE;
+	val |= (DEFAULT_FCRAMRATIO << FFLP_CFG_1_FCRAMRATIO_SHIFT);
+	nw64(FFLP_CFG_1, val);
+
+	val = nr64(FFLP_CFG_1);
+	val |= FFLP_CFG_1_FFLPINITDONE;
+	nw64(FFLP_CFG_1, val);
+
+	val = nr64(FCRAM_REF_TMR);
+	val &= ~(FCRAM_REF_TMR_MAX | FCRAM_REF_TMR_MIN);
+	val |= (DEFAULT_FCRAM_REFRESH_MAX << FCRAM_REF_TMR_MAX_SHIFT);
+	val |= (DEFAULT_FCRAM_REFRESH_MIN << FCRAM_REF_TMR_MIN_SHIFT);
+	nw64(FCRAM_REF_TMR, val);
+}
+
+static int fflp_set_partition(struct niu *np, u64 partition,
+			      u64 mask, u64 base, int enable)
+{
+	unsigned long reg;
+	u64 val;
+
+	if (partition >= FCRAM_NUM_PARTITIONS ||
+	    (mask & ~(u64)0x1f) != 0 ||
+	    (base & ~(u64)0x1f) != 0)
+		return -EINVAL;
+
+	reg = FLW_PRT_SEL(partition);
+
+	val = nr64(reg);
+	val &= ~(FLW_PRT_SEL_EXT | FLW_PRT_SEL_MASK | FLW_PRT_SEL_BASE);
+	val |= (mask << FLW_PRT_SEL_MASK_SHIFT);
+	val |= (base << FLW_PRT_SEL_BASE_SHIFT);
+	if (enable)
+		val |= FLW_PRT_SEL_EXT;
+	nw64(reg, val);
+
+	return 0;
+}
+
+static int fflp_disable_all_partitions(struct niu *np)
+{
+	unsigned long i;
+
+	for (i = 0; i < FCRAM_NUM_PARTITIONS; i++) {
+		int err = fflp_set_partition(np, 0, 0, 0, 0);
+		if (err)
+			return err;
+	}
+	return 0;
+}
+
+static void fflp_llcsnap_enable(struct niu *np, int on)
+{
+	u64 val = nr64(FFLP_CFG_1);
+
+	if (on)
+		val |= FFLP_CFG_1_LLCSNAP;
+	else
+		val &= ~FFLP_CFG_1_LLCSNAP;
+	nw64(FFLP_CFG_1, val);
+}
+
+static void fflp_errors_enable(struct niu *np, int on)
+{
+	u64 val = nr64(FFLP_CFG_1);
+
+	if (on)
+		val &= ~FFLP_CFG_1_ERRORDIS;
+	else
+		val |= FFLP_CFG_1_ERRORDIS;
+	nw64(FFLP_CFG_1, val);
+}
+
+static int fflp_hash_clear(struct niu *np)
+{
+	struct fcram_hash_ipv4 ent;
+	unsigned long i;
+
+	/* IPV4 hash entry with valid bit clear, rest is don't care.  */
+	memset(&ent, 0, sizeof(ent));
+	ent.header = HASH_HEADER_EXT;
+
+	for (i = 0; i < FCRAM_SIZE; i += sizeof(ent)) {
+		int err = hash_write(np, 0, i, 1, (u64 *) &ent);
+		if (err)
+			return err;
+	}
+	return 0;
+}
+
+static int fflp_early_init(struct niu *np)
+{
+	struct niu_parent *parent;
+	unsigned long flags;
+	int err;
+
+	niu_lock_parent(np, flags);
+
+	parent = np->parent;
+	err = 0;
+	if (!(parent->flags & PARENT_FLGS_CLS_HWINIT)) {
+		niudbg(PROBE, "fflp_early_init: Initting hw on port %u\n",
+		       np->port);
+		if (np->parent->plat_type != PLAT_TYPE_NIU) {
+			fflp_reset(np);
+			fflp_set_timings(np);
+			err = fflp_disable_all_partitions(np);
+			if (err) {
+				niudbg(PROBE, "fflp_disable_all_partitions "
+				       "failed, err=%d\n", err);
+				goto out;
+			}
+		}
+
+		err = tcam_early_init(np);
+		if (err) {
+			niudbg(PROBE, "tcam_early_init failed, err=%d\n",
+			       err);
+			goto out;
+		}
+		fflp_llcsnap_enable(np, 1);
+		fflp_errors_enable(np, 0);
+		nw64(H1POLY, 0);
+		nw64(H2POLY, 0);
+
+		err = tcam_flush_all(np);
+		if (err) {
+			niudbg(PROBE, "tcam_flush_all failed, err=%d\n",
+			       err);
+			goto out;
+		}
+		if (np->parent->plat_type != PLAT_TYPE_NIU) {
+			err = fflp_hash_clear(np);
+			if (err) {
+				niudbg(PROBE, "fflp_hash_clear failed, "
+				       "err=%d\n", err);
+				goto out;
+			}
+		}
+
+		vlan_tbl_clear(np);
+
+		niudbg(PROBE, "fflp_early_init: Success\n");
+		parent->flags |= PARENT_FLGS_CLS_HWINIT;
+	}
+out:
+	niu_unlock_parent(np, flags);
+	return err;
+}
+
+static int niu_set_flow_key(struct niu *np, unsigned long class_code, u64 key)
+{
+	if (class_code < CLASS_CODE_USER_PROG1 ||
+	    class_code > CLASS_CODE_SCTP_IPV6)
+		return -EINVAL;
+
+	nw64(FLOW_KEY(class_code - CLASS_CODE_USER_PROG1), key);
+	return 0;
+}
+
+static int niu_set_tcam_key(struct niu *np, unsigned long class_code, u64 key)
+{
+	if (class_code < CLASS_CODE_USER_PROG1 ||
+	    class_code > CLASS_CODE_SCTP_IPV6)
+		return -EINVAL;
+
+	nw64(TCAM_KEY(class_code - CLASS_CODE_USER_PROG1), key);
+	return 0;
+}
+
+static void niu_rx_skb_append(struct sk_buff *skb, struct page *page,
+			      u32 offset, u32 size)
+{
+	int i = skb_shinfo(skb)->nr_frags;
+	skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
+
+	frag->page = page;
+	frag->page_offset = offset;
+	frag->size = size;
+
+	skb->len += size;
+	skb->data_len += size;
+	skb->truesize += size;
+
+	skb_shinfo(skb)->nr_frags = i + 1;
+}
+
+static unsigned int niu_hash_rxaddr(struct rx_ring_info *rp, u64 a)
+{
+	a >>= PAGE_SHIFT;
+	a ^= (a >> ilog2(MAX_RBR_RING_SIZE));
+
+	return (a & (MAX_RBR_RING_SIZE - 1));
+}
+
+static struct page *niu_find_rxpage(struct rx_ring_info *rp, u64 addr,
+				    struct page ***link)
+{
+	unsigned int h = niu_hash_rxaddr(rp, addr);
+	struct page *p, **pp;
+
+	addr &= PAGE_MASK;
+	pp = &rp->rxhash[h];
+	for (; (p = *pp) != NULL; pp = (struct page **) &p->mapping) {
+		if (p->index == addr) {
+			*link = pp;
+			break;
+		}
+	}
+
+	return p;
+}
+
+static void niu_hash_page(struct rx_ring_info *rp, struct page *page, u64 base)
+{
+	unsigned int h = niu_hash_rxaddr(rp, base);
+
+	page->index = base;
+	page->mapping = (struct address_space *) rp->rxhash[h];
+	rp->rxhash[h] = page;
+}
+
+static int niu_rbr_add_page(struct niu *np, struct rx_ring_info *rp,
+			    gfp_t mask, int start_index)
+{
+	struct page *page;
+	u64 addr;
+	int i;
+
+	page = alloc_page(mask);
+	if (!page)
+		return -ENOMEM;
+
+	addr = np->ops->map_page(np->device, page, 0,
+				 PAGE_SIZE, DMA_FROM_DEVICE);
+
+	niu_hash_page(rp, page, addr);
+	if (rp->rbr_blocks_per_page > 1)
+		atomic_add(rp->rbr_blocks_per_page - 1,
+			   &compound_head(page)->_count);
+
+	for (i = 0; i < rp->rbr_blocks_per_page; i++) {
+		__le32 *rbr = &rp->rbr[start_index + i];
+
+		*rbr = cpu_to_le32(addr >> RBR_DESCR_ADDR_SHIFT);
+		addr += rp->rbr_block_size;
+	}
+
+	return 0;
+}
+
+static void niu_rbr_refill(struct niu *np, struct rx_ring_info *rp, gfp_t mask)
+{
+	int index = rp->rbr_index;
+
+	rp->rbr_pending++;
+	if ((rp->rbr_pending % rp->rbr_blocks_per_page) == 0) {
+		int err = niu_rbr_add_page(np, rp, mask, index);
+
+		if (unlikely(err)) {
+			rp->rbr_pending--;
+			return;
+		}
+
+		rp->rbr_index += rp->rbr_blocks_per_page;
+		BUG_ON(rp->rbr_index > rp->rbr_table_size);
+		if (rp->rbr_index == rp->rbr_table_size)
+			rp->rbr_index = 0;
+
+		if (rp->rbr_pending >= rp->rbr_kick_thresh) {
+			nw64(RBR_KICK(rp->rx_channel), rp->rbr_pending);
+			rp->rbr_pending = 0;
+		}
+	}
+}
+
+static int niu_rx_pkt_ignore(struct niu *np, struct rx_ring_info *rp)
+{
+	unsigned int index = rp->rcr_index;
+	int num_rcr = 0;
+
+	rp->rx_dropped++;
+	while (1) {
+		struct page *page, **link;

drivers/net/niu.c line 2146

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+		u64 addr, val;
+		u32 rcr_size;
+
+		num_rcr++;
+
+		val = le64_to_cpup(&rp->rcr[index]);
+		addr = (val & RCR_ENTRY_PKT_BUF_ADDR) <<
+			RCR_ENTRY_PKT_BUF_ADDR_SHIFT;
+		page = niu_find_rxpage(rp, addr, &link);
+		BUG_ON(!page);

BUG_ON checks for NULL are useless if the code following is just going to dereference the pointer anyway.

Quoted 150 lines
drivers/net/niu.c new file +150 -0
+
+		rcr_size = rp->rbr_sizes[(val & RCR_ENTRY_PKTBUFSZ) >>
+					 RCR_ENTRY_PKTBUFSZ_SHIFT];
+		if ((page->index + PAGE_SIZE) - rcr_size == addr) {
+			*link = (struct page *) page->mapping;
+			np->ops->unmap_page(np->device, page->index,
+					    PAGE_SIZE, DMA_FROM_DEVICE);
+			page->index = 0;
+			page->mapping = NULL;
+			__free_page(page);
+			rp->rbr_refill_pending++;
+		}
+
+		index = NEXT_RCR(rp, index);
+		if (!(val & RCR_ENTRY_MULTI))
+			break;
+
+	}
+	rp->rcr_index = index;
+
+	return num_rcr;
+}
+
+static int niu_process_rx_pkt(struct niu *np, struct rx_ring_info *rp)
+{
+	unsigned int index = rp->rcr_index;
+	struct sk_buff *skb;
+	int len, num_rcr;
+
+	skb = netdev_alloc_skb(np->dev, RX_SKB_ALLOC_SIZE);
+	if (unlikely(!skb))
+		return niu_rx_pkt_ignore(np, rp);
+
+	num_rcr = 0;
+	while (1) {
+		struct page *page, **link;
+		u32 rcr_size, append_size;
+		u64 addr, val, off;
+
+		num_rcr++;
+
+		val = le64_to_cpup(&rp->rcr[index]);
+
+		len = (val & RCR_ENTRY_L2_LEN) >>
+			RCR_ENTRY_L2_LEN_SHIFT;
+		len -= ETH_FCS_LEN;
+
+		addr = (val & RCR_ENTRY_PKT_BUF_ADDR) <<
+			RCR_ENTRY_PKT_BUF_ADDR_SHIFT;
+		page = niu_find_rxpage(rp, addr, &link);
+		BUG_ON(!page);
+
+		rcr_size = rp->rbr_sizes[(val & RCR_ENTRY_PKTBUFSZ) >>
+					 RCR_ENTRY_PKTBUFSZ_SHIFT];
+
+		off = addr & ~PAGE_MASK;
+		append_size = rcr_size;
+		if (num_rcr == 1) {
+			int ptype;
+
+			off += 2;
+			append_size -= 2;
+
+			ptype = (val >> RCR_ENTRY_PKT_TYPE_SHIFT);
+			if ((ptype == RCR_PKT_TYPE_TCP ||
+			     ptype == RCR_PKT_TYPE_UDP) &&
+			    !(val & (RCR_ENTRY_NOPORT |
+				     RCR_ENTRY_ERROR)))
+				skb->ip_summed = CHECKSUM_UNNECESSARY;
+			else
+				skb->ip_summed = CHECKSUM_NONE;
+		}
+		if (!(val & RCR_ENTRY_MULTI))
+			append_size = len - skb->len;
+
+		niu_rx_skb_append(skb, page, off, append_size);
+		if ((page->index + rp->rbr_block_size) - rcr_size == addr) {
+			*link = (struct page *) page->mapping;
+			np->ops->unmap_page(np->device, page->index,
+					    PAGE_SIZE, DMA_FROM_DEVICE);
+			page->index = 0;
+			page->mapping = NULL;
+			rp->rbr_refill_pending++;
+		} else
+			get_page(page);
+
+		index = NEXT_RCR(rp, index);
+		if (!(val & RCR_ENTRY_MULTI))
+			break;
+
+	}
+	rp->rcr_index = index;
+
+	skb_reserve(skb, NET_IP_ALIGN);
+	__pskb_pull_tail(skb, min(len, NIU_RXPULL_MAX));
+
+	rp->rx_packets++;
+	rp->rx_bytes += skb->len;
+
+	skb->protocol = eth_type_trans(skb, np->dev);
+	netif_receive_skb(skb);
+
+	return num_rcr;
+}
+
+static int niu_rbr_fill(struct niu *np, struct rx_ring_info *rp, gfp_t mask)
+{
+	int blocks_per_page = rp->rbr_blocks_per_page;
+	int err, index = rp->rbr_index;
+
+	err = 0;
+	while (index < (rp->rbr_table_size - blocks_per_page)) {
+		err = niu_rbr_add_page(np, rp, mask, index);
+		if (err)
+			break;
+
+		index += blocks_per_page;
+	}
+
+	rp->rbr_index = index;
+	return err;
+}
+
+static void niu_rbr_free(struct niu *np, struct rx_ring_info *rp)
+{
+	int i;
+
+	for (i = 0; i < MAX_RBR_RING_SIZE; i++) {
+		struct page *page;
+
+		page = rp->rxhash[i];
+		while (page) {
+			struct page *next = (struct page *) page->mapping;
+			u64 base = page->index;
+
+			np->ops->unmap_page(np->device, base, PAGE_SIZE,
+					    DMA_FROM_DEVICE);
+			page->index = 0;
+			page->mapping = NULL;
+
+			__free_page(page);
+
+			page = next;
+		}
+	}
+
+	for (i = 0; i < rp->rbr_table_size; i++)
+		rp->rbr[i] = cpu_to_le32(0);
+	rp->rbr_index = 0;
+}

drivers/net/niu.c line 2306

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+
+static int release_tx_packet(struct niu *np, struct tx_ring_info *rp, int idx)
+{
+	struct tx_buff_info *tb = &rp->tx_buffs[idx];
+	struct sk_buff *skb = tb->skb;
+	struct tx_pkt_hdr *tp;
+	u64 tx_flags;
+	int i, len;
+
+	BUG_ON(!skb);

BUG_ON checks for NULL are useless if the code following is just going to dereference the pointer anyway.

Quoted 18 lines
drivers/net/niu.c new file +18 -0
+
+	tp = (struct tx_pkt_hdr *) skb->data;
+	tx_flags = le64_to_cpup(&tp->flags);
+
+	rp->tx_packets++;
+	rp->tx_bytes += (((tx_flags & TXHDR_LEN) >> TXHDR_LEN_SHIFT) -
+			 ((tx_flags & TXHDR_PAD) / 2));
+
+	len = skb_headlen(skb);
+	np->ops->unmap_single(np->device, tb->mapping,
+			      len, DMA_TO_DEVICE);
+
+	if (le64_to_cpu(rp->descr[idx]) & TX_DESC_MARK)
+		rp->mark_pending--;
+
+	tb->skb = NULL;
+	do {
+		idx = NEXT_TX(rp, idx);

drivers/net/niu.c line 2333

Quoted 10 lines
drivers/net/niu.c new file +9 -0
+		len -= MAX_TX_DESC_LEN;
+	} while (len > 0);
+
+	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
+		tb = &rp->tx_buffs[idx];
+		BUG_ON(tb->skb != NULL);
 
+		np->ops->unmap_page(np->device, tb->mapping,
+				    skb_shinfo(skb)->frags[i].size,
+				    DMA_TO_DEVICE);

Shouldn't this be skb_shinfo(tb->skb)->frags...

drivers/net/niu.c line 2337

Quoted 4 lines
drivers/net/niu.c new file +4 -0
+		idx = NEXT_TX(rp, idx);
+	}
+
+	dev_kfree_skb(skb);

Should be dev_kfree_skb_any() if you plan on supporting netconsole.

Quoted 132 lines
drivers/net/niu.c new file +132 -0
+
+	return idx;
+}
+
+#define NIU_TX_WAKEUP_THRESH(rp)		((rp)->pending / 4)
+
+static void niu_tx_work(struct niu *np, struct tx_ring_info *rp)
+{
+	u16 pkt_cnt, tmp;
+	int cons;
+	u64 cs;
+
+	cs = rp->tx_cs;
+	if (unlikely(!(cs & (TX_CS_MK | TX_CS_MMK))))
+		goto out;
+
+	tmp = pkt_cnt = (cs & TX_CS_PKT_CNT) >> TX_CS_PKT_CNT_SHIFT;
+	pkt_cnt = (pkt_cnt - rp->last_pkt_cnt) &
+		(TX_CS_PKT_CNT >> TX_CS_PKT_CNT_SHIFT);
+
+	rp->last_pkt_cnt = tmp;
+
+	cons = rp->cons;
+
+	niudbg(TX_WORK, "%s: niu_tx_work() pkt_cnt[%u] cons[%d]\n",
+	       np->dev->name, pkt_cnt, cons);
+
+	while (pkt_cnt--)
+		cons = release_tx_packet(np, rp, cons);
+
+	rp->cons = cons;
+	smp_mb();
+
+out:
+	if (unlikely(netif_queue_stopped(np->dev) &&
+		     (niu_tx_avail(rp) > NIU_TX_WAKEUP_THRESH(rp)))) {
+		netif_tx_lock(np->dev);
+		if (netif_queue_stopped(np->dev) &&
+		    (niu_tx_avail(rp) > NIU_TX_WAKEUP_THRESH(rp)))
+			netif_wake_queue(np->dev);
+		netif_tx_unlock(np->dev);
+	}
+}
+
+static int niu_rx_work(struct niu *np, struct rx_ring_info *rp, int budget)
+{
+	int qlen, rcr_done = 0, work_done = 0;
+	struct rxdma_mailbox *mbox = rp->mbox;
+	u64 stat;
+
+#if 1
+	stat = nr64(RX_DMA_CTL_STAT(rp->rx_channel));
+	qlen = nr64(RCRSTAT_A(rp->rx_channel)) & RCRSTAT_A_QLEN;
+#else
+	stat = le64_to_cpup(&mbox->rx_dma_ctl_stat);
+	qlen = (le64_to_cpup(&mbox->rcrstat_a) & RCRSTAT_A_QLEN);
+#endif
+	mbox->rx_dma_ctl_stat = 0;
+	mbox->rcrstat_a = 0;
+
+	niudbg(RX_WORK, "%s: niu_rx_work(chan[%d]), stat[%llx] qlen=%d\n",
+	       np->dev->name, rp->rx_channel, (unsigned long long) stat, qlen);
+
+	rcr_done = work_done = 0;
+	qlen = min(qlen, budget);
+	while (work_done < qlen) {
+		rcr_done += niu_process_rx_pkt(np, rp);
+		work_done++;
+	}
+
+	if (rp->rbr_refill_pending >= rp->rbr_kick_thresh) {
+		unsigned int i;
+
+		for (i = 0; i < rp->rbr_refill_pending; i++)
+			niu_rbr_refill(np, rp, GFP_ATOMIC);
+		rp->rbr_refill_pending = 0;
+	}
+
+	stat = (RX_DMA_CTL_STAT_MEX |
+		((u64)work_done << RX_DMA_CTL_STAT_PKTREAD_SHIFT) |
+		((u64)rcr_done << RX_DMA_CTL_STAT_PTRREAD_SHIFT));
+
+	nw64(RX_DMA_CTL_STAT(rp->rx_channel), stat);
+
+	return work_done;
+}
+
+static int niu_poll_core(struct niu *np, struct niu_ldg *lp, int budget)
+{
+	u64 v0 = lp->v0;
+	u32 tx_vec = (v0 >> 32);
+	u32 rx_vec = (v0 & 0xffffffff);
+	int i, work_done = 0;
+
+	niudbg(POLL, "%s: niu_poll_core() v0[%016llx]\n",
+	       np->dev->name, (unsigned long long) v0);
+
+	for (i = 0; i < np->num_tx_rings; i++) {
+		struct tx_ring_info *rp = &np->tx_rings[i];
+		if (tx_vec & (1 << rp->tx_channel))
+			niu_tx_work(np, rp);
+		nw64(LD_IM0(LDN_TXDMA(rp->tx_channel)), 0);
+	}
+
+	for (i = 0; i < np->num_rx_rings; i++) {
+		struct rx_ring_info *rp = &np->rx_rings[i];
+
+		if (rx_vec & (1 << rp->rx_channel)) {
+			int this_work_done;
+
+			this_work_done = niu_rx_work(np, rp,
+						     budget);
+
+			budget -= this_work_done;
+			work_done += this_work_done;
+		}
+		nw64(LD_IM0(LDN_RXDMA(rp->rx_channel)), 0);
+	}
+
+	return work_done;
+}
+
+static int niu_poll(struct napi_struct *napi, int budget)
+{
+	struct niu_ldg *lp = container_of(napi, struct niu_ldg, napi);
+	struct niu *np = lp->np;
+	int work_done;
+
+	work_done = niu_poll_core(np, lp, budget);
+
+	if (work_done < budget) {
+		netif_rx_complete(np->dev, napi);

drivers/net/niu.c line 2479

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+		niu_ldg_rearm(np, lp, 1);
+	}
+	return work_done;
+}
+
+static void niu_log_rxchan_errors(struct niu *np, struct rx_ring_info *rp,
+				  u64 stat)
+{
+	printk(KERN_ERR PFX "%s: RX channel %u errors ( ",
+	       np->dev->name, rp->rx_channel);

dev_err??

Quoted 406 lines
drivers/net/niu.c new file +406 -0
+
+	if (stat & RX_DMA_CTL_STAT_RBR_TMOUT)
+		printk("RBR_TMOUT ");
+	if (stat & RX_DMA_CTL_STAT_RSP_CNT_ERR)
+		printk("RSP_CNT ");
+	if (stat & RX_DMA_CTL_STAT_BYTE_EN_BUS)
+		printk("BYTE_EN_BUS ");
+	if (stat & RX_DMA_CTL_STAT_RSP_DAT_ERR)
+		printk("RSP_DAT ");
+	if (stat & RX_DMA_CTL_STAT_RCR_ACK_ERR)
+		printk("RCR_ACK ");
+	if (stat & RX_DMA_CTL_STAT_RCR_SHA_PAR)
+		printk("RCR_SHA_PAR ");
+	if (stat & RX_DMA_CTL_STAT_RBR_PRE_PAR)
+		printk("RBR_PRE_PAR ");
+	if (stat & RX_DMA_CTL_STAT_CONFIG_ERR)
+		printk("CONFIG ");
+	if (stat & RX_DMA_CTL_STAT_RCRINCON)
+		printk("RCRINCON ");
+	if (stat & RX_DMA_CTL_STAT_RCRFULL)
+		printk("RCRFULL ");
+	if (stat & RX_DMA_CTL_STAT_RBRFULL)
+		printk("RBRFULL ");
+	if (stat & RX_DMA_CTL_STAT_RBRLOGPAGE)
+		printk("RBRLOGPAGE ");
+	if (stat & RX_DMA_CTL_STAT_CFIGLOGPAGE)
+		printk("CFIGLOGPAGE ");
+	if (stat & RX_DMA_CTL_STAT_DC_FIFO_ERR)
+		printk("DC_FIDO ");
+
+	printk(")\n");
+}
+
+static int niu_rx_error(struct niu *np, struct rx_ring_info *rp)
+{
+	u64 stat = nr64(RX_DMA_CTL_STAT(rp->rx_channel));
+	int err = 0;
+
+	printk(KERN_ERR PFX "%s: RX channel %u error, stat[%llx]\n",
+	       np->dev->name, rp->rx_channel, (unsigned long long) stat);
+
+	niu_log_rxchan_errors(np, rp, stat);
+
+	if (stat & (RX_DMA_CTL_STAT_CHAN_FATAL |
+		    RX_DMA_CTL_STAT_PORT_FATAL))
+		err = -EINVAL;
+
+	nw64(RX_DMA_CTL_STAT(rp->rx_channel),
+	     stat & RX_DMA_CTL_WRITE_CLEAR_ERRS);
+
+	return err;
+}
+
+static void niu_log_txchan_errors(struct niu *np, struct tx_ring_info *rp,
+				  u64 cs)
+{
+	printk(KERN_ERR PFX "%s: TX channel %u errors ( ",
+	       np->dev->name, rp->tx_channel);
+
+	if (cs & TX_CS_MBOX_ERR)
+		printk("MBOX ");
+	if (cs & TX_CS_PKT_SIZE_ERR)
+		printk("PKT_SIZE ");
+	if (cs & TX_CS_TX_RING_OFLOW)
+		printk("TX_RING_OFLOW ");
+	if (cs & TX_CS_PREF_BUF_PAR_ERR)
+		printk("PREF_BUF_PAR ");
+	if (cs & TX_CS_NACK_PREF)
+		printk("NACK_PREF ");
+	if (cs & TX_CS_NACK_PKT_RD)
+		printk("NACK_PKT_RD ");
+	if (cs & TX_CS_CONF_PART_ERR)
+		printk("CONF_PART ");
+	if (cs & TX_CS_PKT_PRT_ERR)
+		printk("PKT_PTR ");
+
+	printk(")\n");
+}
+
+static int niu_tx_error(struct niu *np, struct tx_ring_info *rp)
+{
+	u64 cs, logh, logl;
+
+	cs = nr64(TX_CS(rp->tx_channel));
+	logh = nr64(TX_RNG_ERR_LOGH(rp->tx_channel));
+	logl = nr64(TX_RNG_ERR_LOGL(rp->tx_channel));
+
+	printk(KERN_ERR PFX "%s: TX channel %u error, "
+	       "cs[%llx] logh[%llx] logl[%llx]\n",
+	       np->dev->name, rp->tx_channel,
+	       (unsigned long long) cs,
+	       (unsigned long long) logh,
+	       (unsigned long long) logl);
+
+	niu_log_txchan_errors(np, rp, cs);
+
+	return -ENODEV;
+}
+
+static int niu_mif_interrupt(struct niu *np)
+{
+	u64 mif_status = nr64(MIF_STATUS);
+	int phy_mdint = 0;
+
+	if (np->flags & NIU_FLAGS_XMAC) {
+		u64 xrxmac_stat = nr64_mac(XRXMAC_STATUS);
+
+		if (xrxmac_stat & XRXMAC_STATUS_PHY_MDINT)
+			phy_mdint = 1;
+	}
+
+	printk(KERN_ERR PFX "%s: MIF interrupt, "
+	       "stat[%llx] phy_mdint(%d)\n",
+	       np->dev->name, (unsigned long long) mif_status, phy_mdint);
+
+	return -ENODEV;
+}
+
+static void niu_xmac_interrupt(struct niu *np)
+{
+	struct niu_xmac_stats *mp = &np->mac_stats.xmac;
+	u64 val;
+
+	val = nr64_mac(XTXMAC_STATUS);
+	if (val & XTXMAC_STATUS_FRAME_CNT_EXP)
+		mp->tx_frames += TXMAC_FRM_CNT_COUNT;
+	if (val & XTXMAC_STATUS_BYTE_CNT_EXP)
+		mp->tx_bytes += TXMAC_BYTE_CNT_COUNT;
+	if (val & XTXMAC_STATUS_TXFIFO_XFR_ERR)
+		mp->tx_fifo_errors++;
+	if (val & XTXMAC_STATUS_TXMAC_OFLOW)
+		mp->tx_overflow_errors++;
+	if (val & XTXMAC_STATUS_MAX_PSIZE_ERR)
+		mp->tx_max_pkt_size_errors++;
+	if (val & XTXMAC_STATUS_TXMAC_UFLOW)
+		mp->tx_underflow_errors++;
+
+	val = nr64_mac(XRXMAC_STATUS);
+	if (val & XRXMAC_STATUS_LCL_FLT_STATUS)
+		mp->rx_local_faults++;
+	if (val & XRXMAC_STATUS_RFLT_DET)
+		mp->rx_remote_faults++;
+	if (val & XRXMAC_STATUS_LFLT_CNT_EXP)
+		mp->rx_link_faults += LINK_FAULT_CNT_COUNT;
+	if (val & XRXMAC_STATUS_ALIGNERR_CNT_EXP)
+		mp->rx_align_errors += RXMAC_ALIGN_ERR_CNT_COUNT;
+	if (val & XRXMAC_STATUS_RXFRAG_CNT_EXP)
+		mp->rx_frags += RXMAC_FRAG_CNT_COUNT;
+	if (val & XRXMAC_STATUS_RXMULTF_CNT_EXP)
+		mp->rx_mcasts += RXMAC_MC_FRM_CNT_COUNT;
+	if (val & XRXMAC_STATUS_RXBCAST_CNT_EXP)
+		mp->rx_bcasts += RXMAC_BC_FRM_CNT_COUNT;
+	if (val & XRXMAC_STATUS_RXBCAST_CNT_EXP)
+		mp->rx_bcasts += RXMAC_BC_FRM_CNT_COUNT;
+	if (val & XRXMAC_STATUS_RXHIST1_CNT_EXP)
+		mp->rx_hist_cnt1 += RXMAC_HIST_CNT1_COUNT;
+	if (val & XRXMAC_STATUS_RXHIST2_CNT_EXP)
+		mp->rx_hist_cnt2 += RXMAC_HIST_CNT2_COUNT;
+	if (val & XRXMAC_STATUS_RXHIST3_CNT_EXP)
+		mp->rx_hist_cnt3 += RXMAC_HIST_CNT3_COUNT;
+	if (val & XRXMAC_STATUS_RXHIST4_CNT_EXP)
+		mp->rx_hist_cnt4 += RXMAC_HIST_CNT4_COUNT;
+	if (val & XRXMAC_STATUS_RXHIST5_CNT_EXP)
+		mp->rx_hist_cnt5 += RXMAC_HIST_CNT5_COUNT;
+	if (val & XRXMAC_STATUS_RXHIST6_CNT_EXP)
+		mp->rx_hist_cnt6 += RXMAC_HIST_CNT6_COUNT;
+	if (val & XRXMAC_STATUS_RXHIST7_CNT_EXP)
+		mp->rx_hist_cnt7 += RXMAC_HIST_CNT7_COUNT;
+	if (val & XRXMAC_STAT_MSK_RXOCTET_CNT_EXP)
+		mp->rx_octets += RXMAC_BT_CNT_COUNT;
+	if (val & XRXMAC_STATUS_CVIOLERR_CNT_EXP)
+		mp->rx_code_violations += RXMAC_CD_VIO_CNT_COUNT;
+	if (val & XRXMAC_STATUS_LENERR_CNT_EXP)
+		mp->rx_len_errors += RXMAC_MPSZER_CNT_COUNT;
+	if (val & XRXMAC_STATUS_CRCERR_CNT_EXP)
+		mp->rx_crc_errors += RXMAC_CRC_ER_CNT_COUNT;
+	if (val & XRXMAC_STATUS_RXUFLOW)
+		mp->rx_underflows++;
+	if (val & XRXMAC_STATUS_RXOFLOW)
+		mp->rx_overflows++;
+
+	val = nr64_mac(XMAC_FC_STAT);
+	if (val & XMAC_FC_STAT_TX_MAC_NPAUSE)
+		mp->pause_off_state++;
+	if (val & XMAC_FC_STAT_TX_MAC_PAUSE)
+		mp->pause_on_state++;
+	if (val & XMAC_FC_STAT_RX_MAC_RPAUSE)
+		mp->pause_received++;
+}
+
+static void niu_bmac_interrupt(struct niu *np)
+{
+	struct niu_bmac_stats *mp = &np->mac_stats.bmac;
+	u64 val;
+
+	val = nr64_mac(BTXMAC_STATUS);
+	if (val & BTXMAC_STATUS_UNDERRUN)
+		mp->tx_underflow_errors++;
+	if (val & BTXMAC_STATUS_MAX_PKT_ERR)
+		mp->tx_max_pkt_size_errors++;
+	if (val & BTXMAC_STATUS_BYTE_CNT_EXP)
+		mp->tx_bytes += BTXMAC_BYTE_CNT_COUNT;
+	if (val & BTXMAC_STATUS_FRAME_CNT_EXP)
+		mp->tx_frames += BTXMAC_FRM_CNT_COUNT;
+
+	val = nr64_mac(BRXMAC_STATUS);
+	if (val & BRXMAC_STATUS_OVERFLOW)
+		mp->rx_overflows++;
+	if (val & BRXMAC_STATUS_FRAME_CNT_EXP)
+		mp->rx_frames += BRXMAC_FRAME_CNT_COUNT;
+	if (val & BRXMAC_STATUS_ALIGN_ERR_EXP)
+		mp->rx_align_errors += BRXMAC_ALIGN_ERR_CNT_COUNT;
+	if (val & BRXMAC_STATUS_CRC_ERR_EXP)
+		mp->rx_crc_errors += BRXMAC_ALIGN_ERR_CNT_COUNT;
+	if (val & BRXMAC_STATUS_LEN_ERR_EXP)
+		mp->rx_len_errors += BRXMAC_CODE_VIOL_ERR_CNT_COUNT;
+
+	val = nr64_mac(BMAC_CTRL_STATUS);
+	if (val & BMAC_CTRL_STATUS_NOPAUSE)
+		mp->pause_off_state++;
+	if (val & BMAC_CTRL_STATUS_PAUSE)
+		mp->pause_on_state++;
+	if (val & BMAC_CTRL_STATUS_PAUSE_RECV)
+		mp->pause_received++;
+}
+
+static int niu_mac_interrupt(struct niu *np)
+{
+	if (np->flags & NIU_FLAGS_XMAC)
+		niu_xmac_interrupt(np);
+	else
+		niu_bmac_interrupt(np);
+
+	return 0;
+}
+
+static void niu_log_device_error(struct niu *np, u64 stat)
+{
+	printk(KERN_ERR PFX "%s: Core device errors ( ",
+	       np->dev->name);
+
+	if (stat & SYS_ERR_MASK_META2)
+		printk("META2 ");
+	if (stat & SYS_ERR_MASK_META1)
+		printk("META1 ");
+	if (stat & SYS_ERR_MASK_PEU)
+		printk("PEU ");
+	if (stat & SYS_ERR_MASK_TXC)
+		printk("TXC ");
+	if (stat & SYS_ERR_MASK_RDMC)
+		printk("RDMC ");
+	if (stat & SYS_ERR_MASK_TDMC)
+		printk("TDMC ");
+	if (stat & SYS_ERR_MASK_ZCP)
+		printk("ZCP ");
+	if (stat & SYS_ERR_MASK_FFLP)
+		printk("FFLP ");
+	if (stat & SYS_ERR_MASK_IPP)
+		printk("IPP ");
+	if (stat & SYS_ERR_MASK_MAC)
+		printk("MAC ");
+	if (stat & SYS_ERR_MASK_SMX)
+		printk("SMX ");
+
+	printk(")\n");
+}
+
+static int niu_device_error(struct niu *np)
+{
+	u64 stat = nr64(SYS_ERR_STAT);
+
+	printk(KERN_ERR PFX "%s: Core device error, stat[%llx]\n",
+	       np->dev->name, (unsigned long long) stat);
+
+	niu_log_device_error(np, stat);
+
+	return -ENODEV;
+}
+
+static int niu_slowpath_interrupt(struct niu *np, struct niu_ldg *lp)
+{
+	u64 v0 = lp->v0;
+	u64 v1 = lp->v1;
+	u64 v2 = lp->v2;
+	int i, err = 0;
+
+	if (v1 & 0x00000000ffffffffULL) {
+		u32 rx_vec = (v1 & 0xffffffff);
+
+		for (i = 0; i < np->num_rx_rings; i++) {
+			struct rx_ring_info *rp = &np->rx_rings[i];
+
+			if (rx_vec & (1 << rp->rx_channel)) {
+				int r = niu_rx_error(np, rp);
+				if (r)
+					err = r;
+			}
+		}
+	}
+	if (v1 & 0x7fffffff00000000ULL) {
+		u32 tx_vec = (v1 >> 32) & 0x7fffffff;
+
+		for (i = 0; i < np->num_tx_rings; i++) {
+			struct tx_ring_info *rp = &np->tx_rings[i];
+
+			if (tx_vec & (1 << rp->tx_channel)) {
+				int r = niu_tx_error(np, rp);
+				if (r)
+					err = r;
+			}
+		}
+	}
+	if ((v0 | v1) & 0x8000000000000000ULL) {
+		int r = niu_mif_interrupt(np);
+		if (r)
+			err = r;
+	}
+	if (v2) {
+		if (v2 & 0x01ef) {
+			int r = niu_mac_interrupt(np);
+			if (r)
+				err = r;
+		}
+		if (v2 & 0x0210) {
+			int r = niu_device_error(np);
+			if (r)
+				err = r;
+		}
+	}
+
+	if (err)
+		niu_enable_interrupts(np, 0);
+
+	return -EINVAL;
+}
+
+static void niu_rxchan_intr(struct niu *np, struct rx_ring_info *rp,
+			    int ldn)
+{
+	struct rxdma_mailbox *mbox = rp->mbox;
+	u64 stat_write, stat = le64_to_cpup(&mbox->rx_dma_ctl_stat);
+
+	stat_write = (RX_DMA_CTL_STAT_RCRTHRES |
+		      RX_DMA_CTL_STAT_RCRTO);
+	nw64(RX_DMA_CTL_STAT(rp->rx_channel), stat_write);
+
+	niudbg(INTERRUPT, "%s: rxchan_intr stat[%llx]\n",
+	       np->dev->name, (unsigned long long) stat);
+}
+
+static void niu_txchan_intr(struct niu *np, struct tx_ring_info *rp,
+			    int ldn)
+{
+	rp->tx_cs = nr64(TX_CS(rp->tx_channel));
+
+	niudbg(INTERRUPT, "%s: txchan_intr cs[%llx]\n",
+	       np->dev->name, (unsigned long long) rp->tx_cs);
+}
+
+static void __niu_fastpath_interrupt(struct niu *np, int ldg, u64 v0)
+{
+	struct niu_parent *parent = np->parent;
+	u32 rx_vec, tx_vec;
+	int i;
+
+	tx_vec = (v0 >> 32);
+	rx_vec = (v0 & 0xffffffff);
+
+	for (i = 0; i < np->num_rx_rings; i++) {
+		struct rx_ring_info *rp = &np->rx_rings[i];
+		int ldn = LDN_RXDMA(rp->rx_channel);
+
+		if (parent->ldg_map[ldn] != ldg)
+			continue;
+
+		nw64(LD_IM0(ldn), LD_IM0_MASK);
+		if (rx_vec & (1 << rp->rx_channel))
+			niu_rxchan_intr(np, rp, ldn);
+	}
+
+	for (i = 0; i < np->num_tx_rings; i++) {
+		struct tx_ring_info *rp = &np->tx_rings[i];
+		int ldn = LDN_TXDMA(rp->tx_channel);
+
+		if (parent->ldg_map[ldn] != ldg)
+			continue;
+
+		nw64(LD_IM0(ldn), LD_IM0_MASK);
+		if (tx_vec & (1 << rp->tx_channel))
+			niu_txchan_intr(np, rp, ldn);
+	}
+}
+
+static void niu_schedule_napi(struct niu *np, struct niu_ldg *lp,
+			      u64 v0, u64 v1, u64 v2)
+{
+	if (likely(netif_rx_schedule_prep(np->dev, &lp->napi))) {
+		lp->v0 = v0;
+		lp->v1 = v1;
+		lp->v2 = v2;
+		__niu_fastpath_interrupt(np, lp->ldg_num, v0);
+		__netif_rx_schedule(np->dev, &lp->napi);
+	}
+}
+
+static irqreturn_t niu_interrupt(int irq, void *dev_id)

drivers/net/niu.c line 2895

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+{
+	struct niu_ldg *lp = dev_id;
+	struct niu *np = lp->np;
+	int ldg = lp->ldg_num;
+	unsigned long flags;
+	u64 v0, v1, v2;
+
+	if (niu_debug & NIU_DEBUG_INTERRUPT)
+		printk(KERN_ERR PFX "niu_interrupt() ldg[%p](%d) ",
+		       lp, ldg);

Why not netif_msg_intr()?

Quoted 2,484 lines
drivers/net/niu.c new file +2484 -0
+
+	spin_lock_irqsave(&np->lock, flags);
+
+	v0 = nr64(LDSV0(ldg));
+	v1 = nr64(LDSV1(ldg));
+	v2 = nr64(LDSV2(ldg));
+
+	if (niu_debug & NIU_DEBUG_INTERRUPT)
+		printk("v0[%llx] v1[%llx] v2[%llx]\n",
+		       (unsigned long long) v0,
+		       (unsigned long long) v1,
+		       (unsigned long long) v2);
+
+	if (unlikely(!v0 && !v1 && !v2)) {
+		spin_unlock_irqrestore(&np->lock, flags);
+		return IRQ_NONE;
+	}
+
+	if (unlikely((v0 & ((u64)1 << LDN_MIF)) || v1 || v2)) {
+		int err = niu_slowpath_interrupt(np, lp);
+		if (err)
+			goto out;
+	}
+	if (likely(v0 & ~((u64)1 << LDN_MIF)))
+		niu_schedule_napi(np, lp, v0, v1, v2);
+	else
+		niu_ldg_rearm(np, lp, 1);
+out:
+	spin_unlock_irqrestore(&np->lock, flags);
+
+	return IRQ_HANDLED;
+}
+
+static void niu_free_rx_ring_info(struct niu *np, struct rx_ring_info *rp)
+{
+	if (rp->mbox) {
+		np->ops->free_coherent(np->device,
+				       sizeof(struct rxdma_mailbox),
+				       rp->mbox, rp->mbox_dma);
+		rp->mbox = NULL;
+	}
+	if (rp->rcr) {
+		np->ops->free_coherent(np->device,
+				       MAX_RCR_RING_SIZE * sizeof(__le64),
+				       rp->rcr, rp->rcr_dma);
+		rp->rcr = NULL;
+		rp->rcr_table_size = 0;
+		rp->rcr_index = 0;
+	}
+	if (rp->rbr) {
+		niu_rbr_free(np, rp);
+
+		np->ops->free_coherent(np->device,
+				       MAX_RBR_RING_SIZE * sizeof(__le32),
+				       rp->rbr, rp->rbr_dma);
+		rp->rbr = NULL;
+		rp->rbr_table_size = 0;
+		rp->rbr_index = 0;
+	}
+	kfree(rp->rxhash);
+	rp->rxhash = NULL;
+}
+
+static void niu_free_tx_ring_info(struct niu *np, struct tx_ring_info *rp)
+{
+	if (rp->mbox) {
+		np->ops->free_coherent(np->device,
+				       sizeof(struct txdma_mailbox),
+				       rp->mbox, rp->mbox_dma);
+		rp->mbox = NULL;
+	}
+	if (rp->descr) {
+		int i;
+
+		for (i = 0; i < MAX_TX_RING_SIZE; i++) {
+			if (rp->tx_buffs[i].skb)
+				(void) release_tx_packet(np, rp, i);
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drivers/net/niu.c line 2982

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+		}
+
+		np->ops->free_coherent(np->device,
+				       MAX_TX_RING_SIZE * sizeof(__le64),
+				       rp->descr, rp->descr_dma);
+		rp->descr = NULL;
+		rp->pending = 0;
+		rp->prod = 0;
+		rp->cons = 0;
+		rp->wrap_bit = 0;
[… more lines in the raw message]

Why not leave function ptr null and get "-EOPNOTSUPP"

drivers/net/niu.c

Quoted 2,230 lines
drivers/net/niu.c new file +2230 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

No need to drop lock for detach? all it does is call stop_queue()

drivers/net/niu.c

Quoted 61 lines
drivers/net/niu.c new file +61 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Generic cod useful for other drivers??

drivers/net/niu.c

Quoted 93 lines
drivers/net/niu.c new file +93 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dev_err() ??

drivers/net/niu.c

Quoted 10 lines
drivers/net/niu.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dev_err() ??

drivers/net/niu.c

Quoted 10 lines
drivers/net/niu.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dev_err() ??

drivers/net/niu.c

Quoted 11 lines
drivers/net/niu.c new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dev_err() ??

drivers/net/niu.c

Quoted 7 lines
drivers/net/niu.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dev_err() ??

Quoted 130 lines
drivers/net/niu.c new file +129 -0

Lines of this file are not shown. View the raw message.

drivers/net/niu.h +0 -0

The rest of this diff is not shown. View the raw message.

Signature · 1 line
Stephen Hemminger <[email protected]>

Part of the diff is not shown here. View the raw message.

author maintainer
#2 lore raw

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:35:56 -0700

Quoted 2 lines

These match with existing netif_msg_XXX and your
driver already has msglvl ethtool hook.

...

Quoted 1 line

Do you really want to print all these at KERN_ERR level?

Both fixed, thanks!

Quoted 1 line

From c97391da9c6f0c92a9babdf7ecd569e2effa9828 Mon Sep 17 00:00:00 2001

From: David S. Miller <[email protected]>
Date: Fri, 5 Oct 2007 15:41:43 -0700
Subject: [PATCH] [NIU]: Use netif_msg_*().

Suggested by Stephen Hemminger.

---
 drivers/net/niu.c |  100 +++++++++++++++++++++++++---------------------------
 1 files changed, 48 insertions(+), 52 deletions(-)
drivers/net/niu.c +48 -52
index 0dfabbe..1d56a1a 100644
@@ -86,34 +86,26 @@ MODULE_DEVICE_TABLE(pci, niu_pci_tbl);
 #define nr64_xpcs(reg)		readq(np->regs + np->xpcs_off + (reg))
 #define nw64_xpcs(reg, val)	writeq((val), np->regs + np->xpcs_off + (reg))
 
-static unsigned int niu_debug;
-#define NIU_DEBUG_INTERRUPT	0x00000001
-#define NIU_DEBUG_TX_WORK	0x00000002
-#define NIU_DEBUG_RX_WORK	0x00000004
-#define NIU_DEBUG_POLL		0x00000008
-#define NIU_DEBUG_PROBE		0x00010000
-#define NIU_DEBUG_MDIO		0x00020000
-#define NIU_DEBUG_MII		0x00040000
-#define NIU_DEBUG_INIT_HW	0x00080000
-#define NIU_DEBUG_STOP_HW	0x00100000
-
-module_param(niu_debug, int, 0);
-MODULE_PARM_DESC(niu_debug,
-"NIU bitmapped debugging message enable value:\n"
-"	0x00000001	Log interrupt events\n"
-"	0x00000002	Log TX work\n"
-"	0x00000004	Log RX work\n"
-"	0x00000008	Log NAPI poll\n"
-"	0x00010000	Log device probe events\n"
-"	0x00020000	Log MDIO reads and writes\n"
-"	0x00040000	Log MII reads and writes\n"
-"	0x00080000	Log HW initialization\n"
-"	0x00100000	Log HW shutdown\n"
-);
+#define NIU_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
+
+static int niu_debug = 0;
+static int debug = -1;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, "NIU debug level");
 
 #define niudbg(TYPE, f, a...) \
-do {	if (niu_debug & NIU_DEBUG_##TYPE) \
-		printk(KERN_ERR PFX f, ## a); \
+do {	if ((np)->msg_enable & NETIF_MSG_##TYPE) \
+		printk(KERN_DEBUG PFX f, ## a); \
+} while (0)
+
+#define niuinfo(TYPE, f, a...) \
+do {	if ((np)->msg_enable & NETIF_MSG_##TYPE) \
+		printk(KERN_INFO PFX f, ## a); \
+} while (0)
+
+#define niuwarn(TYPE, f, a...) \
+do {	if ((np)->msg_enable & NETIF_MSG_##TYPE) \
+		printk(KERN_WARNING PFX f, ## a); \
 } while (0)
 
 #define niu_lock_parent(np, flags) \
@@ -1071,7 +1063,7 @@ static int niu_link_status_common(struct niu *np, int link_up)
 	unsigned long flags;
 
 	if (!netif_carrier_ok(dev) && link_up) {
-		printk(KERN_INFO PFX "%s: Link is up at %s, %s duplex\n",
+		niuinfo(LINK, "%s: Link is up at %s, %s duplex\n",
 		       dev->name,
 		       (lp->active_speed == SPEED_10000 ?
 			"10Gb/sec" :
@@ -1088,7 +1080,7 @@ static int niu_link_status_common(struct niu *np, int link_up)
 
 		netif_carrier_on(dev);
 	} else if (netif_carrier_ok(dev) && !link_up) {
-		printk(KERN_WARNING PFX "%s: Link is down\n", dev->name);
+		niuwarn(LINK, "%s: Link is down\n", dev->name);
 		netif_carrier_off(dev);
 	}
 
@@ -2359,7 +2351,7 @@ static void niu_tx_work(struct niu *np, struct tx_ring_info *rp)
 
 	cons = rp->cons;
 
-	niudbg(TX_WORK, "%s: niu_tx_work() pkt_cnt[%u] cons[%d]\n",
+	niudbg(TX_DONE, "%s: niu_tx_work() pkt_cnt[%u] cons[%d]\n",
 	       np->dev->name, pkt_cnt, cons);
 
 	while (pkt_cnt--)
@@ -2395,7 +2387,7 @@ static int niu_rx_work(struct niu *np, struct rx_ring_info *rp, int budget)
 	mbox->rx_dma_ctl_stat = 0;
 	mbox->rcrstat_a = 0;
 
-	niudbg(RX_WORK, "%s: niu_rx_work(chan[%d]), stat[%llx] qlen=%d\n",
+	niudbg(RX_STATUS, "%s: niu_rx_work(chan[%d]), stat[%llx] qlen=%d\n",
 	       np->dev->name, rp->rx_channel, (unsigned long long) stat, qlen);
 
 	rcr_done = work_done = 0;
@@ -2429,7 +2421,7 @@ static int niu_poll_core(struct niu *np, struct niu_ldg *lp, int budget)
 	u32 rx_vec = (v0 & 0xffffffff);
 	int i, work_done = 0;
 
-	niudbg(POLL, "%s: niu_poll_core() v0[%016llx]\n",
+	niudbg(INTR, "%s: niu_poll_core() v0[%016llx]\n",
 	       np->dev->name, (unsigned long long) v0);
 
 	for (i = 0; i < np->num_tx_rings; i++) {
@@ -2823,7 +2815,7 @@ static void niu_rxchan_intr(struct niu *np, struct rx_ring_info *rp,
 		      RX_DMA_CTL_STAT_RCRTO);
 	nw64(RX_DMA_CTL_STAT(rp->rx_channel), stat_write);
 
-	niudbg(INTERRUPT, "%s: rxchan_intr stat[%llx]\n",
+	niudbg(INTR, "%s: rxchan_intr stat[%llx]\n",
 	       np->dev->name, (unsigned long long) stat);
 }
 
@@ -2832,7 +2824,7 @@ static void niu_txchan_intr(struct niu *np, struct tx_ring_info *rp,
 {
 	rp->tx_cs = nr64(TX_CS(rp->tx_channel));
 
-	niudbg(INTERRUPT, "%s: txchan_intr cs[%llx]\n",
+	niudbg(INTR, "%s: txchan_intr cs[%llx]\n",
 	       np->dev->name, (unsigned long long) rp->tx_cs);
 }
 
@@ -2890,7 +2882,7 @@ static irqreturn_t niu_interrupt(int irq, void *dev_id)
 	unsigned long flags;
 	u64 v0, v1, v2;
 
-	if (niu_debug & NIU_DEBUG_INTERRUPT)
+	if (netif_msg_intr(np))
 		printk(KERN_ERR PFX "niu_interrupt() ldg[%p](%d) ",
 		       lp, ldg);
 
@@ -2900,7 +2892,7 @@ static irqreturn_t niu_interrupt(int irq, void *dev_id)
 	v1 = nr64(LDSV1(ldg));
 	v2 = nr64(LDSV2(ldg));
 
-	if (niu_debug & NIU_DEBUG_INTERRUPT)
+	if (netif_msg_intr(np))
 		printk("v0[%llx] v1[%llx] v2[%llx]\n",
 		       (unsigned long long) v0,
 		       (unsigned long long) v1,
@@ -4581,12 +4573,12 @@ static int niu_init_hw(struct niu *np)
 {
 	int i, err;
 
-	niudbg(INIT_HW, "%s: Initialize TXC\n", np->dev->name);
+	niudbg(IFUP, "%s: Initialize TXC\n", np->dev->name);
 	niu_txc_enable_port(np, 1);
 	niu_txc_port_dma_enable(np, 1);
 	niu_txc_set_imask(np, 0);
 
-	niudbg(INIT_HW, "%s: Initialize TX channels\n", np->dev->name);
+	niudbg(IFUP, "%s: Initialize TX channels\n", np->dev->name);
 	for (i = 0; i < np->num_tx_rings; i++) {
 		struct tx_ring_info *rp = &np->tx_rings[i];
 
@@ -4595,27 +4587,27 @@ static int niu_init_hw(struct niu *np)
 			return err;
 	}
 
-	niudbg(INIT_HW, "%s: Initialize RX channels\n", np->dev->name);
+	niudbg(IFUP, "%s: Initialize RX channels\n", np->dev->name);
 	err = niu_init_rx_channels(np);
 	if (err)
 		goto out_uninit_tx_channels;
 
-	niudbg(INIT_HW, "%s: Initialize classifier\n", np->dev->name);
+	niudbg(IFUP, "%s: Initialize classifier\n", np->dev->name);
 	err = niu_init_classifier_hw(np);
 	if (err)
 		goto out_uninit_rx_channels;
 
-	niudbg(INIT_HW, "%s: Initialize ZCP\n", np->dev->name);
+	niudbg(IFUP, "%s: Initialize ZCP\n", np->dev->name);
 	err = niu_init_zcp(np);
 	if (err)
 		goto out_uninit_rx_channels;
 
-	niudbg(INIT_HW, "%s: Initialize IPP\n", np->dev->name);
+	niudbg(IFUP, "%s: Initialize IPP\n", np->dev->name);
 	err = niu_init_ipp(np);
 	if (err)
 		goto out_uninit_rx_channels;
 
-	niudbg(INIT_HW, "%s: Initialize MAC\n", np->dev->name);
+	niudbg(IFUP, "%s: Initialize MAC\n", np->dev->name);
 	err = niu_init_mac(np);
 	if (err)
 		goto out_uninit_ipp;
@@ -4623,16 +4615,16 @@ static int niu_init_hw(struct niu *np)
 	return 0;
 
 out_uninit_ipp:
-	niudbg(INIT_HW, "%s: Uninit IPP\n", np->dev->name);
+	niudbg(IFUP, "%s: Uninit IPP\n", np->dev->name);
 	niu_disable_ipp(np);
 
 out_uninit_rx_channels:
-	niudbg(INIT_HW, "%s: Uninit RX channels\n", np->dev->name);
+	niudbg(IFUP, "%s: Uninit RX channels\n", np->dev->name);
 	niu_stop_rx_channels(np);
 	niu_reset_rx_channels(np);
 
 out_uninit_tx_channels:
-	niudbg(INIT_HW, "%s: Uninit TX channels\n", np->dev->name);
+	niudbg(IFUP, "%s: Uninit TX channels\n", np->dev->name);
 	niu_stop_tx_channels(np);
 	niu_reset_tx_channels(np);
 
@@ -4641,25 +4633,25 @@ out_uninit_tx_channels:
 
 static void niu_stop_hw(struct niu *np)
 {
-	niudbg(STOP_HW, "%s: Disable interrupts\n", np->dev->name);
+	niudbg(IFDOWN, "%s: Disable interrupts\n", np->dev->name);
 	niu_enable_interrupts(np, 0);
 
-	niudbg(STOP_HW, "%s: Disable RX MAC\n", np->dev->name);
+	niudbg(IFDOWN, "%s: Disable RX MAC\n", np->dev->name);
 	niu_enable_rx_mac(np, 0);
 
-	niudbg(STOP_HW, "%s: Disable IPP\n", np->dev->name);
+	niudbg(IFDOWN, "%s: Disable IPP\n", np->dev->name);
 	niu_disable_ipp(np);
 
-	niudbg(STOP_HW, "%s: Stop TX channels\n", np->dev->name);
+	niudbg(IFDOWN, "%s: Stop TX channels\n", np->dev->name);
 	niu_stop_tx_channels(np);
 
-	niudbg(STOP_HW, "%s: Stop RX channels\n", np->dev->name);
+	niudbg(IFDOWN, "%s: Stop RX channels\n", np->dev->name);
 	niu_stop_rx_channels(np);
 
-	niudbg(STOP_HW, "%s: Reset TX channels\n", np->dev->name);
+	niudbg(IFDOWN, "%s: Reset TX channels\n", np->dev->name);
 	niu_reset_tx_channels(np);
 
-	niudbg(STOP_HW, "%s: Reset RX channels\n", np->dev->name);
+	niudbg(IFDOWN, "%s: Reset RX channels\n", np->dev->name);
 	niu_reset_rx_channels(np);
 }
 
@@ -7376,6 +7368,8 @@ static struct net_device * __devinit niu_alloc_and_init(struct device *gen_dev,
 	np->device = gen_dev;
 	np->ops = ops;
 
+	np->msg_enable = niu_debug;
+
 	spin_lock_init(&np->lock);
 	INIT_WORK(&np->reset_task, niu_reset_task);
 
@@ -7913,6 +7907,8 @@ static int __init niu_init(void)
 		       (PAGE_SIZE % (8 * 1024)) != 0 &&
 		       (PAGE_SIZE % (4 * 1024)) != 0)));
 
+	niu_debug = netif_msg_init(debug, NIU_MSG_DEFAULT);
+
 #ifdef CONFIG_SPARC64
 	err = of_register_driver(&niu_of_driver, &of_bus_type);
 #endif
Signature · 1 line
1.5.3.3
author maintainer
#3 lore raw
In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:35:56 -0700

Quoted 1 line

pr_info() ?

All corrected, thanks!

Quoted 1 line

From 11aaa8adc8e9141a440faaa3260ad5922c71eeda Mon Sep 17 00:00:00 2001

From: David S. Miller <[email protected]>
Date: Fri, 5 Oct 2007 15:53:21 -0700
Subject: [PATCH] [NIU]: Use pr_info().

Suggested by Stephen Hemminger.

---
 drivers/net/niu.c |   78 ++++++++++++++++++++++++++--------------------------
 1 files changed, 39 insertions(+), 39 deletions(-)
drivers/net/niu.c +39 -39
index 1d56a1a..92059d7 100644
@@ -845,21 +845,21 @@ static int xcvr_init_10g(struct niu *np)
 			MII_STAT1000);
 	if (err < 0)
 		return err;
-	printk(KERN_INFO PFX "Port %u PMA_PMD(MII_STAT1000) [%04x]\n",
-	       np->port, err);
+	pr_info(PFX "Port %u PMA_PMD(MII_STAT1000) [%04x]\n",
+		np->port, err);
 
 	err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, 0x20);
 	if (err < 0)
 		return err;
-	printk(KERN_INFO PFX "Port %u USER_DEV3(0x20) [%04x]\n",
-	       np->port, err);
+	pr_info(PFX "Port %u USER_DEV3(0x20) [%04x]\n",
+		np->port, err);
 
 	err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
 			MII_NWAYTEST);
 	if (err < 0)
 		return err;
-	printk(KERN_INFO PFX "Port %u PHYXS(MII_NWAYTEST) [%04x]\n",
-	       np->port, err);
+	pr_info(PFX "Port %u PHYXS(MII_NWAYTEST) [%04x]\n",
+		np->port, err);
 #endif
 
 	/* XXX dig this out it might not be so useful XXX */
@@ -885,11 +885,11 @@ static int xcvr_init_10g(struct niu *np)
 
 	if (analog_stat0 != 0x03fc) {
 		if ((analog_stat0 == 0x43bc) && (tx_alarm_status != 0)) {
-			printk(KERN_INFO PFX "Port %u cable not connected "
-			       "or bad cable.\n", np->port);
+			pr_info(PFX "Port %u cable not connected "
+				"or bad cable.\n", np->port);
 		} else if (analog_stat0 == 0x639c) {
-			printk(KERN_INFO PFX "Port %u optical module is bad "
-			       "or missing.\n", np->port);
+			pr_info(PFX "Port %u optical module is bad "
+				"or missing.\n", np->port);
 		}
 	}
 
@@ -6295,13 +6295,13 @@ static int __devinit phy_record(struct niu_parent *parent,
 			return 0;
 	}
 
-	printk(KERN_INFO PFX "niu%d: Found PHY %08x type %s at phy_port %u\n",
-	       parent->index, id,
-	       (type == PHY_TYPE_PMA_PMD ?
-		"PMA/PMD" :
-		(type == PHY_TYPE_PCS ?
-		 "PCS" : "MII")),
-	       phy_port);
+	pr_info("niu%d: Found PHY %08x type %s at phy_port %u\n",
+		parent->index, id,
+		(type == PHY_TYPE_PMA_PMD ?
+		 "PMA/PMD" :
+		 (type == PHY_TYPE_PCS ?
+		  "PCS" : "MII")),
+		phy_port);
 
 	if (p->cur[type] >= NIU_MAX_PORTS) {
 		printk(KERN_ERR PFX "Too many PHY ports.\n");
@@ -6365,11 +6365,11 @@ static void __devinit niu_n2_divide_channels(struct niu_parent *parent)
 		parent->rxchan_per_port[i] = (16 / num_ports);
 		parent->txchan_per_port[i] = (16 / num_ports);
 
-		printk(KERN_INFO PFX "niu%d: Port %u [%u RX chans] "
-		       "[%u TX chans]\n",
-		       parent->index, i,
-		       parent->rxchan_per_port[i],
-		       parent->txchan_per_port[i]);
+		pr_info(PFX "niu%d: Port %u [%u RX chans] "
+			"[%u TX chans]\n",
+			parent->index, i,
+			parent->rxchan_per_port[i],
+			parent->txchan_per_port[i]);
 	}
 }
 
@@ -6409,11 +6409,11 @@ static void __devinit niu_divide_channels(struct niu_parent *parent,
 			parent->rxchan_per_port[i] = rx_chans_per_1g;
 			parent->txchan_per_port[i] = tx_chans_per_1g;
 		}
-		printk(KERN_INFO PFX "niu%d: Port %u [%u RX chans] "
-		       "[%u TX chans]\n",
-		       parent->index, i,
-		       parent->rxchan_per_port[i],
-		       parent->txchan_per_port[i]);
+		pr_info(PFX "niu%d: Port %u [%u RX chans] "
+			"[%u TX chans]\n",
+			parent->index, i,
+			parent->rxchan_per_port[i],
+			parent->txchan_per_port[i]);
 		tot_rx += parent->rxchan_per_port[i];
 		tot_tx += parent->txchan_per_port[i];
 	}
@@ -6463,8 +6463,8 @@ static void __devinit niu_divide_rdc_groups(struct niu_parent *parent,
 			struct rdc_table *rt = &tp->tables[grp];
 			int slot;
 
-			printk(KERN_INFO PFX "niu%d: Port %d RDC tbl(%d) [ ",
-			       parent->index, i, tp->first_table_num + grp);
+			pr_info(PFX "niu%d: Port %d RDC tbl(%d) [ ",
+				parent->index, i, tp->first_table_num + grp);
 			for (slot = 0; slot < NIU_RDC_TABLE_SLOTS; slot++) {
 				rt->rxdma_channel[slot] =
 					rdc_channel_base + this_channel_offset;
@@ -7342,7 +7342,7 @@ static void __devinit niu_driver_version(void)
 	static int niu_version_printed = 0;
 
 	if (niu_version_printed++ == 0)
-		printk(KERN_INFO "%s", version);
+		pr_info("%s", version);
 }
 
 static struct net_device * __devinit niu_alloc_and_init(struct device *gen_dev,
@@ -7398,19 +7398,19 @@ static void __devinit niu_device_announce(struct niu *np)
 	struct net_device *dev = np->dev;
 	int i;
 
-	printk(KERN_INFO "%s: NIU Ethernet ", dev->name);
+	pr_info("%s: NIU Ethernet ", dev->name);
 	for (i = 0; i < 6; i++)
 		printk("%2.2x%c", dev->dev_addr[i],
 		       i == 5 ? '\n' : ':');
 
-	printk(KERN_INFO "%s: Port type[%s] mode[%s:%s] XCVR[%s] phy[%s]\n",
-	       dev->name,
-	       (np->flags & NIU_FLAGS_XMAC ? "XMAC" : "BMAC"),
-	       (np->flags & NIU_FLAGS_10G ? "10G" : "1G"),
-	       (np->flags & NIU_FLAGS_FIBER ? "FIBER" : "COPPER"),
-	       (np->mac_xcvr == MAC_XCVR_MII ? "MII" :
-		(np->mac_xcvr == MAC_XCVR_PCS ? "PCS" : "XPCS")),
-	       np->vpd.phy_type);
+	pr_info("%s: Port type[%s] mode[%s:%s] XCVR[%s] phy[%s]\n",
+		dev->name,
+		(np->flags & NIU_FLAGS_XMAC ? "XMAC" : "BMAC"),
+		(np->flags & NIU_FLAGS_10G ? "10G" : "1G"),
+		(np->flags & NIU_FLAGS_FIBER ? "FIBER" : "COPPER"),
+		(np->mac_xcvr == MAC_XCVR_MII ? "MII" :
+		 (np->mac_xcvr == MAC_XCVR_PCS ? "PCS" : "XPCS")),
+		np->vpd.phy_type);
 }
 
 static int __devinit niu_pci_init_one(struct pci_dev *pdev,
Signature · 1 line
1.5.3.3
#4 lore raw
Quoted 12 lines · David Miller

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:35:56 -0700

Quoted 1 line

pr_info() ?

All corrected, thanks!

Quoted 1 line

From 11aaa8adc8e9141a440faaa3260ad5922c71eeda Mon Sep 17 00:00:00 2001

From: David S. Miller <[email protected]>
Date: Fri, 5 Oct 2007 15:53:21 -0700
Subject: [PATCH] [NIU]: Use pr_info().

Quoted 6 lines

Suggested by Stephen Hemminger.

---
 drivers/net/niu.c |   78 ++++++++++++++++++++++++++--------------------------
 1 files changed, 39 insertions(+), 39 deletions(-)

ACK

however long term, I would tend to prefer that we utilize the embedded struct device we have, which seems to be the way things are moving long term.

	struct net_device *ndev = ...;
	struct nic_private *np = netdev_priv(ndev);

	dev_printk(KERN_INFO, &ndev->dev,
		   "we all live in a %s submarine, "
		   "a %s submarine\n",
		   np->color ? "yellow" : "silly");

I say "long term" because we want netdev->dev.bus_id to match the net_device->name[], and it may not at this point (needs research/verification).

[as an aside...] If the message isn't directly related to a net_device, you should go ahead and use

	struct pci_dev *pdev = ...;

	dev_printk(KERN_INFO, &pdev->dev, "my message...");

because that stuff is reasonably mature (and seemingly the preferred direction).

Jeff

author maintainer
#5 lore raw
In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:35:56 -0700

Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+static int __niu_wait_bits_clear(struct niu *np, unsigned long reg,
+				 u64 bits, int limit, int delay)
+{
+	BUILD_BUG_ON(limit <= 0 || delay < 0);

redundant you already checked

Good catch, fixed!

Quoted 1 line

From 63f926e5b11d3d03815aeb7bd769e8116a3061fb Mon Sep 17 00:00:00 2001

From: David S. Miller <[email protected]>
Date: Fri, 5 Oct 2007 15:55:55 -0700
Subject: [PATCH] [NIU]: Remove redundant BUILD_BUG_ON() in __niu_wait_bits_clear().

Noticed by Stephen Hemminger.

---
 drivers/net/niu.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/net/niu.c +0 -1
index 92059d7..450d95e 100644
@@ -192,7 +192,6 @@ static int __niu_set_and_wait_clear_ipp(struct niu *np, unsigned long reg,
 static int __niu_wait_bits_clear(struct niu *np, unsigned long reg,
 				 u64 bits, int limit, int delay)
 {
-	BUILD_BUG_ON(limit <= 0 || delay < 0);
 	while (--limit >= 0) {
 		u64 val = nr64(reg);
 
Signature · 1 line
1.5.3.3
author maintainer
#6 lore raw
In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:35:56 -0700

Quoted 4 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		BUG_ON(!page);

BUG_ON checks for NULL are useless if the code following is just going to dereference the pointer anyway.

Agreed, all such cases fixed in the patch below, thanks!

Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +6 -0
+	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
+		tb = &rp->tx_buffs[idx];
+		BUG_ON(tb->skb != NULL);
 
+		np->ops->unmap_page(np->device, tb->mapping,
+				    skb_shinfo(skb)->frags[i].size,
+				    DMA_TO_DEVICE);

Shouldn't this be skb_shinfo(tb->skb)->frags...

Nope, look at the logic, the assertion is making surethat tb->skb == NULL.

When transmitting, the first descriptor holds the SKB pointer and the rest of the descriptors for that packet explicitly set the slots' SKB to NULL.

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+		idx = NEXT_TX(rp, idx);
+	}
+
+	dev_kfree_skb(skb);

Should be dev_kfree_skb_any() if you plan on supporting netconsole.

I have no such plans at this time :-)

I think I've covered all of your feedback from this email, thanks again for the review.

Quoted 1 line

From 418d57645f3132241eb180f9d381ef6541745e23 Mon Sep 17 00:00:00 2001

From: David S. Miller <[email protected]>
Date: Fri, 5 Oct 2007 16:04:16 -0700
Subject: [PATCH] [NIU]: Remove BUG_ON() NULL pointer checks.

As mentioned by Stephen Hemminger, these are superfluous if we are about to dereference the thing anyways. The OOPS has the same effect and will show the problem just as clearly.

---
 drivers/net/niu.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)
drivers/net/niu.c +0 -4
index 450d95e..c29235e 100644
@@ -2134,7 +2134,6 @@ static int niu_rx_pkt_ignore(struct niu *np, struct rx_ring_info *rp)
 		addr = (val & RCR_ENTRY_PKT_BUF_ADDR) <<
 			RCR_ENTRY_PKT_BUF_ADDR_SHIFT;
 		page = niu_find_rxpage(rp, addr, &link);
-		BUG_ON(!page);
 
 		rcr_size = rp->rbr_sizes[(val & RCR_ENTRY_PKTBUFSZ) >>
 					 RCR_ENTRY_PKTBUFSZ_SHIFT];
@@ -2185,7 +2184,6 @@ static int niu_process_rx_pkt(struct niu *np, struct rx_ring_info *rp)
 		addr = (val & RCR_ENTRY_PKT_BUF_ADDR) <<
 			RCR_ENTRY_PKT_BUF_ADDR_SHIFT;
 		page = niu_find_rxpage(rp, addr, &link);
-		BUG_ON(!page);
 
 		rcr_size = rp->rbr_sizes[(val & RCR_ENTRY_PKTBUFSZ) >>
 					 RCR_ENTRY_PKTBUFSZ_SHIFT];
@@ -2294,8 +2292,6 @@ static int release_tx_packet(struct niu *np, struct tx_ring_info *rp, int idx)
 	u64 tx_flags;
 	int i, len;
 
-	BUG_ON(!skb);
-
 	tp = (struct tx_pkt_hdr *) skb->data;
 	tx_flags = le64_to_cpup(&tp->flags);
 
Signature · 1 line
1.5.3.3
author maintainer
#7 lore raw
In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:35:56 -0700

Quoted 6 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static void niu_log_rxchan_errors(struct niu *np, struct rx_ring_info *rp,
+				  u64 stat)
+{
+	printk(KERN_ERR PFX "%s: RX channel %u errors ( ",
+	       np->dev->name, rp->rx_channel);

dev_err??

I've made conversions over to dev_err() where possible.

Thanks!

Quoted 1 line

From cbc4b58382eab08aa231f23d21839c011b4c9f8c Mon Sep 17 00:00:00 2001

From: David S. Miller <[email protected]>
Date: Fri, 5 Oct 2007 16:22:39 -0700
Subject: [PATCH] [NIU]: Use dev_err().

Suggested by Stephen Hemminger.

---
 drivers/net/niu.c |  317 +++++++++++++++++++++++++++--------------------------
 1 files changed, 161 insertions(+), 156 deletions(-)
drivers/net/niu.c +161 -156
index c29235e..1669a0f 100644
@@ -137,10 +137,10 @@ static int __niu_set_and_wait_clear_mac(struct niu *np, unsigned long reg,
 	nw64_mac(reg, bits);
 	err = __niu_wait_bits_clear_mac(np, reg, bits, limit, delay);
 	if (err)
-		printk(KERN_ERR PFX "%s: bits (%llx) of register %s "
-		       "would not clear, val[%llx]\n",
-		       np->dev->name, (unsigned long long) bits, reg_name,
-		       (unsigned long long) nr64_mac(reg));
+		dev_err(np->device, PFX "%s: bits (%llx) of register %s "
+			"would not clear, val[%llx]\n",
+			np->dev->name, (unsigned long long) bits, reg_name,
+			(unsigned long long) nr64_mac(reg));
 	return err;
 }
 
@@ -177,10 +177,10 @@ static int __niu_set_and_wait_clear_ipp(struct niu *np, unsigned long reg,
 
 	err = __niu_wait_bits_clear_ipp(np, reg, bits, limit, delay);
 	if (err)
-		printk(KERN_ERR PFX "%s: bits (%llx) of register %s "
-		       "would not clear, val[%llx]\n",
-		       np->dev->name, (unsigned long long) bits, reg_name,
-		       (unsigned long long) nr64_ipp(reg));
+		dev_err(np->device, PFX "%s: bits (%llx) of register %s "
+			"would not clear, val[%llx]\n",
+			np->dev->name, (unsigned long long) bits, reg_name,
+			(unsigned long long) nr64_ipp(reg));
 	return err;
 }
 
@@ -218,10 +218,10 @@ static int __niu_set_and_wait_clear(struct niu *np, unsigned long reg,
 	nw64(reg, bits);
 	err = __niu_wait_bits_clear(np, reg, bits, limit, delay);
 	if (err)
-		printk(KERN_ERR PFX "%s: bits (%llx) of register %s "
-		       "would not clear, val[%llx]\n",
-		       np->dev->name, (unsigned long long) bits, reg_name,
-		       (unsigned long long) nr64(reg));
+		dev_err(np->device, PFX "%s: bits (%llx) of register %s "
+			"would not clear, val[%llx]\n",
+			np->dev->name, (unsigned long long) bits, reg_name,
+			(unsigned long long) nr64(reg));
 	return err;
 }
 
@@ -549,8 +549,9 @@ static int esr_reset(struct niu *np)
 	if (err)
 		return err;
 	if (reset != 0) {
-		printk(KERN_ERR PFX "Port %u ESR_RESET did not clear [%08x]\n",
-		       np->port, reset);
+		dev_err(np->device, PFX "Port %u ESR_RESET "
+			"did not clear [%08x]\n",
+			np->port, reset);
 		return -ENODEV;
 	}
 
@@ -670,8 +671,8 @@ static int serdes_init_10g(struct niu *np)
 	}
 
 	if ((sig & mask) != val) {
-		printk(KERN_ERR PFX "Port %u signal bits [%08x] are not "
-		       "[%08x]\n", np->port, (int) (sig & mask), (int) val);
+		dev_err(np->device, PFX "Port %u signal bits [%08x] are not "
+			"[%08x]\n", np->port, (int) (sig & mask), (int) val);
 		return -ENODEV;
 	}
 
@@ -729,8 +730,8 @@ static int bcm8704_reset(struct niu *np)
 			break;
 	}
 	if (limit < 0) {
-		printk(KERN_ERR PFX "Port %u PHY will not reset "
-		       "(bmcr=%04x)\n", np->port, (err & 0xffff));
+		dev_err(np->device, PFX "Port %u PHY will not reset "
+			"(bmcr=%04x)\n", np->port, (err & 0xffff));
 		return -ENODEV;
 	}
 	return 0;
@@ -910,8 +911,8 @@ static int mii_reset(struct niu *np)
 			break;
 	}
 	if (limit < 0) {
-		printk(KERN_ERR PFX "Port %u MII would not reset, "
-		       "bmcr[%04x]\n", np->port, err);
+		dev_err(np->device, PFX "Port %u MII would not reset, "
+			"bmcr[%04x]\n", np->port, err);
 		return -ENODEV;
 	}
 
@@ -1010,8 +1011,8 @@ static int mii_init_common(struct niu *np)
 	if (err < 0)
 		return err;
 #if 0
-	printk(KERN_ERR PFX "Port %u after MII init bmcr[%04x] bmsr[%04x]\n",
-	       np->port, bmcr, bmsr);
+	pr_info(PFX "Port %u after MII init bmcr[%04x] bmsr[%04x]\n",
+		np->port, bmcr, bmsr);
 #endif
 
 	return 0;
@@ -2462,8 +2463,8 @@ static int niu_poll(struct napi_struct *napi, int budget)
 static void niu_log_rxchan_errors(struct niu *np, struct rx_ring_info *rp,
 				  u64 stat)
 {
-	printk(KERN_ERR PFX "%s: RX channel %u errors ( ",
-	       np->dev->name, rp->rx_channel);
+	dev_err(np->device, PFX "%s: RX channel %u errors ( ",
+		np->dev->name, rp->rx_channel);
 
 	if (stat & RX_DMA_CTL_STAT_RBR_TMOUT)
 		printk("RBR_TMOUT ");
@@ -2502,8 +2503,8 @@ static int niu_rx_error(struct niu *np, struct rx_ring_info *rp)
 	u64 stat = nr64(RX_DMA_CTL_STAT(rp->rx_channel));
 	int err = 0;
 
-	printk(KERN_ERR PFX "%s: RX channel %u error, stat[%llx]\n",
-	       np->dev->name, rp->rx_channel, (unsigned long long) stat);
+	dev_err(np->device, PFX "%s: RX channel %u error, stat[%llx]\n",
+		np->dev->name, rp->rx_channel, (unsigned long long) stat);
 
 	niu_log_rxchan_errors(np, rp, stat);
 
@@ -2520,8 +2521,8 @@ static int niu_rx_error(struct niu *np, struct rx_ring_info *rp)
 static void niu_log_txchan_errors(struct niu *np, struct tx_ring_info *rp,
 				  u64 cs)
 {
-	printk(KERN_ERR PFX "%s: TX channel %u errors ( ",
-	       np->dev->name, rp->tx_channel);
+	dev_err(np->device, PFX "%s: TX channel %u errors ( ",
+		np->dev->name, rp->tx_channel);
 
 	if (cs & TX_CS_MBOX_ERR)
 		printk("MBOX ");
@@ -2551,12 +2552,12 @@ static int niu_tx_error(struct niu *np, struct tx_ring_info *rp)
 	logh = nr64(TX_RNG_ERR_LOGH(rp->tx_channel));
 	logl = nr64(TX_RNG_ERR_LOGL(rp->tx_channel));
 
-	printk(KERN_ERR PFX "%s: TX channel %u error, "
-	       "cs[%llx] logh[%llx] logl[%llx]\n",
-	       np->dev->name, rp->tx_channel,
-	       (unsigned long long) cs,
-	       (unsigned long long) logh,
-	       (unsigned long long) logl);
+	dev_err(np->device, PFX "%s: TX channel %u error, "
+		"cs[%llx] logh[%llx] logl[%llx]\n",
+		np->dev->name, rp->tx_channel,
+		(unsigned long long) cs,
+		(unsigned long long) logh,
+		(unsigned long long) logl);
 
 	niu_log_txchan_errors(np, rp, cs);
 
@@ -2575,9 +2576,9 @@ static int niu_mif_interrupt(struct niu *np)
 			phy_mdint = 1;
 	}
 
-	printk(KERN_ERR PFX "%s: MIF interrupt, "
-	       "stat[%llx] phy_mdint(%d)\n",
-	       np->dev->name, (unsigned long long) mif_status, phy_mdint);
+	dev_err(np->device, PFX "%s: MIF interrupt, "
+		"stat[%llx] phy_mdint(%d)\n",
+		np->dev->name, (unsigned long long) mif_status, phy_mdint);
 
 	return -ENODEV;
 }
@@ -2702,8 +2703,8 @@ static int niu_mac_interrupt(struct niu *np)
 
 static void niu_log_device_error(struct niu *np, u64 stat)
 {
-	printk(KERN_ERR PFX "%s: Core device errors ( ",
-	       np->dev->name);
+	dev_err(np->device, PFX "%s: Core device errors ( ",
+		np->dev->name);
 
 	if (stat & SYS_ERR_MASK_META2)
 		printk("META2 ");
@@ -2735,8 +2736,8 @@ static int niu_device_error(struct niu *np)
 {
 	u64 stat = nr64(SYS_ERR_STAT);
 
-	printk(KERN_ERR PFX "%s: Core device error, stat[%llx]\n",
-	       np->dev->name, (unsigned long long) stat);
+	dev_err(np->device, PFX "%s: Core device error, stat[%llx]\n",
+		np->dev->name, (unsigned long long) stat);
 
 	niu_log_device_error(np, stat);
 
@@ -2878,7 +2879,7 @@ static irqreturn_t niu_interrupt(int irq, void *dev_id)
 	u64 v0, v1, v2;
 
 	if (netif_msg_intr(np))
-		printk(KERN_ERR PFX "niu_interrupt() ldg[%p](%d) ",
+		printk(KERN_DEBUG PFX "niu_interrupt() ldg[%p](%d) ",
 		       lp, ldg);
 
 	spin_lock_irqsave(&np->lock, flags);
@@ -3013,8 +3014,8 @@ static int niu_alloc_rx_ring_info(struct niu *np,
 	if (!rp->mbox)
 		return -ENOMEM;
 	if ((unsigned long)rp->mbox & (64UL - 1)) {
-		printk(KERN_ERR PFX "%s: Coherent alloc gives misaligned "
-		       "RXDMA mailbox %p\n", np->dev->name, rp->mbox);
+		dev_err(np->device, PFX "%s: Coherent alloc gives misaligned "
+			"RXDMA mailbox %p\n", np->dev->name, rp->mbox);
 		return -EINVAL;
 	}
 
@@ -3024,8 +3025,8 @@ static int niu_alloc_rx_ring_info(struct niu *np,
 	if (!rp->rcr)
 		return -ENOMEM;
 	if ((unsigned long)rp->rcr & (64UL - 1)) {
-		printk(KERN_ERR PFX "%s: Coherent alloc gives misaligned "
-		       "RXDMA RCR table %p\n", np->dev->name, rp->rcr);
+		dev_err(np->device, PFX "%s: Coherent alloc gives misaligned "
+			"RXDMA RCR table %p\n", np->dev->name, rp->rcr);
 		return -EINVAL;
 	}
 	rp->rcr_table_size = MAX_RCR_RING_SIZE;
@@ -3037,8 +3038,8 @@ static int niu_alloc_rx_ring_info(struct niu *np,
 	if (!rp->rbr)
 		return -ENOMEM;
 	if ((unsigned long)rp->rbr & (64UL - 1)) {
-		printk(KERN_ERR PFX "%s: Coherent alloc gives misaligned "
-		       "RXDMA RBR table %p\n", np->dev->name, rp->rbr);
+		dev_err(np->device, PFX "%s: Coherent alloc gives misaligned "
+			"RXDMA RBR table %p\n", np->dev->name, rp->rbr);
 		return -EINVAL;
 	}
 	rp->rbr_table_size = MAX_RBR_RING_SIZE;
@@ -3068,8 +3069,8 @@ static int niu_alloc_tx_ring_info(struct niu *np,
 	if (!rp->mbox)
 		return -ENOMEM;
 	if ((unsigned long)rp->mbox & (64UL - 1)) {
-		printk(KERN_ERR PFX "%s: Coherent alloc gives misaligned "
-		       "TXDMA mailbox %p\n", np->dev->name, rp->mbox);
+		dev_err(np->device, PFX "%s: Coherent alloc gives misaligned "
+			"TXDMA mailbox %p\n", np->dev->name, rp->mbox);
 		return -EINVAL;
 	}
 
@@ -3079,8 +3080,8 @@ static int niu_alloc_tx_ring_info(struct niu *np,
 	if (!rp->descr)
 		return -ENOMEM;
 	if ((unsigned long)rp->descr & (64UL - 1)) {
-		printk(KERN_ERR PFX "%s: Coherent alloc gives misaligned "
-		       "TXDMA descr table %p\n", np->dev->name, rp->descr);
+		dev_err(np->device, PFX "%s: Coherent alloc gives misaligned "
+			"TXDMA descr table %p\n", np->dev->name, rp->descr);
 		return -EINVAL;
 	}
 
@@ -3353,10 +3354,10 @@ static int niu_init_one_tx_channel(struct niu *np, struct tx_ring_info *rp)
 
 	if (rp->descr_dma & ~(TX_RNG_CFIG_STADDR_BASE |
 			      TX_RNG_CFIG_STADDR)) {
-		printk(KERN_ERR PFX "%s: TX ring channel %d "
-		       "DMA addr (%llx) is not aligned.\n",
-		       np->dev->name, channel,
-		       (unsigned long long) rp->descr_dma);
+		dev_err(np->device, PFX "%s: TX ring channel %d "
+			"DMA addr (%llx) is not aligned.\n",
+			np->dev->name, channel,
+			(unsigned long long) rp->descr_dma);
 		return -EINVAL;
 	}
 
@@ -3373,10 +3374,10 @@ static int niu_init_one_tx_channel(struct niu *np, struct tx_ring_info *rp)
 
 	if (((rp->mbox_dma >> 32) & ~TXDMA_MBH_MBADDR) ||
 	    ((u32)rp->mbox_dma & ~TXDMA_MBL_MBADDR)) {
-		printk(KERN_ERR PFX "%s: TX ring channel %d "
-		       "MBOX addr (%llx) is has illegal bits.\n",
-		       np->dev->name, channel,
-		       (unsigned long long) rp->mbox_dma);
+		dev_err(np->device, PFX "%s: TX ring channel %d "
+			"MBOX addr (%llx) is has illegal bits.\n",
+			np->dev->name, channel,
+			(unsigned long long) rp->mbox_dma);
 		return -EINVAL;
 	}
 	nw64(TXDMA_MBH(channel), rp->mbox_dma >> 32);
@@ -3771,9 +3772,9 @@ static int niu_zcp_read(struct niu *np, int index, u64 *data)
 	err = niu_wait_bits_clear(np, ZCP_RAM_ACC, ZCP_RAM_ACC_BUSY,
 				  1000, 100);
 	if (err) {
-		printk(KERN_ERR PFX "%s: ZCP read busy won't clear, "
-		       "ZCP_RAM_ACC[%llx]\n", np->dev->name,
-		       (unsigned long long) nr64(ZCP_RAM_ACC));
+		dev_err(np->device, PFX "%s: ZCP read busy won't clear, "
+			"ZCP_RAM_ACC[%llx]\n", np->dev->name,
+			(unsigned long long) nr64(ZCP_RAM_ACC));
 		return err;
 	}
 
@@ -3785,9 +3786,9 @@ static int niu_zcp_read(struct niu *np, int index, u64 *data)
 	err = niu_wait_bits_clear(np, ZCP_RAM_ACC, ZCP_RAM_ACC_BUSY,
 				  1000, 100);
 	if (err) {
-		printk(KERN_ERR PFX "%s: ZCP read busy2 won't clear, "
-		       "ZCP_RAM_ACC[%llx]\n", np->dev->name,
-		       (unsigned long long) nr64(ZCP_RAM_ACC));
+		dev_err(np->device, PFX "%s: ZCP read busy2 won't clear, "
+			"ZCP_RAM_ACC[%llx]\n", np->dev->name,
+			(unsigned long long) nr64(ZCP_RAM_ACC));
 		return err;
 	}
 
@@ -4114,10 +4115,10 @@ static int niu_reset_tx_bmac(struct niu *np)
 		udelay(100);
 	}
 	if (limit < 0) {
-		printk(KERN_ERR PFX "Port %u TX BMAC would not reset, "
-		       "BTXMAC_SW_RST[%llx]\n",
-		       np->port,
-		       (unsigned long long) nr64_mac(BTXMAC_SW_RST));
+		dev_err(np->device, PFX "Port %u TX BMAC would not reset, "
+			"BTXMAC_SW_RST[%llx]\n",
+			np->port,
+			(unsigned long long) nr64_mac(BTXMAC_SW_RST));
 		return -ENODEV;
 	}
 
@@ -4220,10 +4221,10 @@ static int niu_reset_rx_xmac(struct niu *np)
 		udelay(100);
 	}
 	if (limit < 0) {
-		printk(KERN_ERR PFX "Port %u RX XMAC would not reset, "
-		       "XRXMAC_SW_RST[%llx]\n",
-		       np->port,
-		       (unsigned long long) nr64_mac(XRXMAC_SW_RST));
+		dev_err(np->device, PFX "Port %u RX XMAC would not reset, "
+			"XRXMAC_SW_RST[%llx]\n",
+			np->port,
+			(unsigned long long) nr64_mac(XRXMAC_SW_RST));
 		return -ENODEV;
 	}
 
@@ -4242,10 +4243,10 @@ static int niu_reset_rx_bmac(struct niu *np)
 		udelay(100);
 	}
 	if (limit < 0) {
-		printk(KERN_ERR PFX "Port %u RX BMAC would not reset, "
-		       "BRXMAC_SW_RST[%llx]\n",
-		       np->port,
-		       (unsigned long long) nr64_mac(BRXMAC_SW_RST));
+		dev_err(np->device, PFX "Port %u RX BMAC would not reset, "
+			"BRXMAC_SW_RST[%llx]\n",
+			np->port,
+			(unsigned long long) nr64_mac(BRXMAC_SW_RST));
 		return -ENODEV;
 	}
 
@@ -4547,11 +4548,11 @@ static void niu_disable_ipp(struct niu *np)
 	}
 	if (limit < 0 &&
 	    (rd != 0 && wr != 1)) {
-		printk(KERN_ERR PFX "%s: IPP would not quiesce, "
-		       "rd_ptr[%llx] wr_ptr[%llx]\n",
-		       np->dev->name,
-		       (unsigned long long) nr64_ipp(IPP_DFIFO_RD_PTR),
-		       (unsigned long long) nr64_ipp(IPP_DFIFO_WR_PTR));
+		dev_err(np->device, PFX "%s: IPP would not quiesce, "
+			"rd_ptr[%llx] wr_ptr[%llx]\n",
+			np->dev->name,
+			(unsigned long long) nr64_ipp(IPP_DFIFO_RD_PTR),
+			(unsigned long long) nr64_ipp(IPP_DFIFO_WR_PTR));
 	}
 
 	val = nr64_ipp(IPP_CFIG);
@@ -5068,8 +5069,8 @@ static void niu_tx_timeout(struct net_device *dev)
 {
 	struct niu *np = netdev_priv(dev);
 
-	printk(KERN_ERR PFX "%s: Transmit timed out, resetting\n",
-	       dev->name);
+	dev_err(np->device, PFX "%s: Transmit timed out, resetting\n",
+		dev->name);
 
 	schedule_work(&np->reset_task);
 }
@@ -5171,8 +5172,8 @@ static int niu_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	if (niu_tx_avail(rp) <= (skb_shinfo(skb)->nr_frags + 1)) {
 		netif_stop_queue(dev);
-		printk(KERN_ERR PFX "%s: BUG! Tx ring full when "
-		       "queue awake!\n", dev->name);
+		dev_err(np->device, PFX "%s: BUG! Tx ring full when "
+			"queue awake!\n", dev->name);
 		rp->tx_errors++;
 		return NETDEV_TX_BUSY;
 	}
@@ -5687,10 +5688,11 @@ static int niu_ldg_assign_ldn(struct niu *np, struct niu_parent *parent,
 		 * interrupts and that's painful to debug.
 		 */
 		if (nr64(LDG_NUM(ldn)) != ldg) {
-			printk(KERN_ERR PFX "Port %u, mis-matched LDG assignment "
-			       "for ldn %d, should be %d is %llu\n",
-			       np->port, ldn, ldg,
-			       (unsigned long long) nr64(LDG_NUM(ldn)));
+			dev_err(np->device, PFX "Port %u, mis-matched "
+				"LDG assignment "
+				"for ldn %d, should be %d is %llu\n",
+				np->port, ldn, ldg,
+				(unsigned long long) nr64(LDG_NUM(ldn)));
 			return -EINVAL;
 		}
 	} else
@@ -5741,8 +5743,8 @@ static int __devinit niu_pci_eeprom_read(struct niu *np, u32 addr)
 			break;
 	} while (limit--);
 	if (!(frame & ESPC_PIO_STAT_READ_END)) {
-		printk(KERN_ERR PFX "EEPROM read timeout frame[%llx]\n",
-		       (unsigned long long) frame);
+		dev_err(np->device, PFX "EEPROM read timeout frame[%llx]\n",
+			(unsigned long long) frame);
 		return -ENODEV;
 	}
 
@@ -5756,8 +5758,8 @@ static int __devinit niu_pci_eeprom_read(struct niu *np, u32 addr)
 			break;
 	} while (limit--);
 	if (!(frame & ESPC_PIO_STAT_READ_END)) {
-		printk(KERN_ERR PFX "EEPROM read timeout frame[%llx]\n",
-		       (unsigned long long) frame);
+		dev_err(np->device, PFX "EEPROM read timeout frame[%llx]\n",
+			(unsigned long long) frame);
 		return -ENODEV;
 	}
 
@@ -5913,8 +5915,8 @@ static int __devinit niu_pci_vpd_scan_props(struct niu *np,
 		}
 
 		if (max_len && prop_len > max_len) {
-			printk(KERN_ERR PFX "Property '%s' length (%d) is "
-			       "too long.\n", namebuf, prop_len);
+			dev_err(np->device, PFX "Property '%s' length (%d) is "
+				"too long.\n", namebuf, prop_len);
 			return -EINVAL;
 		}
 
@@ -6060,17 +6062,17 @@ static void __devinit niu_pci_vpd_validate(struct niu *np)
 	u8 val8;
 
 	if (!is_valid_ether_addr(&vpd->local_mac[0])) {
-		printk(KERN_ERR PFX "VPD MAC invalid, "
-		       "falling back to SPROM.\n");
+		dev_err(np->device, PFX "VPD MAC invalid, "
+			"falling back to SPROM.\n");
 
 		np->flags &= ~NIU_FLAGS_VPD_VALID;
 		return;
 	}
 
 	if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) {
-		printk(KERN_ERR PFX "Illegal phy string [%s].\n",
-		       np->vpd.phy_type);
-		printk(KERN_ERR PFX "Falling back to SPROM.\n");
+		dev_err(np->device, PFX "Illegal phy string [%s].\n",
+			np->vpd.phy_type);
+		dev_err(np->device, PFX "Falling back to SPROM.\n");
 		np->flags &= ~NIU_FLAGS_VPD_VALID;
 		return;
 	}
@@ -6110,8 +6112,8 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
 	}
 	niudbg(PROBE, "SPROM: Checksum %x\n", (int)(sum & 0xff));
 	if ((sum & 0xff) != 0xab) {
-		printk(KERN_ERR PFX "Bad SPROM checksum "
-		       "(%x, should be 0xab)\n", (int) (sum & 0xff));
+		dev_err(np->device, PFX "Bad SPROM checksum "
+			"(%x, should be 0xab)\n", (int) (sum & 0xff));
 		return -EINVAL;
 	}
 
@@ -6134,8 +6136,8 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
 			ESPC_PHY_TYPE_PORT3_SHIFT;
 		break;
 	default:
-		printk(KERN_ERR PFX "Bogus port number %u\n",
-		       np->port);
+		dev_err(np->device, PFX "Bogus port number %u\n",
+			np->port);
 		return -EINVAL;
 	}
 	niudbg(PROBE, "SPROM: PHY type %llx\n", (unsigned long long) val);
@@ -6170,8 +6172,8 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
 		break;
 
 	default:
-		printk(KERN_ERR PFX "Bogus SPROM phy type %llu\n",
-		       (unsigned long long) val);
+		dev_err(np->device, PFX "Bogus SPROM phy type %llu\n",
+			(unsigned long long) val);
 		return -EINVAL;
 	}
 
@@ -6190,8 +6192,8 @@ static int __devinit niu_pci_probe_sprom(struct niu *np)
 	dev->perm_addr[5] = (val >>  8) & 0xff;
 
 	if (!is_valid_ether_addr(&dev->perm_addr[0])) {
-		printk(KERN_ERR PFX "SPROM MAC address invalid\n");
-		printk(KERN_ERR PFX "[ \n");
+		dev_err(np->device, PFX "SPROM MAC address invalid\n");
+		dev_err(np->device, PFX "[ \n");
 		for (i = 0; i < 6; i++)
 			printk("%02x ", dev->perm_addr[i]);
 		printk("]\n");
@@ -6716,8 +6718,8 @@ static int __devinit niu_init_mac_ipp_pcs_base(struct niu *np)
 		break;
 
 	default:
-		printk(KERN_ERR PFX "Port %u is invalid, cannot "
-		       "compute MAC block offset.\n", np->port);
+		dev_err(np->device, PFX "Port %u is invalid, cannot "
+			"compute MAC block offset.\n", np->port);
 		return -EINVAL;
 	}
 
@@ -6926,8 +6928,9 @@ static int __devinit niu_get_of_props(struct niu *np)
 
 	phy_type = of_get_property(dp, "phy-type", &prop_len);
 	if (!phy_type) {
-		printk(KERN_ERR PFX "%s: OF node lacks phy-type property\n",
-		       dp->full_name);
+		dev_err(np->device, PFX "%s: OF node lacks "
+			"phy-type property\n",
+			dp->full_name);
 		return -EINVAL;
 	}
 
@@ -6937,29 +6940,31 @@ static int __devinit niu_get_of_props(struct niu *np)
 	strcpy(np->vpd.phy_type, phy_type);
 
 	if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) {
-		printk(KERN_ERR PFX "%s: Illegal phy string [%s].\n",
-		       dp->full_name, np->vpd.phy_type);
+		dev_err(np->device, PFX "%s: Illegal phy string [%s].\n",
+			dp->full_name, np->vpd.phy_type);
 		return -EINVAL;
 	}
 
 	mac_addr = of_get_property(dp, "local-mac-address", &prop_len);
 	if (!mac_addr) {
-		printk(KERN_ERR PFX "%s: OF node lacks local-mac-address property\n",
-		       dp->full_name);
+		dev_err(np->device, PFX "%s: OF node lacks "
+			"local-mac-address property\n",
+			dp->full_name);
 		return -EINVAL;
 	}
 	if (prop_len != dev->addr_len) {
-		printk(KERN_ERR PFX "%s: OF MAC address prop len (%d) is wrong.\n",
-		       dp->full_name, prop_len);
+		dev_err(np->device, PFX "%s: OF MAC address prop len (%d) "
+			"is wrong.\n",
+			dp->full_name, prop_len);
 	}
 	memcpy(dev->perm_addr, mac_addr, dev->addr_len);
 	if (!is_valid_ether_addr(&dev->perm_addr[0])) {
 		int i;
 
-		printk(KERN_ERR PFX "%s: OF MAC address is invalid\n",
-		       dp->full_name);
-		printk(KERN_ERR PFX "%s: [ \n",
-		       dp->full_name);
+		dev_err(np->device, PFX "%s: OF MAC address is invalid\n",
+			dp->full_name);
+		dev_err(np->device, PFX "%s: [ \n",
+			dp->full_name);
 		for (i = 0; i < 6; i++)
 			printk("%02x ", dev->perm_addr[i]);
 		printk("]\n");
@@ -7350,7 +7355,7 @@ static struct net_device * __devinit niu_alloc_and_init(struct device *gen_dev,
 	struct niu *np;
 
 	if (!dev) {
-		printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
+		dev_err(gen_dev, PFX "Etherdev alloc failed, aborting.\n");
 		return NULL;
 	}
 
@@ -7423,30 +7428,30 @@ static int __devinit niu_pci_init_one(struct pci_dev *pdev,
 
 	err = pci_enable_device(pdev);
 	if (err) {
-		printk(KERN_ERR PFX "Cannot enable PCI device, "
-		       "aborting.\n");
+		dev_err(&pdev->dev, PFX "Cannot enable PCI device, "
+			"aborting.\n");
 		return err;
 	}
 
 	if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
 	    !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
-		printk(KERN_ERR PFX "Cannot find proper PCI device "
-		       "base addresses, aborting.\n");
+		dev_err(&pdev->dev, PFX "Cannot find proper PCI device "
+			"base addresses, aborting.\n");
 		err = -ENODEV;
 		goto err_out_disable_pdev;
 	}
 
 	err = pci_request_regions(pdev, DRV_MODULE_NAME);
 	if (err) {
-		printk(KERN_ERR PFX "Cannot obtain PCI resources, "
-		       "aborting.\n");
+		dev_err(&pdev->dev, PFX "Cannot obtain PCI resources, "
+			"aborting.\n");
 		goto err_out_disable_pdev;
 	}
 
 	pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
 	if (pos <= 0) {
-		printk(KERN_ERR PFX "Cannot find PCI Express capability, "
-		       "aborting.\n");
+		dev_err(&pdev->dev, PFX "Cannot find PCI Express capability, "
+			"aborting.\n");
 		goto err_out_free_res;
 	}
 
@@ -7485,17 +7490,17 @@ static int __devinit niu_pci_init_one(struct pci_dev *pdev,
 		dev->features |= NETIF_F_HIGHDMA;
 		err = pci_set_consistent_dma_mask(pdev, dma_mask);
 		if (err) {
-			printk(KERN_ERR PFX "Unable to obtain 44 bit "
-			       "DMA for consistent allocations, "
-			       "aborting.\n");
+			dev_err(&pdev->dev, PFX "Unable to obtain 44 bit "
+				"DMA for consistent allocations, "
+				"aborting.\n");
 			goto err_out_release_parent;
 		}
 	}
 	if (err || dma_mask == DMA_32BIT_MASK) {
 		err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
 		if (err) {
-			printk(KERN_ERR PFX "No usable DMA configuration, "
-			       "aborting.\n");
+			dev_err(&pdev->dev, PFX "No usable DMA configuration, "
+				"aborting.\n");
 			goto err_out_release_parent;
 		}
 	}
@@ -7507,8 +7512,8 @@ static int __devinit niu_pci_init_one(struct pci_dev *pdev,
 
 	np->regs = ioremap_nocache(niureg_base, niureg_len);
 	if (!np->regs) {
-		printk(KERN_ERR PFX "Cannot map device registers, "
-		       "aborting.\n");
+		dev_err(&pdev->dev, PFX "Cannot map device registers, "
+			"aborting.\n");
 		err = -ENOMEM;
 		goto err_out_release_parent;
 	}
@@ -7523,15 +7528,15 @@ static int __devinit niu_pci_init_one(struct pci_dev *pdev,
 	err = niu_get_invariants(np);
 	if (err) {
 		if (err != -ENODEV)
-			printk(KERN_ERR PFX "Problem fetching invariants "
-			       "of chip, aborting.\n");
+			dev_err(&pdev->dev, PFX "Problem fetching invariants "
+				"of chip, aborting.\n");
 		goto err_out_iounmap;
 	}
 
 	err = register_netdev(dev);
 	if (err) {
-		printk(KERN_ERR PFX "Cannot register net device, "
-		       "aborting.\n");
+		dev_err(&pdev->dev, PFX "Cannot register net device, "
+			"aborting.\n");
 		goto err_out_iounmap;
 	}
 
@@ -7729,8 +7734,8 @@ static int __devinit niu_of_probe(struct of_device *op, const struct of_device_i
 
 	reg = of_get_property(op->node, "reg", NULL);
 	if (!reg) {
-		printk(KERN_ERR PFX "%s: No 'reg' property, aborting.\n",
-		       op->node->full_name);
+		dev_err(&op->dev, PFX "%s: No 'reg' property, aborting.\n",
+			op->node->full_name);
 		return -ENODEV;
 	}
 
@@ -7758,8 +7763,8 @@ static int __devinit niu_of_probe(struct of_device *op, const struct of_device_i
 			      res_size(&op->resource[1]),
 			      "niu regs");
 	if (!np->regs) {
-		printk(KERN_ERR PFX "Cannot map device registers, "
-		       "aborting.\n");
+		dev_err(&op->dev, PFX "Cannot map device registers, "
+			"aborting.\n");
 		err = -ENOMEM;
 		goto err_out_release_parent;
 	}
@@ -7768,8 +7773,8 @@ static int __devinit niu_of_probe(struct of_device *op, const struct of_device_i
 				    res_size(&op->resource[2]),
 				    "niu vregs-1");
 	if (!np->vir_regs_1) {
-		printk(KERN_ERR PFX "Cannot map device vir registers 1, "
-		       "aborting.\n");
+		dev_err(&op->dev, PFX "Cannot map device vir registers 1, "
+			"aborting.\n");
 		err = -ENOMEM;
 		goto err_out_iounmap;
 	}
@@ -7778,8 +7783,8 @@ static int __devinit niu_of_probe(struct of_device *op, const struct of_device_i
 				    res_size(&op->resource[3]),
 				    "niu vregs-2");
 	if (!np->vir_regs_2) {
-		printk(KERN_ERR PFX "Cannot map device vir registers 2, "
-		       "aborting.\n");
+		dev_err(&op->dev, PFX "Cannot map device vir registers 2, "
+			"aborting.\n");
 		err = -ENOMEM;
 		goto err_out_iounmap;
 	}
@@ -7789,15 +7794,15 @@ static int __devinit niu_of_probe(struct of_device *op, const struct of_device_i
 	err = niu_get_invariants(np);
 	if (err) {
 		if (err != -ENODEV)
-			printk(KERN_ERR PFX "Problem fetching invariants "
-			       "of chip, aborting.\n");
+			dev_err(&op->dev, PFX "Problem fetching invariants "
+				"of chip, aborting.\n");
 		goto err_out_iounmap;
 	}
 
 	err = register_netdev(dev);
 	if (err) {
-		printk(KERN_ERR PFX "Cannot register net device, "
-		       "aborting.\n");
+		dev_err(&op->dev, PFX "Cannot register net device, "
+			"aborting.\n");
 		goto err_out_iounmap;
 	}
 
Signature · 1 line
1.5.3.3
#8 lore raw
Quoted 14 lines · David Miller

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:35:56 -0700

Quoted 6 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+static void niu_log_rxchan_errors(struct niu *np, struct rx_ring_info *rp,
+				  u64 stat)
+{
+	printk(KERN_ERR PFX "%s: RX channel %u errors ( ",
+	       np->dev->name, rp->rx_channel);

dev_err??

I've made conversions over to dev_err() where possible.

Thanks!

Quoted 8 lines
Quoted 1 line

From cbc4b58382eab08aa231f23d21839c011b4c9f8c Mon Sep 17 00:00:00 2001

From: David S. Miller <[email protected]>
Date: Fri, 5 Oct 2007 16:22:39 -0700
Subject: [PATCH] [NIU]: Use dev_err().

Suggested by Stephen Hemminger.

It seems you made redundant 1/2 of the comment I just sent :)

ACK

author maintainer
#9 lore raw
In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:35:56 -0700

Quoted 6 lines

drivers/net/niu.c line 5389

Quoted 4 lines
drivers/net/niu.c new file +4 -0
+static int niu_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+	return -EINVAL;
+}

Why not leave function ptr null and get "-EOPNOTSUPP"

To be honest, it's there mostly to remind me that I need to implement this routine :-)

Quoted 7 lines

drivers/net/niu.c line 7619

Quoted 5 lines
drivers/net/niu.c new file +5 -0
+	spin_lock_irqsave(&np->lock, flags);
+	niu_enable_interrupts(np, 0);
+	spin_unlock_irqrestore(&np->lock, flags);
+
+	netif_device_detach(dev);

No need to drop lock for detach? all it does is call stop_queue()

I think I'm just being paranoid here, I think it's fine either way.

Quoted 7 lines
Quoted 7 lines
drivers/net/niu.c new file +7 -0
+static void *niu_phys_alloc_coherent(struct device *dev, size_t size,
+				     u64 *dma_addr, gfp_t flag)
+{
+	unsigned long order = get_order(size);
+	unsigned long page = __get_free_pages(flag, order);
+
+	if (page == 0UL)
Quoted 8 lines

drivers/net/niu.c line 7680

Quoted 6 lines
drivers/net/niu.c new file +6 -0
+		return NULL;
+	memset((char *)page, 0, PAGE_SIZE << order);
+	*dma_addr = __pa(page);
+
+	return (void *) page;
+}

Generic cod useful for other drivers??

Quite possibly, once we have something else that wants this we can split it out into some generic place. Currently I am unaware of any such in-tree cases.

Thanks.

#10 lore raw
In reply to David Miller
Quoted 7 lines

I just checked the following into net-2.6.24, besides minor tweaks and bug fixes, this is probably what is going to Linus.

I verified it builds no just on sparc64 but also even on 32-bit platforms such as x86. :-)

Thanks!

Build failed on x86_64

ERROR: "__bad_udelay" [drivers/net/niu.ko] undefined!

author maintainer
#11 lore raw

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:39:24 -0700

Quoted 3 lines

Build failed on x86_64

ERROR: "__bad_udelay" [drivers/net/niu.ko] undefined!

Can you figure out which udelay() call is too big and thus causing problems?

#12 lore raw
Quoted 9 lines · On Fri, 05 Oct 2007 14:12:47 -0700 (PDT) David Miller <[email protected]>…

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:39:24 -0700

Quoted 3 lines

Build failed on x86_64

ERROR: "__bad_udelay" [drivers/net/niu.ko] undefined!

Can you figure out which udelay() call is too big and thus causing problems?

drivers/net/niu.c +1 -1
@@ -804,7 +804,7 @@ static int bcm8704_init_user_dev3(struct
 	if (err)
 		return err;
 
-	udelay(1000000);
+	mdelay(1000);
 
 	return 0;
 }
Signature · 1 line
Stephen Hemminger <[email protected]>
author maintainer Applied
#13 lore raw

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 14:18:50 -0700

drivers/net/niu.c static int bcm8704_init_user_dev3(struct · line 810

Quoted 12 lines
drivers/net/niu.c +1 -1
@@ -804,7 +804,7 @@ static int bcm8704_init_user_dev3(struct
 	if (err)
 		return err;
 
-	udelay(1000000);
+	mdelay(1000);
 
 	return 0;
 }

Applied, thanks Stephen.

#14 lore raw
In reply to David Miller
Quoted 7 lines

I just checked the following into net-2.6.24, besides minor tweaks and bug fixes, this is probably what is going to Linus.

I verified it builds no just on sparc64 but also even on 32-bit platforms such as x86. :-)

Thanks!

Output of checkpatch.pl for your patch:
CHECK: Use #include <linux/io.h> instead of <asm/io.h> #114: FILE: drivers/net/niu.c:26:
+#include <asm/io.h>

ERROR: trailing whitespace
#632: FILE: drivers/net/niu.c:544:
+^I$

WARNING: braces {} are not necessary for single statement blocks #691: FILE: drivers/net/niu.c:603:
+ if (lp->loopback_mode == LOOPBACK_PHY) {
+ test_cfg_val |= ((ENET_TEST_MD_PAD_LOOPBACK <<
+ ENET_SERDES_TEST_MD_0_SHIFT) |
+ (ENET_TEST_MD_PAD_LOOPBACK <<
+ ENET_SERDES_TEST_MD_1_SHIFT) |
+ (ENET_TEST_MD_PAD_LOOPBACK <<
+ ENET_SERDES_TEST_MD_2_SHIFT) |
+ (ENET_TEST_MD_PAD_LOOPBACK <<
+ ENET_SERDES_TEST_MD_3_SHIFT));
+ }

CHECK: if this code is redundant consider removing it #1109: FILE: drivers/net/niu.c:1021:
+#if 0

CHECK: if this code is redundant consider removing it #1665: FILE: drivers/net/niu.c:1577:
+#if 0

CHECK: if this code is redundant consider removing it #1703: FILE: drivers/net/niu.c:1615:
+#if 0

CHECK: if this code is redundant consider removing it #1773: FILE: drivers/net/niu.c:1685:
+#if 0

CHECK: if this code is redundant consider removing it #1816: FILE: drivers/net/niu.c:1728:
+#if 0

CHECK: if this code is redundant consider removing it #1887: FILE: drivers/net/niu.c:1799:
+#if 0

ERROR: trailing whitespace
#1924: FILE: drivers/net/niu.c:1836:
+^I $

WARNING: multiple assignments should be avoided
#2442: FILE: drivers/net/niu.c:2354:
+ tmp = pkt_cnt = (cs & TX_CS_PKT_CNT) >> TX_CS_PKT_CNT_SHIFT;

CHECK: memory barrier without comment
#2457: FILE: drivers/net/niu.c:2369:
+ smp_mb();

WARNING: multiple assignments should be avoided
#2489: FILE: drivers/net/niu.c:2401:
+ rcr_done = work_done = 0;

WARNING: multiple assignments should be avoided
#3254: FILE: drivers/net/niu.c:3166:
+ first_rx_channel = first_tx_channel = 0;

ERROR: trailing whitespace
#4241: FILE: drivers/net/niu.c:4153:
+^Ival &= ~(XMAC_MIN_TX_MIN_PKT_SIZE | $

WARNING: braces {} are not necessary for single statement blocks #4649: FILE: drivers/net/niu.c:4561:
+ if (limit < 0 &&
+ (rd != 0 && wr != 1)) {
+ printk(KERN_ERR PFX "%s: IPP would not quiesce, "

+		       "rd_ptr[%llx] wr_ptr[%llx]\n",
+		       np->dev->name,
+		       (unsigned long long) nr64_ipp(IPP_DFIFO_RD_PTR),
+		       (unsigned long long) nr64_ipp(IPP_DFIFO_WR_PTR));

+ }

WARNING: multiple assignments should be avoided
#4950: FILE: drivers/net/niu.c:4862:
+ pkts = dropped = errors = bytes = 0;

WARNING: multiple assignments should be avoided
#4970: FILE: drivers/net/niu.c:4882:
+ pkts = errors = bytes = 0;

WARNING: multiple assignments should be avoided
#5207: FILE: drivers/net/niu.c:5119:
+ ipv6 = ihl = 0;

WARNING: multiple assignments should be avoided
#5219: FILE: drivers/net/niu.c:5131:
+ ip_proto = ihl = 0;

WARNING: multiple assignments should be avoided
#5342: FILE: drivers/net/niu.c:5254:
+ mrk = nfg = 0;

ERROR: use tabs not spaces
#5458: FILE: drivers/net/niu.c:5370:
+ ^Istruct niu *np = netdev_priv(dev);$

WARNING: multiple assignments should be avoided
#5512: FILE: drivers/net/niu.c:5424:
+ len = eeprom->len = np->eeprom_len - offset;

WARNING: line over 80 characters
#5786: FILE: drivers/net/niu.c:5698:
+ * the firmware, and we're not supposed to change them. Validate

WARNING: line over 80 characters
#5791: FILE: drivers/net/niu.c:5703:
+ printk(KERN_ERR PFX "Port %u, mis-matched LDG assignment "

WARNING: braces {} are not necessary for single statement blocks #5890: FILE: drivers/net/niu.c:5802:
+ if (err < 0) {
+ return err;
+ }

WARNING: braces {} are not necessary for single statement blocks #5895: FILE: drivers/net/niu.c:5807:
+ if (err < 0) {
+ return err;
+ }

ERROR: trailing whitespace
#5969: FILE: drivers/net/niu.c:5881:
+^I $

WARNING: line over 80 characters
#6129: FILE: drivers/net/niu.c:6041:
+static int __devinit niu_phy_type_prop_decode(struct niu *np, const char *phy_prop)

WARNING: printk() should include KERN_ facility level #6297: FILE: drivers/net/niu.c:6209:
+ printk("%02x ", dev->perm_addr[i]);

WARNING: multiple assignments should be avoided
#6481: FILE: drivers/net/niu.c:6393:
+ rx_chans_per_10g = rx_chans_per_1g =

WARNING: multiple assignments should be avoided
#6483: FILE: drivers/net/niu.c:6395:
+ tx_chans_per_10g = tx_chans_per_1g =

WARNING: multiple assignments should be avoided
#6497: FILE: drivers/net/niu.c:6409:
+ tot_rx = tot_tx = 0;

WARNING: braces {} are not necessary for single statement blocks #6531: FILE: drivers/net/niu.c:6443:
+ if (tot_rx < NIU_NUM_RXCHAN || tot_tx < NIU_NUM_TXCHAN) {
+ printk(KERN_WARNING PFX "niu%d: Driver bug, wasted channels, "
+ "RX[%d] TX[%d]\n",
+ parent->index, tot_rx, tot_tx);
+ }

WARNING: multiple assignments should be avoided
#6777: FILE: drivers/net/niu.c:6689:
+ lp->speed = lp->active_speed = SPEED_INVALID;

WARNING: multiple assignments should be avoided
#6778: FILE: drivers/net/niu.c:6690:
+ lp->duplex = lp->active_duplex = DUPLEX_INVALID;

CHECK: if this code is redundant consider removing it #6779: FILE: drivers/net/niu.c:6691:
+#if 0

WARNING: line over 80 characters
#7048: FILE: drivers/net/niu.c:6960:
+ printk(KERN_ERR PFX "%s: OF node lacks local-mac-address property\n",

WARNING: braces {} are not necessary for single statement blocks #7052: FILE: drivers/net/niu.c:6964:
+ if (prop_len != dev->addr_len) {
+ printk(KERN_ERR PFX "%s: OF MAC address prop len (%d) is wrong.\n",
+ dp->full_name, prop_len);
+ }

WARNING: line over 80 characters
#7053: FILE: drivers/net/niu.c:6965:
+ printk(KERN_ERR PFX "%s: OF MAC address prop len (%d) is wrong.\n",

WARNING: printk() should include KERN_ facility level #7065: FILE: drivers/net/niu.c:6977:
+ printk("%02x ", dev->perm_addr[i]);

WARNING: braces {} are not necessary for single statement blocks #7209: FILE: drivers/net/niu.c:7121:
+ for (i = 0; i < p->num_ports; i++) {
+ buf += sprintf(buf,
+ (i == 0) ? "%d" : " %d",
+ arr[i]);
+ }

ERROR: "foo * bar" should be "foo *bar"
#7249: FILE: drivers/net/niu.c:7161:
+static struct niu_parent * __devinit niu_new_parent(struct niu *np,

ERROR: "foo * bar" should be "foo *bar"
#7316: FILE: drivers/net/niu.c:7228:
+static struct niu_parent * __devinit niu_get_parent(struct niu *np,

ERROR: do not initialise statics to 0 or NULL
#7438: FILE: drivers/net/niu.c:7350:
+ static int niu_version_printed = 0;

ERROR: "foo * bar" should be "foo *bar"
#7444: FILE: drivers/net/niu.c:7356:
+static struct net_device * __devinit niu_alloc_and_init(struct device *gen_dev,

WARNING: line over 80 characters
#7447: FILE: drivers/net/niu.c:7359:
+ const struct niu_ops *ops,

WARNING: line over 80 characters
#7819: FILE: drivers/net/niu.c:7731:
+static int __devinit niu_of_probe(struct of_device *op, const struct of_device_id *match)

ERROR: trailing whitespace
#8318: FILE: drivers/net/niu.h:284:
+#define XMAC_ADDR2^I 0x000b0UL $

ERROR: need space after that ',' (ctx:VxV)
#9610: FILE: drivers/net/niu.h:1576:

+#define RDC_TBL(TBL,SLOT)		(FZC_ZCP + 0x10000UL + \
                    ^

WARNING: line over 80 characters
#10002: FILE: drivers/net/niu.h:1968:
+#define RXDMA_CFIG1_MBADDR_H 0x0000000000000fffULL /* mboxaddr 43:32 */

WARNING: line over 80 characters
#10005: FILE: drivers/net/niu.h:1971:
+#define RXDMA_CFIG2_MBADDR_L 0x00000000ffffffc0ULL /* mboxaddr 31:6 */

CHECK: spinlock_t definition without comment
#11039: FILE: drivers/net/niu.h:3005:
+ spinlock_t lock;

WARNING: line over 80 characters
#11203: FILE: drivers/net/niu.h:3169:
+#define NIU_FLAGS_MCAST 0x00200000 /* multicast filter enabled */

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

author maintainer
#15 lore raw

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:40:36 -0700

drivers/net/niu.c line 612

Quoted 12 lines

WARNING: braces {} are not necessary for single statement blocks #691: FILE: drivers/net/niu.c:603:

drivers/net/niu.c new file +10 -0
+	if (lp->loopback_mode == LOOPBACK_PHY) {
+		test_cfg_val |= ((ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_0_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_1_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_2_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_3_SHIFT));
+	}

This is why I don't run checkpatch on my work.

This statement is a "single statement" but it's broken up into multiple lines for readability, and it make perfect sense to put braces around this basic block so it's easier for humans to see what's going on.

#16 lore raw
Quoted 17 lines · David Miller

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:40:36 -0700

drivers/net/niu.c line 612

Quoted 12 lines

WARNING: braces {} are not necessary for single statement blocks #691: FILE: drivers/net/niu.c:603:

drivers/net/niu.c new file +10 -0
+	if (lp->loopback_mode == LOOPBACK_PHY) {
+		test_cfg_val |= ((ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_0_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_1_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_2_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_3_SHIFT));
+	}

This is why I don't run checkpatch on my work.

IMO it -is- useful.

You just have to ignore some of its complaints. Part of my coding style includes the multiple assignment thing that checkpatch complains about:

	status =
	msi->status = br32(QDMA_STAT);

and I am not going to stop doing that just because checkpatch complains :)

Quoted 4 lines

This statement is a "single statement" but it's broken up into multiple lines for readability, and it make perfect sense to put braces around this basic block so it's easier for humans to see what's going on.

Strongly agreed.

Jeff

#17 lore raw
Quoted 30 lines · On Fri, 05 Oct 2007 17:14:31 -0400 Jeff Garzik <[email protected]> wrote:
Quoted 17 lines · David Miller

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:40:36 -0700

drivers/net/niu.c line 612

Quoted 12 lines

WARNING: braces {} are not necessary for single statement blocks #691: FILE: drivers/net/niu.c:603:

drivers/net/niu.c new file +10 -0
+	if (lp->loopback_mode == LOOPBACK_PHY) {
+		test_cfg_val |= ((ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_0_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_1_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_2_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_3_SHIFT));
+	}

This is why I don't run checkpatch on my work.

IMO it -is- useful.

You just have to ignore some of its complaints. Part of my coding style includes the multiple assignment thing that checkpatch complains about:

	status =
	msi->status = br32(QDMA_STAT);

and I am not going to stop doing that just because checkpatch complains :)

Quoted 8 lines
Quoted 4 lines

This statement is a "single statement" but it's broken up into multiple lines for readability, and it make perfect sense to put braces around this basic block so it's easier for humans to see what's going on.

Strongly agreed.

Jeff

Agreed, don't turn into a bot.
All it's complaints don't have to be fixed, same goes for sparse. It just helps catch unintentional cruft.

Signature · 1 line
Stephen Hemminger <[email protected]>
author maintainer
#18 lore raw

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 14:21:48 -0700

Quoted 2 lines

All it's complaints don't have to be fixed, same goes for sparse. It just helps catch unintentional cruft.

That's true.

author maintainer
#19 lore raw
In reply to Jeff Garzik

From: Jeff Garzik <[email protected]>
Date: Fri, 05 Oct 2007 17:14:31 -0400

Quoted 7 lines

You just have to ignore some of its complaints. Part of my coding style includes the multiple assignment thing that checkpatch complains about:

	status =
	msi->status = br32(QDMA_STAT);

and I am not going to stop doing that just because checkpatch complains :)

Whilst I wouldn't condone this practice personally, I fail to see a reason to prevent someone willing to write and maintain a 10,000 line driver from doing so :-)

author maintainer
#20 lore raw
In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:40:36 -0700

Quoted 1 line

Output of checkpatch.pl for your patch:

I've made cures for the cases which make sense, thanks!

commit 2ab9ea48dae8fd46e525460700e7e497c9cb92f8

Author: David S. Miller <[email protected]>
Date:   Fri Oct 5 16:41:00 2007 -0700

[NIU]: Fix some checkpatch caught coding style issues.

1) Remove initializing of statics to 0/NULL.
2) Use tabs instead of spaces.
3) Kill trailing spaces.
4) Cure lines over 80 columns.

drivers/net/niu.c +21 -21
index 63c902d..da15a91 100644
@@ -88,7 +88,7 @@ MODULE_DEVICE_TABLE(pci, niu_pci_tbl);
 
 #define NIU_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
 
-static int niu_debug = 0;
+static int niu_debug;
 static int debug = -1;
 module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "NIU debug level");
@@ -532,7 +532,6 @@ static int esr_reset(struct niu *np)
 		return err;
 	udelay(200);
 
-	
 	err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR,
 			 ESR_RXTX_RESET_CTRL_L, 0xffff);
 	if (err)
@@ -1825,7 +1824,7 @@ static int hash_write(struct niu *np, unsigned long partition,
 
 	return 0;
 }
-		       
+
 static void fflp_reset(struct niu *np)
 {
 	u64 val;
@@ -4138,7 +4137,7 @@ static void niu_init_tx_xmac(struct niu *np, u64 min, u64 max)
 	u64 val;
 
 	val = nr64_mac(XMAC_MIN);
-	val &= ~(XMAC_MIN_TX_MIN_PKT_SIZE | 
+	val &= ~(XMAC_MIN_TX_MIN_PKT_SIZE |
 		 XMAC_MIN_RX_MIN_PKT_SIZE);
 	val |= (min << XMAC_MIN_RX_MIN_PKT_SIZE_SHFT);
 	val |= (min << XMAC_MIN_TX_MIN_PKT_SIZE_SHFT);
@@ -5355,7 +5354,7 @@ static void niu_get_drvinfo(struct net_device *dev,
 
 static int niu_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
-  	struct niu *np = netdev_priv(dev);
+	struct niu *np = netdev_priv(dev);
 	struct niu_link_config *lp;
 
 	lp = &np->link_config;
@@ -5683,9 +5682,9 @@ static int niu_ldg_assign_ldn(struct niu *np, struct niu_parent *parent,
 
 	if (np->parent->plat_type == PLAT_TYPE_NIU) {
 		/* On N2 NIU, the ldn-->ldg assignments are setup and fixed by
-		 * the firmware, and we're not supposed to change them.  Validate
-		 * the mapping, because if it's wrong we probably won't get any
-		 * interrupts and that's painful to debug.
+		 * the firmware, and we're not supposed to change them.
+		 * Validate the mapping, because if it's wrong we probably
+		 * won't get any interrupts and that's painful to debug.
 		 */
 		if (nr64(LDG_NUM(ldn)) != ldg) {
 			dev_err(np->device, PFX "Port %u, mis-matched "
@@ -5788,14 +5787,14 @@ static int __devinit niu_pci_eeprom_read16_swp(struct niu *np, u32 off)
 	int err = niu_pci_eeprom_read(np, off);
 	u16 val;
 
-	if (err < 0) {
+	if (err < 0)
 		return err;
-	}
+
 	val = (err & 0xff);
 	err = niu_pci_eeprom_read(np, off + 1);
-	if (err < 0) {
+	if (err < 0)
 		return err;
-	}
+
 	val |= (err & 0xff) << 8;
 
 	return val;
@@ -5867,7 +5866,7 @@ static int __devinit niu_pci_vpd_scan_props(struct niu *np,
 		char namebuf[64];
 		u8 *prop_buf;
 		int max_len;
-		
+
 		if (found_mask == FOUND_MASK_ALL) {
 			niu_vpd_parse_version(np);
 			return 1;
@@ -6027,7 +6026,8 @@ static u32 __devinit niu_pci_vpd_offset(struct niu *np)
 	return 0;
 }
 
-static int __devinit niu_phy_type_prop_decode(struct niu *np, const char *phy_prop)
+static int __devinit niu_phy_type_prop_decode(struct niu *np,
+					      const char *phy_prop)
 {
 	if (!strcmp(phy_prop, "mif")) {
 		/* 1G copper, MII */
@@ -7339,17 +7339,16 @@ static const struct niu_ops niu_pci_ops = {
 
 static void __devinit niu_driver_version(void)
 {
-	static int niu_version_printed = 0;
+	static int niu_version_printed;
 
 	if (niu_version_printed++ == 0)
 		pr_info("%s", version);
 }
 
-static struct net_device * __devinit niu_alloc_and_init(struct device *gen_dev,
-							struct pci_dev *pdev,
-							struct of_device *op,
-							const struct niu_ops *ops,
-							u8 port)
+static struct net_device * __devinit niu_alloc_and_init(
+	struct device *gen_dev, struct pci_dev *pdev,
+	struct of_device *op, const struct niu_ops *ops,
+	u8 port)
 {
 	struct net_device *dev = alloc_etherdev(sizeof(struct niu));
 	struct niu *np;
@@ -7722,7 +7721,8 @@ static unsigned long res_size(struct resource *r)
 	return r->end - r->start + 1UL;
 }
 
-static int __devinit niu_of_probe(struct of_device *op, const struct of_device_id *match)
+static int __devinit niu_of_probe(struct of_device *op,
+				  const struct of_device_id *match)
 {
 	union niu_parent_id parent_id;
 	struct net_device *dev;
#21 lore raw
In reply to David Miller
Quoted 7 lines

I just checked the following into net-2.6.24, besides minor tweaks and bug fixes, this is probably what is going to Linus.

I verified it builds no just on sparc64 but also even on 32-bit platforms such as x86. :-)

Thanks!

Sparse warnings from new driver.
CHECK drivers/net/niu.c
drivers/net/niu.c:619:7: warning: symbol 'err' shadows an earlier one drivers/net/niu.c:574:6: originally declared here drivers/net/niu.c:4673:7: warning: symbol 'err' shadows an earlier one drivers/net/niu.c:4668:12: originally declared here drivers/net/niu.c:203:2: error: bad constant expression drivers/net/niu.c:203:2: error: cannot size expression drivers/net/niu.c:4214:2: error: bad constant expression drivers/net/niu.c:4214:2: error: cannot size expression

author maintainer
#22 lore raw

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:43:17 -0700

Quoted 6 lines

Sparse warnings from new driver.
CHECK drivers/net/niu.c
drivers/net/niu.c:619:7: warning: symbol 'err' shadows an earlier one drivers/net/niu.c:574:6: originally declared here drivers/net/niu.c:4673:7: warning: symbol 'err' shadows an earlier one drivers/net/niu.c:4668:12: originally declared here

I fixed these two, the first was harmless but the second one would cause error cases to return the wrong error status to the caller.

Quoted 4 lines

drivers/net/niu.c:203:2: error: bad constant expression drivers/net/niu.c:203:2: error: cannot size expression drivers/net/niu.c:4214:2: error: bad constant expression drivers/net/niu.c:4214:2: error: cannot size expression

I can't figure out what sparse doesn't like here.

Thanks.

Quoted 1 line

From 81d1d30537ae388a9ee385d0640999195967b905 Mon Sep 17 00:00:00 2001

From: David S. Miller <[email protected]>
Date: Fri, 5 Oct 2007 17:03:19 -0700
Subject: [PATCH] [NIU]: Fix shadowed local variables.

Noticed by sparse.

---
 drivers/net/niu.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/net/niu.c +0 -2
index da15a91..64b988b 100644
@@ -607,7 +607,6 @@ static int serdes_init_10g(struct niu *np)
 
 	for (i = 0; i < 4; i++) {
 		u32 rxtx_ctrl, glue0;
-		int err;
 
 		err = esr_read_rxtx_ctrl(np, i, &rxtx_ctrl);
 		if (err)
@@ -4657,7 +4656,6 @@ static int niu_request_irq(struct niu *np)
 	err = 0;
 	for (i = 0; i < np->num_ldg; i++) {
 		struct niu_ldg *lp = &np->ldg[i];
-		int err;
 
 		err = request_irq(lp->irq, niu_interrupt,
 				  IRQF_SHARED | IRQF_SAMPLE_RANDOM,
Signature · 1 line
1.5.3.3
#23 lore raw
Quoted 14 lines · On Fri, 05 Oct 2007 17:04:28 -0700 (PDT) David Miller <[email protected]>…

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:43:17 -0700

Quoted 6 lines

Sparse warnings from new driver.
CHECK drivers/net/niu.c
drivers/net/niu.c:619:7: warning: symbol 'err' shadows an earlier one drivers/net/niu.c:574:6: originally declared here drivers/net/niu.c:4673:7: warning: symbol 'err' shadows an earlier one drivers/net/niu.c:4668:12: originally declared here

I fixed these two, the first was harmless but the second one would cause error cases to return the wrong error status to the caller.

Quoted 6 lines
Quoted 4 lines

drivers/net/niu.c:203:2: error: bad constant expression drivers/net/niu.c:203:2: error: cannot size expression drivers/net/niu.c:4214:2: error: bad constant expression drivers/net/niu.c:4214:2: error: cannot size expression

I can't figure out what sparse doesn't like here.

Sparse doesn't like dynamically sized arrays, which is what BUILD_BUG_ON() expands into. Not sure why it is hostile to dynamic arrays, probably just a Linus (or Viro) taste thing.

author maintainer
#24 lore raw

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 17:28:01 -0700

Quoted 11 lines
Quoted 8 lines · On Fri, 05 Oct 2007 17:04:28 -0700 (PDT) David Miller <[email protected]>…

From: Stephen Hemminger <[email protected]>
Date: Fri, 5 Oct 2007 08:43:17 -0700

Quoted 4 lines

drivers/net/niu.c:203:2: error: bad constant expression drivers/net/niu.c:203:2: error: cannot size expression drivers/net/niu.c:4214:2: error: bad constant expression drivers/net/niu.c:4214:2: error: cannot size expression

Quoted 5 lines
Quoted 1 line

I can't figure out what sparse doesn't like here.

Sparse doesn't like dynamically sized arrays, which is what BUILD_BUG_ON() expands into. Not sure why it is hostile to dynamic arrays, probably just a Linus (or Viro) taste thing.

Ok, thanks for tracking it down Stephen.

#25 lore raw
In reply to Stephen Hemminger
Quoted 3 lines · Stephen Hemminger

Sparse doesn't like dynamically sized arrays, which is what BUILD_BUG_ON() expands into. Not sure why it is hostile to dynamic arrays, probably just a Linus (or Viro) taste thing.

sparse from git copes with it.

johannes

#26 lore raw
In reply to David Miller

Hi David,

some minor nits.

Could this driver be split into more files. 8k lines per file is quite a lot. Although GCC might optimize it best this way :-)

Quoted 4 lines · David Miller
drivers/net/niu.c new file +4 -0
+#define nr64(reg)		readq(np->regs + (reg))
+#define nw64(reg, val)		writeq((val), np->regs + (reg))
+
+#define nr64_mac(reg)		readq(np->mac_regs + (reg))

drivers/net/niu.c line 87

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+#define nw64_mac(reg, val)	writeq((val), np->mac_regs + (reg))
+
+#define nr64_ipp(reg)		readq(np->regs + np->ipp_off + (reg))
+#define nw64_ipp(reg, val)	writeq((val), np->regs + np->ipp_off + (reg))
+
+#define nr64_pcs(reg)		readq(np->regs + np->pcs_off + (reg))
+#define nw64_pcs(reg, val)	writeq((val), np->regs + np->pcs_off + (reg))
+
+#define nr64_xpcs(reg)		readq(np->regs + np->xpcs_off + (reg))
+#define nw64_xpcs(reg, val)	writeq((val), np->regs + np->xpcs_off + (reg))

Can these be static inline and get the "struct niu *np" passed?

drivers/net/niu.c line 122

Quoted 4 lines
drivers/net/niu.c new file +4 -0
+#define niu_lock_parent(np, flags) \
+	spin_lock_irqsave(&np->parent->lock, flags)
+#define niu_unlock_parent(np, flags) \
+	spin_unlock_irqrestore(&np->parent->lock, flags)

Maybe fold that into its callers.

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+static int serdes_init_10g(struct niu *np)
+{
+	struct niu_link_config *lp = &np->link_config;
+	unsigned long ctrl_reg, test_cfg_reg, i;
+	u64 ctrl_val, test_cfg_val, sig, mask, val;
+	int err;
+
+	switch (np->port) {
+	case 0:
+		ctrl_reg = ENET_SERDES_0_CTRL_CFG;

drivers/net/niu.c line 588

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+		test_cfg_reg = ENET_SERDES_0_TEST_CFG;
+		break;
+	case 1:
+		ctrl_reg = ENET_SERDES_1_CTRL_CFG;
+		test_cfg_reg = ENET_SERDES_1_TEST_CFG;
+		break;
+
+	default:
+		return -EINVAL;
+	}

Maybe small table?

Quoted 19 lines
drivers/net/niu.c new file +19 -0
+	ctrl_val = (ENET_SERDES_CTRL_SDET_0 |
+		    ENET_SERDES_CTRL_SDET_1 |
+		    ENET_SERDES_CTRL_SDET_2 |
+		    ENET_SERDES_CTRL_SDET_3 |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT));
+	test_cfg_val = 0;
+
+	if (lp->loopback_mode == LOOPBACK_PHY) {
+		test_cfg_val |= ((ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_0_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_1_SHIFT) |

drivers/net/niu.c line 617

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_2_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_3_SHIFT));
+	}
+
+	nw64(ctrl_reg, ctrl_val);
+	nw64(test_cfg_reg, test_cfg_val);
+
+	for (i = 0; i < 4; i++) {

why 4? (magic number)

Quoted 52 lines
drivers/net/niu.c new file +52 -0
+		u32 rxtx_ctrl, glue0;
+		int err;
+
+		err = esr_read_rxtx_ctrl(np, i, &rxtx_ctrl);
+		if (err)
+			return err;
+		err = esr_read_glue0(np, i, &glue0);
+		if (err)
+			return err;
+
+		rxtx_ctrl &= ~(ESR_RXTX_CTRL_VMUXLO);
+		rxtx_ctrl |= (ESR_RXTX_CTRL_ENSTRETCH |
+			      (2 << ESR_RXTX_CTRL_VMUXLO_SHIFT));
+
+		glue0 &= ~(ESR_GLUE_CTRL0_SRATE |
+			   ESR_GLUE_CTRL0_THCNT |
+			   ESR_GLUE_CTRL0_BLTIME);
+		glue0 |= (ESR_GLUE_CTRL0_RXLOSENAB |
+			  (0xf << ESR_GLUE_CTRL0_SRATE_SHIFT) |
+			  (0xff << ESR_GLUE_CTRL0_THCNT_SHIFT) |
+			  (BLTIME_300_CYCLES <<
+			   ESR_GLUE_CTRL0_BLTIME_SHIFT));
+
+		err = esr_write_rxtx_ctrl(np, i, rxtx_ctrl);
+		if (err)
+			return err;
+		err = esr_write_glue0(np, i, glue0);
+		if (err)
+			return err;
+	}
+
+	err = esr_reset(np);
+	if (err)
+		return err;
+
+	sig = nr64(ESR_INT_SIGNALS);
+	switch (np->port) {
+	case 0:
+		mask = ESR_INT_SIGNALS_P0_BITS;
+		val = (ESR_INT_SRDY0_P0 |
+		       ESR_INT_DET0_P0 |
+		       ESR_INT_XSRDY_P0 |
+		       ESR_INT_XDP_P0_CH3 |
+		       ESR_INT_XDP_P0_CH2 |
+		       ESR_INT_XDP_P0_CH1 |
+		       ESR_INT_XDP_P0_CH0);
+		break;
+
+	case 1:
+		mask = ESR_INT_SIGNALS_P1_BITS;
+		val = (ESR_INT_SRDY0_P1 |
+		       ESR_INT_DET0_P1 |

drivers/net/niu.c line 679

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+		       ESR_INT_XSRDY_P1 |
+		       ESR_INT_XDP_P1_CH3 |
+		       ESR_INT_XDP_P1_CH2 |
+		       ESR_INT_XDP_P1_CH1 |
+		       ESR_INT_XDP_P1_CH0);
+		break;
+
+	default:
+		return -EINVAL;
+	}

maybe small table? (maybe combined with the other one suggsted above)

Quoted 22 lines
drivers/net/niu.c new file +22 -0
+
+	if ((sig & mask) != val) {
+		printk(KERN_ERR PFX "Port %u signal bits [%08x] are not "
+		       "[%08x]\n", np->port, (int) (sig & mask), (int) val);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+static int serdes_init_1g(struct niu *np)
+{
+	u64 val;
+
+	val = nr64(ENET_SERDES_1_PLL_CFG);
+	val &= ~ENET_SERDES_PLL_FBDIV2;
+	switch (np->port) {
+	case 0:
+		val |= ENET_SERDES_PLL_HRATE0;
+		break;
+	case 1:
+		val |= ENET_SERDES_PLL_HRATE1;

drivers/net/niu.c line 711

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+		break;
+	case 2:
+		val |= ENET_SERDES_PLL_HRATE2;
+		break;
+	case 3:
+		val |= ENET_SERDES_PLL_HRATE3;
+		break;
+	default:
+		return -EINVAL;
+	}

Maybe small table.

Quoted 5 lines
drivers/net/niu.c new file +5 -0
+	nw64(ENET_SERDES_1_PLL_CFG, val);
+
+	return 0;
+}
+

[...]

Quoted 36 lines
drivers/net/niu.c new file +36 -0
+static int bcm8704_init_user_dev3(struct niu *np)
+{
+	int err;
+
+	err = mdio_write(np, np->phy_addr,
+			 BCM8704_USER_DEV3_ADDR, BCM8704_USER_CONTROL,
+			 (USER_CONTROL_OPTXRST_LVL |
+			  USER_CONTROL_OPBIASFLT_LVL |
+			  USER_CONTROL_OBTMPFLT_LVL |
+			  USER_CONTROL_OPPRFLT_LVL |
+			  USER_CONTROL_OPTXFLT_LVL |
+			  USER_CONTROL_OPRXLOS_LVL |
+			  USER_CONTROL_OPRXFLT_LVL |
+			  USER_CONTROL_OPTXON_LVL |
+			  (0x3f << USER_CONTROL_RES1_SHIFT)));
+	if (err)
+		return err;
+
+	err = mdio_write(np, np->phy_addr,
+			 BCM8704_USER_DEV3_ADDR, BCM8704_USER_PMD_TX_CONTROL,
+			 (USER_PMD_TX_CTL_XFP_CLKEN |
+			  (1 << USER_PMD_TX_CTL_TX_DAC_TXD_SH) |
+			  (2 << USER_PMD_TX_CTL_TX_DAC_TXCK_SH) |
+			  USER_PMD_TX_CTL_TSCK_LPWREN));
+	if (err)
+		return err;
+
+	err = bcm8704_user_dev3_readback(np, BCM8704_USER_CONTROL);
+	if (err)
+		return err;
+	err = bcm8704_user_dev3_readback(np, BCM8704_USER_PMD_TX_CONTROL);
+	if (err)
+		return err;
+
+	err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
+			BCM8704_USER_OPT_DIGITAL_CTRL);

drivers/net/niu.c line 807

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+	if (err < 0)
+		return err;
+	err &= ~USER_ODIG_CTRL_GPIOS;
+	err |= (0x3 << USER_ODIG_CTRL_GPIOS_SHIFT);
+	err = mdio_write(np, np->phy_addr, BCM8704_USER_DEV3_ADDR,
+			 BCM8704_USER_OPT_DIGITAL_CTRL, err);
+	if (err)
+		return err;
+
+	udelay(1000000);

maybe convert to mdelay?

Quoted 4 lines
drivers/net/niu.c new file +4 -0
+
+	return 0;
+}
+

[...]

Quoted 8 lines
drivers/net/niu.c new file +8 -0
+static void niu_init_xif(struct niu *);
+
+static int link_status_10g(struct niu *np, int *link_up_p)
+{
+	unsigned long flags;
+	int err, link_up;
+
+	if (np->link_config.loopback_mode != LOOPBACK_DISABLED)

drivers/net/niu.c line 1113

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+		return -EINVAL;
+
+	link_up = 0;
+
+	spin_lock_irqsave(&np->lock, flags);
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
+			BCM8704_PMD_RCV_SIGDET);
+	if (err < 0)
+		return err;

missing spin_unlock_irqsave()?

drivers/net/niu.c line 1120

Quoted 7 lines
drivers/net/niu.c new file +7 -0
+	if (!(err & PMD_RCV_SIGDET_GLOBAL))
+		goto out;
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
+			BCM8704_PCS_10G_R_STATUS);
+	if (err < 0)
+		return err;

missing spin_unlock_irqsave()?

Quoted 26 lines
drivers/net/niu.c new file +26 -0
+	if (!(err & PCS_10G_R_STATUS_BLK_LOCK))
+		goto out;
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
+			BCM8704_PHYXS_XGXS_LANE_STAT);
+	if (err < 0)
+		return err;
+
+	if (err != (PHYXS_XGXS_LANE_STAT_ALINGED |
+		    PHYXS_XGXS_LANE_STAT_MAGIC |
+		    PHYXS_XGXS_LANE_STAT_LANE3 |
+		    PHYXS_XGXS_LANE_STAT_LANE2 |
+		    PHYXS_XGXS_LANE_STAT_LANE1 |
+		    PHYXS_XGXS_LANE_STAT_LANE0))
+		goto out;
+
+	link_up = 1;
+	np->link_config.active_speed = SPEED_10000;
+	np->link_config.active_duplex = DUPLEX_FULL;
+
+out:
+	spin_unlock_irqrestore(&np->lock, flags);
+
+	*link_up_p = link_up;
+	return 0;
+}

[...]

Quoted 8 lines
drivers/net/niu.c new file +8 -0
+static void niu_set_primary_mac(struct niu *np, unsigned char *addr)
+{
+	u16 reg0 = addr[4] << 8 | addr[5];
+	u16 reg1 = addr[2] << 8 | addr[3];
+	u16 reg2 = addr[0] << 8 | addr[1];
+
+	if (np->flags & NIU_FLAGS_XMAC) {
+		nw64_mac(XMAC_ADDR0, reg0);

drivers/net/niu.c line 1404

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+		nw64_mac(XMAC_ADDR1, reg1);
+		nw64_mac(XMAC_ADDR2, reg2);
+	} else {
+		nw64_mac(BMAC_ADDR0, reg0);
+		nw64_mac(BMAC_ADDR1, reg1);
+		nw64_mac(BMAC_ADDR2, reg2);
+	}
+}
+
+static int niu_num_alt_addr(struct niu *np)

static int niu_num_alt_addr(const struct niu *np)

Quoted 7 lines
drivers/net/niu.c new file +7 -0
+{
+	if (np->flags & NIU_FLAGS_XMAC)
+		return XMAC_NUM_ALT_ADDR;
+	else
+		return BMAC_NUM_ALT_ADDR;
+}
+

[...]

drivers/net/niu.c line 3070

Quoted 7 lines
drivers/net/niu.c new file +7 -0
+static void niu_set_max_burst(struct niu *np, struct tx_ring_info *rp)
+{
+	int mtu = np->dev->mtu;
+
+	rp->max_burst = mtu + 32;
+	if (rp->max_burst > 4096)
+		rp->max_burst = 4096;

Why 32 and 4096? (Magic values)

Review

Quoted 2 lines
(quoted diff) +2 -0
+}
+

... ok, I stop here, since this drivers is damn big :-)

Best Regards

Ingo Oeser

#27 lore raw
Quoted 12 lines · Ingo Oeser
Quoted 12 lines
drivers/net/niu.c new file +12 -0
+static void niu_init_xif(struct niu *);
+
+static int link_status_10g(struct niu *np, int *link_up_p)
+{
+	unsigned long flags;
+	int err, link_up;
+
+	if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
+		return -EINVAL;
+
+	link_up = 0;
+
Quoted 8 lines

drivers/net/niu.c line 1113

Quoted 6 lines
drivers/net/niu.c new file +6 -0
+	spin_lock_irqsave(&np->lock, flags);
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
+			BCM8704_PMD_RCV_SIGDET);
+	if (err < 0)
+		return err;

missing spin_unlock_irqsave()?

I mean spin_unlock_irqrestore()

Quoted 8 lines

drivers/net/niu.c line 1120

Quoted 7 lines
drivers/net/niu.c new file +7 -0
+	if (!(err & PMD_RCV_SIGDET_GLOBAL))
+		goto out;
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
+			BCM8704_PCS_10G_R_STATUS);
+	if (err < 0)
+		return err;

missing spin_unlock_irqsave()?

I mean spin_unlock_irqrestore()

Quoted 18 lines
Quoted 18 lines
drivers/net/niu.c new file +18 -0
+	if (!(err & PCS_10G_R_STATUS_BLK_LOCK))
+		goto out;
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
+			BCM8704_PHYXS_XGXS_LANE_STAT);
+	if (err < 0)
+		return err;
+
+	if (err != (PHYXS_XGXS_LANE_STAT_ALINGED |
+		    PHYXS_XGXS_LANE_STAT_MAGIC |
+		    PHYXS_XGXS_LANE_STAT_LANE3 |
+		    PHYXS_XGXS_LANE_STAT_LANE2 |
+		    PHYXS_XGXS_LANE_STAT_LANE1 |
+		    PHYXS_XGXS_LANE_STAT_LANE0))
+		goto out;
+
+	link_up = 1;
+	np->link_config.active_speed = SPEED_10000;
Quoted 9 lines

drivers/net/niu.c line 1146

Quoted 8 lines
drivers/net/niu.c new file +8 -0
+	np->link_config.active_duplex = DUPLEX_FULL;
+
+out:
+	spin_unlock_irqrestore(&np->lock, flags);
+
+	*link_up_p = link_up;
+	return 0;
+}

Ok, enough for today...

Best Regards

Ingo Oeser

author maintainer
#28 lore raw

From: Ingo Oeser <[email protected]>
Date: Fri, 5 Oct 2007 18:49:49 +0200

Quoted 22 lines
Quoted 12 lines · Ingo Oeser
Quoted 12 lines
(quoted diff) +12 -0
+static void niu_init_xif(struct niu *);
+
+static int link_status_10g(struct niu *np, int *link_up_p)
+{
+	unsigned long flags;
+	int err, link_up;
+
+	if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
+		return -EINVAL;
+
+	link_up = 0;
+
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+	spin_lock_irqsave(&np->lock, flags);
+
+	err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
+			BCM8704_PMD_RCV_SIGDET);
+	if (err < 0)
+		return err;

missing spin_unlock_irqsave()?

Quoted 1 line

I mean spin_unlock_irqrestore()

Definitely a locking error, fixed below, thanks for catching this Ingo!

Quoted 1 line

From 586752eb74a7f303eb2e0693bba0f0a8111ef1e7 Mon Sep 17 00:00:00 2001

From: David S. Miller <[email protected]>
Date: Fri, 5 Oct 2007 17:07:15 -0700
Subject: [PATCH] [NIU]: Fix locking errors in link_status_10g().

When MDIO accesses give an error we forget to drop the np->lock, noticed by Ingo Oeser.

---
 drivers/net/niu.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
drivers/net/niu.c +7 -3
index 64b988b..1a38530 100644
@@ -1100,21 +1100,21 @@ static int link_status_10g(struct niu *np, int *link_up_p)
 	err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
 			BCM8704_PMD_RCV_SIGDET);
 	if (err < 0)
-		return err;
+		goto out_err;
 	if (!(err & PMD_RCV_SIGDET_GLOBAL))
 		goto out;
 
 	err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR,
 			BCM8704_PCS_10G_R_STATUS);
 	if (err < 0)
-		return err;
+		goto out_err;
 	if (!(err & PCS_10G_R_STATUS_BLK_LOCK))
 		goto out;
 
 	err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR,
 			BCM8704_PHYXS_XGXS_LANE_STAT);
 	if (err < 0)
-		return err;
+		goto out_err;
 
 	if (err != (PHYXS_XGXS_LANE_STAT_ALINGED |
 		    PHYXS_XGXS_LANE_STAT_MAGIC |
@@ -1133,6 +1133,10 @@ out:
 
 	*link_up_p = link_up;
 	return 0;
+
+out_err:
+	spin_unlock_irqrestore(&np->lock, flags);
+	return err;
 }
 
 static int link_status_1g(struct niu *np, int *link_up_p)
Signature · 1 line
1.5.3.3
#29 lore raw
Quoted 8 lines · David Miller
drivers/net/niu.c +1 -1
 	if (err < 0)
-		return err;
+		goto out_err;
 
 	if (err != (PHYXS_XGXS_LANE_STAT_ALINGED |
 		    PHYXS_XGXS_LANE_STAT_MAGIC |

drivers/net/niu.c out: · line 1142

Quoted 10 lines
drivers/net/niu.c +4 -0
@@ -1133,6 +1133,10 @@ out:
 
 	*link_up_p = link_up;
 	return 0;
+
+out_err:
+	spin_unlock_irqrestore(&np->lock, flags);
+	return err;
 }
 
 static int link_status_1g(struct niu *np, int *link_up_p)

Should *link_up_p be set to any valid value in the out_err case in link_status_10g()?

Oliver

#30 lore raw
In reply to Ingo Oeser
Quoted 6 lines · Ingo Oeser

Hi David,

some minor nits.

Could this driver be split into more files. 8k lines per file is quite a lot. Although GCC might optimize it best this way :-)

gcc does optimize it better this way, but overall, it's maintainer's preference. It's far easier for many to have everything in a single file, when editing.

Quoted 17 lines
Quoted 4 lines · David Miller
drivers/net/niu.c new file +4 -0
+#define nr64(reg)		readq(np->regs + (reg))
+#define nw64(reg, val)		writeq((val), np->regs + (reg))
+
+#define nr64_mac(reg)		readq(np->mac_regs + (reg))

drivers/net/niu.c line 87

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+#define nw64_mac(reg, val)	writeq((val), np->mac_regs + (reg))
+
+#define nr64_ipp(reg)		readq(np->regs + np->ipp_off + (reg))
+#define nw64_ipp(reg, val)	writeq((val), np->regs + np->ipp_off + (reg))
+
+#define nr64_pcs(reg)		readq(np->regs + np->pcs_off + (reg))
+#define nw64_pcs(reg, val)	writeq((val), np->regs + np->pcs_off + (reg))
+
+#define nr64_xpcs(reg)		readq(np->regs + np->xpcs_off + (reg))
+#define nw64_xpcs(reg, val)	writeq((val), np->regs + np->xpcs_off + (reg))

Can these be static inline and get the "struct niu *np" passed?

We have to answer this every single time... :) it makes the code more readable, and this is common practice all over the place.

Jeff

#31 lore raw
In reply to Ingo Oeser
Quoted 7 lines · Ingo Oeser

Hi David,

some minor nits.

Could this driver be split into more files. 8k lines per file is quite a lot. Although GCC might optimize it best this way :-)

Ingo,

Some r info on Neptune HW to explains some of the constants ... Regards
Matheos

Quoted 24 lines
Quoted 24 lines
drivers/net/niu.c new file +24 -0
+	ctrl_val = (ENET_SERDES_CTRL_SDET_0 |
+		    ENET_SERDES_CTRL_SDET_1 |
+		    ENET_SERDES_CTRL_SDET_2 |
+		    ENET_SERDES_CTRL_SDET_3 |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT));
+	test_cfg_val = 0;
+
+	if (lp->loopback_mode == LOOPBACK_PHY) {
+		test_cfg_val |= ((ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_0_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_1_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_2_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_3_SHIFT));
+	}
Quoted 9 lines

drivers/net/niu.c line 617

Quoted 6 lines
drivers/net/niu.c new file +5 -0
+
+	nw64(ctrl_reg, ctrl_val);
+	nw64(test_cfg_reg, test_cfg_val);
+
+	for (i = 0; i < 4; i++) {

why 4? (magic number)

The MAC HW has 4 SERDES lanes. Need to configure each lane

Quoted 13 lines

drivers/net/niu.c line 3070

Quoted 10 lines
drivers/net/niu.c new file +7 -0
+static void niu_set_max_burst(struct niu *np, struct tx_ring_info *rp)
+{
+	int mtu = np->dev->mtu;
+
+	rp->max_burst = mtu + 32;
+	if (rp->max_burst > 4096)
+		rp->max_burst = 4096;

Why 32 and 4096? (Magic values)

These values were recommended by the HW designers for fair utilization of DRR feature among TX/RX rings.

Quoted 11 lines

Review

Quoted 4 lines
(quoted diff) +2 -0
+}
+

... ok, I stop here, since this drivers is damn big :-)

Best Regards

Ingo Oeser

author maintainer
#32 lore raw
In reply to Ingo Oeser

From: Ingo Oeser <[email protected]>
Date: Fri, 5 Oct 2007 18:46:19 +0200

Quoted 2 lines

Could this driver be split into more files. 8k lines per file is quite a lot. Although GCC might optimize it best this way :-)

Absolutely not!!!!!!!

I hate multiple file drivers, with a passion, they absolutely and positivel suck. I cringe every time I have to study a driver that is broken up into multiple files.

They are a nightmare to hack on. You have to keep typing in grep commands, be a cscope wizard, or whatever to search around and find the file in which the function or variable you want to learn about.

If it's all in one file, you can just sit in your single editor buffer and get a lot of work done.

And to top it off such multi-file drivers tend to be a lot larger and thus even harder to understand.

Multi-file drivers, just say no.

author maintainer
#33 lore raw
In reply to Ingo Oeser

From: Ingo Oeser <[email protected]>
Date: Fri, 5 Oct 2007 18:46:19 +0200

Quoted 17 lines
Quoted 4 lines · David Miller
drivers/net/niu.c new file +4 -0
+#define nr64(reg)		readq(np->regs + (reg))
+#define nw64(reg, val)		writeq((val), np->regs + (reg))
+
+#define nr64_mac(reg)		readq(np->mac_regs + (reg))

drivers/net/niu.c line 87

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+#define nw64_mac(reg, val)	writeq((val), np->mac_regs + (reg))
+
+#define nr64_ipp(reg)		readq(np->regs + np->ipp_off + (reg))
+#define nw64_ipp(reg, val)	writeq((val), np->regs + np->ipp_off + (reg))
+
+#define nr64_pcs(reg)		readq(np->regs + np->pcs_off + (reg))
+#define nw64_pcs(reg, val)	writeq((val), np->regs + np->pcs_off + (reg))
+
+#define nr64_xpcs(reg)		readq(np->regs + np->xpcs_off + (reg))
+#define nw64_xpcs(reg, val)	writeq((val), np->regs + np->xpcs_off + (reg))

Can these be static inline and get the "struct niu *np" passed?

Absolutely not, this was discussed to death in the first review. This is a common sequence which is used in several driver, which saves a lot of typing and carpel-tunnel syndrome.

A message that is not in the archive (sent off-list or not yet received): [email protected]

author maintainer
#35 lore raw

Matheos, no developers, including me, are going to read this since it was in HTML, please post in plain ASCII text if you'd like to discuss the driver with us, thanks.

#36 lore raw
In reply to Ingo Oeser
Quoted 1 line · Ingo Oeser

Hi David,

Repost since my last post ended up being html
Regards,

matheos

Quoted 2 lines

some minor nits.

Some Neptune HW info to explain some of the constants ...

Quoted 42 lines

Could this driver be split into more files. 8k lines per file

drivers/net/niu.c line 588

Quoted 12 lines
drivers/net/niu.c new file +12 -0
+	case 0:
+		ctrl_reg = ENET_SERDES_0_CTRL_CFG;
+		test_cfg_reg = ENET_SERDES_0_TEST_CFG;
+		break;
+	case 1:
+		ctrl_reg = ENET_SERDES_1_CTRL_CFG;
+		test_cfg_reg = ENET_SERDES_1_TEST_CFG;
+		break;
+
+	default:
+		return -EINVAL;
+	}

Maybe small table?

Quoted 23 lines
drivers/net/niu.c new file +23 -0
+	ctrl_val = (ENET_SERDES_CTRL_SDET_0 |
+		    ENET_SERDES_CTRL_SDET_1 |
+		    ENET_SERDES_CTRL_SDET_2 |
+		    ENET_SERDES_CTRL_SDET_3 |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT) |
+		    (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT) |
+		    (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT));
+	test_cfg_val = 0;
+
+	if (lp->loopback_mode == LOOPBACK_PHY) {
+		test_cfg_val |= ((ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_0_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_1_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_2_SHIFT) |
+				 (ENET_TEST_MD_PAD_LOOPBACK <<
+				  ENET_SERDES_TEST_MD_3_SHIFT));
Quoted 8 lines

drivers/net/niu.c line 617

Quoted 6 lines
drivers/net/niu.c new file +6 -0
+	}
+
+	nw64(ctrl_reg, ctrl_val);
+	nw64(test_cfg_reg, test_cfg_val);
+
+	for (i = 0; i < 4; i++) {

why 4? (magic number)

The MAC HW has 4 SERDES lanes. Need to configure each lane.

Quoted 15 lines
Quoted 10 lines
drivers/net/niu.c new file +8 -0
+		u32 rxtx_ctrl, glue0;
+		int err;
+
+		err = esr_read_rxtx_ctrl(np, i, &rxtx_ctrl);
+		if (err)
+			return err;
+		err = esr_read_glue0(np, i, &glue0);
 
+

[...]

Quoted 9 lines

drivers/net/niu.c line 3070

Quoted 7 lines
drivers/net/niu.c new file +7 -0
+static void niu_set_max_burst(struct niu *np, struct tx_ring_info *rp)
+{
+	int mtu = np->dev->mtu;
+
+	rp->max_burst = mtu + 32;
+	if (rp->max_burst > 4096)
+		rp->max_burst = 4096;

Why 32 and 4096? (Magic values)

These values were recommended by the HW designers for fair utilization of DRR feature among TX/RX rings.

Quoted 9 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+}
+

... ok, I stop here, since this drivers is damn big :-)

Best Regards

Ingo Oeser

author maintainer
#37 lore raw

From: Matheos Worku <[email protected]>
Date: Fri, 05 Oct 2007 15:18:37 -0700

Quoted 11 lines
Quoted 10 lines

drivers/net/niu.c line 3070

Quoted 8 lines
drivers/net/niu.c new file +7 -0
+static void niu_set_max_burst(struct niu *np, struct tx_ring_info *rp)
+{
+	int mtu = np->dev->mtu;
+
+	rp->max_burst = mtu + 32;
+	if (rp->max_burst > 4096)
+		rp->max_burst = 4096;

Why 32 and 4096? (Magic values)

Quoted 2 lines

These values were recommended by the HW designers for fair utilization of DRR feature among TX/RX rings.

I'll add macro defines for these, thanks for the feedback.

author maintainer
#38 lore raw
In reply to Ingo Oeser

From: Ingo Oeser <[email protected]>
Date: Fri, 5 Oct 2007 18:46:19 +0200

Quoted 2 lines
Quoted 1 line

+static int niu_num_alt_addr(struct niu *np)

static int niu_num_alt_addr(const struct niu *np)

There are a lot of functions that can be modified to take a const "struct niu *" argument, if I find some time I'll go over the entire driver and make this transformation.

Thanks.

#39 lore raw
In reply to David Miller

drivers/net/niu.c line 1156

Quoted 11 lines · David Miller
drivers/net/niu.c new file +10 -0
+
+static int link_status_1g(struct niu *np, int *link_up_p)
+{
+	u16 current_speed, bmsr;
+	unsigned long flags;
+	u8 current_duplex;
+	int err, link_up;
+
+	if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
+		return -EINVAL;

Should *link_up_p be set to any value before returning?

Quoted 58 lines
drivers/net/niu.c new file +57 -0
+
+	link_up = 0;
+	current_speed = SPEED_INVALID;
+	current_duplex = DUPLEX_INVALID;
+
+	spin_lock_irqsave(&np->lock, flags);
+
+	err = mii_read(np, np->phy_addr, MII_BMSR);
+	if (err < 0)
+		goto out;
+
+	bmsr = err;
+	if (bmsr & BMSR_LSTATUS) {
+		u16 adv, lpa, common, estat;
+
+		err = mii_read(np, np->phy_addr, MII_ADVERTISE);
+		if (err < 0)
+			goto out;
+		adv = err;
+
+		err = mii_read(np, np->phy_addr, MII_LPA);
+		if (err < 0)
+			goto out;
+		lpa = err;
+
+		common = adv & lpa;
+
+		err = mii_read(np, np->phy_addr, MII_ESTATUS);
+		if (err < 0)
+			goto out;
+		estat = err;
+
+		if (estat & (ESTATUS_1000_TFULL | ESTATUS_1000_THALF)) {
+			current_speed = SPEED_1000;
+			if (estat == ESTATUS_1000_TFULL)
+				current_duplex = DUPLEX_FULL;
+			else
+				current_duplex = DUPLEX_HALF;
+		} else {
+			if (common & ADVERTISE_100BASE4) {
+				current_speed = SPEED_100;
+				current_duplex = DUPLEX_HALF;
+			} else if (common & ADVERTISE_100FULL) {
+				current_speed = SPEED_100;
+				current_duplex = DUPLEX_FULL;
+			} else if (common & ADVERTISE_100HALF) {
+				current_speed = SPEED_100;
+				current_duplex = DUPLEX_HALF;
+			} else if (common & ADVERTISE_10FULL) {
+				current_speed = SPEED_10;
+				current_duplex = DUPLEX_FULL;
+			} else if (common & ADVERTISE_10HALF) {
+				current_speed = SPEED_10;
+				current_duplex = DUPLEX_HALF;
+			} else
+				goto out;
+		}

drivers/net/niu.c line 1223

Quoted 10 lines
drivers/net/niu.c new file +10 -0
+		link_up = 1;
+	}
+
+out:
+	spin_unlock_irqrestore(&np->lock, flags);
+
+	*link_up_p = link_up;
+	return 0;
+}
+

Although you added a proper return value in link_status_10g() while fixing the locking issue, you should think about providing a similar return value for link_status_1g() to be constistent here.

Oliver

author maintainer
#40 lore raw

From: Oliver Hartkopp <[email protected]>
Date: Mon, 08 Oct 2007 18:01:20 +0200

Quoted 3 lines
Quoted 2 lines · David Miller
(quoted diff) +2 -0
+
+static int link_status_1g(struct niu *np, int *link_up_p)

...

Quoted 1 line

Should *link_up_p be set to any value before returning?

...

Quoted 11 lines

Review

Quoted 8 lines
(quoted diff) +7 -0
+out:
+	spin_unlock_irqrestore(&np->lock, flags);
+
+	*link_up_p = link_up;
+	return 0;
+}
+

Although you added a proper return value in link_status_10g() while fixing the locking issue, you should think about providing a similar return value for link_status_1g() to be constistent here.

Thanks for finding these two issues. I've fixed it in the patch below.

Luckily, this case was harmless. When we enable a loopback mode, niu_open() forces the link up by calling netif_carrier_on(). Then, niu_timer() always sees -EINVAL coming back from niu_link_status() because of these loopback checks, and in such cases never uses the link_up value because niu_link_status_common() will not be invoked.

Anyways, thanks again!

commit ec3ec3566a8ee3c8c262606e06299c8212ebd53f

Author: David S. Miller <[email protected]>
Date:   Mon Oct 8 16:08:17 2007 -0700

[NIU]: Make sure link_up status is set to something in link_status_{1,10}g().

Noticed by Oliver Hartkopp.

drivers/net/niu.c +13 -13
index 2a69cee..7c09243 100644
@@ -1082,13 +1082,14 @@ static int link_status_10g(struct niu *np, int *link_up_p)
 	unsigned long flags;
 	int err, link_up;
 
-	if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
-		return -EINVAL;
-
 	link_up = 0;
 
 	spin_lock_irqsave(&np->lock, flags);
 
+	err = -EINVAL;
+	if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
+		return out;
+
 	err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR,
 			BCM8704_PMD_RCV_SIGDET);
 	if (err < 0)
@@ -1119,15 +1120,12 @@ static int link_status_10g(struct niu *np, int *link_up_p)
 	link_up = 1;
 	np->link_config.active_speed = SPEED_10000;
 	np->link_config.active_duplex = DUPLEX_FULL;
+	err = 0;
 
 out:
 	spin_unlock_irqrestore(&np->lock, flags);
 
 	*link_up_p = link_up;
-	return 0;
-
-out_err:
-	spin_unlock_irqrestore(&np->lock, flags);
 	return err;
 }
 
@@ -1138,15 +1136,16 @@ static int link_status_1g(struct niu *np, int *link_up_p)
 	u8 current_duplex;
 	int err, link_up;
 
-	if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
-		return -EINVAL;
-
 	link_up = 0;
 	current_speed = SPEED_INVALID;
 	current_duplex = DUPLEX_INVALID;
 
 	spin_lock_irqsave(&np->lock, flags);
 
+	err = -EINVAL;
+	if (np->link_config.loopback_mode != LOOPBACK_DISABLED)
+		goto out;
+
 	err = mii_read(np, np->phy_addr, MII_BMSR);
 	if (err < 0)
 		goto out;
@@ -1172,6 +1171,7 @@ static int link_status_1g(struct niu *np, int *link_up_p)
 			goto out;
 		estat = err;
 
+		link_up = 1;
 		if (estat & (ESTATUS_1000_TFULL | ESTATUS_1000_THALF)) {
 			current_speed = SPEED_1000;
 			if (estat & ESTATUS_1000_TFULL)
@@ -1195,16 +1195,16 @@ static int link_status_1g(struct niu *np, int *link_up_p)
 				current_speed = SPEED_10;
 				current_duplex = DUPLEX_HALF;
 			} else
-				goto out;
+				link_up = 0;
 		}
-		link_up = 1;
 	}
+	err = 0;
 
 out:
 	spin_unlock_irqrestore(&np->lock, flags);
 
 	*link_up_p = link_up;
-	return 0;
+	return err;
 }
 
 static int niu_link_status(struct niu *np, int *link_up_p)