Skip to contentSkip to conversation

new driver ixgbe for Intel(R) 10GbE PCI Express adapters.

ANNOUNCE In review [email protected] 12 participants 41 messages Jun 12, 2007 – Jul 10, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

All,

We are pleased to release the new driver "ixgbe" for Intel(R) 82598 based 10GbE PCI Express adapters. The 82598 silicon and the adapters will be released soon.

Please find the full driver as a patch to latest linus-2.6 tree here:
git-pull git://lost.foo-projects.org/~aveerani/git/linux-2.6 ixgbe

Also, I am posting the driver patch in the followup mail.

Short introduction on the "ixgbe" driver and 82598 silicon:

The 82598 (PCI Express) silicon's architecture and SW interface is vastly different from legacy 82597 (PCI-X device). The register offsets and the bit definitions are very different from 82597. The EEPROM/FLASH, SERDES interface for external PHY and other interfaces are also different. 82598 has new Tx and Rx descriptor interfaces (adavanced descriptors) to support packet/header split Rx feauture and Rx packet steering (based on 5 tuples or MAC addresses). It supports list of new features like MSI-X, Multiple Rx and Tx queues, TSO for IPv6. Because of all these differences, we had to write a new driver for 82598 and the new driver is lot cleaner with no 82597 errata workarounds in the hot path.

This driver has been tested extensively for the last couple of months in our labs.

Please review and provide comments.

Apart from implementing the community feedback, here is the list of things in TODO list...

1. Add suspend/resume support.
2. Rewrite the driver handling of LLTX logic. Will post a patch very soon for review.
3. Add PCI error handler support.

thanks,
Ayyappan

#1 lore raw

PATCH 1/1 ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

This patch adds support for the 82598 based Intel PCI Express 10GbE adapters. This driver uses MSIX and enables multiple Rx queus, uses Packet split in Rx side for Jumbo frame configurations, uses "adavanced descriptors" for both Tx & Rx.

---

 Documentation/networking/ixgbe.txt |  155 ++
 MAINTAINERS                        |   15 
 drivers/net/Kconfig                |   22 
 drivers/net/Makefile               |    1 
 drivers/net/ixgbe/Makefile         |   36 
 drivers/net/ixgbe/ixgbe.h          |  213 +++
 drivers/net/ixgbe/ixgbe_82598.c    |  555 ++++++++
 drivers/net/ixgbe/ixgbe_api.c      |  635 +++++++++
 drivers/net/ixgbe/ixgbe_api.h      |   89 +
 drivers/net/ixgbe/ixgbe_common.c   | 1725 ++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_common.h   |   74 +
 drivers/net/ixgbe/ixgbe_ethtool.c  |  491 +++++++
 drivers/net/ixgbe/ixgbe_main.c     | 2623 ++++++++++++++++++++++++++++++++++++
 drivers/net/ixgbe/ixgbe_osdep.h    |   76 +
 drivers/net/ixgbe/ixgbe_param.c    |  510 +++++++
 drivers/net/ixgbe/ixgbe_phy.c      |  574 ++++++++
 drivers/net/ixgbe/ixgbe_phy.h      |   61 +
 drivers/net/ixgbe/ixgbe_type.h     | 1385 +++++++++++++++++++
 18 files changed, 9240 insertions(+), 0 deletions(-)
