1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2012 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 /* Linux PRO/1000 Ethernet Driver main header file */
33 #include <linux/kobject.h>
39 #include <linux/pci.h>
40 #include <linux/netdevice.h>
41 #include <linux/vmalloc.h>
44 #include <linux/ethtool.h>
47 #undef HAVE_HW_TIME_STAMP
48 #ifdef HAVE_HW_TIME_STAMP
49 #include <linux/clocksource.h>
50 #include <linux/timecompare.h>
51 #include <linux/net_tstamp.h>
56 #if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE)
60 #include <linux/dca.h>
63 #ifndef HAVE_HW_TIME_STAMP
64 #undef IGB_PER_PKT_TIMESTAMP
71 #include <linux/sctp.h>
74 #include "e1000_api.h"
75 #include "e1000_82575.h"
76 #include "e1000_manage.h"
77 #include "e1000_mbx.h"
79 #define IGB_ERR(args...) printk(KERN_ERR "igb: " args)
82 #define DPRINTK(nlevel, klevel, fmt, args...) \
83 (void)((NETIF_MSG_##nlevel & adapter->msg_enable) && \
84 printk(KERN_##klevel PFX "%s: %s: " fmt, adapter->netdev->name, \
85 __FUNCTION__ , ## args))
87 /* Interrupt defines */
88 #define IGB_START_ITR 648 /* ~6000 ints/sec */
89 #define IGB_4K_ITR 980
90 #define IGB_20K_ITR 196
91 #define IGB_70K_ITR 56
93 /* Interrupt modes, as used by the IntMode paramter */
94 #define IGB_INT_MODE_LEGACY 0
95 #define IGB_INT_MODE_MSI 1
96 #define IGB_INT_MODE_MSIX 2
98 /* TX/RX descriptor defines */
99 #define IGB_DEFAULT_TXD 256
100 #define IGB_DEFAULT_TX_WORK 128
101 #define IGB_MIN_TXD 80
102 #define IGB_MAX_TXD 4096
104 #define IGB_DEFAULT_RXD 256
105 #define IGB_MIN_RXD 80
106 #define IGB_MAX_RXD 4096
108 #define IGB_MIN_ITR_USECS 10 /* 100k irq/sec */
109 #define IGB_MAX_ITR_USECS 8191 /* 120 irq/sec */
111 #define NON_Q_VECTORS 1
112 #define MAX_Q_VECTORS 10
114 /* Transmit and receive queues */
115 #define IGB_MAX_RX_QUEUES 16
116 #define IGB_MAX_TX_QUEUES 16
118 #define IGB_MAX_VF_MC_ENTRIES 30
119 #define IGB_MAX_VF_FUNCTIONS 8
120 #define IGB_82576_VF_DEV_ID 0x10CA
121 #define IGB_I350_VF_DEV_ID 0x1520
122 #define IGB_MAX_UTA_ENTRIES 128
123 #define MAX_EMULATION_MAC_ADDRS 16
125 #define IGB_MAX_VMDQ_QUEUES 8
128 struct vf_data_storage {
129 unsigned char vf_mac_addresses[ETH_ALEN];
130 u16 vf_mc_hashes[IGB_MAX_VF_MC_ENTRIES];
131 u16 num_vf_mc_hashes;
132 u16 default_vf_vlan_id;
134 unsigned char em_mac_addresses[MAX_EMULATION_MAC_ADDRS * ETH_ALEN];
135 u32 uta_table_copy[IGB_MAX_UTA_ENTRIES];
137 unsigned long last_nack;
139 u16 pf_vlan; /* When set, guest VLAN config not allowed. */
143 struct pci_dev *vfdev;
146 #define IGB_VF_FLAG_CTS 0x00000001 /* VF is clear to send data */
147 #define IGB_VF_FLAG_UNI_PROMISC 0x00000002 /* VF has unicast promisc */
148 #define IGB_VF_FLAG_MULTI_PROMISC 0x00000004 /* VF has multicast promisc */
149 #define IGB_VF_FLAG_PF_SET_MAC 0x00000008 /* PF has set MAC address */
151 /* RX descriptor control thresholds.
152 * PTHRESH - MAC will consider prefetch if it has fewer than this number of
153 * descriptors available in its onboard memory.
154 * Setting this to 0 disables RX descriptor prefetch.
155 * HTHRESH - MAC will only prefetch if there are at least this many descriptors
156 * available in host memory.
157 * If PTHRESH is 0, this should also be 0.
158 * WTHRESH - RX descriptor writeback threshold - MAC will delay writing back
159 * descriptors until either it has this many to write back, or the
162 #define IGB_RX_PTHRESH 8
163 #define IGB_RX_HTHRESH 8
164 #define IGB_TX_PTHRESH 8
165 #define IGB_TX_HTHRESH 1
166 #define IGB_RX_WTHRESH ((hw->mac.type == e1000_82576 && \
167 adapter->msix_entries) ? 1 : 4)
168 #define IGB_TX_WTHRESH ((hw->mac.type == e1000_82576 && \
169 adapter->msix_entries) ? 1 : 16)
171 /* this is the size past which hardware will drop packets when setting LPE=0 */
172 #define MAXIMUM_ETHERNET_VLAN_SIZE 1522
174 /* NOTE: netdev_alloc_skb reserves 16 bytes, NET_IP_ALIGN means we
175 * reserve 2 more, and skb_shared_info adds an additional 384 more,
176 * this adds roughly 448 bytes of extra data meaning the smallest
177 * allocation we could have is 1K.
178 * i.e. RXBUFFER_512 --> size-1024 slab
180 /* Supported Rx Buffer Sizes */
181 #define IGB_RXBUFFER_512 512
182 #define IGB_RXBUFFER_16384 16384
183 #define IGB_RX_HDR_LEN IGB_RXBUFFER_512
186 /* Packet Buffer allocations */
187 #define IGB_PBA_BYTES_SHIFT 0xA
188 #define IGB_TX_HEAD_ADDR_SHIFT 7
189 #define IGB_PBA_TX_MASK 0xFFFF0000
191 #define IGB_FC_PAUSE_TIME 0x0680 /* 858 usec */
193 /* How many Tx Descriptors do we need to call netif_wake_queue ? */
194 #define IGB_TX_QUEUE_WAKE 32
195 /* How many Rx Buffers do we bundle into one write to the hardware ? */
196 #define IGB_RX_BUFFER_WRITE 16 /* Must be power of 2 */
198 #define IGB_EEPROM_APME 0x0400
200 #define AUTO_ALL_MODES 0
203 #ifndef IGB_MASTER_SLAVE
204 /* Switch to override PHY master/slave setting */
205 #define IGB_MASTER_SLAVE e1000_ms_hw_default
208 #define IGB_MNG_VLAN_NONE -1
211 #define IGB_LRO_MAX 32 /*Maximum number of LRO descriptors*/
212 struct igb_lro_stats {
219 * igb_lro_header - header format to be aggregated by LRO
220 * @iph: IP header without options
222 * @ts: Optional TCP timestamp data in TCP options
224 * This structure relies on the check above that verifies that the header
225 * is IPv4 and does not contain any options.
233 struct igb_lro_list {
234 struct sk_buff_head active;
235 struct igb_lro_stats stats;
238 #endif /* IGB_NO_LRO */
241 union { /* Union defining head/tail partner */
242 struct sk_buff *head;
243 struct sk_buff *tail;
245 __be32 tsecr; /* timestamp echo response */
246 u32 tsval; /* timestamp value in host order */
247 u32 next_seq; /* next expected sequence number */
248 u16 free; /* 65521 minus total size */
249 u16 mss; /* size of data portion of packet */
250 u16 append_cnt; /* number of skb's appended */
251 #endif /* IGB_NO_LRO */
252 #ifdef HAVE_VLAN_RX_REGISTER
253 u16 vid; /* VLAN tag */
256 #define IGB_CB(skb) ((struct igb_cb *)(skb)->cb)
258 #define IGB_TX_FLAGS_CSUM 0x00000001
259 #define IGB_TX_FLAGS_VLAN 0x00000002
260 #define IGB_TX_FLAGS_TSO 0x00000004
261 #define IGB_TX_FLAGS_IPV4 0x00000008
262 #define IGB_TX_FLAGS_TSTAMP 0x00000010
263 #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
264 #define IGB_TX_FLAGS_VLAN_SHIFT 16
266 /* wrapper around a pointer to a socket buffer,
267 * so a DMA handle can be stored along with the buffer */
268 struct igb_tx_buffer {
269 union e1000_adv_tx_desc *next_to_watch;
270 unsigned long time_stamp;
272 unsigned int bytecount;
275 DEFINE_DMA_UNMAP_ADDR(dma);
276 DEFINE_DMA_UNMAP_LEN(len);
280 struct igb_rx_buffer {
283 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
290 struct igb_tx_queue_stats {
296 struct igb_rx_queue_stats {
304 struct igb_ring_container {
305 struct igb_ring *ring; /* pointer to linked list of rings */
306 unsigned int total_bytes; /* total bytes processed this int */
307 unsigned int total_packets; /* total packets processed this int */
308 u16 work_limit; /* total work allowed per interrupt */
309 u8 count; /* total number of rings in vector */
310 u8 itr; /* current ITR setting for ring */
313 struct igb_q_vector {
314 struct igb_adapter *adapter; /* backlink */
315 int cpu; /* CPU for DCA */
316 u32 eims_value; /* EIMS mask value */
318 struct igb_ring_container rx, tx;
320 struct napi_struct napi;
325 void __iomem *itr_register;
328 struct igb_lro_list *lrolist; /* LRO list for queue vector*/
330 char name[IFNAMSIZ + 9];
331 #ifndef HAVE_NETDEV_NAPI_LIST
332 struct net_device poll_dev;
334 } ____cacheline_internodealigned_in_smp;
337 struct igb_q_vector *q_vector; /* backlink to q_vector */
338 struct net_device *netdev; /* back pointer to net_device */
339 struct device *dev; /* device for dma mapping */
340 union { /* array of buffer info structs */
341 struct igb_tx_buffer *tx_buffer_info;
342 struct igb_rx_buffer *rx_buffer_info;
344 void *desc; /* descriptor ring memory */
345 unsigned long flags; /* ring specific flags */
346 void __iomem *tail; /* pointer to ring tail register */
348 u16 count; /* number of desc. in the ring */
349 u8 queue_index; /* logical index of the ring*/
350 u8 reg_idx; /* physical index of the ring */
351 u32 size; /* length of desc. ring in bytes */
353 /* everything past this point are written often */
354 u16 next_to_clean ____cacheline_aligned_in_smp;
360 struct igb_tx_queue_stats tx_stats;
364 struct igb_rx_queue_stats rx_stats;
365 #ifdef CONFIG_IGB_DISABLE_PACKET_SPLIT
370 #ifdef CONFIG_IGB_VMDQ_NETDEV
371 struct net_device *vmdq_netdev;
372 int vqueue_index; /* queue index for virtual netdev */
374 /* Items past this point are only used during ring alloc / free */
375 dma_addr_t dma; /* phys address of the ring */
376 int numa_node; /* node to alloc ring memory on */
378 } ____cacheline_internodealigned_in_smp;
380 enum e1000_ring_flags_t {
381 #ifndef HAVE_NDO_SET_FEATURES
382 IGB_RING_FLAG_RX_CSUM,
384 IGB_RING_FLAG_RX_SCTP_CSUM,
385 IGB_RING_FLAG_RX_LB_VLAN_BSWAP,
386 IGB_RING_FLAG_TX_CTX_IDX,
387 IGB_RING_FLAG_TX_DETECT_HANG,
389 struct igb_mac_addr {
392 u16 state; /* bitmask */
394 #define IGB_MAC_STATE_DEFAULT 0x1
395 #define IGB_MAC_STATE_MODIFIED 0x2
396 #define IGB_MAC_STATE_IN_USE 0x4
398 #define IGB_TXD_DCMD (E1000_ADVTXD_DCMD_EOP | E1000_ADVTXD_DCMD_RS)
400 #define IGB_RX_DESC(R, i) \
401 (&(((union e1000_adv_rx_desc *)((R)->desc))[i]))
402 #define IGB_TX_DESC(R, i) \
403 (&(((union e1000_adv_tx_desc *)((R)->desc))[i]))
404 #define IGB_TX_CTXTDESC(R, i) \
405 (&(((struct e1000_adv_tx_context_desc *)((R)->desc))[i]))
407 #ifdef CONFIG_IGB_VMDQ_NETDEV
408 #define netdev_ring(ring) \
409 ((ring->vmdq_netdev ? ring->vmdq_netdev : ring->netdev))
410 #define ring_queue_index(ring) \
411 ((ring->vmdq_netdev ? ring->vqueue_index : ring->queue_index))
413 #define netdev_ring(ring) (ring->netdev)
414 #define ring_queue_index(ring) (ring->queue_index)
415 #endif /* CONFIG_IGB_VMDQ_NETDEV */
417 /* igb_test_staterr - tests bits within Rx descriptor status and error fields */
418 static inline __le32 igb_test_staterr(union e1000_adv_rx_desc *rx_desc,
419 const u32 stat_err_bits)
421 return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits);
424 /* igb_desc_unused - calculate if we have unused descriptors */
425 static inline u16 igb_desc_unused(const struct igb_ring *ring)
427 u16 ntc = ring->next_to_clean;
428 u16 ntu = ring->next_to_use;
430 return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
434 static inline struct netdev_queue *txring_txq(const struct igb_ring *tx_ring)
436 return netdev_get_tx_queue(tx_ring->netdev, tx_ring->queue_index);
438 #endif /* CONFIG_BQL */
440 // #ifdef EXT_THERMAL_SENSOR_SUPPORT
442 struct igb_therm_proc_data
445 struct e1000_thermal_diode_data *sensor_data;
448 // #endif /* IGB_PROCFS */
449 // #endif /* EXT_THERMAL_SENSOR_SUPPORT */
451 /* board specific private data structure */
453 #ifdef HAVE_VLAN_RX_REGISTER
454 /* vlgrp must be first member of structure */
455 struct vlan_group *vlgrp;
457 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
459 struct net_device *netdev;
464 unsigned int num_q_vectors;
465 struct msix_entry *msix_entries;
470 u32 tx_timeout_count;
472 struct igb_ring *tx_ring[IGB_MAX_TX_QUEUES];
476 struct igb_ring *rx_ring[IGB_MAX_RX_QUEUES];
478 struct timer_list watchdog_timer;
479 struct timer_list dma_err_timer;
480 struct timer_list phy_info_timer;
489 /* Interrupt Throttle Rate */
493 struct work_struct reset_task;
494 struct work_struct watchdog_task;
495 struct work_struct dma_err_task;
497 u8 tx_timeout_factor;
501 /* OS defined structs */
502 struct pci_dev *pdev;
503 #ifndef HAVE_NETDEV_STATS_IN_NETDEV
504 struct net_device_stats net_stats;
507 struct igb_lro_stats lro_stats;
509 #ifdef HAVE_HW_TIME_STAMP
510 struct cyclecounter cycles;
511 struct timecounter clock;
512 struct timecompare compare;
513 struct hwtstamp_config hwtstamp_config;
516 /* structs defined in e1000_hw.h */
518 struct e1000_hw_stats stats;
519 struct e1000_phy_info phy_info;
520 struct e1000_phy_stats phy_stats;
524 struct igb_ring test_tx_ring;
525 struct igb_ring test_rx_ring;
530 struct igb_q_vector *q_vector[MAX_Q_VECTORS];
531 u32 eims_enable_mask;
534 /* to not mess up cache alignment, always add to the bottom */
540 struct vf_data_storage *vf_data;
542 int vf_rate_link_speed;
546 unsigned int vfs_allocated_count;
547 /* Malicious Driver Detection flag. Valid only when SR-IOV is enabled */
555 struct igb_mac_addr *mac_table;
556 #ifdef CONFIG_IGB_VMDQ_NETDEV
557 struct net_device *vmdq_netdev[IGB_MAX_VMDQ_QUEUES];
563 /* External Thermal Sensor support flag */
566 struct kobject *info_kobj;
567 struct kobject *therm_kobj[E1000_MAX_SENSORS];
568 #else /* IGB_SYSFS */
570 struct proc_dir_entry *eth_dir;
571 struct proc_dir_entry *info_dir;
572 struct proc_dir_entry *therm_dir[E1000_MAX_SENSORS];
573 struct igb_therm_proc_data therm_data[E1000_MAX_SENSORS];
574 #endif /* IGB_PROCFS */
575 #endif /* IGB_SYSFS */
578 #ifdef CONFIG_IGB_VMDQ_NETDEV
579 struct igb_vmdq_adapter {
580 #ifdef HAVE_VLAN_RX_REGISTER
581 /* vlgrp must be first member of structure */
582 struct vlan_group *vlgrp;
584 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
586 struct igb_adapter *real_adapter;
587 struct net_device *vnetdev;
588 struct net_device_stats net_stats;
589 struct igb_ring *tx_ring;
590 struct igb_ring *rx_ring;
595 #define IGB_FLAG_HAS_MSI (1 << 0)
596 #define IGB_FLAG_MSI_ENABLE (1 << 1)
597 #define IGB_FLAG_DCA_ENABLED (1 << 2)
598 #define IGB_FLAG_LLI_PUSH (1 << 3)
599 #define IGB_FLAG_QUAD_PORT_A (1 << 4)
600 #define IGB_FLAG_QUEUE_PAIRS (1 << 5)
601 #define IGB_FLAG_EEE (1 << 6)
602 #define IGB_FLAG_DMAC (1 << 7)
603 #define IGB_FLAG_DETECT_BAD_DMA (1 << 8)
605 #define IGB_MIN_TXPBSIZE 20408
606 #define IGB_TX_BUF_4096 4096
608 #define IGB_DMCTLX_DCFLUSH_DIS 0x80000000 /* Disable DMA Coal Flush */
610 /* DMA Coalescing defines */
611 #define IGB_DMAC_DISABLE 0
612 #define IGB_DMAC_MIN 250
613 #define IGB_DMAC_500 500
614 #define IGB_DMAC_EN_DEFAULT 1000
615 #define IGB_DMAC_2000 2000
616 #define IGB_DMAC_3000 3000
617 #define IGB_DMAC_4000 4000
618 #define IGB_DMAC_5000 5000
619 #define IGB_DMAC_6000 6000
620 #define IGB_DMAC_7000 7000
621 #define IGB_DMAC_8000 8000
622 #define IGB_DMAC_9000 9000
623 #define IGB_DMAC_MAX 10000
626 #define IGB_82576_TSYNC_SHIFT 19
627 #define IGB_82580_TSYNC_SHIFT 24
628 #define IGB_TS_HDR_LEN 16
631 #define FW_HDR_LEN 0x4
632 #define FW_CMD_DRV_INFO 0xDD
633 #define FW_CMD_DRV_INFO_LEN 0x5
634 #define FW_CMD_RESERVED 0X0
635 #define FW_RESP_SUCCESS 0x1
636 #define FW_UNUSED_VER 0x0
637 #define FW_MAX_RETRIES 3
638 #define FW_STATUS_SUCCESS 0x1
639 #define FW_FAMILY_DRV_VER 0Xffffffff
641 #define IGB_MAX_LINK_TRIES 20
643 struct e1000_fw_hdr {
653 struct e1000_fw_drv_info {
654 struct e1000_fw_hdr hdr;
657 u16 pad; /* end spacing to ensure length is mult. of dword */
658 u8 pad2; /* end spacing to ensure length is mult. of dword2 */
666 extern char igb_driver_name[];
667 extern char igb_driver_version[];
669 extern int igb_up(struct igb_adapter *);
670 extern void igb_down(struct igb_adapter *);
671 extern void igb_reinit_locked(struct igb_adapter *);
672 extern void igb_reset(struct igb_adapter *);
673 extern int igb_set_spd_dplx(struct igb_adapter *, u16);
674 extern int igb_setup_tx_resources(struct igb_ring *);
675 extern int igb_setup_rx_resources(struct igb_ring *);
676 extern void igb_free_tx_resources(struct igb_ring *);
677 extern void igb_free_rx_resources(struct igb_ring *);
678 extern void igb_configure_tx_ring(struct igb_adapter *, struct igb_ring *);
679 extern void igb_configure_rx_ring(struct igb_adapter *, struct igb_ring *);
680 extern void igb_setup_tctl(struct igb_adapter *);
681 extern void igb_setup_rctl(struct igb_adapter *);
682 extern netdev_tx_t igb_xmit_frame_ring(struct sk_buff *, struct igb_ring *);
683 extern void igb_unmap_and_free_tx_resource(struct igb_ring *,
684 struct igb_tx_buffer *);
685 extern void igb_alloc_rx_buffers(struct igb_ring *, u16);
686 extern void igb_clean_rx_ring(struct igb_ring *);
687 extern void igb_update_stats(struct igb_adapter *);
688 extern bool igb_has_link(struct igb_adapter *adapter);
689 extern void igb_set_ethtool_ops(struct net_device *);
690 extern void igb_check_options(struct igb_adapter *);
691 extern void igb_power_up_link(struct igb_adapter *);
692 #ifdef ETHTOOL_OPS_COMPAT
693 extern int ethtool_ioctl(struct ifreq *);
695 extern int igb_write_mc_addr_list(struct net_device *netdev);
696 extern int igb_add_mac_filter(struct igb_adapter *adapter, u8 *addr, u16 queue);
697 extern int igb_del_mac_filter(struct igb_adapter *adapter, u8* addr, u16 queue);
698 extern int igb_available_rars(struct igb_adapter *adapter);
699 extern s32 igb_vlvf_set(struct igb_adapter *, u32, bool, u32);
700 extern void igb_configure_vt_default_pool(struct igb_adapter *adapter);
701 extern void igb_enable_vlan_tags(struct igb_adapter *adapter);
702 #ifndef HAVE_VLAN_RX_REGISTER
703 extern void igb_vlan_mode(struct net_device *, u32);
708 void igb_sysfs_exit(struct igb_adapter *adapter);
709 int igb_sysfs_init(struct igb_adapter *adapter);
712 int igb_procfs_init(struct igb_adapter* adapter);
713 void igb_procfs_exit(struct igb_adapter* adapter);
714 int igb_procfs_topdir_init(void);
715 void igb_procfs_topdir_exit(void);
716 #endif /* IGB_PROCFS */
717 #endif /* IGB_SYSFS */