Skip to contentSkip to conversation

atl1: Header files for Attansic L1 driver

PATCH In review Jay Cliburn 4 participants 8 messages Jan 11, 2007 – Jan 15, 2007

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

PATCH 2/4 atl1: Header files for Attansic L1 driver

From: Jay Cliburn <[email protected]>
From: Chris Snook <[email protected]>

This patch contains the header files needed by the Attansic L1 gigabit ethernet adapter driver.

---

 atl1.h    |  266 +++++++++++++++
 atl1_hw.h | 1053 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1319 insertions(+)
drivers/net/atl1/atl1.h new file +266 -0
new file mode 100644
index 0000000..9578104
@@ -0,0 +1,266 @@
+/**
+ * atl1.h - atl1 main header
+ * 
+ * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
+ * Copyright(c) 2006 Chris Snook <[email protected]>
+ * Copyright(c) 2006 Jay Cliburn <[email protected]>
+ * 
+ * Derived from Intel e1000 driver
+ * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
+ * 
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ * 
+ * This program is distributed in the hope that 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., 59
+ * Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ **/
+
+#ifndef _ATL1_H_
+#define _ATL1_H_
+
+#include <linux/tcp.h>
+#include <linux/skbuff.h>
+#include <linux/netdevice.h>
+#include <linux/pci.h>
+#include <linux/spinlock_types.h>
+#include <linux/workqueue.h>
+#include <linux/timer.h>
+#include <linux/delay.h>
+#include <linux/if_vlan.h>
+
+#include <asm/types.h>
+#include <asm/atomic.h>
+
+#include "atl1_hw.h"
+
+#ifdef NETIF_F_TSO
+#include <net/checksum.h>
+#endif
+
+#ifdef SIOCGMIIPHY
+#include <linux/mii.h>
+#endif
+
+#ifdef SIOCETHTOOL
+#include <linux/ethtool.h>
+#endif
+
+#define BAR_0	0
+
+/* function prototypes needed by multiple files */
+s32 atl1_up(struct atl1_adapter *adapter);
+void atl1_down(struct atl1_adapter *adapter);
+int atl1_reset(struct atl1_adapter *adapter);
+s32 atl1_setup_ring_resources(struct atl1_adapter *adapter);
+void atl1_free_ring_resources(struct atl1_adapter *adapter);
+
+struct atl1_adapter;
+
+#define ATL1_MAX_INTR		3
+
+#define ATL1_DEFAULT_TPD	256
+#define ATL1_MAX_TPD		1023
+#define ATL1_MIN_TPD		64
+#define ATL1_DEFAULT_RFD	512
+#define ATL1_MIN_RFD		128
+#define ATL1_MAX_RFD		2047
+
+#define ATL1_GET_DESC(R, i, type)	(&(((type *)((R)->desc))[i]))
+#define ATL1_RFD_DESC(R, i)		ATL1_GET_DESC(R, i, struct rx_free_desc)
+#define ATL1_TPD_DESC(R, i)		ATL1_GET_DESC(R, i, struct tx_packet_desc)
+#define ATL1_RRD_DESC(R, i)		ATL1_GET_DESC(R, i, struct rx_return_desc)
+
+#define usec_delay(x)	udelay(x)
+#ifndef msec_delay
+#define msec_delay(x)	do { if(in_interrupt()) { \
+			/* Don't mdelay in interrupt context!*/ \
+				BUG(); \
+			} else { \
+				msleep(x); \
+			}} while(0)
+/**
+ * Some workarounds require millisecond delays and are run during interrupt
+ * context.  Most notably, when establishing link, the phy may need tweaking
+ * but cannot process phy register reads/writes faster than millisecond
+ * intervals...and we establish link due to a "link status change" interrupt.
+ **/
+#define msec_delay_irq(x) mdelay(x)
+#endif
+
+/**
+ * wrapper around a pointer to a socket buffer,
+ * so a DMA handle can be stored along with the buffer
+ **/
+struct atl1_buffer {
+	struct sk_buff *skb;
+	u16 length;
+	u16 alloced;
+	dma_addr_t dma;
+};
+
+#define MAX_TX_BUF_LEN		0x3000	/* 12KB */
+
+struct atl1_tpd_ring {
+	void *desc;		/* pointer to the descriptor ring memory */
+	dma_addr_t dma;		/* physical adress of the descriptor ring */
+	u16 size;		/* length of descriptor ring in bytes */
+	u16 count;		/* number of descriptors in the ring */
+
+	u16 hw_idx;		/* hardware index */
+	atomic_t next_to_clean;
+	atomic_t next_to_use;
+	struct atl1_buffer *buffer_info;
+};
+
+struct atl1_rfd_ring {
+	void *desc;
+	dma_addr_t dma;
+	u16 size;
+	u16 count;
+	atomic_t next_to_use;
+	u16 next_to_clean;
+	struct atl1_buffer *buffer_info;
+};
+
+struct atl1_rrd_ring {
+	void *desc;
+	dma_addr_t dma;
+	unsigned int size;
+	u16 count;
+	u16 next_to_use;
+	atomic_t next_to_clean;
+};
+
+struct atl1_ring_header {
+	/* pointer to the descriptor ring memory */
+	void *desc;
+	/* physical adress of the descriptor ring */
+	dma_addr_t dma;
+	/* length of descriptor ring in bytes */
+	unsigned int size;
+};
+
+struct atl1_cmb {
+	struct coals_msg_block *cmb;
+	dma_addr_t dma;
+};
+
+struct atl1_smb {
+	struct stats_msg_block *smb;
+	dma_addr_t dma;
+};
+
+/* Statistics counters */
+struct atl1_sft_stats {
+	u64 rx_packets;
+	u64 tx_packets;
+	u64 rx_bytes;
+	u64 tx_bytes;
+	u64 multicast;
+	u64 collisions;
+	u64 rx_errors;
+	u64 rx_length_errors;
+	u64 rx_crc_errors;
+	u64 rx_frame_errors;
+	u64 rx_fifo_errors;
+	u64 rx_missed_errors;
+	u64 tx_errors;
+	u64 tx_fifo_errors;
+	u64 tx_aborted_errors;
+	u64 tx_window_errors;
+	u64 tx_carrier_errors;
+
+	u64 tx_pause;		/* The number of Pause packet transmitted. */
+	u64 excecol;		/* The number of transmit packets aborted due to excessive collisions. */
+	u64 deffer;		/* The number of packets transmitted that is deferred. */
+	u64 scc;		/* The number of packets subsequently transmitted successfully with a single prior collision. */
+	u64 mcc;		/* The number of packets subsequently transmitted successfully with multiple prior collisions. */
+	u64 latecol;		/* The number of packets transmitted with late collisions. */
+	u64 tx_underun;		/* The number of transmit packets aborted due to transmit FIFO underrun, or TRD FIFO underrun */
+	u64 tx_trunc;		/* The number of transmit packets truncated due to size exceeding MTU, regardless if it is truncated by Selene or not.
+				 * (The name is not really reflects the meaning in this case here.) */
+	u64 rx_pause;		/* The number of Pause packet received. */
+	u64 rx_rrd_ov;
+	u64 rx_trunc;
+};
+
+/* board specific private data structure */
+#define ATL1_REGS_LEN	8
+
+struct atl1_adapter {
+	/* OS defined structs */
+	struct net_device *netdev;
+	struct pci_dev *pdev;
+	struct net_device_stats net_stats;
+	struct atl1_sft_stats soft_stats;
+
+	struct vlan_group *vlgrp;
+	u32 rx_buffer_len;
+	u32 wol;
+	u16 link_speed;
+	u16 link_duplex;
+	spinlock_t stats_lock;
+	spinlock_t tx_lock;
+	spinlock_t vl_lock;
+	spinlock_t mii_lock;
+	atomic_t irq_sem;
+	struct work_struct tx_timeout_task;
+	struct work_struct link_chg_task;
+	struct work_struct pcie_dma_to_rst_task;
+	struct timer_list watchdog_timer;
+	struct timer_list phy_config_timer;
+	bool phy_timer_pending;
+
+	bool mac_disabled;
+
+	/* All descriptor rings' memory */
+	struct atl1_ring_header ring_header;
+
+	/* TX */
+	struct atl1_tpd_ring tpd_ring;
+	spinlock_t mb_lock;
+
+	/* RX */
+	struct atl1_rfd_ring rfd_ring;
+	struct atl1_rrd_ring rrd_ring;
+	u64 hw_csum_err;
+	u64 hw_csum_good;
+
+	u32 gorcl;
+	u64 gorcl_old;
+
+	/* Interrupt Moderator timer ( 2us resolution) */
+	u16 imt;
+	/* Interrupt Clear timer (2us resolution) */
+	u16 ict;
+
+	/* MII interface info */
+	struct mii_if_info mii;
+
+	/* structs defined in atl1_hw.h */
+	u32 bd_number;		/* board number */
+	bool pci_using_64;
+	struct atl1_hw hw;
+	struct atl1_smb smb;
+	struct atl1_cmb cmb;
+
+#ifdef ETHTOOL_TEST
+	u32 test_icr;
+	struct atl1_ring_header test_ring_header;
+	struct atl1_tpd_ring test_tpd_ring;
+	struct atl1_rfd_ring test_rfd_ring;
+	struct atl1_rrd_ring test_rrd_ring;
+#endif
+	int enable_msi;
+	u32 pci_state[16];
+};
+
+#endif	/* _ATL1_H_ */
drivers/net/atl1/atl1_hw.h new file +1053 -0