Documentation/networking/ixgbe.txt new file +155 -0
new file mode 100644
index 0000000..99db4a5
@@ -0,0 +1,155 @@
+Linux* Base Driver for the 10 Gigabit PCI Express Family of Adapters
+================================================================
+
+June 3, 2007
+
+
+Contents
+========
+
+- In This Release
+- Identifying Your Adapter
+- Command Line Parameters
+- Support
+
+In This Release
+===============
+
+This file describes the Linux* Base Driver for the 10 Gigabit PCI Express
+Family of Adapters.  This driver supports the 2.6.x kernel. This driver
+includes support for Itanium(R)2-based systems.
+
+The following features are now available in supported kernels:
+ - Native VLANs
+ - Channel Bonding (teaming)
+ - SNMP
+
+Channel Bonding documentation can be found in the Linux kernel source:
+/Documentation/networking/bonding.txt
+
+Instructions on updating ethtool can be found in the section "Additional
+Configurations" later in this document.
+
+
+Identifying Your Adapter
+========================
+
+The following Intel network adapters are compatible with the drivers in this
+release:
+
+Controller  Adapter Name                 Physical Layer
+----------  ------------                 --------------
+82598       Intel(R) 10GbE-LR/LRM/SR
+            Server Adapters              10G Base -SR (850 nm optical fiber)
+                                         10G Base -LRM (850 nm optical fiber)
+                                         10G Base -LR (1310 nm optical fiber)
+
+For more information on how to identify your adapter, go to the Adapter &
+Driver ID Guide at:
+
+    http://support.intel.com/support/network/sb/CS-012904.htm
+
+For the latest Intel network drivers for Linux, refer to the following
+website.  In the search field, enter your adapter name or type, or use the
+networking link on the left to search for your adapter:
+
+    http://downloadfinder.intel.com/scripts-df/support_intel.asp
+
+Command Line Parameters
+=======================
+
+If the driver is built as a module, the  following optional parameters are
+used by entering them on the command line with the modprobe command using
+this syntax:
+
+     modprobe ixgbe [<option>=<VAL1>,<VAL2>,...]
+
+For example, with two PRO/10GbE PCI Express adapters, entering:
+
+     modprobe ixgbe TxDescriptors=80,128
+
+loads the ixgbe driver with 80 TX resources for the first adapter and 128 TX
+resources for the second adapter.
+
+The default value for each parameter is generally the recommended setting,
+unless otherwise noted.
+
+RxDescriptors
+Valid Range: 64-4096
+Default Value: 1024
+    This value is the number of receive descriptors allocated by the driver.
+    Increasing this value allows the driver to buffer more incoming packets.
+    Each descriptor is 16 bytes.  A receive buffer is also allocated for
+    each descriptor and can be either 1522 or 4096 bytes,
+    depending on the MTU setting.  When the MTU size is 1500 or less, the
+    receive buffer size is 1522 bytes. When the MTU is greater than 1500 the
+    receive buffer size will be either 4096 bytes.  The
+    maximum MTU size is 16110.
+
+TxDescriptors
+Valid Range: 64-4096
+Default Value: 1024
+    This value is the number of transmit descriptors allocated by the driver.
+    Increasing this value allows the driver to queue more transmits.  Each
+    descriptor is 16 bytes.
+
+RxQueues
+Valid Range: 1-8
+Default Value: 8
+    Rx Queues count.
+   
+RxFCHighThresh
+Valid Range: 1,536 - 262,136 (0x600 - 0x3FFF8, 8 byte granularity)
+Default Value: 196,608 (0x30000)
+    Receive Flow control high threshold (when we send a pause frame)
+
+RxFCLowThresh
+Valid Range: 64 - 262,136 (0x40 - 0x3FFF8, 8 byte granularity)
+             *  must be less than high threshold by at least 8 bytes
+Default Value:  163,840 (0x28000)
+Receive Flow control low threshold (when we send a resume frame)
+
+InterruptType
+Valid Range: 0-2 0 = Legacy Int, 1 = MSI and 2 = MSIX
+Default Value: 2
+    Interrupt type
+
+FCReqTimeout
+Valid Range: 1 - 65535
+Default Value:  65535 (0xffff) (will send an xon if we recover)
+    Flow control request timeout (how long to pause the link partner's tx)
+    
+InterruptThrottleRate
+Valid Range: 100-100000 (0=off, 1=dynamic)
+Default Value: 
+    Interrupt Throttle Rate (interrupts/sec)
+
+FlowControl
+Valid Range: 0-3
+0 - No Flow Control
+1 - Rx only, respond to PAUSE frames but do not generate them
+2 - Tx only, generate PAUSE frames but ignore them on receive
+3 - Full Flow Control Support
+Default Value: 1 - Rx only 
+    User Specified Flow Control Override
+
+XsumRX
+Valid Range: 0-1
+Default Value: 1
+    A value of '1' indicates that the driver should enable IP checksum
+    offload for received packets (both UDP and TCP) to the adapter hardware.
+
+Support
+=======
+
+For general information, go to the Intel support website at:
+
+    http://support.intel.com
+
+or the Intel Wired Networking project hosted by Sourceforge at:
+
+    http://sourceforge.net/projects/e1000
+
+If an issue is identified with the released source code on the supported
+kernel with a supported adapter, email the specific information related
+to the issue to [email protected]
MAINTAINERS +15 -0
index 4c715a7..517da6e 100644
@@ -1945,6 +1945,21 @@ L:	[email protected]
 W:	http://sourceforge.net/projects/e1000/
 S:	Supported
 
+INTEL PRO/10GbE PCI Express SUPPORT
+P:	Jeff Kirsher
+M:	[email protected]
+P:	Ayyappan Veeraiyan
+M:	[email protected]
+P:	John Ronciak
+M:	[email protected]
+P:	Jesse Brandeburg
+M:	[email protected]
+P:	Auke Kok
+M:	[email protected]
+L:	[email protected]
+W:	http://sourceforge.net/projects/e1000/
+S:	Supported
+
 INTEL PRO/WIRELESS 2100 NETWORK CONNECTION SUPPORT
 P:	Yi Zhu
 M:	[email protected]
drivers/net/Kconfig +22 -0
index 7d57f4a..b616e64 100644
@@ -2445,6 +2445,28 @@ config IXGB_NAPI
 
 	  If in doubt, say N.
 
+config IXGBE
+	tristate "Intel(R) PRO/10GbE PCI Express adapters support"
+	depends on PCI
+	---help---
+	  This driver supports Intel(R) PRO/10GbE PCI Express family of
+	  adapters.  For more information on how to identify your adapter, go
+	  to the Adapter & Driver ID Guide at:
+
+	  <http://support.intel.com/support/network/adapter/pro100/21397.htm>
+
+	  For general information and support, go to the Intel support
+	  website at:
+
+	  <http://support.intel.com>
+
+	  More specific information on configuring the driver is in 
+	  <file:Documentation/networking/ixgbe.txt>.
+
+	  To compile this driver as a module, choose M here and read
+	  <file:Documentation/networking/net-modules.txt>.  The module
+	  will be called ixgbe.
+
 config S2IO
 	tristate "S2IO 10Gbe XFrame NIC"
 	depends on PCI
drivers/net/Makefile +1 -0
index a77affa..427c8b6 100644
@@ -5,6 +5,7 @@
 obj-$(CONFIG_E1000) += e1000/
 obj-$(CONFIG_IBM_EMAC) += ibm_emac/
 obj-$(CONFIG_IXGB) += ixgb/
+obj-$(CONFIG_IXGBE) += ixgbe/
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
drivers/net/ixgbe/Makefile new file +36 -0
new file mode 100644
index 0000000..e06d5a7
@@ -0,0 +1,36 @@
+################################################################################
+#
+# Intel PRO/10GbE PCI Express Linux driver
+# Copyright(c) 1999 - 2007 Intel Corporation.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# The full GNU General Public License is included in this distribution in
+# the file called "COPYING".
+#
+# Contact Information:
+# Linux NICS <[email protected]>
+# e1000-devel Mailing List <[email protected]>
+# Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+#
+################################################################################
+
+#
+# Makefile for the Intel(R) PRO/10GbE PCI Express ethernet driver
+#
+
+obj-$(CONFIG_IXGBE) += ixgbe.o
+
+ixgbe-objs := ixgbe_main.o ixgbe_common.o ixgbe_api.o ixgbe_ethtool.o \
+              ixgbe_param.o ixgbe_82598.o ixgbe_phy.o
drivers/net/ixgbe/ixgbe.h new file +213 -0

213 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_82598.c new file +555 -0

555 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_api.c new file +635 -0

635 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_api.h new file +89 -0

89 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_common.c new file +1725 -0

1,261 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_common.h new file +74 -0

74 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_ethtool.c new file +491 -0

491 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_main.c new file +2623 -0

2,623 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_osdep.h new file +76 -0

76 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_param.c new file +510 -0

510 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_phy.c new file +574 -0

574 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_phy.h new file +61 -0

61 lines not on this page · raw message

drivers/net/ixgbe/ixgbe_type.h new file +1385 -0

1,385 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.

#2 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

drivers/net/ixgbe/ixgbe.h line 84

Quoted 6 lines · Ayyappan Veeraiyan
drivers/net/ixgbe/ixgbe.h new file +6 -0
+#define IXGBE_TX_FLAGS_CSUM		0x00000001
+#define IXGBE_TX_FLAGS_VLAN		0x00000002
+#define IXGBE_TX_FLAGS_TSO		0x00000004
+#define IXGBE_TX_FLAGS_IPV4		0x00000008
+#define IXGBE_TX_FLAGS_VLAN_MASK	0xffff0000
+#define IXGBE_TX_FLAGS_VLAN_SHIFT	16

defining bits using the form "(1 << n)" is preferred. Makes it easier to read, by eliminating the requirement of the human brain to decode hex into bit numbers.

drivers/net/ixgbe/ixgbe.h line 129

Quoted 5 lines
drivers/net/ixgbe/ixgbe.h new file +5 -0
+	union {
+		/* To protect race between sender and clean_tx_irq */
+		spinlock_t tx_lock;
+		struct net_device netdev;
+	};

Embedded a struct net_device into your ring? How can I put this?

Wrong, wrong. Wrong, wrong, wrong. Wrong.

drivers/net/ixgbe/ixgbe.h line 138

Quoted 8 lines
drivers/net/ixgbe/ixgbe.h new file +8 -0
+	struct ixgbe_queue_stats stats;
+
+	u32 eims_value;
+	u32 itr_val;
+	u16 itr_range;
+	u16 itr_register;
+
+	char name[IFNAMSIZ + 5];

The interface name should not be stored by your ring structure

Quoted 12 lines
drivers/net/ixgbe/ixgbe.h new file +12 -0
+#define IXGBE_DESC_UNUSED(R) \
+	((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \
+	(R)->next_to_clean - (R)->next_to_use - 1)
+
+#define IXGBE_RX_DESC_ADV(R, i)	    \
+	(&(((union ixgbe_adv_rx_desc *)((R).desc))[i]))
+#define IXGBE_TX_DESC_ADV(R, i)	    \
+	(&(((union ixgbe_adv_tx_desc *)((R).desc))[i]))
+#define IXGBE_TX_CTXTDESC_ADV(R, i)	    \
+	(&(((struct ixgbe_adv_tx_context_desc *)((R).desc))[i]))
+
+#define IXGBE_MAX_JUMBO_FRAME_SIZE	16128

drivers/net/ixgbe/ixgbe.h line 163

Quoted 10 lines
drivers/net/ixgbe/ixgbe.h new file +10 -0
+
+/* board specific private data structure */
+struct ixgbe_adapter {
+	struct timer_list watchdog_timer;
+	struct vlan_group *vlgrp;
+	u16 bd_number;
+	u16 rx_buf_len;
+	u32 part_num;
+	u32 link_speed;
+	unsigned long io_base;

Kill io_base and stop setting netdev->base_addr

Quoted 25 lines
drivers/net/ixgbe/ixgbe.h new file +25 -0
+	atomic_t irq_sem;
+	struct work_struct reset_task;
+
+	/* TX */
+	struct ixgbe_ring *tx_ring;	/* One per active queue */
+	u64 restart_queue;
+	u64 lsc_int;
+	u32 txd_cmd;
+	u64 hw_tso_ctxt;
+	u64 hw_tso6_ctxt;
+	u32 tx_timeout_count;
+	boolean_t detect_tx_hung;
+
+	/* RX */
+	struct ixgbe_ring *rx_ring;	/* One per active queue */
+	u64 hw_csum_tx_good;
+	u64 hw_csum_rx_error;
+	u64 hw_csum_rx_good;
+	u64 non_eop_descs;
+	int num_tx_queues;
+	int num_rx_queues;
+	struct msix_entry *msix_entries;
+
+	u64 rx_hdr_split;
+	u32 alloc_rx_page_failed;

drivers/net/ixgbe/ixgbe.h line 198

Quoted 10 lines
drivers/net/ixgbe/ixgbe.h new file +10 -0
+	u32 alloc_rx_buff_failed;
+	struct {
+		unsigned int rx_csum_enabled	:1;
+		unsigned int msi_capable	:1;
+		unsigned int msi_enabled	:1;
+		unsigned int msix_capable	:1;
+		unsigned int msix_enabled	:1;
+		unsigned int imir_enabled	:1;
+		unsigned int in_netpoll		:1;
+	} flags;

always avoid bitfields. They generate horrible code, and endian problems abound (though no endian problems are apparent here).

drivers/net/ixgbe/ixgbe.h line 211

Quoted 13 lines
drivers/net/ixgbe/ixgbe.h new file +13 -0
+	u32 max_frame_size;	/* Maximum frame size supported */
+	u32 eitr;		/* Interrupt Throttle Rate */
+
+	/* OS defined structs */
+	struct net_device *netdev;
+	struct pci_dev *pdev;
+	struct net_device_stats net_stats;
+
+	/* structs defined in ixgbe_hw.h */
+	struct ixgbe_hw hw;
+	u16 msg_enable;
+	struct ixgbe_hw_stats stats;
+	char lsc_name[IFNAMSIZ + 5];

delete lsc_name and use netdev name directly in request_irq()

Will review more after you fix these problems.

#3 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 11 lines

drivers/net/ixgbe/ixgbe.h line 198

Quoted 10 lines
drivers/net/ixgbe/ixgbe.h new file +10 -0
+    u32 alloc_rx_buff_failed;
+    struct {
+        unsigned int rx_csum_enabled    :1;
+        unsigned int msi_capable    :1;
+        unsigned int msi_enabled    :1;
+        unsigned int msix_capable    :1;
+        unsigned int msix_enabled    :1;
+        unsigned int imir_enabled    :1;
+        unsigned int in_netpoll        :1;
+    } flags;
Quoted 1 line

always avoid bitfields. They generate horrible code, and endian problems abound (though no endian problems are apparent here).

they generate no worse code than open coding the checks for these feature flags...

#4 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 11 lines · Arjan van de Ven
Quoted 11 lines
Quoted 10 lines
drivers/net/ixgbe/ixgbe.h new file +10 -0
+    u32 alloc_rx_buff_failed;
+    struct {
+        unsigned int rx_csum_enabled    :1;
+        unsigned int msi_capable    :1;
+        unsigned int msi_enabled    :1;
+        unsigned int msix_capable    :1;
+        unsigned int msix_enabled    :1;
+        unsigned int imir_enabled    :1;
+        unsigned int in_netpoll        :1;
+    } flags;
Quoted 3 lines
Quoted 1 line

always avoid bitfields. They generate horrible code, and endian problems abound (though no endian problems are apparent here).

they generate no worse code than open coding the checks for these feature flags...

That would be the logical assumption, but reality does not bear that logic out to be true.

I'm not sure whether gcc is confused about ABI alignment or such, on various platforms, but every time I look at the asm generated it is /not/ equivalent to open-coded feature flags and bitwise logic. Often it is demonstrably worse.

The same is true for icc too :) Bitfields are just bad juju for compilers, I guess.

Jeff

#5 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 6 lines · Jeff Garzik
Quoted 3 lines
Quoted 1 line

always avoid bitfields. They generate horrible code, and endian problems abound (though no endian problems are apparent here).

they generate no worse code than open coding the checks for these feature flags...

That would be the logical assumption, but reality does not bear that logic out to be true.

I just checked a small example and gcc just generates a testb with an immediate value, which isn't all that bad code.

Do you remember which gcc you tested with?

#6 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 11 lines · Arjan van de Ven
Quoted 6 lines · Jeff Garzik
Quoted 3 lines
Quoted 1 line

always avoid bitfields. They generate horrible code, and endian problems abound (though no endian problems are apparent here).

they generate no worse code than open coding the checks for these feature flags...

That would be the logical assumption, but reality does not bear that logic out to be true.

I just checked a small example and gcc just generates a testb with an immediate value, which isn't all that bad code.

Do you remember which gcc you tested with?

gcc 2.95, gcc 3.x, gcc 4.x, ... on multiple architectures, not just ia32.

It's simple logic: using machine integers are the easiest for the compiler to Do The Right Thing, the easiest way to eliminate endian problems, the easiest way for programmers to read and understand struct alignment.

Just say no to bitfields.

Jeff

#7 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 1 line · Jeff Garzik

It's simple logic: using machine integers are the easiest for the compiler to Do The Right Thing, the easiest way to eliminate endian problems, the easiest way for programmers to read and understand struct alignment.

using integers pure is obviously natural..
but using integers and then manually doing bit masking yourself... that's not fundamentally better than what the compiler can do.

yes bitfields are hard for not-1-bit cases and for cases where you mimick hardware layouts. neither is the case in this code.
The code gets actually harder to read for the feature flags if you don't use bitfields.... so unless the code is really worse (and so far I've not seen that, but I'll investigate more when I get to work), I think it's fair to use single-bit, non-packed bitfields for them...

#8 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Jeff Garzik
Quoted 6 lines · Jeff Garzik
Quoted 5 lines · Arjan van de Ven
Quoted 4 lines · Jeff Garzik
Quoted 2 lines
Quoted 1 line

always avoid bitfields. They generate horrible code, and endian problems abound (though no endian problems are apparent here).

they generate no worse code than open coding the checks for these feature flags...

That would be the logical assumption, but reality does not bear that logic out to be true.

Quoted 7 lines
Quoted 3 lines

I just checked a small example and gcc just generates a testb with an immediate value, which isn't all that bad code.

Do you remember which gcc you tested with?

gcc 2.95, gcc 3.x, gcc 4.x, ... on multiple architectures, not just ia32.

It's simple logic: using machine integers are the easiest for the compiler to Do The Right Thing, the easiest way to eliminate endian problems, the easiest way for programmers to read and understand struct alignment.

I really disagree with you here, I much rather prefer using code style like:

if (adapter->flags.msi_enabled) ..

than

if (adapter->flags & E1000_FLAG_MSI_ENABLED) ...

not only does it read easier, it's also shorter and not prone to &/&& confusion typo's, takes away parentheses when the test has multiple parts etc...

Maybe this is not most important for ixgbe, where we only have 8 or so flags, but the new e1000 driver that I posted this weekend currently has 63 (you wanted flags ;)) of them. Do you want me to use 63 integers or just 2 ?

And as Arjan said, we're not passing any of these to hardware, so there should not be any endian issues.

I think acme would agree with me that pahole currently is the easiest way to show struct alignment ...

Auke

#9 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 1 line · Auke

Maybe this is not most important for ixgbe, where we only have 8 or so flags, but the new e1000 driver that I posted this weekend currently has 63 (you wanted flags ;)) of them. Do you want me to use 63 integers or just 2 ?

