: Preliminary release of Sun Neptune driver
Subsystems (2)
David Miller
maintainerPATCH 1/1 : Preliminary release of Sun Neptune driver
This is a preliminary posting of my Sun Neptune driver against the net-2.6.24 tree.
The TODO list is very long, but it's a lot of small things, most of the basic substance of the driver is all there.
Things which are known to be broken:
1) Niagara-2 frontend not written, I have recently received the hardware necessary to code that part up.
2) Jumbo MTU. I have to add some code to adjust the RBR sizes when the MTU goes above 1500, should be about an afternoon of work.
3) Need to add an API for adding TCAM entries and modifying other state. However, the driver does have full multicast and alternate MAC support.
4) Need an API for adding user classification entries, and also modifying the flow hashing selections.
I anticipate that #3 and #4 will use a new ethtool interface of some sort, and this was suggested by Jeff.
Things I know I will change:
1) All the "#if 1" code blocks will disappear or be changed into controllable logging statements. They are there now to catch non-fastpath interrupt events etc. for initial driver debugging.
2) All the "#if 0" code blocks will either have users added or be removed.
Things which I know are not tested:
1) BMAC and bcm5464r support
I simply lack the hardware which can make use of the 10/100Mbit PHY support.
The locking also needs to be audited, and I plan to add a lockless interrupt quiesce scheme like what we use in the tg3 driver. And on the topic of interrupts I need to investigate if it's too rude to try and use so many MSI-X vectors for a single device and in particular if that can consume all of the MSIs available on some machines. Currently the driver just tries to acquire as many as it can.
Finally, I need to performance tune this driver. In particular I am setting the MARK bit on every TX descriptor. I have to do this because the chip provides no way to interrupt the host when the TX queue drains completely. So if we get some packets before we hit the threshold for setting the MARK bit, and then get no future packets, those packet buffers won't be released which is totally illegal because those buffers are charged against sockets which cannot be released until the packet buffers get freed.
My initial idea is to use some kind of timer when we have packets pending in the TX queue but no MARK bits set yet. As soon as we set the first MARK bit, we kill the timer. Otherwise the timer fires and we process the TX completion queue.
On the performance side there is also the issue of how much I should pre-pull from the page vector data into the linear packet buffer. Basically this is amortizing all the pskb_may_pull() calls the stack is going to do anyways. It might be possible to check out the classification result to figure out how much would be an optimal pre-pull.
We could also sprinkle some prefetches around the RX path.
The NAPI stuff could be significantly improved especially when we know that the MSI-X points only to RX DMA events of a specific channel. We could avoid all the silly tests on data structures and also we'd only have to read the V0 and V1 LDG status values.
Anyways, enough yapping, I should save my fingers for implementing all of the stuff above :-) This posting is just so people can take an initial look at the driver.
commit 123f82e3a952726b28c8fb0d6c10d6100e56ff0e
Author: David S. Miller <[email protected]> Date: Tue Sep 18 14:58:50 2007 -0700
[NIU]: Add Sun Neptune ethernet driver.
drivers/net/Kconfig +7 -0
@@ -2638,6 +2638,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
@@ -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 +7406 -0
2,983 lines not on this page · raw message
drivers/net/niu.h new file +3208 -0
3,208 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.
O
Quoted 10 lines
drivers/net/niu.c new file +10
-0+#define DRV_MODULE_NAME "niu" +#define PFX DRV_MODULE_NAME ": " +#define DRV_MODULE_VERSION "0.06" +#define DRV_MODULE_RELDATE "September 18, 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" );
drivers/net/niu.c line 49
Quoted 10 lines
drivers/net/niu.c new file +10
-0+MODULE_LICENSE ("GPL" ); +MODULE_VERSION (DRV_MODULE_VERSION ); + +#ifndef DMA_44BIT_MASK +#define DMA_44BIT_MASK 0x00000fffffffffffULL +#endif + +#ifndef PCI_DEVICE_ID_SUN_NEPTUNE +#define PCI_DEVICE_ID_SUN_NEPTUNE 0xabcd +#endif
Why bother defining the ID, and what good does driver_data do you?
drivers/net/niu.c line 62
Quoted 12 lines
drivers/net/niu.c new file +12
-0+static struct pci_device_id niu_pci_tbl[] = { + {PCI_DEVICE (PCI_VENDOR_ID_SUN ,PCI_DEVICE_ID_SUN_NEPTUNE ), + .driver_data =0xff }, + {} +}; + +MODULE_DEVICE_TABLE (pci, niu_pci_tbl); + +#define NIU_TX_TIMEOUT (5 * HZ) + +#define nr64 (reg) readq(np->regs + (reg)) +#define nw64 (val, reg) writeq((val), np->regs + (reg))
Macro's that make assumptions about context (ie variable name np) are evil and bad style.
Quoted 12 lines
drivers/net/niu.c new file +12
-0+#define nr64_mac (reg) readq(np->mac_regs + (reg)) +#define nw64_mac (val, reg) writeq((val), np->mac_regs + (reg)) + +#define nr64_ipp (reg) readq(np->regs + np->ipp_off + (reg)) +#define nw64_ipp (val, reg) writeq((val), np->regs + np->ipp_off + (reg)) + +#define nr64_pcs (reg) readq(np->regs + np->pcs_off + (reg)) +#define nw64_pcs (val, reg) writeq((val), np->regs + np->pcs_off + (reg)) + +#define nr64_xpcs (reg) readq(np->regs + np->xpcs_off + (reg)) +#define nw64_xpcs (val, reg) writeq((val), np->regs + np->xpcs_off + (reg)) +
drivers/net/niu.c line 85
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 0x00080000
Please use or extend already existing netif_msg debug methods.
Quoted 14 lines
drivers/net/niu.c new file +13
-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" +" 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" +);
drivers/net/niu.c line 109
Quoted 10 lines
drivers/net/niu.c new file +10
-0+ +#define niudbg(TYPE, f, a...) \ +do { if (niu_debug & NIU_DEBUG_##TYPE) \ + printk(KERN_ERR PFX f, ## a); \ +} 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)
Wrapping locking is poor style and makes code review harder.
drivers/net/niu.c line 114
Quoted 4 lines
drivers/net/niu.c new file +4
-0+static int niu_wait_bits_clear_mac (struct niu *np,unsigned long reg,u64 bits, +int limit,int delay) +{ +BUILD_BUG_ON (limit <=0 || delay <0 );
There is no way compiler can evaluate limit or delay.
Quoted 167 lines
drivers/net/niu.c new file +167
-0+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 (bits, reg); + err =niu_wait_bits_clear_mac (np, reg, bits, limit, delay); +if (err) + printk(KERN_ERR PFX "%s: bits (%lx) of register %s " +"would not clear, val[%lx]\n" , + np->dev->name, bits, reg_name, +nr64_mac (reg)); +return err; +} + +static int niu_wait_bits_clear_ipp (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_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 (val, reg); + + err =niu_wait_bits_clear_ipp (np, reg, bits, limit, delay); +if (err) + printk(KERN_ERR PFX "%s: bits (%lx) of register %s " +"would not clear, val[%lx]\n" , + np->dev->name, bits, reg_name, +nr64_ipp (reg)); +return err; +} + +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); + +if (!(val & bits)) +break ; +udelay (delay); + } +if (limit <0 ) +return -ENODEV ; +return 0 ; +} + +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 (bits, reg); + err =niu_wait_bits_clear (np, reg, bits, limit, delay); +if (err) + printk(KERN_ERR PFX "%s: bits (%lx) of register %s " +"would not clear, val[%lx]\n" , + np->dev->name, bits, reg_name, +nr64 (reg)); +return err; +} + +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 (val,LDG_IMGMT (lp->ldg_num)); +} + +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 (val, mask_reg); + +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 ; +}
drivers/net/niu.c line 291
Quoted 10 lines
drivers/net/niu.c new file +10
-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 ; +}
Why are you using __u32? That is reserved for values going out to user space.
Quoted 15 lines · Stephen Hemminger
O
Quoted 14 lines
drivers/net/niu.c new file +14
-0+#define DRV_MODULE_NAME "niu" +#define PFX DRV_MODULE_NAME ": " +#define DRV_MODULE_VERSION "0.06" +#define DRV_MODULE_RELDATE "September 18, 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
Quoted 8 lines
drivers/net/niu.c line 49
Quoted 6 lines
drivers/net/niu.c new file +6
-0+#define DMA_44BIT_MASK 0x00000fffffffffffULL +#endif + +#ifndef PCI_DEVICE_ID_SUN_NEPTUNE +#define PCI_DEVICE_ID_SUN_NEPTUNE 0xabcd +#endif Why bother defining the ID
Yes, its pointless to use anything but the hex number for PCI IDs that are only used in a single place.
Quoted 7 lines
Quoted 7 lines
drivers/net/niu.c new file +7
-0+static struct pci_device_id niu_pci_tbl[] = { + {PCI_DEVICE (PCI_VENDOR_ID_SUN ,PCI_DEVICE_ID_SUN_NEPTUNE ), + .driver_data =0xff }, + {} +}; + +MODULE_DEVICE_TABLE (pci, niu_pci_tbl);
Quoted 8 lines
drivers/net/niu.c line 62
Quoted 5 lines
drivers/net/niu.c new file +5
-0+ +#define NIU_TX_TIMEOUT (5 * HZ) + +#define nr64 (reg) readq(np->regs + (reg)) +#define nw64 (val, reg) writeq((val), np->regs + (reg))Macro's that make assumptions about context (ie variable name np) are evil and bad style.
No, that's a common and encouraged convenience that makes the code a lot easier to read.
That said, the 2-arg macro arg order is wrong. It should be (reg,val) like tg3 and other drivers.
Jeff
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Wed, 19 Sep 2007 14:59:00 -0700
Quoted 5 lines
drivers/net/niu.c line 49
Quoted 3 lines
drivers/net/niu.c new file +3
-0+#ifndef PCI_DEVICE_ID_SUN_NEPTUNE +#define PCI_DEVICE_ID_SUN_NEPTUNE 0xabcd +#endif Why bother defining the ID, and what good does
driver_datado you?
Good point, I'll put this 0xabcd thing directly into the table.
Quoted 5 lines
drivers/net/niu.c line 62
Quoted 2 lines
drivers/net/niu.c new file +2
-0+#define nr64 (reg) readq(np->regs + (reg)) +#define nw64 (val, reg) writeq((val), np->regs + (reg))Macro's that make assumptions about context (ie variable name np) are evil and bad style.
Too bad, it saves developers who write 20,000 line drivers from carpel tunnel symdrome.
It's so repetitive to state things over and over again, and this macro scheme is 1) established widely (tg3 amonst many other drivers do it) and 2) forces the driver to use a consistent naming convention for primary driver private struct variables.
Quoted 1 line
Wrapping locking is poor style and makes code review harder.
I disagree, because in this case the macro says exactly what the thing is doing, locking the parent of the port. The implementation is arbitrary and can be reviewed independently of the uses.
Quoted 6 lines
drivers/net/niu.c line 114
Quoted 4 lines
drivers/net/niu.c new file +4
-0+static int niu_wait_bits_clear_mac (struct niu *np,unsigned long reg,u64 bits, +int limit,int delay) +{ +BUILD_BUG_ON (limit <=0 || delay <0 );There is no way compiler can evaluate limit or delay.
Check the callers, they all pass contant values.
Quoted 2 lines
Why are you using
__u32? That is reserved for values going out to user space.
Right, I'll fix those up, thanks.
David Miller
maintainerFrom: Jeff Garzik <[email protected]>
Date: Wed, 19 Sep 2007 18:05:25 -0400
Quoted 2 lines
That said, the 2-arg macro arg order is wrong. It should be (reg,val) like tg3 and other drivers.
I actually wanted to mirror the ordering that writel() uses.
So the choice is arbitrary, either be consistent with our well established asm/io.h interfaces or a bunch of network driver :-)
Quoted 11 lines · David Miller
From: Jeff Garzik <[email protected]>
Date: Wed, 19 Sep 2007 18:05:25 -0400Quoted 1 line
That said, the 2-arg macro arg order is wrong. It should be (reg,val) like tg3 and other drivers.
I actually wanted to mirror the ordering that
writel()uses.So the choice is arbitrary, either be consistent with our well established
asm/io.hinterfaces or a bunch of network driver :-)
IMO (val,reg) was always unnatural. From looking at the register read/write interfaces people continually reinvent, humans definitely lean towards (reg,val).
Jeff
Quoted 10 lines · David Miller
Quoted 2 lines
Macro's that make assumptions about context (ie variable name np) are evil and bad style.
Too bad, it saves developers who write 20,000 line drivers from carpel tunnel symdrome.
It's so repetitive to state things over and over again, and this macro scheme is 1) established widely (tg3 amonst many other drivers do it) and 2) forces the driver to use a consistent naming convention for primary driver private struct variables.
It also makes review easier -- IMO an important factor.
Which is more clear at a glance:
status = tr32(MAC_STAT_1);
or
status = foo_mac_read32(priv, MAC_STAT_1);
?
tg3 and other net drivers show that this technique improves code readability.
Jeff
Quoted 3 lines · On Wed, 19 Sep 2007 15:07:55 -0700 (PDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Wed, 19 Sep 2007 14:59:00 -0700
...
Quoted 8 lines
Quoted 6 lines
drivers/net/niu.c line 114
Quoted 4 lines
drivers/net/niu.c new file +4
-0+static int niu_wait_bits_clear_mac (struct niu *np,unsigned long reg,u64 bits, +int limit,int delay) +{ +BUILD_BUG_ON (limit <=0 || delay <0 );There is no way compiler can evaluate limit or delay.
Check the callers, they all pass contant values.
GCC is not as smart as you think... Try the following test:
--------------------
#include <stdio.h>
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) #define ENODEV -10
static int niu_wait_bits_clear_mac(void *np, unsigned long reg,
int limit, int delay)
{
BUILD_BUG_ON(limit <= 0 || delay < 0);
if (limit < 0)
return -ENODEV;
while (limit > 0)
sleep(delay);
return 0;
}int main(int argc, char **argv) {
printf("start\n");
niu_wait_bits_clear_mac(NULL, 0, 10, 1);
niu_wait_bits_clear_mac(NULL, 0, -1, 0);
niu_wait_bits_clear_mac(NULL, 0, 0, -1);
return 0;
}David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Wed, 19 Sep 2007 16:05:20 -0700
Quoted 1 line
GCC is not as smart as you think... Try the following test:
Indeed, thanks for pointing that out. I'll have to macroize it like this to get the check:
static int __niu_wait_bits_clear_mac(void *np, unsigned long reg,
int limit, int delay)
{
...
#define niu_wait_bits_clear_mac(NP, REG, LIM, DELAY) \
({ BUILD_BUG_ON(LIM <= 0 || DELAY < 0); \
__niu_wait_bits_clear_mac(NP, REG, LIM, DELAY); \
})Quoted 4 lines
Quoted 4 lines
drivers/net/niu.c new file +4
-0+#define DRV_MODULE_NAME "niu" +#define PFX DRV_MODULE_NAME ": " +#define DRV_MODULE_VERSION "0.06" +#define DRV_MODULE_RELDATE "September 18, 2007"
Quoted 8 lines
drivers/net/niu.c line 41
Quoted 8 lines
drivers/net/niu.c new file +8
-0+ +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 );
A somewhat pedantic question... some grepping in a kernel tree suggests the obvious name "netptune" is at least already taken for PCI ID macros:
hpcpc105:~/linux-2.6.23-rc5# grep -i neptune ./drivers/scsi/lpfc/lpfc_hw.h #define PCI_DEVICE_ID_NEPTUNE 0xf0f5 #define PCI_DEVICE_ID_NEPTUNE_SCSP 0xf0f6 #define PCI_DEVICE_ID_NEPTUNE_DCSP 0xf0f7
and shows-up in comments elsewhere, but that same (perhaps too cursory?) search didn't seem to find "neptune" used as an actual module/driver name, so why "niu?" To what does niu translate anyway?
sincerely,
rick jones
now left with the quandry of whether to run netperf against a driver for a card from a .com other than his own or an OEM :) On the plus side though, this driver has no EULA restrictions :)
David Miller
maintainerFrom: Rick Jones <[email protected]>
Date: Wed, 19 Sep 2007 16:20:39 -0700
Quoted 1 line
so why "niu?" To what does niu translate anyway?
Network Interface Unit. This is what the Niagara-2 programmers manual refers to the chip as.
I try to name the files for most drivers I write as a 2 or 3 letter acronyms, it looks so much better than the usual verbose names. It's very unix.
Thanks Dave for your preliminary posting of the driver.
I am copying Matheos Worku. Matheos is intimately familiar with the Neptune/NIU family of devices and their respective drivers.
Not only he can be a good reviewer, he can also clarify issues around naming and so on. I agree that Neptune is just an overused internal codename not worth propagating in the code.
Please feel free to add [email protected] to the reviewers list.
Ariel
Quoted 13 lines · David Miller
From: Rick Jones <[email protected]>
Date: Wed, 19 Sep 2007 16:20:39 -0700Quoted 1 line
so why "niu?" To what does niu translate anyway?
Network Interface Unit. This is what the Niagara-2 programmers manual refers to the chip as.
I try to name the files for most drivers I write as a 2 or 3 letter acronyms, it looks so much better than the usual verbose names. It's very unix.