1,053 lines not on this page · raw message

#1 lore raw
Quoted 2 lines · Jay Cliburn

+/**
+ * atl1.h - atl1 main header

Please remove these kind of comments, they get out of date far too soon and don't really help anything. (Also everywhere else in the driver)

drivers/net/atl1/atl1.h line 39

Quoted 11 lines
drivers/net/atl1/atl1.h new file +11 -0
+#include <linux/tcp.h>
+#include <linux/skbuff.h>
+#include <linux/netdevice.h>
+#include <linux/pci.h>
+#include <linux/spinlock_types.h>
+#include <linux/workqueue.h>
+#include <linux/timer.h>
+#include <linux/delay.h>
+#include <linux/if_vlan.h>
+
+#include <asm/types.h>

Please always include <linux/types.h>

Quoted 2 lines

+#include <asm/atomic.h>

Please only includ headers where you use them - that's mostly the .c files unless you have lots of inlines or complex structures in the headers.

drivers/net/atl1/atl1.h line 54

Quoted 11 lines
drivers/net/atl1/atl1.h new file +11 -0
+#ifdef NETIF_F_TSO
+#include <net/checksum.h>
+#endif
+
+#ifdef SIOCGMIIPHY
+#include <linux/mii.h>
+#endif
+
+#ifdef SIOCETHTOOL
+#include <linux/ethtool.h>
+#endif

Please remove all these ifdefs.

Quoted 1 line

+#define BAR_0 0

This looks etirely superflous.

Quoted 6 lines
drivers/net/atl1/atl1.h new file +6 -0
+#define usec_delay(x)	udelay(x)
+#ifndef msec_delay
+#define msec_delay(x)	do { if(in_interrupt()) { \
+			/* Don't mdelay in interrupt context!*/ \
+				BUG(); \
+			} else { \

drivers/net/atl1/atl1.h line 96

Quoted 10 lines
drivers/net/atl1/atl1.h new file +10 -0
+				msleep(x); \
+			}} while(0)
+/**
+ * Some workarounds require millisecond delays and are run during interrupt
+ * context.  Most notably, when establishing link, the phy may need tweaking
+ * but cannot process phy register reads/writes faster than millisecond
+ * intervals...and we establish link due to a "link status change" interrupt.
+ **/
+#define msec_delay_irq(x) mdelay(x)
+#endif