Don't be silly. We are talking about single-bit feature flags implemented using machine ints (a la tg3 with 32 flags per int), versus bitfields.

Bitfields are to be avoided for many reasons:
* more difficult, in general, for a compiler to generate optimal code
* in particular, known to generate worse code on various architectures
* often causes endian problems
* often enhances programmer confusion, when trying to review structs and determine optimal layout and alignment
* programmers have proven they will screw up bitfields in e.g. cases with 1-bit and signedness.

I can probably think up more reasons to avoid bitfields if given another 5 minutes :)

Jeff

#10 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 11 lines · On Mon, 02 Jul 2007 11:32:41 -0400 Jeff Garzik <[email protected]> wrote:

Bitfields are to be avoided for many reasons:
* more difficult, in general, for a compiler to generate optimal code
* in particular, known to generate worse code on various architectures
* often causes endian problems
* often enhances programmer confusion, when trying to review structs and determine optimal layout and alignment
* programmers have proven they will screw up bitfields in e.g. cases with 1-bit and signedness.

I can probably think up more reasons to avoid bitfields if given another 5 minutes :)

A significant problem is that modifications to "nearby" bitfields need
locking: concurrent modifications to two bitfields can result in concurrent modifications to the same word.

And that's OK, but it's pretty unobvious that these stores are nonatomic from the source code and people could easily forget to do it.

