atl1: Header files for Attansic L1 driver
Subsystems (2)
PATCH 2/4 atl1: Header files for Attansic L1 driver
From: Jay Cliburn <[email protected]>
This patch contains the header files needed by the Attansic L1 gigabit ethernet adapter driver.
---
atl1.h | 251 ++++++++++++++ atl1_hw.h | 991 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ atl1_osdep.h | 78 ++++ 3 files changed, 1320 insertions(+)
drivers/net/atl1/atl1.h new file +251 -0
@@ -0,0 +1,251 @@ +/** 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 <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 + +#ifdef NETIF_F_HW_VLAN_TX +#include <linux/if_vlan.h> +#endif + +#define BAR_0 0 + +#define LBYTESWAP ( a ) ( ( ( (a) & 0x00ff00ff ) << 8 ) | ( ( (a) & 0xff00ff00 ) >> 8 ) ) +#define LONGSWAP ( a ) ( ( LBYTESWAP( a ) << 16 ) | ( LBYTESWAP( a ) >> 16 ) ) +#define SHORTSWAP ( a ) ( ( (a) << 8 ) | ( (a) >> 8 ) ) + +struct at_adapter ; + +#define AT_MAX_INTR 3 + +#define AT_DEFAULT_TPD 256 +#define AT_MAX_TPD 1023 +#define AT_MIN_TPD 64 +#define AT_DEFAULT_RFD 512 +#define AT_MIN_RFD 128 +#define AT_MAX_RFD 2047 + +#define AT_DESC_UNUSED (R ) \ + ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \ + (R)->next_to_clean - (R)->next_to_use - 1) + +#define AT_DESC_USED (R ) \ + (((R)->next_to_clean > (R)->next_to_use) ? \ + ((R)->count+(R)->next_to_use-(R)->next_to_clean+1) : \ + ((R)->next_to_use-(R)->next_to_clean+1)) + +#define AT_GET_DESC (R , i, type) (&(((type *)((R)->desc))[i])) +#define AT_RFD_DESC (R , i) AT_GET_DESC(R, i, struct rx_free_desc) +#define AT_TPD_DESC (R , i) AT_GET_DESC(R, i, struct tx_packet_desc) +#define AT_RRD_DESC (R , i) AT_GET_DESC(R, i, struct rx_return_desc) + +/** wrapper around a pointer to a socket buffer, +* so a DMA handle can be stored along with the buffer +*/ +struct at_buffer { +struct sk_buff *skb; +u16 length; +u16 alloced; +dma_addr_t dma; +}; + +#define MAX_TX_BUF_LEN 0x3000/* 12KB */ + +struct at_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 at_buffer *buffer_info; +}; + +struct at_rfd_ring { +void *desc; +dma_addr_t dma; +u16 size; +u16 count; +atomic_t next_to_use; +u16 next_to_clean; +struct at_buffer *buffer_info; +}; + +struct at_rrd_ring { +void *desc; +dma_addr_t dma; +unsigned int size; +u16 count; +u16 next_to_use; +atomic_t next_to_clean; +}; + +struct at_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 at_cmb { +struct coals_msg_block *cmb; +dma_addr_t dma; +}; + +struct at_smb { +struct stats_msg_block *smb; +dma_addr_t dma; +}; + +/* Statistics counters */ +struct at_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 AT_REGS_LEN 8 + +struct at_adapter { +/* OS defined structs */ +struct net_device *netdev; +struct pci_dev *pdev; +struct net_device_stats net_stats; +struct at_sft_stats soft_stats; + +#ifdef NETIF_F_HW_VLAN_TX +struct vlan_group *vlgrp; +#endif +u32 rx_buffer_len; +u32 wol; +u16 link_speed; +u16 link_duplex; +spinlock_t stats_lock; +spinlock_t tx_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 at_ring_header ring_header; + +/* TX */ +struct at_tpd_ring tpd_ring; +spinlock_t mb_lock; + +/* RX */ +struct at_rfd_ring rfd_ring; +struct at_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; + +/* structs defined in at_hw.h */ +u32 bd_number;/* board number */ +bool pci_using_64; +struct at_hw hw; +struct at_smb smb; +struct at_cmb cmb; + +#ifdef ETHTOOL_TEST +u32 test_icr; +struct at_ring_header test_ring_header; +struct at_tpd_ring test_tpd_ring; +struct at_rfd_ring test_rfd_ring; +struct at_rrd_ring test_rrd_ring; +#endif +u32 pci_state[16 ]; +}; + +#endif /* _ATL1_H_ */
drivers/net/atl1/atl1_hw.h new file +991 -0
991 lines not on this page · raw message
drivers/net/atl1/atl1_osdep.h new file +78 -0
78 lines not on this page · raw message
drivers/net/atl1/atl1.h line 61
Quoted 4 lines · Jay Cliburn
drivers/net/atl1/atl1.h new file +4
-0+ +#define LBYTESWAP ( a ) ( ( ( (a) & 0x00ff00ff ) << 8 ) | ( ( (a) & 0xff00ff00 ) >> 8 ) ) +#define LONGSWAP ( a ) ( ( LBYTESWAP( a ) << 16 ) | ( LBYTESWAP( a ) >> 16 ) ) +#define SHORTSWAP ( a ) ( ( (a) << 8 ) | ( (a) >> 8 ) )
Please use swab16/swab32 for these.
drivers/net/atl1/atl1.h line 81
Quoted 8 lines
drivers/net/atl1/atl1.h new file +8
-0+#define AT_DESC_UNUSED (R ) \ + ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \ + (R)->next_to_clean - (R)->next_to_use - 1) + +#define AT_DESC_USED (R ) \ + (((R)->next_to_clean > (R)->next_to_use) ? \ + ((R)->count+(R)->next_to_use-(R)->next_to_clean+1) : \ + ((R)->next_to_use-(R)->next_to_clean+1))
These look like they are on the edge to be written as a static-inline function. What do others think?
Quoted 13 lines
drivers/net/atl1/atl1_osdep.h new file +13
-0+#define AT_WRITE_REG (a, reg, value) ( \ + writel((value), ((a)->hw_addr + reg))) + +#define AT_READ_REG (a, reg) ( \ + readl((a)->hw_addr + reg )) + +#define AT_WRITE_REGB (a, reg, value) (\ + writeb((value), ((a)->hw_addr + reg))) + +#define AT_READ_REGB (a, reg) (\ + readb((a)->hw_addr + reg)) + +#define AT_WRITE_REGW (a, reg, value) (\
drivers/net/atl1/atl1_osdep.h line 76
Quoted 10 lines
drivers/net/atl1/atl1_osdep.h new file +10
-0+ writew((value), ((a)->hw_addr + reg))) + +#define AT_READ_REGW (a, reg) (\ + readw((a)->hw_addr + reg)) + +#define AT_WRITE_REG_ARRAY (a, reg, offset, value) ( \ + writel((value), (((a)->hw_addr + reg) + ((offset) << 2)))) + +#define AT_READ_REG_ARRAY (a, reg, offset) ( \ + readl(((a)->hw_addr + reg) + ((offset) << 2)))
Possibly similarly.
-`J'
Quoted 7 lines · Jan Engelhardt
drivers/net/atl1/atl1.h line 61
Quoted 4 lines · Jay Cliburn
drivers/net/atl1/atl1.h new file +4
-0+ +#define LBYTESWAP ( a ) ( ( ( (a) & 0x00ff00ff ) << 8 ) | ( ( (a) & 0xff00ff00 ) >> 8 ) ) +#define LONGSWAP ( a ) ( ( LBYTESWAP( a ) << 16 ) | ( LBYTESWAP( a ) >> 16 ) ) +#define SHORTSWAP ( a ) ( ( (a) << 8 ) | ( (a) >> 8 ) )Please use swab16/swab32 for these.
Thanks for pointing this out. There's a lot of self-rolled stuff in the vendor driver, and we haven't removed it all yet. That one should be easy though.
Quoted 11 lines
drivers/net/atl1/atl1.h line 81
Quoted 8 lines
drivers/net/atl1/atl1.h new file +8
-0+#define AT_DESC_UNUSED (R ) \ + ((((R)->next_to_clean > (R)->next_to_use) ? 0 : (R)->count) + \ + (R)->next_to_clean - (R)->next_to_use - 1) + +#define AT_DESC_USED (R ) \ + (((R)->next_to_clean > (R)->next_to_use) ? \ + ((R)->count+(R)->next_to_use-(R)->next_to_clean+1) : \ + ((R)->next_to_use-(R)->next_to_clean+1))These look like they are on the edge to be written as a static-inline function. What do others think?
I agree. There's a lot of cosmetic work left to do on this driver, but we felt it was time to get more eyes on it.
Quoted 17 lines
Quoted 17 lines
drivers/net/atl1/atl1_osdep.h new file +17
-0+#define AT_WRITE_REG (a, reg, value) ( \ + writel((value), ((a)->hw_addr + reg))) + +#define AT_READ_REG (a, reg) ( \ + readl((a)->hw_addr + reg )) + +#define AT_WRITE_REGB (a, reg, value) (\ + writeb((value), ((a)->hw_addr + reg))) + +#define AT_READ_REGB (a, reg) (\ + readb((a)->hw_addr + reg)) + +#define AT_WRITE_REGW (a, reg, value) (\ + writew((value), ((a)->hw_addr + reg))) + +#define AT_READ_REGW (a, reg) (\ + readw((a)->hw_addr + reg))
Quoted 8 lines
drivers/net/atl1/atl1_osdep.h line 76
Quoted 6 lines
drivers/net/atl1/atl1_osdep.h new file +6
-0+ +#define AT_WRITE_REG_ARRAY (a, reg, offset, value) ( \ + writel((value), (((a)->hw_addr + reg) + ((offset) << 2)))) + +#define AT_READ_REG_ARRAY (a, reg, offset) ( \ + readl(((a)->hw_addr + reg) + ((offset) << 2)))Possibly similarly.
Yeah, we'll inline these as well. Would you say that level of cosmetic cleanliness is required for merging, or should we focus solely on the functional issues for now?
-- Chris
Quoted 9 lines · Chris Snook
Quoted 4 lines · Jan Engelhardt
drivers/net/atl1/atl1_osdep.h line 76
Quoted 2 lines
drivers/net/atl1/atl1_osdep.h new file +2
-0+#define AT_READ_REG_ARRAY (a, reg, offset) ( \ + readl(((a)->hw_addr + reg) + ((offset) << 2)))Possibly similarly.
Yeah, we'll inline these as well. Would you say that level of cosmetic cleanliness is required for merging, or should we focus solely on the functional issues for now?
Required? No I do not think so, there is worse code than this. (Don't take that as an excuse to write bad code! :-)
It's just that it's easier to read if there are less parentheses. These defines are a good example of border (define vs inline) cases.
-`J'
Quoted 7 lines · Jay Cliburn
From: Jay Cliburn <[email protected]>
This patch contains the header files needed by the Attansic L1 gigabit ethernet adapter driver.
Signed-off-by Jay Cliburn <[email protected]>---
Also add
From: Chris Snook <[email protected]>
-- Chris