Please kill all these wrappers.

Quoted 1 line

+} _ATL1_ATTRIB_PACK_;

All your structs seems to be properly packed from a first sight. Please doble-check this and get rid of the attribute packed.

Quoted 12 lines
drivers/net/atl1/atl1_hw.h new file +12 -0
+struct csum_param {
+	unsigned buf_len:14;
+	unsigned dma_int:1;
+	unsigned pkt_int:1;
+	u16 valan_tag;
+	unsigned eop:1;
+	/* command */
+	unsigned coalese:1;
+	unsigned ins_vlag:1;
+	unsigned custom_chksum:1;
+	unsigned segment:1;
+	unsigned ip_chksum:1;

drivers/net/atl1/atl1_hw.h line 877

Quoted 10 lines
drivers/net/atl1/atl1_hw.h new file +10 -0
+	unsigned tcp_chksum:1;
+	unsigned udp_chksum:1;
+	/* packet state */
+	unsigned vlan_tagged:1;
+	unsigned eth_type:1;
+	unsigned iphl:4;
+	unsigned:2;
+	unsigned payload_offset:8;
+	unsigned xsum_offset:8;
+} _ATL1_ATTRIB_PACK_;

Bitfields should not be used for hardware datastructures ever. Please convert this to explicit masking and shifting.

drivers/net/atl1/atl1_hw.h line 937