That being said, they _are_ attractive from the nice-to-read POV...

#11 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 9 lines · Andrew Morton
Quoted 7 lines · On Mon, 02 Jul 2007 11:32:41 -0400 Jeff Garzik <[email protected]> wrote:

Bitfields are to be avoided for many reasons:
* more difficult, in general, for a compiler to generate optimal code
* in particular, known to generate worse code on various architectures
* often causes endian problems
* often enhances programmer confusion, when trying to review structs and determine optimal layout and alignment
* programmers have proven they will screw up bitfields in e.g. cases with 1-bit and signedness.

Quoted 8 lines
Quoted 1 line

I can probably think up more reasons to avoid bitfields if given another 5 minutes :)

A significant problem is that modifications to "nearby" bitfields need
locking: concurrent modifications to two bitfields can result in concurrent modifications to the same word.

And that's OK, but it's pretty unobvious that these stores are nonatomic from the source code and people could easily forget to do it.

Indeed.

Overall, it isn't any one specific thing that makes me reject bitfields in new code, it's the sum of all these reasons.

Kernel and compiler history proves that humans and compilers screw up bitfields early and often :)

Another reason that I just thought of: bitfields cannot be conglomerated into easy-to-assign-and-test masks, making

	foo = (1 << 0),
	bar = (1 << 4),
	baz = (1 << 9),
	default_feature_flags = foo | bar | baz,

	foo->flags = default_feature_flags;

impossible with bitfields.

You also cannot test multiple bits at one time, with bitfields.

Quoted 1 line

That being said, they _are_ attractive from the nice-to-read POV...

My personal style disagrees, but that's a personal taste. I can see how other people might think that, though, agreed.

Jeff

#12 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Jeff Garzik
Quoted 4 lines · Jeff Garzik
Quoted 1 line · Auke

Maybe this is not most important for ixgbe, where we only have 8 or so flags, but the new e1000 driver that I posted this weekend currently has 63 (you wanted flags ;)) of them. Do you want me to use 63 integers or just 2 ?

Don't be silly. We are talking about single-bit feature flags implemented using machine ints (a la tg3 with 32 flags per int), versus bitfields.

tg3.c:

	if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
	    (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))

is obviously _not_ easier to read than

        if (tp->tg3_flags.pcix_target_hwbug || tp->tg3_flags.ich_workaround)

you even have to cascade your flags into a second integer, prone to error and confusion!

I would say that this method is definately worse for readability. I would much rather then stick with 'bool' instead.

Auke

#13 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Hi Auke,

Quoted 9 lines · Auke

tg3.c:

	if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) ||
	    (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND))

is obviously _not_ easier to read than

         if (tp->tg3_flags.pcix_target_hwbug || tp->tg3_flags.ich_workaround)

Yes, but what about:

static bool tg3_has_pcix_target_hwdebug(const struct tg3 *tp)

{
	return (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) != 0;
}

static bool tg3_has_ich_workaround(const struct tg3 *tp)

{
	return (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) != 0;
}
if (tg3_has_pcix_target_hwdebug(tp) || tg3_has_ich_workaround(tp)) {
	/* do foo */
}

That is just as nice as bitfields and makes that stuff more readable. This is also a migration path while going from bitfields to flags incrementally.

If you find out that two of these tests are always done together you could even test two of them in one.

Quoted 1 line

I would say that this method is definately worse for readability.

Yes, open coding this bit masking mess IS making code hardly readable!

Quoted 1 line

I would much rather then stick with 'bool' instead.

If you can afford the space, that is just as good. If you are undecided, try the accessors. You can even write code, which generates them once.

Maybe we could get such nice script for generating a set of bitmasks and accessors in the kernel :-)

Source would than be a struct definition with bitfields.

All points raised be the people here are actually valid and I consider bitfields nice and clear for specification and example code, but avoid them while doing real coding.

Best Regards

Ingo Oeser

#14 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Jeff Garzik
Quoted 2 lines · Jeff Garzik

I'm not sure whether gcc is confused about ABI alignment or such, on various platforms, but every time I look at the asm generated it is /not/ equivalent to open-coded feature flags and bitwise logic. Often it is demonstrably worse.

(I can imagine this being different if you forcefully pack your structure to align with hw masks, but that is obviously not the case here)

#15 lore raw

RE: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Jeff Garzik
Quoted 6 lines · Jeff Garzik

drivers/net/ixgbe/ixgbe.h line 84

Quoted 2 lines · Ayyappan Veeraiyan
drivers/net/ixgbe/ixgbe.h new file +2 -0
+#define IXGBE_TX_FLAGS_VLAN_MASK     0xffff0000
+#define IXGBE_TX_FLAGS_VLAN_SHIFT    16

defining bits using the form "(1 << n)" is preferred. Makes it easier to read, by eliminating the requirement of the human brain to decode

hex

Quoted 3 lines

into bit numbers.

Ok.

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             struct net_device netdev;
+     };

Embedded a struct net_device into your ring? How can I put this?

Wrong, wrong. Wrong, wrong, wrong. Wrong.

Agreed.
Fake netdevs are needed for doing the multiple Rx queues in NAPI mode. We are thinking to solve in 2 ways. Having netdev pointer in ring structure or having an array of netdev pointers in ixgbe_adatper struct which would be visible to all rings.

Quoted 5 lines

drivers/net/ixgbe/ixgbe.h line 138

Quoted 2 lines
drivers/net/ixgbe/ixgbe.h new file +2 -0
+
+     char name[IFNAMSIZ + 5];

The interface name should not be stored by your ring structure

Yes, I agree and also (pointed out by someone before) this would break if the user changes the interface name..
But, having the "cause" in the MSIX vector name really helps in debugging and helps the user also.

I think the below output is much better

[root@ayyapsz src]# cat /proc/interrupts | grep eth0

214:          0          0   PCI-MSI-edge      eth0-lsc
215:      11763          4   PCI-MSI-edge      eth0-rx7
216:          0          0   PCI-MSI-edge      eth0-rx6
217:      77324          0   PCI-MSI-edge      eth0-rx5
218:          0          0   PCI-MSI-edge      eth0-rx4
219:      52911          0   PCI-MSI-edge      eth0-rx3
220:      80271          0   PCI-MSI-edge      eth0-rx2
221:      80244          6   PCI-MSI-edge      eth0-rx1
222:         12          0   PCI-MSI-edge      eth0-rx0
223:     124870      28543   PCI-MSI-edge      eth0-tx0

Compared to

[root@ayyapsz src]# cat /proc/interrupts | grep eth0

214:          0          0   PCI-MSI-edge      eth0
215:      11763          4   PCI-MSI-edge      eth0
216:          0          0   PCI-MSI-edge      eth0
217:      77324          0   PCI-MSI-edge      eth0
218:          0          0   PCI-MSI-edge      eth0
219:      52911          0   PCI-MSI-edge      eth0
220:      80271          0   PCI-MSI-edge      eth0
221:      80244          6   PCI-MSI-edge      eth0
222:         12          0   PCI-MSI-edge      eth0
223:     124900      28543   PCI-MSI-edge      eth0

Since we wanted to distinguish the various MSIX vectors in /proc/interrupts and since request_irq expects memory for name to be allocated somewhere, I added this part of the ring struct.

Quoted 2 lines

Kill io_base and stop setting netdev->base_addr

In my latest internal version, I already removed the io_base member (and couple more from ixgbe_adapter) but still setting the netdev->base_addr. I will remove that also..

Quoted 5 lines

drivers/net/ixgbe/ixgbe.h line 211

Quoted 2 lines
drivers/net/ixgbe/ixgbe.h new file +2 -0
+     struct ixgbe_hw_stats stats;
+     char lsc_name[IFNAMSIZ + 5];

delete lsc_name and use netdev name directly in request_irq()

Please see the response for the name member of ring structure.

Quoted 3 lines

Will review more after you fix these problems.

Thanks for the feedback. I will post another version shortly (except the feature flags change and the ring struct name members) which fixes my previous TODO list and also most of Francois comments..

Ayyappan

#16 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 2 lines · Ayyappan

Thanks for the feedback. I will post another version shortly (except the feature flags change and the ring struct name members) which fixes my

