1dee1ad47SJeff Kirsher /******************************************************************************* 2dee1ad47SJeff Kirsher 3dee1ad47SJeff Kirsher Intel PRO/1000 Linux driver 4bf67044bSBruce Allan Copyright(c) 1999 - 2013 Intel Corporation. 5dee1ad47SJeff Kirsher 6dee1ad47SJeff Kirsher This program is free software; you can redistribute it and/or modify it 7dee1ad47SJeff Kirsher under the terms and conditions of the GNU General Public License, 8dee1ad47SJeff Kirsher version 2, as published by the Free Software Foundation. 9dee1ad47SJeff Kirsher 10dee1ad47SJeff Kirsher This program is distributed in the hope it will be useful, but WITHOUT 11dee1ad47SJeff Kirsher ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12dee1ad47SJeff Kirsher FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13dee1ad47SJeff Kirsher more details. 14dee1ad47SJeff Kirsher 15dee1ad47SJeff Kirsher You should have received a copy of the GNU General Public License along with 16dee1ad47SJeff Kirsher this program; if not, write to the Free Software Foundation, Inc., 17dee1ad47SJeff Kirsher 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 18dee1ad47SJeff Kirsher 19dee1ad47SJeff Kirsher The full GNU General Public License is included in this distribution in 20dee1ad47SJeff Kirsher the file called "COPYING". 21dee1ad47SJeff Kirsher 22dee1ad47SJeff Kirsher Contact Information: 23dee1ad47SJeff Kirsher Linux NICS <linux.nics@intel.com> 24dee1ad47SJeff Kirsher e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 25dee1ad47SJeff Kirsher Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 26dee1ad47SJeff Kirsher 27dee1ad47SJeff Kirsher *******************************************************************************/ 28dee1ad47SJeff Kirsher 29dee1ad47SJeff Kirsher /* Linux PRO/1000 Ethernet Driver main header file */ 30dee1ad47SJeff Kirsher 31dee1ad47SJeff Kirsher #ifndef _E1000_H_ 32dee1ad47SJeff Kirsher #define _E1000_H_ 33dee1ad47SJeff Kirsher 34dee1ad47SJeff Kirsher #include <linux/bitops.h> 35dee1ad47SJeff Kirsher #include <linux/types.h> 36dee1ad47SJeff Kirsher #include <linux/timer.h> 37dee1ad47SJeff Kirsher #include <linux/workqueue.h> 38dee1ad47SJeff Kirsher #include <linux/io.h> 39dee1ad47SJeff Kirsher #include <linux/netdevice.h> 40dee1ad47SJeff Kirsher #include <linux/pci.h> 41dee1ad47SJeff Kirsher #include <linux/pci-aspm.h> 42dee1ad47SJeff Kirsher #include <linux/crc32.h> 43dee1ad47SJeff Kirsher #include <linux/if_vlan.h> 44b67e1913SBruce Allan #include <linux/clocksource.h> 45b67e1913SBruce Allan #include <linux/net_tstamp.h> 46d89777bfSBruce Allan #include <linux/ptp_clock_kernel.h> 47d89777bfSBruce Allan #include <linux/ptp_classify.h> 48c2ade1a4SBruce Allan #include <linux/mii.h> 49dee1ad47SJeff Kirsher #include "hw.h" 50dee1ad47SJeff Kirsher 51dee1ad47SJeff Kirsher struct e1000_info; 52dee1ad47SJeff Kirsher 53dee1ad47SJeff Kirsher #define e_dbg(format, arg...) \ 54dee1ad47SJeff Kirsher netdev_dbg(hw->adapter->netdev, format, ## arg) 55dee1ad47SJeff Kirsher #define e_err(format, arg...) \ 56dee1ad47SJeff Kirsher netdev_err(adapter->netdev, format, ## arg) 57dee1ad47SJeff Kirsher #define e_info(format, arg...) \ 58dee1ad47SJeff Kirsher netdev_info(adapter->netdev, format, ## arg) 59dee1ad47SJeff Kirsher #define e_warn(format, arg...) \ 60dee1ad47SJeff Kirsher netdev_warn(adapter->netdev, format, ## arg) 61dee1ad47SJeff Kirsher #define e_notice(format, arg...) \ 62dee1ad47SJeff Kirsher netdev_notice(adapter->netdev, format, ## arg) 63dee1ad47SJeff Kirsher 64dee1ad47SJeff Kirsher 65dee1ad47SJeff Kirsher /* Interrupt modes, as used by the IntMode parameter */ 66dee1ad47SJeff Kirsher #define E1000E_INT_MODE_LEGACY 0 67dee1ad47SJeff Kirsher #define E1000E_INT_MODE_MSI 1 68dee1ad47SJeff Kirsher #define E1000E_INT_MODE_MSIX 2 69dee1ad47SJeff Kirsher 70dee1ad47SJeff Kirsher /* Tx/Rx descriptor defines */ 71dee1ad47SJeff Kirsher #define E1000_DEFAULT_TXD 256 72dee1ad47SJeff Kirsher #define E1000_MAX_TXD 4096 73dee1ad47SJeff Kirsher #define E1000_MIN_TXD 64 74dee1ad47SJeff Kirsher 75dee1ad47SJeff Kirsher #define E1000_DEFAULT_RXD 256 76dee1ad47SJeff Kirsher #define E1000_MAX_RXD 4096 77dee1ad47SJeff Kirsher #define E1000_MIN_RXD 64 78dee1ad47SJeff Kirsher 79dee1ad47SJeff Kirsher #define E1000_MIN_ITR_USECS 10 /* 100000 irq/sec */ 80dee1ad47SJeff Kirsher #define E1000_MAX_ITR_USECS 10000 /* 100 irq/sec */ 81dee1ad47SJeff Kirsher 82dee1ad47SJeff Kirsher #define E1000_FC_PAUSE_TIME 0x0680 /* 858 usec */ 83dee1ad47SJeff Kirsher 84dee1ad47SJeff Kirsher /* How many Tx Descriptors do we need to call netif_wake_queue ? */ 85dee1ad47SJeff Kirsher /* How many Rx Buffers do we bundle into one write to the hardware ? */ 86dee1ad47SJeff Kirsher #define E1000_RX_BUFFER_WRITE 16 /* Must be power of 2 */ 87dee1ad47SJeff Kirsher 88dee1ad47SJeff Kirsher #define AUTO_ALL_MODES 0 89dee1ad47SJeff Kirsher #define E1000_EEPROM_APME 0x0400 90dee1ad47SJeff Kirsher 91dee1ad47SJeff Kirsher #define E1000_MNG_VLAN_NONE (-1) 92dee1ad47SJeff Kirsher 93dee1ad47SJeff Kirsher /* Number of packet split data buffers (not including the header buffer) */ 94dee1ad47SJeff Kirsher #define PS_PAGE_BUFFERS (MAX_PS_BUFFERS - 1) 95dee1ad47SJeff Kirsher 96dee1ad47SJeff Kirsher #define DEFAULT_JUMBO 9234 97dee1ad47SJeff Kirsher 98dee1ad47SJeff Kirsher /* Time to wait before putting the device into D3 if there's no link (in ms). */ 99dee1ad47SJeff Kirsher #define LINK_TIMEOUT 100 100dee1ad47SJeff Kirsher 101e921eb1aSBruce Allan /* Count for polling __E1000_RESET condition every 10-20msec. 102bb9e44d0SBruce Allan * Experimentation has shown the reset can take approximately 210msec. 103bb9e44d0SBruce Allan */ 104bb9e44d0SBruce Allan #define E1000_CHECK_RESET_COUNT 25 105bb9e44d0SBruce Allan 106dee1ad47SJeff Kirsher #define DEFAULT_RDTR 0 107dee1ad47SJeff Kirsher #define DEFAULT_RADV 8 108dee1ad47SJeff Kirsher #define BURST_RDTR 0x20 109dee1ad47SJeff Kirsher #define BURST_RADV 0x20 110dee1ad47SJeff Kirsher 111e921eb1aSBruce Allan /* in the case of WTHRESH, it appears at least the 82571/2 hardware 112dee1ad47SJeff Kirsher * writes back 4 descriptors when WTHRESH=5, and 3 descriptors when 1138edc0e62SHiroaki SHIMODA * WTHRESH=4, so a setting of 5 gives the most efficient bus 1148edc0e62SHiroaki SHIMODA * utilization but to avoid possible Tx stalls, set it to 1 115dee1ad47SJeff Kirsher */ 116dee1ad47SJeff Kirsher #define E1000_TXDCTL_DMA_BURST_ENABLE \ 117dee1ad47SJeff Kirsher (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \ 118dee1ad47SJeff Kirsher E1000_TXDCTL_COUNT_DESC | \ 1198edc0e62SHiroaki SHIMODA (1 << 16) | /* wthresh must be +1 more than desired */\ 120dee1ad47SJeff Kirsher (1 << 8) | /* hthresh */ \ 121dee1ad47SJeff Kirsher 0x1f) /* pthresh */ 122dee1ad47SJeff Kirsher 123dee1ad47SJeff Kirsher #define E1000_RXDCTL_DMA_BURST_ENABLE \ 124dee1ad47SJeff Kirsher (0x01000000 | /* set descriptor granularity */ \ 125dee1ad47SJeff Kirsher (4 << 16) | /* set writeback threshold */ \ 126dee1ad47SJeff Kirsher (4 << 8) | /* set prefetch threshold */ \ 127dee1ad47SJeff Kirsher 0x20) /* set hthresh */ 128dee1ad47SJeff Kirsher 129dee1ad47SJeff Kirsher #define E1000_TIDV_FPD (1 << 31) 130dee1ad47SJeff Kirsher #define E1000_RDTR_FPD (1 << 31) 131dee1ad47SJeff Kirsher 132dee1ad47SJeff Kirsher enum e1000_boards { 133dee1ad47SJeff Kirsher board_82571, 134dee1ad47SJeff Kirsher board_82572, 135dee1ad47SJeff Kirsher board_82573, 136dee1ad47SJeff Kirsher board_82574, 137dee1ad47SJeff Kirsher board_82583, 138dee1ad47SJeff Kirsher board_80003es2lan, 139dee1ad47SJeff Kirsher board_ich8lan, 140dee1ad47SJeff Kirsher board_ich9lan, 141dee1ad47SJeff Kirsher board_ich10lan, 142dee1ad47SJeff Kirsher board_pchlan, 143dee1ad47SJeff Kirsher board_pch2lan, 1442fbe4526SBruce Allan board_pch_lpt, 145dee1ad47SJeff Kirsher }; 146dee1ad47SJeff Kirsher 147dee1ad47SJeff Kirsher struct e1000_ps_page { 148dee1ad47SJeff Kirsher struct page *page; 149dee1ad47SJeff Kirsher u64 dma; /* must be u64 - written to hw */ 150dee1ad47SJeff Kirsher }; 151dee1ad47SJeff Kirsher 152e921eb1aSBruce Allan /* wrappers around a pointer to a socket buffer, 153dee1ad47SJeff Kirsher * so a DMA handle can be stored along with the buffer 154dee1ad47SJeff Kirsher */ 155dee1ad47SJeff Kirsher struct e1000_buffer { 156dee1ad47SJeff Kirsher dma_addr_t dma; 157dee1ad47SJeff Kirsher struct sk_buff *skb; 158dee1ad47SJeff Kirsher union { 159dee1ad47SJeff Kirsher /* Tx */ 160dee1ad47SJeff Kirsher struct { 161dee1ad47SJeff Kirsher unsigned long time_stamp; 162dee1ad47SJeff Kirsher u16 length; 163dee1ad47SJeff Kirsher u16 next_to_watch; 164dee1ad47SJeff Kirsher unsigned int segs; 165dee1ad47SJeff Kirsher unsigned int bytecount; 166dee1ad47SJeff Kirsher u16 mapped_as_page; 167dee1ad47SJeff Kirsher }; 168dee1ad47SJeff Kirsher /* Rx */ 169dee1ad47SJeff Kirsher struct { 170dee1ad47SJeff Kirsher /* arrays of page information for packet split */ 171dee1ad47SJeff Kirsher struct e1000_ps_page *ps_pages; 172dee1ad47SJeff Kirsher struct page *page; 173dee1ad47SJeff Kirsher }; 174dee1ad47SJeff Kirsher }; 175dee1ad47SJeff Kirsher }; 176dee1ad47SJeff Kirsher 177dee1ad47SJeff Kirsher struct e1000_ring { 17855aa6985SBruce Allan struct e1000_adapter *adapter; /* back pointer to adapter */ 179dee1ad47SJeff Kirsher void *desc; /* pointer to ring memory */ 180dee1ad47SJeff Kirsher dma_addr_t dma; /* phys address of ring */ 181dee1ad47SJeff Kirsher unsigned int size; /* length of ring in bytes */ 182dee1ad47SJeff Kirsher unsigned int count; /* number of desc. in ring */ 183dee1ad47SJeff Kirsher 184dee1ad47SJeff Kirsher u16 next_to_use; 185dee1ad47SJeff Kirsher u16 next_to_clean; 186dee1ad47SJeff Kirsher 187c5083cf6SBruce Allan void __iomem *head; 188c5083cf6SBruce Allan void __iomem *tail; 189dee1ad47SJeff Kirsher 190dee1ad47SJeff Kirsher /* array of buffer information structs */ 191dee1ad47SJeff Kirsher struct e1000_buffer *buffer_info; 192dee1ad47SJeff Kirsher 193dee1ad47SJeff Kirsher char name[IFNAMSIZ + 5]; 194dee1ad47SJeff Kirsher u32 ims_val; 195dee1ad47SJeff Kirsher u32 itr_val; 196c5083cf6SBruce Allan void __iomem *itr_register; 197dee1ad47SJeff Kirsher int set_itr; 198dee1ad47SJeff Kirsher 199dee1ad47SJeff Kirsher struct sk_buff *rx_skb_top; 200dee1ad47SJeff Kirsher }; 201dee1ad47SJeff Kirsher 202dee1ad47SJeff Kirsher /* PHY register snapshot values */ 203dee1ad47SJeff Kirsher struct e1000_phy_regs { 204dee1ad47SJeff Kirsher u16 bmcr; /* basic mode control register */ 205dee1ad47SJeff Kirsher u16 bmsr; /* basic mode status register */ 206dee1ad47SJeff Kirsher u16 advertise; /* auto-negotiation advertisement */ 207dee1ad47SJeff Kirsher u16 lpa; /* link partner ability register */ 208dee1ad47SJeff Kirsher u16 expansion; /* auto-negotiation expansion reg */ 209dee1ad47SJeff Kirsher u16 ctrl1000; /* 1000BASE-T control register */ 210dee1ad47SJeff Kirsher u16 stat1000; /* 1000BASE-T status register */ 211dee1ad47SJeff Kirsher u16 estatus; /* extended status register */ 212dee1ad47SJeff Kirsher }; 213dee1ad47SJeff Kirsher 214dee1ad47SJeff Kirsher /* board specific private data structure */ 215dee1ad47SJeff Kirsher struct e1000_adapter { 216dee1ad47SJeff Kirsher struct timer_list watchdog_timer; 217dee1ad47SJeff Kirsher struct timer_list phy_info_timer; 218dee1ad47SJeff Kirsher struct timer_list blink_timer; 219dee1ad47SJeff Kirsher 220dee1ad47SJeff Kirsher struct work_struct reset_task; 221dee1ad47SJeff Kirsher struct work_struct watchdog_task; 222dee1ad47SJeff Kirsher 223dee1ad47SJeff Kirsher const struct e1000_info *ei; 224dee1ad47SJeff Kirsher 225dee1ad47SJeff Kirsher unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)]; 226dee1ad47SJeff Kirsher u32 bd_number; 227dee1ad47SJeff Kirsher u32 rx_buffer_len; 228dee1ad47SJeff Kirsher u16 mng_vlan_id; 229dee1ad47SJeff Kirsher u16 link_speed; 230dee1ad47SJeff Kirsher u16 link_duplex; 231dee1ad47SJeff Kirsher u16 eeprom_vers; 232dee1ad47SJeff Kirsher 233dee1ad47SJeff Kirsher /* track device up/down/testing state */ 234dee1ad47SJeff Kirsher unsigned long state; 235dee1ad47SJeff Kirsher 236dee1ad47SJeff Kirsher /* Interrupt Throttle Rate */ 237dee1ad47SJeff Kirsher u32 itr; 238dee1ad47SJeff Kirsher u32 itr_setting; 239dee1ad47SJeff Kirsher u16 tx_itr; 240dee1ad47SJeff Kirsher u16 rx_itr; 241dee1ad47SJeff Kirsher 242e921eb1aSBruce Allan /* Tx */ 243dee1ad47SJeff Kirsher struct e1000_ring *tx_ring /* One per active queue */ 244dee1ad47SJeff Kirsher ____cacheline_aligned_in_smp; 245d821a4c4SBruce Allan u32 tx_fifo_limit; 246dee1ad47SJeff Kirsher 247dee1ad47SJeff Kirsher struct napi_struct napi; 248dee1ad47SJeff Kirsher 24994fb848bSBruce Allan unsigned int uncorr_errors; /* uncorrectable ECC errors */ 25094fb848bSBruce Allan unsigned int corr_errors; /* correctable ECC errors */ 251dee1ad47SJeff Kirsher unsigned int restart_queue; 252dee1ad47SJeff Kirsher u32 txd_cmd; 253dee1ad47SJeff Kirsher 254dee1ad47SJeff Kirsher bool detect_tx_hung; 25509357b00SJeff Kirsher bool tx_hang_recheck; 256dee1ad47SJeff Kirsher u8 tx_timeout_factor; 257dee1ad47SJeff Kirsher 258dee1ad47SJeff Kirsher u32 tx_int_delay; 259dee1ad47SJeff Kirsher u32 tx_abs_int_delay; 260dee1ad47SJeff Kirsher 261dee1ad47SJeff Kirsher unsigned int total_tx_bytes; 262dee1ad47SJeff Kirsher unsigned int total_tx_packets; 263dee1ad47SJeff Kirsher unsigned int total_rx_bytes; 264dee1ad47SJeff Kirsher unsigned int total_rx_packets; 265dee1ad47SJeff Kirsher 266dee1ad47SJeff Kirsher /* Tx stats */ 267dee1ad47SJeff Kirsher u64 tpt_old; 268dee1ad47SJeff Kirsher u64 colc_old; 269dee1ad47SJeff Kirsher u32 gotc; 270dee1ad47SJeff Kirsher u64 gotc_old; 271dee1ad47SJeff Kirsher u32 tx_timeout_count; 272dee1ad47SJeff Kirsher u32 tx_fifo_head; 273dee1ad47SJeff Kirsher u32 tx_head_addr; 274dee1ad47SJeff Kirsher u32 tx_fifo_size; 275dee1ad47SJeff Kirsher u32 tx_dma_failed; 276dee1ad47SJeff Kirsher 277e921eb1aSBruce Allan /* Rx */ 27855aa6985SBruce Allan bool (*clean_rx) (struct e1000_ring *ring, int *work_done, 27955aa6985SBruce Allan int work_to_do) ____cacheline_aligned_in_smp; 28055aa6985SBruce Allan void (*alloc_rx_buf) (struct e1000_ring *ring, int cleaned_count, 28155aa6985SBruce Allan gfp_t gfp); 282dee1ad47SJeff Kirsher struct e1000_ring *rx_ring; 283dee1ad47SJeff Kirsher 284dee1ad47SJeff Kirsher u32 rx_int_delay; 285dee1ad47SJeff Kirsher u32 rx_abs_int_delay; 286dee1ad47SJeff Kirsher 287dee1ad47SJeff Kirsher /* Rx stats */ 288dee1ad47SJeff Kirsher u64 hw_csum_err; 289dee1ad47SJeff Kirsher u64 hw_csum_good; 290dee1ad47SJeff Kirsher u64 rx_hdr_split; 291dee1ad47SJeff Kirsher u32 gorc; 292dee1ad47SJeff Kirsher u64 gorc_old; 293dee1ad47SJeff Kirsher u32 alloc_rx_buff_failed; 294dee1ad47SJeff Kirsher u32 rx_dma_failed; 295b67e1913SBruce Allan u32 rx_hwtstamp_cleared; 296dee1ad47SJeff Kirsher 297dee1ad47SJeff Kirsher unsigned int rx_ps_pages; 298dee1ad47SJeff Kirsher u16 rx_ps_bsize0; 299dee1ad47SJeff Kirsher u32 max_frame_size; 300dee1ad47SJeff Kirsher u32 min_frame_size; 301dee1ad47SJeff Kirsher 302dee1ad47SJeff Kirsher /* OS defined structs */ 303dee1ad47SJeff Kirsher struct net_device *netdev; 304dee1ad47SJeff Kirsher struct pci_dev *pdev; 305dee1ad47SJeff Kirsher 306dee1ad47SJeff Kirsher /* structs defined in e1000_hw.h */ 307dee1ad47SJeff Kirsher struct e1000_hw hw; 308dee1ad47SJeff Kirsher 3099d57088bSBruce Allan spinlock_t stats64_lock; /* protects statistics counters */ 310dee1ad47SJeff Kirsher struct e1000_hw_stats stats; 311dee1ad47SJeff Kirsher struct e1000_phy_info phy_info; 312dee1ad47SJeff Kirsher struct e1000_phy_stats phy_stats; 313dee1ad47SJeff Kirsher 314dee1ad47SJeff Kirsher /* Snapshot of PHY registers */ 315dee1ad47SJeff Kirsher struct e1000_phy_regs phy_regs; 316dee1ad47SJeff Kirsher 317dee1ad47SJeff Kirsher struct e1000_ring test_tx_ring; 318dee1ad47SJeff Kirsher struct e1000_ring test_rx_ring; 319dee1ad47SJeff Kirsher u32 test_icr; 320dee1ad47SJeff Kirsher 321dee1ad47SJeff Kirsher u32 msg_enable; 322dee1ad47SJeff Kirsher unsigned int num_vectors; 323dee1ad47SJeff Kirsher struct msix_entry *msix_entries; 324dee1ad47SJeff Kirsher int int_mode; 325dee1ad47SJeff Kirsher u32 eiac_mask; 326dee1ad47SJeff Kirsher 327dee1ad47SJeff Kirsher u32 eeprom_wol; 328dee1ad47SJeff Kirsher u32 wol; 329dee1ad47SJeff Kirsher u32 pba; 330dee1ad47SJeff Kirsher u32 max_hw_frame_size; 331dee1ad47SJeff Kirsher 332dee1ad47SJeff Kirsher bool fc_autoneg; 333dee1ad47SJeff Kirsher 334dee1ad47SJeff Kirsher unsigned int flags; 335dee1ad47SJeff Kirsher unsigned int flags2; 336dee1ad47SJeff Kirsher struct work_struct downshift_task; 337dee1ad47SJeff Kirsher struct work_struct update_phy_task; 338dee1ad47SJeff Kirsher struct work_struct print_hang_task; 339dee1ad47SJeff Kirsher 340dee1ad47SJeff Kirsher bool idle_check; 341dee1ad47SJeff Kirsher int phy_hang_count; 34255aa6985SBruce Allan 34355aa6985SBruce Allan u16 tx_ring_count; 34455aa6985SBruce Allan u16 rx_ring_count; 345b67e1913SBruce Allan 346b67e1913SBruce Allan struct hwtstamp_config hwtstamp_config; 347b67e1913SBruce Allan struct delayed_work systim_overflow_work; 348b67e1913SBruce Allan struct sk_buff *tx_hwtstamp_skb; 349b67e1913SBruce Allan struct work_struct tx_hwtstamp_work; 350b67e1913SBruce Allan spinlock_t systim_lock; /* protects SYSTIML/H regsters */ 351b67e1913SBruce Allan struct cyclecounter cc; 352b67e1913SBruce Allan struct timecounter tc; 353d89777bfSBruce Allan struct ptp_clock *ptp_clock; 354d89777bfSBruce Allan struct ptp_clock_info ptp_clock_info; 355dee1ad47SJeff Kirsher }; 356dee1ad47SJeff Kirsher 357dee1ad47SJeff Kirsher struct e1000_info { 358dee1ad47SJeff Kirsher enum e1000_mac_type mac; 359dee1ad47SJeff Kirsher unsigned int flags; 360dee1ad47SJeff Kirsher unsigned int flags2; 361dee1ad47SJeff Kirsher u32 pba; 362dee1ad47SJeff Kirsher u32 max_hw_frame_size; 363dee1ad47SJeff Kirsher s32 (*get_variants)(struct e1000_adapter *); 3648ce9d6c7SJeff Kirsher const struct e1000_mac_operations *mac_ops; 3658ce9d6c7SJeff Kirsher const struct e1000_phy_operations *phy_ops; 3668ce9d6c7SJeff Kirsher const struct e1000_nvm_operations *nvm_ops; 367dee1ad47SJeff Kirsher }; 368dee1ad47SJeff Kirsher 369d89777bfSBruce Allan s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca); 370d89777bfSBruce Allan 371b67e1913SBruce Allan /* The system time is maintained by a 64-bit counter comprised of the 32-bit 372b67e1913SBruce Allan * SYSTIMH and SYSTIML registers. How the counter increments (and therefore 373b67e1913SBruce Allan * its resolution) is based on the contents of the TIMINCA register - it 374b67e1913SBruce Allan * increments every incperiod (bits 31:24) clock ticks by incvalue (bits 23:0). 375b67e1913SBruce Allan * For the best accuracy, the incperiod should be as small as possible. The 376b67e1913SBruce Allan * incvalue is scaled by a factor as large as possible (while still fitting 377b67e1913SBruce Allan * in bits 23:0) so that relatively small clock corrections can be made. 378b67e1913SBruce Allan * 379b67e1913SBruce Allan * As a result, a shift of INCVALUE_SHIFT_n is used to fit a value of 380b67e1913SBruce Allan * INCVALUE_n into the TIMINCA register allowing 32+8+(24-INCVALUE_SHIFT_n) 381b67e1913SBruce Allan * bits to count nanoseconds leaving the rest for fractional nonseconds. 382b67e1913SBruce Allan */ 383b67e1913SBruce Allan #define INCVALUE_96MHz 125 384b67e1913SBruce Allan #define INCVALUE_SHIFT_96MHz 17 385b67e1913SBruce Allan #define INCPERIOD_SHIFT_96MHz 2 386b67e1913SBruce Allan #define INCPERIOD_96MHz (12 >> INCPERIOD_SHIFT_96MHz) 387b67e1913SBruce Allan 388b67e1913SBruce Allan #define INCVALUE_25MHz 40 389b67e1913SBruce Allan #define INCVALUE_SHIFT_25MHz 18 390b67e1913SBruce Allan #define INCPERIOD_25MHz 1 391b67e1913SBruce Allan 392b67e1913SBruce Allan /* Another drawback of scaling the incvalue by a large factor is the 393b67e1913SBruce Allan * 64-bit SYSTIM register overflows more quickly. This is dealt with 394b67e1913SBruce Allan * by simply reading the clock before it overflows. 395b67e1913SBruce Allan * 396b67e1913SBruce Allan * Clock ns bits Overflows after 397b67e1913SBruce Allan * ~~~~~~ ~~~~~~~ ~~~~~~~~~~~~~~~ 398b67e1913SBruce Allan * 96MHz 47-bit 2^(47-INCPERIOD_SHIFT_96MHz) / 10^9 / 3600 = 9.77 hrs 399b67e1913SBruce Allan * 25MHz 46-bit 2^46 / 10^9 / 3600 = 19.55 hours 400b67e1913SBruce Allan */ 401b67e1913SBruce Allan #define E1000_SYSTIM_OVERFLOW_PERIOD (HZ * 60 * 60 * 4) 402b67e1913SBruce Allan 403dee1ad47SJeff Kirsher /* hardware capability, feature, and workaround flags */ 404dee1ad47SJeff Kirsher #define FLAG_HAS_AMT (1 << 0) 405dee1ad47SJeff Kirsher #define FLAG_HAS_FLASH (1 << 1) 406dee1ad47SJeff Kirsher #define FLAG_HAS_HW_VLAN_FILTER (1 << 2) 407dee1ad47SJeff Kirsher #define FLAG_HAS_WOL (1 << 3) 40879d4e908SBruce Allan /* reserved bit4 */ 409dee1ad47SJeff Kirsher #define FLAG_HAS_CTRLEXT_ON_LOAD (1 << 5) 410dee1ad47SJeff Kirsher #define FLAG_HAS_SWSM_ON_LOAD (1 << 6) 411dee1ad47SJeff Kirsher #define FLAG_HAS_JUMBO_FRAMES (1 << 7) 412dee1ad47SJeff Kirsher #define FLAG_READ_ONLY_NVM (1 << 8) 413dee1ad47SJeff Kirsher #define FLAG_IS_ICH (1 << 9) 414dee1ad47SJeff Kirsher #define FLAG_HAS_MSIX (1 << 10) 415dee1ad47SJeff Kirsher #define FLAG_HAS_SMART_POWER_DOWN (1 << 11) 416dee1ad47SJeff Kirsher #define FLAG_IS_QUAD_PORT_A (1 << 12) 417dee1ad47SJeff Kirsher #define FLAG_IS_QUAD_PORT (1 << 13) 418b67e1913SBruce Allan #define FLAG_HAS_HW_TIMESTAMP (1 << 14) 419dee1ad47SJeff Kirsher #define FLAG_APME_IN_WUC (1 << 15) 420dee1ad47SJeff Kirsher #define FLAG_APME_IN_CTRL3 (1 << 16) 421dee1ad47SJeff Kirsher #define FLAG_APME_CHECK_PORT_B (1 << 17) 422dee1ad47SJeff Kirsher #define FLAG_DISABLE_FC_PAUSE_TIME (1 << 18) 423dee1ad47SJeff Kirsher #define FLAG_NO_WAKE_UCAST (1 << 19) 424dee1ad47SJeff Kirsher #define FLAG_MNG_PT_ENABLED (1 << 20) 425dee1ad47SJeff Kirsher #define FLAG_RESET_OVERWRITES_LAA (1 << 21) 426dee1ad47SJeff Kirsher #define FLAG_TARC_SPEED_MODE_BIT (1 << 22) 427dee1ad47SJeff Kirsher #define FLAG_TARC_SET_BIT_ZERO (1 << 23) 428dee1ad47SJeff Kirsher #define FLAG_RX_NEEDS_RESTART (1 << 24) 429dee1ad47SJeff Kirsher #define FLAG_LSC_GIG_SPEED_DROP (1 << 25) 430dee1ad47SJeff Kirsher #define FLAG_SMART_POWER_DOWN (1 << 26) 431dee1ad47SJeff Kirsher #define FLAG_MSI_ENABLED (1 << 27) 432dc221294SBruce Allan /* reserved (1 << 28) */ 433dee1ad47SJeff Kirsher #define FLAG_TSO_FORCE (1 << 29) 43412d43f7dSBruce Allan #define FLAG_RESTART_NOW (1 << 30) 435dee1ad47SJeff Kirsher #define FLAG_MSI_TEST_FAILED (1 << 31) 436dee1ad47SJeff Kirsher 437dee1ad47SJeff Kirsher #define FLAG2_CRC_STRIPPING (1 << 0) 438dee1ad47SJeff Kirsher #define FLAG2_HAS_PHY_WAKEUP (1 << 1) 439dee1ad47SJeff Kirsher #define FLAG2_IS_DISCARDING (1 << 2) 440dee1ad47SJeff Kirsher #define FLAG2_DISABLE_ASPM_L1 (1 << 3) 441dee1ad47SJeff Kirsher #define FLAG2_HAS_PHY_STATS (1 << 4) 442dee1ad47SJeff Kirsher #define FLAG2_HAS_EEE (1 << 5) 443dee1ad47SJeff Kirsher #define FLAG2_DMA_BURST (1 << 6) 444dee1ad47SJeff Kirsher #define FLAG2_DISABLE_ASPM_L0S (1 << 7) 445dee1ad47SJeff Kirsher #define FLAG2_DISABLE_AIM (1 << 8) 446dee1ad47SJeff Kirsher #define FLAG2_CHECK_PHY_HANG (1 << 9) 447823dcd25SDavid S. Miller #define FLAG2_NO_DISABLE_RX (1 << 10) 448823dcd25SDavid S. Miller #define FLAG2_PCIM2PCI_ARBITER_WA (1 << 11) 4490184039aSBen Greear #define FLAG2_DFLT_CRC_STRIPPING (1 << 12) 450b67e1913SBruce Allan #define FLAG2_CHECK_RX_HWTSTAMP (1 << 13) 451dee1ad47SJeff Kirsher 452dee1ad47SJeff Kirsher #define E1000_RX_DESC_PS(R, i) \ 453dee1ad47SJeff Kirsher (&(((union e1000_rx_desc_packet_split *)((R).desc))[i])) 4545f450212SBruce Allan #define E1000_RX_DESC_EXT(R, i) \ 4555f450212SBruce Allan (&(((union e1000_rx_desc_extended *)((R).desc))[i])) 456dee1ad47SJeff Kirsher #define E1000_GET_DESC(R, i, type) (&(((struct type *)((R).desc))[i])) 457dee1ad47SJeff Kirsher #define E1000_TX_DESC(R, i) E1000_GET_DESC(R, i, e1000_tx_desc) 458dee1ad47SJeff Kirsher #define E1000_CONTEXT_DESC(R, i) E1000_GET_DESC(R, i, e1000_context_desc) 459dee1ad47SJeff Kirsher 460dee1ad47SJeff Kirsher enum e1000_state_t { 461dee1ad47SJeff Kirsher __E1000_TESTING, 462dee1ad47SJeff Kirsher __E1000_RESETTING, 463a90b412cSBruce Allan __E1000_ACCESS_SHARED_RESOURCE, 464dee1ad47SJeff Kirsher __E1000_DOWN 465dee1ad47SJeff Kirsher }; 466dee1ad47SJeff Kirsher 467dee1ad47SJeff Kirsher enum latency_range { 468dee1ad47SJeff Kirsher lowest_latency = 0, 469dee1ad47SJeff Kirsher low_latency = 1, 470dee1ad47SJeff Kirsher bulk_latency = 2, 471dee1ad47SJeff Kirsher latency_invalid = 255 472dee1ad47SJeff Kirsher }; 473dee1ad47SJeff Kirsher 474dee1ad47SJeff Kirsher extern char e1000e_driver_name[]; 475dee1ad47SJeff Kirsher extern const char e1000e_driver_version[]; 476dee1ad47SJeff Kirsher 477dee1ad47SJeff Kirsher extern void e1000e_check_options(struct e1000_adapter *adapter); 478dee1ad47SJeff Kirsher extern void e1000e_set_ethtool_ops(struct net_device *netdev); 479dee1ad47SJeff Kirsher 480dee1ad47SJeff Kirsher extern int e1000e_up(struct e1000_adapter *adapter); 481dee1ad47SJeff Kirsher extern void e1000e_down(struct e1000_adapter *adapter); 482dee1ad47SJeff Kirsher extern void e1000e_reinit_locked(struct e1000_adapter *adapter); 483dee1ad47SJeff Kirsher extern void e1000e_reset(struct e1000_adapter *adapter); 484dee1ad47SJeff Kirsher extern void e1000e_power_up_phy(struct e1000_adapter *adapter); 48555aa6985SBruce Allan extern int e1000e_setup_rx_resources(struct e1000_ring *ring); 48655aa6985SBruce Allan extern int e1000e_setup_tx_resources(struct e1000_ring *ring); 48755aa6985SBruce Allan extern void e1000e_free_rx_resources(struct e1000_ring *ring); 48855aa6985SBruce Allan extern void e1000e_free_tx_resources(struct e1000_ring *ring); 489dee1ad47SJeff Kirsher extern struct rtnl_link_stats64 *e1000e_get_stats64(struct net_device *netdev, 490dee1ad47SJeff Kirsher struct rtnl_link_stats64 491dee1ad47SJeff Kirsher *stats); 492dee1ad47SJeff Kirsher extern void e1000e_set_interrupt_capability(struct e1000_adapter *adapter); 493dee1ad47SJeff Kirsher extern void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter); 494dee1ad47SJeff Kirsher extern void e1000e_get_hw_control(struct e1000_adapter *adapter); 495dee1ad47SJeff Kirsher extern void e1000e_release_hw_control(struct e1000_adapter *adapter); 49622a4cca2SMatthew Vick extern void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr); 497dee1ad47SJeff Kirsher 498dee1ad47SJeff Kirsher extern unsigned int copybreak; 499dee1ad47SJeff Kirsher 5008ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_82571_info; 5018ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_82572_info; 5028ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_82573_info; 5038ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_82574_info; 5048ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_82583_info; 5058ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_ich8_info; 5068ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_ich9_info; 5078ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_ich10_info; 5088ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_pch_info; 5098ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_pch2_info; 5102fbe4526SBruce Allan extern const struct e1000_info e1000_pch_lpt_info; 5118ce9d6c7SJeff Kirsher extern const struct e1000_info e1000_es2_info; 512dee1ad47SJeff Kirsher 513d89777bfSBruce Allan extern void e1000e_ptp_init(struct e1000_adapter *adapter); 514d89777bfSBruce Allan extern void e1000e_ptp_remove(struct e1000_adapter *adapter); 515dee1ad47SJeff Kirsher 516dee1ad47SJeff Kirsher static inline s32 e1000_phy_hw_reset(struct e1000_hw *hw) 517dee1ad47SJeff Kirsher { 518dee1ad47SJeff Kirsher return hw->phy.ops.reset(hw); 519dee1ad47SJeff Kirsher } 520dee1ad47SJeff Kirsher 521dee1ad47SJeff Kirsher static inline s32 e1e_rphy(struct e1000_hw *hw, u32 offset, u16 *data) 522dee1ad47SJeff Kirsher { 523dee1ad47SJeff Kirsher return hw->phy.ops.read_reg(hw, offset, data); 524dee1ad47SJeff Kirsher } 525dee1ad47SJeff Kirsher 526f1430d69SBruce Allan static inline s32 e1e_rphy_locked(struct e1000_hw *hw, u32 offset, u16 *data) 527f1430d69SBruce Allan { 528f1430d69SBruce Allan return hw->phy.ops.read_reg_locked(hw, offset, data); 529f1430d69SBruce Allan } 530f1430d69SBruce Allan 531dee1ad47SJeff Kirsher static inline s32 e1e_wphy(struct e1000_hw *hw, u32 offset, u16 data) 532dee1ad47SJeff Kirsher { 533dee1ad47SJeff Kirsher return hw->phy.ops.write_reg(hw, offset, data); 534dee1ad47SJeff Kirsher } 535dee1ad47SJeff Kirsher 536f1430d69SBruce Allan static inline s32 e1e_wphy_locked(struct e1000_hw *hw, u32 offset, u16 data) 537f1430d69SBruce Allan { 538f1430d69SBruce Allan return hw->phy.ops.write_reg_locked(hw, offset, data); 539f1430d69SBruce Allan } 540f1430d69SBruce Allan 541e85e3639SBruce Allan extern void e1000e_reload_nvm_generic(struct e1000_hw *hw); 542dee1ad47SJeff Kirsher 543dee1ad47SJeff Kirsher static inline s32 e1000e_read_mac_addr(struct e1000_hw *hw) 544dee1ad47SJeff Kirsher { 545dee1ad47SJeff Kirsher if (hw->mac.ops.read_mac_addr) 546dee1ad47SJeff Kirsher return hw->mac.ops.read_mac_addr(hw); 547dee1ad47SJeff Kirsher 548dee1ad47SJeff Kirsher return e1000_read_mac_addr_generic(hw); 549dee1ad47SJeff Kirsher } 550dee1ad47SJeff Kirsher 551dee1ad47SJeff Kirsher static inline s32 e1000_validate_nvm_checksum(struct e1000_hw *hw) 552dee1ad47SJeff Kirsher { 553dee1ad47SJeff Kirsher return hw->nvm.ops.validate(hw); 554dee1ad47SJeff Kirsher } 555dee1ad47SJeff Kirsher 556dee1ad47SJeff Kirsher static inline s32 e1000e_update_nvm_checksum(struct e1000_hw *hw) 557dee1ad47SJeff Kirsher { 558dee1ad47SJeff Kirsher return hw->nvm.ops.update(hw); 559dee1ad47SJeff Kirsher } 560dee1ad47SJeff Kirsher 561*c29c3ba5SBruce Allan static inline s32 e1000_read_nvm(struct e1000_hw *hw, u16 offset, u16 words, 562*c29c3ba5SBruce Allan u16 *data) 563dee1ad47SJeff Kirsher { 564dee1ad47SJeff Kirsher return hw->nvm.ops.read(hw, offset, words, data); 565dee1ad47SJeff Kirsher } 566dee1ad47SJeff Kirsher 567*c29c3ba5SBruce Allan static inline s32 e1000_write_nvm(struct e1000_hw *hw, u16 offset, u16 words, 568*c29c3ba5SBruce Allan u16 *data) 569dee1ad47SJeff Kirsher { 570dee1ad47SJeff Kirsher return hw->nvm.ops.write(hw, offset, words, data); 571dee1ad47SJeff Kirsher } 572dee1ad47SJeff Kirsher 573dee1ad47SJeff Kirsher static inline s32 e1000_get_phy_info(struct e1000_hw *hw) 574dee1ad47SJeff Kirsher { 575dee1ad47SJeff Kirsher return hw->phy.ops.get_info(hw); 576dee1ad47SJeff Kirsher } 577dee1ad47SJeff Kirsher 578dee1ad47SJeff Kirsher static inline u32 __er32(struct e1000_hw *hw, unsigned long reg) 579dee1ad47SJeff Kirsher { 580dee1ad47SJeff Kirsher return readl(hw->hw_addr + reg); 581dee1ad47SJeff Kirsher } 582dee1ad47SJeff Kirsher 583bdc125f7SBruce Allan #define er32(reg) __er32(hw, E1000_##reg) 584bdc125f7SBruce Allan 585bdc125f7SBruce Allan /** 586bdc125f7SBruce Allan * __ew32_prepare - prepare to write to MAC CSR register on certain parts 587bdc125f7SBruce Allan * @hw: pointer to the HW structure 588bdc125f7SBruce Allan * 589bdc125f7SBruce Allan * When updating the MAC CSR registers, the Manageability Engine (ME) could 590bdc125f7SBruce Allan * be accessing the registers at the same time. Normally, this is handled in 591bdc125f7SBruce Allan * h/w by an arbiter but on some parts there is a bug that acknowledges Host 592bdc125f7SBruce Allan * accesses later than it should which could result in the register to have 593bdc125f7SBruce Allan * an incorrect value. Workaround this by checking the FWSM register which 594bdc125f7SBruce Allan * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set 595bdc125f7SBruce Allan * and try again a number of times. 596bdc125f7SBruce Allan **/ 597bdc125f7SBruce Allan static inline s32 __ew32_prepare(struct e1000_hw *hw) 598bdc125f7SBruce Allan { 599bdc125f7SBruce Allan s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT; 600bdc125f7SBruce Allan 601bdc125f7SBruce Allan while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i) 602bdc125f7SBruce Allan udelay(50); 603bdc125f7SBruce Allan 604bdc125f7SBruce Allan return i; 605bdc125f7SBruce Allan } 606bdc125f7SBruce Allan 607dee1ad47SJeff Kirsher static inline void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val) 608dee1ad47SJeff Kirsher { 609bdc125f7SBruce Allan if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA) 610bdc125f7SBruce Allan __ew32_prepare(hw); 611bdc125f7SBruce Allan 612dee1ad47SJeff Kirsher writel(val, hw->hw_addr + reg); 613dee1ad47SJeff Kirsher } 614dee1ad47SJeff Kirsher 615bdc125f7SBruce Allan #define ew32(reg, val) __ew32(hw, E1000_##reg, (val)) 616bdc125f7SBruce Allan 617bdc125f7SBruce Allan #define e1e_flush() er32(STATUS) 618bdc125f7SBruce Allan 619bdc125f7SBruce Allan #define E1000_WRITE_REG_ARRAY(a, reg, offset, value) \ 620bdc125f7SBruce Allan (__ew32((a), (reg + ((offset) << 2)), (value))) 621bdc125f7SBruce Allan 622bdc125f7SBruce Allan #define E1000_READ_REG_ARRAY(a, reg, offset) \ 623bdc125f7SBruce Allan (readl((a)->hw_addr + reg + ((offset) << 2))) 624bdc125f7SBruce Allan 625dee1ad47SJeff Kirsher #endif /* _E1000_H_ */ 626