Quoted 4 lines
drivers/net/atl1/atl1_hw.h new file +4 -0
+/* Structure containing variables used by the shared code */
+struct atl1_hw {
+	u8 __iomem *hw_addr;
+	void *back;

This is definitly a kernel data structure. Shouldn't it be in atl1.h instead of _hw.h? Also does back really need to be a void pointer or can it be something typed?

drivers/net/atl1/atl1_hw.h line 992

Quoted 6 lines
drivers/net/atl1/atl1_hw.h new file +6 -0
+	u16 dev_rev;
+	u16 device_id;
+	u16 vendor_id;
+	u16 subsystem_id;
+	u16 subsystem_vendor_id;
+	u8 revision_id;

Please just use the values from the pci_dev insead of duplicating them.

drivers/net/atl1/atl1_hw.h line 1015

Quoted 11 lines
drivers/net/atl1/atl1_hw.h new file +11 -0
+/* formerly ATL1_WRITE_REG */
+static inline void atl1_write32(const struct atl1_hw *hw, int reg, u32 val)
+{
+        writel(val, hw->hw_addr + reg);
+}
+
+/* formerly ATL1_READ_REG */
+static inline u32 atl1_read32(const struct atl1_hw *hw, int reg)
+{
+        return readl(hw->hw_addr + reg);
+}

Just kill all these wrappers. Also you probably want to convert to pci_iomap + ioread*/iowrite*.

#2 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Jay Cliburn

+/**
+ * atl1.h - atl1 main header

Please remove these kind of comments, they get out of date far too soon and don't really help anything. (Also everywhere else in the driver)

Is your concern here with the filename portion of the comment only, or with the entire comment including the copyright and other material?

Jay

#3 lore raw
Quoted 5 lines · On Thu, 11 Jan 2007 10:53:30 -0600 Jay Cliburn <[email protected]> wrote:
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · Jay Cliburn

+/**
+ * atl1.h - atl1 main header

Quoted 7 lines
Quoted 2 lines

Please remove these kind of comments, they get out of date far too soon and don't really help anything. (Also everywhere else in the driver)

Is your concern here with the filename portion of the comment only, or with the entire comment including the copyright and other material?

Jay

Comments should not insult the reader by stating the obvious.

#4 lore raw
In reply to Jay Cliburn
Quoted 10 lines · Jay Cliburn
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Jay Cliburn

+/**
+ * atl1.h - atl1 main header

Please remove these kind of comments, they get out of date far too soon and don't really help anything. (Also everywhere else in the driver)

Is your concern here with the filename portion of the comment only, or with the entire comment including the copyright and other material?

Only the line I quoted. Copyright statements and similar things are obviously fine :)

#5 lore raw
In reply to Christoph Hellwig
Quoted 29 lines · Christoph Hellwig
Quoted 12 lines · Jay Cliburn
drivers/net/atl1/atl1_hw.h new file +12 -0
+struct csum_param {
+	unsigned buf_len:14;
+	unsigned dma_int:1;
+	unsigned pkt_int:1;
+	u16 valan_tag;
+	unsigned eop:1;
+	/* command */
+	unsigned coalese:1;
+	unsigned ins_vlag:1;
+	unsigned custom_chksum:1;
+	unsigned segment:1;
+	unsigned ip_chksum:1;

drivers/net/atl1/atl1_hw.h line 877

Quoted 10 lines
drivers/net/atl1/atl1_hw.h new file +10 -0
+	unsigned tcp_chksum:1;
+	unsigned udp_chksum:1;
+	/* packet state */
+	unsigned vlan_tagged:1;
+	unsigned eth_type:1;
+	unsigned iphl:4;
+	unsigned:2;
+	unsigned payload_offset:8;
+	unsigned xsum_offset:8;
+} _ATL1_ATTRIB_PACK_;

Bitfields should not be used for hardware datastructures ever. Please convert this to explicit masking and shifting.

Quoted 14 lines

drivers/net/atl1/atl1_hw.h line 1015

Quoted 11 lines
drivers/net/atl1/atl1_hw.h new file +11 -0
+/* formerly ATL1_WRITE_REG */
+static inline void atl1_write32(const struct atl1_hw *hw, int reg, u32 val)
+{
+        writel(val, hw->hw_addr + reg);
+}
+
+/* formerly ATL1_READ_REG */
+static inline u32 atl1_read32(const struct atl1_hw *hw, int reg)
+{
+        return readl(hw->hw_addr + reg);
+}

Just kill all these wrappers. Also you probably want to convert to pci_iomap + ioread*/iowrite*.

Christoph et al.,

I've incorporated all your comments except the two shown above. I killed the indicated atl1_write*/atl1_read* wrappers, but I'm not yet familiar enough with pci_iomap/iowrite*/ioread* to make that particular conversion, and I'm having trouble getting the bitfield struct converted to shift/mask semantics (No matter how hard I try, I keep breaking the transmit side of the adapter).

I'd like to plead for relief on these two items and submit a new version of the driver containing all your other comments. I need help from a more experienced netdev hacker, and in my mind, the best way to do that is to get the driver in the kernel so more people can use it and contribute changes and make improvements.

I welcome any comments on the rationality of this approach.

Jay

#6 lore raw

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

Quoted 1 line

I welcome any comments on the rationality of this approach.

An URL for the current version of the patch would be welcome too :o)

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

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

Quoted 1 line

I welcome any comments on the rationality of this approach.

An URL for the current version of the patch would be welcome too :o)

Sorry. Forgot to do that. The current version may be found here:

ftp://hogchain.net/pub/linux/m2v/attansic/kernel_driver/atl1-2.0.4/atl1-2.0.4-linux-2.6.20.rc5.patch.bz2

Jay