Just to clarify this, I will wait some more time for feature flags discussion and the ring structure name feedback..

Ayyappan

#17 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Veeraiyan, Ayyappan
Quoted 5 lines · Ayyappan

Agreed.
Fake netdevs are needed for doing the multiple Rx queues in NAPI mode. We are thinking to solve in 2 ways. Having netdev pointer in ring structure or having an array of netdev pointers in ixgbe_adatper struct which would be visible to all rings.

Didn't we have a patchset floating around recently that separates NAPI state from struct netdevice?

#18 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Veeraiyan, Ayyappan
Quoted 19 lines · Ayyappan
Quoted 6 lines · Jeff Garzik

drivers/net/ixgbe/ixgbe.h line 84

Quoted 2 lines · Ayyappan Veeraiyan
drivers/net/ixgbe/ixgbe.h new file +2 -0
+#define IXGBE_TX_FLAGS_VLAN_MASK     0xffff0000
+#define IXGBE_TX_FLAGS_VLAN_SHIFT    16

defining bits using the form "(1 << n)" is preferred. Makes it easier to read, by eliminating the requirement of the human brain to decode

hex

Quoted 3 lines

into bit numbers.

Ok.

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             struct net_device netdev;
+     };

Embedded a struct net_device into your ring? How can I put this?

Quoted 8 lines
Quoted 2 lines

Wrong, wrong. Wrong, wrong, wrong. Wrong.

Agreed.
Fake netdevs are needed for doing the multiple Rx queues in NAPI mode. We are thinking to solve in 2 ways. Having netdev pointer in ring structure or having an array of netdev pointers in ixgbe_adatper struct which would be visible to all rings.

Wait until Davem & I separate NAPI from network device.
The patch is close to ready for 2.6.24 when this driver will need to show up.

Since I know Intel will be forced to backport this to older distro's. You would be best to have a single receive queue version when you have to make it work on the older code.

Quoted 5 lines
Quoted 5 lines

drivers/net/ixgbe/ixgbe.h line 138

Quoted 2 lines
drivers/net/ixgbe/ixgbe.h new file +2 -0
+
+     char name[IFNAMSIZ + 5];

The interface name should not be stored by your ring structure

Gag

Quoted 4 lines

Yes, I agree and also (pointed out by someone before) this would break if the user changes the interface name..
But, having the "cause" in the MSIX vector name really helps in debugging and helps the user also.

If you need a unique token use ifindex

Quoted 29 lines

I think the below output is much better

[root@ayyapsz src]# cat /proc/interrupts | grep eth0

214:          0          0   PCI-MSI-edge      eth0-lsc
215:      11763          4   PCI-MSI-edge      eth0-rx7
216:          0          0   PCI-MSI-edge      eth0-rx6
217:      77324          0   PCI-MSI-edge      eth0-rx5
218:          0          0   PCI-MSI-edge      eth0-rx4
219:      52911          0   PCI-MSI-edge      eth0-rx3
220:      80271          0   PCI-MSI-edge      eth0-rx2
221:      80244          6   PCI-MSI-edge      eth0-rx1
222:         12          0   PCI-MSI-edge      eth0-rx0
223:     124870      28543   PCI-MSI-edge      eth0-tx0

Compared to

[root@ayyapsz src]# cat /proc/interrupts | grep eth0

214:          0          0   PCI-MSI-edge      eth0
215:      11763          4   PCI-MSI-edge      eth0
216:          0          0   PCI-MSI-edge      eth0
217:      77324          0   PCI-MSI-edge      eth0
218:          0          0   PCI-MSI-edge      eth0
219:      52911          0   PCI-MSI-edge      eth0
220:      80271          0   PCI-MSI-edge      eth0
221:      80244          6   PCI-MSI-edge      eth0
222:         12          0   PCI-MSI-edge      eth0
223:     124900      28543   PCI-MSI-edge      eth0
Quoted 3 lines

Since we wanted to distinguish the various MSIX vectors in /proc/interrupts and since request_irq expects memory for name to be allocated somewhere, I added this part of the ring struct.

You only need to store the name for when you are doing request_irq, so it can just be a stack temporary.

Quoted 24 lines
Quoted 2 lines

Kill io_base and stop setting netdev->base_addr

In my latest internal version, I already removed the io_base member (and couple more from ixgbe_adapter) but still setting the netdev->base_addr. I will remove that also..

Quoted 5 lines

drivers/net/ixgbe/ixgbe.h line 211

Quoted 2 lines
drivers/net/ixgbe/ixgbe.h new file +2 -0
+     struct ixgbe_hw_stats stats;
+     char lsc_name[IFNAMSIZ + 5];

delete lsc_name and use netdev name directly in request_irq()

Please see the response for the name member of ring structure.

Quoted 3 lines

Will review more after you fix these problems.

Thanks for the feedback. I will post another version shortly (except the feature flags change and the ring struct name members) which fixes my previous TODO list and also most of Francois comments..

Ayyappan

Signature · 1 line
Stephen Hemminger <[email protected]>
#19 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 1 line · Stephen Hemminger

The patch is close to ready for 2.6.24 when this driver will need to show up.

If intel manages to fix up the reamining issues I'd rather see it appear in 2.6.23..

Quoted 3 lines

Since I know Intel will be forced to backport this to older distro's. You would be best to have a single receive queue version when you have to make it work on the older code.

But that'll require the single receiver queue version I guess. The netdevice abuse is the only really major issue I see, although I'd of course really like to see the driver getting rid of the bitfield abuse aswell.

Quoted 6 lines
Quoted 3 lines

Since we wanted to distinguish the various MSIX vectors in /proc/interrupts and since request_irq expects memory for name to be allocated somewhere, I added this part of the ring struct.

You only need to store the name for when you are doing request_irq, so it can just be a stack temporary.

Lots of drivers where the interface name is assigned after request_irq just use an internal name, e.g. ixgbeX in the case of this driver.

#20 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 6 lines · Christoph Hellwig
Quoted 1 line · Stephen Hemminger

The patch is close to ready for 2.6.24 when this driver will need to show up.

If intel manages to fix up the reamining issues I'd rather see it appear in 2.6.23..

Quoted 8 lines
Quoted 3 lines

Since I know Intel will be forced to backport this to older distro's. You would be best to have a single receive queue version when you have to make it work on the older code.

But that'll require the single receiver queue version I guess. The netdevice abuse is the only really major issue I see, although I'd of course really like to see the driver getting rid of the bitfield abuse aswell.

well, FWIW when I started looking at adding these flags I looked in various subsystems in the kernel and picked an implementation that suited. Guess what pci.h has? ...:

	unsigned int msi_enabled:1;
	unsigned int msix_enabled:1;

this is literally where I copied the example from

I suppose I can fix those, but I really don't understand what all the fuzz is about here. We're only conserving memory and staying far away from the real risks of bitmasks, so forgive me if I don't grasp the problem.

Honestly, if this is really considered "Bad coding" (TM) then we need to fix these prominent abuses of it too.

I count about 60 or so of these bitfields in drivers/net... (and countless more in other parts) !

Auke

#21 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 1 line · Auke

I suppose I can fix those, but I really don't understand what all the fuzz is about here. We're only conserving memory and staying far away from the real risks of bitmasks, so forgive me if I don't grasp the problem.

Be it machine ints or bitfields, you're not conserving memory. Think about struct padding.

As to the overall question, I already posted a long list of problems with bitfields. Shall I repeat?

Jeff

#22 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Kok, Auke
Quoted 11 lines · Auke

well, FWIW when I started looking at adding these flags I looked in various subsystems in the kernel and picked an implementation that suited. Guess what pci.h has? ...:

	unsigned int msi_enabled:1;
	unsigned int msix_enabled:1;

this is literally where I copied the example from

I suppose I can fix those, but I really don't understand what all the fuzz is about here. We're only conserving memory and staying far away from the real

I'm not sure if these bitfields actually _do_ conserve memory. Generated code gets bigger (need bitwise masks and stuff). Code also needs memory. It probably only conserves memory, if the structure is instanciated a lot.

Signature · 1 line
Greetings Michael.
#23 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 6 lines · Michael Buesch
Quoted 5 lines · Auke

well, FWIW when I started looking at adding these flags I looked in various subsystems in the kernel and picked an implementation that suited. Guess what pci.h has? ...:

	unsigned int msi_enabled:1;
	unsigned int msix_enabled:1;
Quoted 8 lines
Quoted 3 lines

this is literally where I copied the example from

I suppose I can fix those, but I really don't understand what all the fuzz is about here. We're only conserving memory and staying far away from the real

I'm not sure if these bitfields actually _do_ conserve memory. Generated code gets bigger (need bitwise masks and stuff). Code also needs memory. It probably only conserves memory, if the structure is instanciated a lot.

Actually, that's a good point. On several RISC architectures it certainly generates bigger code.

Jeff

#24 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 9 lines · Jeff Garzik
Quoted 8 lines · Michael Buesch
Quoted 7 lines · Auke

well, FWIW when I started looking at adding these flags I looked in various subsystems in the kernel and picked an implementation that suited. Guess what pci.h has? ...:

	unsigned int msi_enabled:1;
	unsigned int msix_enabled:1;

this is literally where I copied the example from

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I suppose I can fix those, but I really don't understand what all the fuzz is about here. We're only conserving memory and staying far away from the real

I'm not sure if these bitfields actually _do_ conserve memory. Generated code gets bigger (need bitwise masks and stuff). Code also needs memory. It probably only conserves memory, if the structure is instanciated a lot.

Actually, that's a good point. On several RISC architectures it certainly generates bigger code.

so, even on i386 it does (17 bytes and 6 instructions to test vs. 10:3 if using a "bool"):

unsigned int:1:

 8048365:       0f b6 45 f8             movzbl 0xfffffff8(%ebp),%eax
 8048369:       0c 01                   or     $0x1,%al
 804836b:       88 45 f8                mov    %al,0xfffffff8(%ebp)
 804836e:       0f b6 45 f8             movzbl 0xfffffff8(%ebp),%eax
 8048372:       24 01                   and    $0x1,%al
 8048374:       84 c0                   test   %al,%al

bool:

 8048365:       c6 45 fb 01             movb   $0x1,0xfffffffb(%ebp)
 8048369:       0f b6 45 fb             movzbl 0xfffffffb(%ebp),%eax
 804836d:       84 c0                   test   %al,%al

unsigned int:

 8048365:       c7 45 f8 01 00 00 00    movl   $0x1,0xfffffff8(%ebp)
 804836c:       8b 45 f8                mov    0xfffffff8(%ebp),%eax
 804836f:       85 c0                   test   %eax,%eax

using var & flag:

 8048365:       c7 45 f8 01 00 00 00    movl   $0x1,0xfffffff8(%ebp)
 804836c:       8b 45 f8                mov    0xfffffff8(%ebp),%eax
 804836f:       25 00 04 00 00          and    $0x400,%eax
 8048374:       85 c0                   test   %eax,%eax

note that using "var & flag" is slightly larger here... 1 extra instruction and 7 more bytes.

interesting...

but let's stay constructive here:

~/git/linux-2.6 $ grep -r 'unsigned int.*:1;' * | wc -l 748

Is anyone going to fix those? If we don't, someone will certainly again submit patches to add more of these bitfields, after all, some very prominent parts of the kernel still use them. Only recently for instance mac80211 merged like 30 of these.... and drivers/net, include etc.. certainly has a lot of these.

Cheers,

Auke

#25 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 6 lines · Auke

but let's stay constructive here:

~/git/linux-2.6 $ grep -r 'unsigned int.*:1;' * | wc -l 748

Is anyone going to fix those? If we don't, someone will certainly again submit patches to add more of these bitfields, after all, some very prominent parts of the kernel still use them. Only recently for instance mac80211 merged like 30 of these.... and drivers/net, include etc.. certainly has a lot of these.

There is a lot of crap in the kernel. Just look at all the grotty SCSI or char drivers, for example. The first task is to avoid adding more crap :)

Jeff

#26 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Kok, Auke
Quoted 26 lines · Auke
Quoted 13 lines · Jeff Garzik
Quoted 12 lines · Michael Buesch
Quoted 11 lines · Auke

well, FWIW when I started looking at adding these flags I looked in various subsystems in the kernel and picked an implementation that suited. Guess what pci.h has? ...:

	unsigned int msi_enabled:1;
	unsigned int msix_enabled:1;

this is literally where I copied the example from

I suppose I can fix those, but I really don't understand what all the fuzz is about here. We're only conserving memory and staying far away from the real

Quoted 7 lines
Quoted 4 lines

I'm not sure if these bitfields actually _do_ conserve memory. Generated code gets bigger (need bitwise masks and stuff). Code also needs memory. It probably only conserves memory, if the structure is instanciated a lot.

Actually, that's a good point. On several RISC architectures it certainly generates bigger code.

...

but let's stay constructive here:

Quoted 7 lines

~/git/linux-2.6 $ grep -r 'unsigned int.*:1;' * | wc -l 748

Is anyone going to fix those? If we don't, someone will certainly again submit patches to add more of these bitfields, after all, some very prominent parts of the kernel still use them. Only recently for instance mac80211 merged like 30 of these.... and drivers/net, include etc.. certainly has a lot of these.

I don't think bitfields are broken. Maybe it's the compiler what should be fixed (*)

...bitfields are there to save the coder having to type masks by hand. There should be no difference in the generated code from doing

u32 value = readl(fromsomewhere);
printf("bits 16 & 15 0x%08x\n", value & 0x00018000 >> 15);

union {

  struct {
    u32 reserved1:15;
    u32 val:2;

} __attribute__((packed))
u32 data;
} value;
value.data = readl(fromsomewhere);
printf("bits 16 & 15 0x%08x\n", value.val);

Granted, that looks big, but once you nail it out at your struct definitons, it makes maintenance much easier when looking at the bitmasks in the specs. Masks and shifts tend to suck on the long term when they accumulate.

-- Inaky

(*) not to mention the endianness mess

#27 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 1 line · Inaky Perez-Gonzalez

I don't think bitfields are broken. Maybe it's the compiler what should be fixed (*)

Then you do not understand bitfields. It is -axiomatic- that bitfields are more difficult for compilers to implement.

Access to bitfields are not atomic within the machine int in which they are stored... you need to "unpack" the values stored in bitfields, even if they are single-bit bitfields.

You cannot set multiple bitfields at one time, without even more complex data structures. You cannot compare and test multiple bitfields at one
time.

Humans have proven in kernel-land to screw up bitfields repeatedly.

The evidence is plain to see:

Quoted 7 lines

union {

  struct {
    u32 reserved1:15;
    u32 val:2;

} __attribute__((packed))
u32 data;
} value;

Using "u32 flags", and nothing else, is just so much more simple and obvious.

Finally, this is -nothing new-. I've been telling other driver writers not to use bitfields in their drivers. Google for 'garzik' and 'bitfield'.

Jeff

#28 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 9 lines · Jeff Garzik
Quoted 1 line · Inaky Perez-Gonzalez

I don't think bitfields are broken. Maybe it's the compiler what should be fixed (*)

Then you do not understand bitfields. It is -axiomatic- that bitfields are more difficult for compilers to implement.

Access to bitfields are not atomic within the machine int in which they are stored... you need to "unpack" the values stored in bitfields, even if they are single-bit bitfields.

Which we do manually when we don't use bitfields. Again, conceptually, there is no difference.

Quoted 3 lines

You cannot set multiple bitfields at one time, without even more complex data structures. You cannot compare and test multiple bitfields at one
time.

But I am not saying that you only use bitfields. There are cases where they make the code much more readable (for me, at least), and cases (like the one you mention) where they not [this is why I use unions, btw]..

Quoted 4 lines

...

Finally, this is -nothing new-. I've been telling other driver writers not to use bitfields in their drivers. Google for 'garzik' and 'bitfield'.

I know, I am just disagreeing. This is one of those things each person is entrenched on and is impossible to change (like emacs vs vi).

#29 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 6 lines · Inaky Perez-Gonzalez
Quoted 2 lines · Jeff Garzik

Inaky Perez-Gonzalez wrote:
Access to bitfields are not atomic within the machine int in which they are stored... you need to "unpack" the values stored in bitfields, even if they are single-bit bitfields.

Which we do manually when we don't use bitfields. Again, conceptually, there is no difference.

Practically speaking -- there are differences.

The "manual" method hides nothing from the programmer, while use of bitfields hides the lack of atomicity.

When you have programmers who make mistakes -- i.e. real humans -- these things matter.

But overall, it is not any one detail that discourages use of bitfields; it is the sum of all the reasons. Practical experience, compiler technology, mistakes made (and not made), all point to avoiding bitfields.

Jeff

#30 lore raw

RE: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

But that'll require the single receiver queue version I guess. The netdevice abuse is the only really major issue I see, although I'd of course really like to see the driver getting rid of the bitfield abuse aswell.

The submitted driver code supports single queue version in case of MSIX allocation failures... As I said in the other mail, I feel, restricting to single Rx queue in NAPI mode is better approach till Stephen's and DaveM' work of separating NAPI from netdevice is done..

Quoted 3 lines

Lots of drivers where the interface name is assigned after request_irq just use an internal name, e.g. ixgbeX in the case of this driver.

This sounds ok to me.

With this change, this is the output..

[root@ayyapsz src]# ip link
1: lo: <LOOPBACK,UP,10000> mtu 16436 qdisc noqueue

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: sit0: <NOARP> mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0
3: eth6: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen
1000
    link/ether 00:50:8b:05:5f:95 brd ff:ff:ff:ff:ff:ff
29: eth0: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen
1000
    link/ether 00:1b:21:01:e4:93 brd ff:ff:ff:ff:ff:ff
30: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
    link/ether 00:1b:21:01:e4:92 brd ff:ff:ff:ff:ff:ff

[root@ayyapsz src]# cat /proc/interrupts | grep 29

214:          0          0   PCI-MSI-edge      ixgbe29-lsc
215:      11764      80213   PCI-MSI-edge      ixgbe29-rx7
216:      80257          0   PCI-MSI-edge      ixgbe29-rx6
217:      77331          0   PCI-MSI-edge      ixgbe29-rx5
218:      24201          0   PCI-MSI-edge      ixgbe29-rx4
219:      52911          0   PCI-MSI-edge      ixgbe29-rx3
220:     104591          0   PCI-MSI-edge      ixgbe29-rx2
221:      80249          8   PCI-MSI-edge      ixgbe29-rx1
222:         14          0   PCI-MSI-edge      ixgbe29-rx0
223:     194023     118220   PCI-MSI-edge      ixgbe29-tx0 

Ayyappan

#31 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 10 lines · Ayyappan

On 7/2/07, Christoph Hellwig <[email protected]> wrote:

The submitted driver code supports single queue version in case of MSIX allocation failures... As I said in the other mail, I feel, restricting to single Rx queue in NAPI mode is better approach till Stephen's and DaveM' work of separating NAPI from netdevice is done..

Quoted 3 lines

Lots of drivers where the interface name is assigned after request_irq just use an internal name, e.g. ixgbeX in the case of this driver.

Actually looking closer, we don't need to worry about interface name change after request_irq. This driver calls request_irq only on interface up. If interface is up, kernel (dev.c) doesn't allow the name change. So it is a non-issue for this driver.

Ayyappan

#32 lore raw

RE: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Stephen Hemminger
Quoted 1 line · Stephen Hemminger
Quoted 1 line

Fake netdevs are needed for doing the multiple Rx queues in NAPI

mode.

Quoted 2 lines
Quoted 2 lines

We are thinking to solve in 2 ways. Having netdev pointer in ring structure or having an array of netdev pointers in ixgbe_adatper

struct

Quoted 4 lines
Quoted 1 line

which would be visible to all rings.

Wait until Davem & I separate NAPI from network device. The patch is close to ready for 2.6.24 when this driver will need to

show up.

Quoted 2 lines

Since I know Intel will be forced to backport this to older distro's.

You

Quoted 1 line

would be best to have a single receive queue version when you have to

make

Quoted 1 line

it work on the older code.

So far all our testing indicates we need multiple Rx queues to have better CPU utilization number at 10Gig line rate. So I am thinking adding the non-NAPI support to the driver (like other 10Gig drivers) and restrict to single rx queue in case of NAPI. I already have the non-NAPI version coded up and went through internal testing. I will add this in the next submission. We will add the multiple Rx queues support in NAPI mode once when "separate NAPI from network device" is done. Does this sound ok?

Quoted 4 lines

You only need to store the name for when you are doing request_irq, so it can just be a stack temporary.

request_irq expects allocated memory not just stack temporary. I glanced the kernel source.. There are precedents to the way we did.

linux-2.6/source/drivers/usb/core/hcd.c

1594 /* enable irqs just before we start the controller */
1595 if (hcd->driver->irq) {
1596 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr),
"%s:usb%d",
1597 hcd->driver->description,
hcd->self.busnum);
1598 if ((retval = request_irq(irqnum, &usb_hcd_irq,
irqflags,
1599 hcd->irq_descr, hcd)) != 0) {
1600 dev_err(hcd->self.controller,
1601 "request interrupt %d
failed\n", irqnum);
1602 goto err_request_irq;
1603 }

Quoted 1 line

Stephen Hemminger <[email protected]>

I appreciate the feedback.

Thanks,
Ayyappa

#33 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

In reply to Veeraiyan, Ayyappan
Quoted 19 lines · Ayyappan
Quoted 6 lines · Jeff Garzik

drivers/net/ixgbe/ixgbe.h line 84

Quoted 2 lines · Ayyappan Veeraiyan
drivers/net/ixgbe/ixgbe.h new file +2 -0
+#define IXGBE_TX_FLAGS_VLAN_MASK     0xffff0000
+#define IXGBE_TX_FLAGS_VLAN_SHIFT    16

defining bits using the form "(1 << n)" is preferred. Makes it easier to read, by eliminating the requirement of the human brain to decode

hex

Quoted 3 lines

into bit numbers.

Ok.

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             struct net_device netdev;
+     };

Embedded a struct net_device into your ring? How can I put this?

Quoted 9 lines
Quoted 2 lines

Wrong, wrong. Wrong, wrong, wrong. Wrong.

Agreed.
Fake netdevs are needed for doing the multiple Rx queues in NAPI mode. We are thinking to solve in 2 ways. Having netdev pointer in ring structure or having an array of netdev pointers in ixgbe_adatper struct which would be visible to all rings.

If thats what you're using the netdev pointers in the ring structure for, I'd like to remind you that you tried using Fake netdevs in e1000 last year, and the results were crashes and potential data corruption.

http://marc.info/?l=linux-netdev&m=114954878711789&w=2

The consensus there at the
end of the above thread was to revert out the e1000 multiple rx queue code until such time as the netpoll code could be updated to better interoperate with multiple rx queues (Andy Grover I believe was the person who volunteered for the job). Given that I've not seen any netpoll updates regarding netpoll and multi-rx since then, I'm guessing the use of fake netdevs is still a problem. I've not checked this driver for all of the potential problems we found, but I will, and let you know if I see any.

Regards
Neil

Signature · 8 lines
/***************************************************
 *Neil Horman
 *Software Engineer
 *Red Hat, Inc.
 *[email protected]
 *gpg keyid: 1024D / 0x92A74FA1
 *http://pgp.mit.edu
 ***************************************************/
#34 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 44 lines · Neil Horman
Quoted 19 lines · Ayyappan
Quoted 6 lines · Jeff Garzik

drivers/net/ixgbe/ixgbe.h line 84

Quoted 2 lines · Ayyappan Veeraiyan
drivers/net/ixgbe/ixgbe.h new file +2 -0
+#define IXGBE_TX_FLAGS_VLAN_MASK     0xffff0000
+#define IXGBE_TX_FLAGS_VLAN_SHIFT    16

defining bits using the form "(1 << n)" is preferred. Makes it easier to read, by eliminating the requirement of the human brain to decode

hex

Quoted 3 lines

into bit numbers.

Ok.

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+             struct net_device netdev;
+     };

Embedded a struct net_device into your ring? How can I put this?

Quoted 9 lines
Quoted 2 lines

Wrong, wrong. Wrong, wrong, wrong. Wrong.

Agreed.
Fake netdevs are needed for doing the multiple Rx queues in NAPI mode. We are thinking to solve in 2 ways. Having netdev pointer in ring structure or having an array of netdev pointers in ixgbe_adatper struct which would be visible to all rings.

If thats what you're using the netdev pointers in the ring structure for, I'd like to remind you that you tried using Fake netdevs in e1000 last year, and the results were crashes and potential data corruption.

http://marc.info/?l=linux-netdev&m=114954878711789&w=2

The consensus there at the
end of the above thread was to revert out the e1000 multiple rx queue code until such time as the netpoll code could be updated to better interoperate with multiple rx queues (Andy Grover I believe was the person who volunteered for the job). Given that I've not seen any netpoll updates regarding netpoll and multi-rx since then, I'm guessing the use of fake netdevs is still a problem. I've not checked this driver for all of the potential problems we found, but I will, and let you know if I see any.

Quoted 3 lines

Regards
Neil

Replying to myself...
I've looked through the driver pretty throughly with regards to my above
concern, and it appears the driver is reasonably free of netpoll issues at the moment, at least as far as what we found in e1000 was concerned. I do however, see a concern in the use of the in_netpoll flag within the driver. Given that the primary registered net_device, and all the dummy net_devices in the rx_ring point to the same ixgbe_adapter structure, there can be some level of confusion over weather a given rx queue is in netpoll_mode or not. When the primary adapter prforms a netpoll, all the individual rx queues will follow the in_netpoll path in the receive path (assuming misx interrupts are used). The result I think is the potential for a large amount of packet reordering during a netpoll operation. Perhaps not a serious problem, but likely worth looking into further.

Regards
Neil

Signature · 8 lines
/***************************************************
 *Neil Horman
 *Software Engineer
 *Red Hat, Inc.
 *[email protected]
 *gpg keyid: 1024D / 0x92A74FA1
 *http://pgp.mit.edu
 ***************************************************/
#35 lore raw

RE: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 3 lines

From: Neil Horman [mailto:[email protected]]
Replying to myself...
I've looked through the driver pretty throughly with regards to

my

Quoted 2 lines

above
concern, and it appears the driver is reasonably free of netpoll issues

at

Quoted 2 lines

the
moment, at least as far as what we found in e1000 was concerned. I do

Thanks for reviewing the code..

Quoted 2 lines

however,
see a concern in the use of the in_netpoll flag within the driver.

Given

Quoted 6 lines

that
the primary registered net_device, and all the dummy net_devices in the rx_ring
point to the same ixgbe_adapter structure, there can be some level of confusion
over weather a given rx queue is in netpoll_mode or not.

The revised driver I am going to post today will not have fake netdevs...

Quoted 2 lines

adapter prforms a netpoll, all the individual rx queues will follow the in_netpoll path in the receive path (assuming misx interrupts are

used).

Quoted 4 lines

The
result I think is the potential for a large amount of packet reordering during a
netpoll operation. Perhaps not a serious problem, but likely worth

looking

Multiple Rx queues are used in non-NAPI mode only, and all Rx queues use one netdev (which is associated with the adapter struct). Also, the RSS (receive side scaling or rx packet steering) feature is used in multiple rx queues mode. In this mode, HW will always select the same Rx queue (for a flow) and this should prevent any packet reordering issue.

Quoted 1 line

Neil

Ayyappan

#36 lore raw

Re: [PATCH] ixgbe: Introduce new 10GbE driver for Intel 82598 based PCI Express adapters...

Quoted 41 lines · Ayyappan
Quoted 3 lines

From: Neil Horman [mailto:[email protected]]
Replying to myself...
I've looked through the driver pretty throughly with regards to

my

Quoted 2 lines

above
concern, and it appears the driver is reasonably free of netpoll issues

at

Quoted 2 lines

the
moment, at least as far as what we found in e1000 was concerned. I do

Thanks for reviewing the code..

Quoted 2 lines

however,
see a concern in the use of the in_netpoll flag within the driver.

Given

Quoted 6 lines

that
the primary registered net_device, and all the dummy net_devices in the rx_ring
point to the same ixgbe_adapter structure, there can be some level of confusion
over weather a given rx queue is in netpoll_mode or not.

The revised driver I am going to post today will not have fake netdevs...

Quoted 2 lines

adapter prforms a netpoll, all the individual rx queues will follow the in_netpoll path in the receive path (assuming misx interrupts are

used).

Quoted 4 lines

The
result I think is the potential for a large amount of packet reordering during a
netpoll operation. Perhaps not a serious problem, but likely worth

looking

Multiple Rx queues are used in non-NAPI mode only, and all Rx queues use one netdev (which is associated with the adapter struct). Also, the RSS (receive side scaling or rx packet steering) feature is used in multiple rx queues mode. In this mode, HW will always select the same Rx queue (for a flow) and this should prevent any packet reordering issue.

Quoted 3 lines
Quoted 1 line

Neil

Ayyappan

Thank you, I think that satisfies all my concerns.

Regards
Neil

#37 lore raw
In reply to [email protected]

[email protected] <[email protected]> :
[...]

Quoted 1 line

Please review and provide comments.

o ixgbe_call_func and the ton of wrappers which go along with it should go.

o boolean_t duplicates the existing 'bool'

o The options below {should be/are} handled through ethtool:
- TxDescriptors
- RxDescriptors
- XsumRX

o No __iomem annotations ?

o pci_alloc_consistent() returns a zeroed area: no need for memset.

o ixgbe_clean_tx_irq() is issued from the NAPI poll handler (as the name suggests...). Its locking will probably cause a deadlock if it is interrupted and a call to netpoll_send_skb follows.

Signature · 1 line
Ueimor
#38 lore raw
Quoted 6 lines · Francois Romieu

[email protected] <[email protected]> :
[...]

Quoted 1 line

Please review and provide comments.

o ixgbe_call_func and the ton of wrappers which go along with it should go.

hmmm good point, this is a bit too verbose perhaps ;)

Quoted 1 line

o boolean_t duplicates the existing 'bool'

yes, that's definately on the TODO list.... did I mention that sparse really doesn't like bool yet? :)

Quoted 4 lines

o The options below {should be/are} handled through ethtool:
- TxDescriptors
- RxDescriptors
- XsumRX

I have been putting this on the todo list as well, but we kept it in for convenience reasons... not to mention that we've been keeping these options around in the other drivers, is there really a pressing need to remove them? I'll put it on the todo list for sure tho.

Quoted 1 line

o No __iomem annotations ?

Ack! that slipped through the cracks... DOH

Quoted 1 line

o pci_alloc_consistent() returns a zeroed area: no need for memset.

that is good to know, I didn't know that

Quoted 3 lines

o ixgbe_clean_tx_irq() is issued from the NAPI poll handler (as the name suggests...). Its locking will probably cause a deadlock if it is interrupted and a call to netpoll_send_skb follows.

OK, we'll look into that. I'm not sure this is an issue tho.

Thanks for the feedback!

Auke

Auke

#39 lore raw
In reply to Francois Romieu

On 6/13/07, Francois Romieu <[email protected]> wrote:

Please ignore my previous response. Forgot to reply_all..

Quoted 5 lines

o ixgbe_clean_tx_irq() is issued from the NAPI poll handler (as the name suggests...). Its locking will probably cause a deadlock if it is interrupted and a call to netpoll_send_skb follows.

netpoll_send_skb should not deadlock because ixgbe_xmit_frame should bail out because of this...

     if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
              /* Collision - tell upper layer to requeue */
              return NETDEV_TX_LOCKED;

Right?

The LLTX and tx_lock handling in the driver is not clean and I am working on to fix it. Also will make sure we are handling the net_poll case correctly...

Thanks for the feedback..

Ayyappan

#40 lore raw

Ayyappan Veeraiyan <[email protected]> :
[...]

Quoted 8 lines

netpoll_send_skb should not deadlock because ixgbe_xmit_frame should bail out because of this...

     if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
              /* Collision - tell upper layer to requeue */
              return NETDEV_TX_LOCKED;

Right?

Yes.

Signature · 1 line
Ueimor