1d89f8841SSasha Neftin /* SPDX-License-Identifier: GPL-2.0 */ 2d89f8841SSasha Neftin /* Copyright (c) 2018 Intel Corporation */ 3d89f8841SSasha Neftin 4d89f8841SSasha Neftin #ifndef _IGC_H_ 5d89f8841SSasha Neftin #define _IGC_H_ 6d89f8841SSasha Neftin 7d89f8841SSasha Neftin #include <linux/kobject.h> 8d89f8841SSasha Neftin #include <linux/pci.h> 9d89f8841SSasha Neftin #include <linux/netdevice.h> 10d89f8841SSasha Neftin #include <linux/vmalloc.h> 11d89f8841SSasha Neftin #include <linux/ethtool.h> 12d89f8841SSasha Neftin #include <linux/sctp.h> 13d89f8841SSasha Neftin 14146740f9SSasha Neftin #include "igc_hw.h" 15146740f9SSasha Neftin 168c5ad0daSSasha Neftin /* forward declaration */ 178c5ad0daSSasha Neftin void igc_set_ethtool_ops(struct net_device *); 188c5ad0daSSasha Neftin 198c5ad0daSSasha Neftin struct igc_adapter; 208c5ad0daSSasha Neftin struct igc_ring; 218c5ad0daSSasha Neftin 228c5ad0daSSasha Neftin void igc_up(struct igc_adapter *adapter); 238c5ad0daSSasha Neftin void igc_down(struct igc_adapter *adapter); 248c5ad0daSSasha Neftin int igc_setup_tx_resources(struct igc_ring *ring); 258c5ad0daSSasha Neftin int igc_setup_rx_resources(struct igc_ring *ring); 268c5ad0daSSasha Neftin void igc_free_tx_resources(struct igc_ring *ring); 278c5ad0daSSasha Neftin void igc_free_rx_resources(struct igc_ring *ring); 288c5ad0daSSasha Neftin unsigned int igc_get_max_rss_queues(struct igc_adapter *adapter); 298c5ad0daSSasha Neftin void igc_set_flag_queue_pairs(struct igc_adapter *adapter, 308c5ad0daSSasha Neftin const u32 max_rss_queues); 318c5ad0daSSasha Neftin int igc_reinit_queues(struct igc_adapter *adapter); 328c5ad0daSSasha Neftin bool igc_has_link(struct igc_adapter *adapter); 338c5ad0daSSasha Neftin void igc_reset(struct igc_adapter *adapter); 348c5ad0daSSasha Neftin int igc_set_spd_dplx(struct igc_adapter *adapter, u32 spd, u8 dplx); 358c5ad0daSSasha Neftin 36d89f8841SSasha Neftin extern char igc_driver_name[]; 37d89f8841SSasha Neftin extern char igc_driver_version[]; 38d89f8841SSasha Neftin 398c5ad0daSSasha Neftin #define IGC_REGS_LEN 740 408c5ad0daSSasha Neftin #define IGC_RETA_SIZE 128 418c5ad0daSSasha Neftin 423df25e4cSSasha Neftin /* Interrupt defines */ 433df25e4cSSasha Neftin #define IGC_START_ITR 648 /* ~6000 ints/sec */ 443df25e4cSSasha Neftin #define IGC_FLAG_HAS_MSI BIT(0) 458c5ad0daSSasha Neftin #define IGC_FLAG_QUEUE_PAIRS BIT(3) 468c5ad0daSSasha Neftin #define IGC_FLAG_DMAC BIT(4) 470507ef8aSSasha Neftin #define IGC_FLAG_NEED_LINK_UPDATE BIT(9) 48208983f0SSasha Neftin #define IGC_FLAG_MEDIA_RESET BIT(10) 49208983f0SSasha Neftin #define IGC_FLAG_MAS_ENABLE BIT(12) 503df25e4cSSasha Neftin #define IGC_FLAG_HAS_MSIX BIT(13) 510507ef8aSSasha Neftin #define IGC_FLAG_VLAN_PROMISC BIT(15) 528c5ad0daSSasha Neftin #define IGC_FLAG_RX_LEGACY BIT(16) 533df25e4cSSasha Neftin 543df25e4cSSasha Neftin #define IGC_START_ITR 648 /* ~6000 ints/sec */ 553df25e4cSSasha Neftin #define IGC_4K_ITR 980 563df25e4cSSasha Neftin #define IGC_20K_ITR 196 573df25e4cSSasha Neftin #define IGC_70K_ITR 56 583df25e4cSSasha Neftin 590507ef8aSSasha Neftin #define IGC_DEFAULT_ITR 3 /* dynamic */ 600507ef8aSSasha Neftin #define IGC_MAX_ITR_USECS 10000 610507ef8aSSasha Neftin #define IGC_MIN_ITR_USECS 10 620507ef8aSSasha Neftin #define NON_Q_VECTORS 1 630507ef8aSSasha Neftin #define MAX_MSIX_ENTRIES 10 640507ef8aSSasha Neftin 650507ef8aSSasha Neftin /* TX/RX descriptor defines */ 660507ef8aSSasha Neftin #define IGC_DEFAULT_TXD 256 670507ef8aSSasha Neftin #define IGC_DEFAULT_TX_WORK 128 680507ef8aSSasha Neftin #define IGC_MIN_TXD 80 690507ef8aSSasha Neftin #define IGC_MAX_TXD 4096 700507ef8aSSasha Neftin 710507ef8aSSasha Neftin #define IGC_DEFAULT_RXD 256 720507ef8aSSasha Neftin #define IGC_MIN_RXD 80 730507ef8aSSasha Neftin #define IGC_MAX_RXD 4096 740507ef8aSSasha Neftin 75c9a11c23SSasha Neftin /* Transmit and receive queues */ 76c9a11c23SSasha Neftin #define IGC_MAX_RX_QUEUES 4 77c9a11c23SSasha Neftin #define IGC_MAX_TX_QUEUES 4 78c9a11c23SSasha Neftin 79c9a11c23SSasha Neftin #define MAX_Q_VECTORS 8 80c9a11c23SSasha Neftin #define MAX_STD_JUMBO_FRAME_SIZE 9216 81c9a11c23SSasha Neftin 8213b5b7fdSSasha Neftin /* Supported Rx Buffer Sizes */ 8313b5b7fdSSasha Neftin #define IGC_RXBUFFER_256 256 8413b5b7fdSSasha Neftin #define IGC_RXBUFFER_2048 2048 8513b5b7fdSSasha Neftin #define IGC_RXBUFFER_3072 3072 8613b5b7fdSSasha Neftin 878c5ad0daSSasha Neftin #define AUTO_ALL_MODES 0 8813b5b7fdSSasha Neftin #define IGC_RX_HDR_LEN IGC_RXBUFFER_256 8913b5b7fdSSasha Neftin 9013b5b7fdSSasha Neftin /* RX and TX descriptor control thresholds. 9113b5b7fdSSasha Neftin * PTHRESH - MAC will consider prefetch if it has fewer than this number of 9213b5b7fdSSasha Neftin * descriptors available in its onboard memory. 9313b5b7fdSSasha Neftin * Setting this to 0 disables RX descriptor prefetch. 9413b5b7fdSSasha Neftin * HTHRESH - MAC will only prefetch if there are at least this many descriptors 9513b5b7fdSSasha Neftin * available in host memory. 9613b5b7fdSSasha Neftin * If PTHRESH is 0, this should also be 0. 9713b5b7fdSSasha Neftin * WTHRESH - RX descriptor writeback threshold - MAC will delay writing back 9813b5b7fdSSasha Neftin * descriptors until either it has this many to write back, or the 9913b5b7fdSSasha Neftin * ITR timer expires. 10013b5b7fdSSasha Neftin */ 10113b5b7fdSSasha Neftin #define IGC_RX_PTHRESH 8 10213b5b7fdSSasha Neftin #define IGC_RX_HTHRESH 8 10313b5b7fdSSasha Neftin #define IGC_TX_PTHRESH 8 10413b5b7fdSSasha Neftin #define IGC_TX_HTHRESH 1 10513b5b7fdSSasha Neftin #define IGC_RX_WTHRESH 4 10613b5b7fdSSasha Neftin #define IGC_TX_WTHRESH 16 10713b5b7fdSSasha Neftin 10813b5b7fdSSasha Neftin #define IGC_RX_DMA_ATTR \ 10913b5b7fdSSasha Neftin (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING) 11013b5b7fdSSasha Neftin 11113b5b7fdSSasha Neftin #define IGC_TS_HDR_LEN 16 11213b5b7fdSSasha Neftin 11313b5b7fdSSasha Neftin #define IGC_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN) 11413b5b7fdSSasha Neftin 11513b5b7fdSSasha Neftin #if (PAGE_SIZE < 8192) 11613b5b7fdSSasha Neftin #define IGC_MAX_FRAME_BUILD_SKB \ 11713b5b7fdSSasha Neftin (SKB_WITH_OVERHEAD(IGC_RXBUFFER_2048) - IGC_SKB_PAD - IGC_TS_HDR_LEN) 11813b5b7fdSSasha Neftin #else 11913b5b7fdSSasha Neftin #define IGC_MAX_FRAME_BUILD_SKB (IGC_RXBUFFER_2048 - IGC_TS_HDR_LEN) 12013b5b7fdSSasha Neftin #endif 12113b5b7fdSSasha Neftin 1220507ef8aSSasha Neftin /* How many Rx Buffers do we bundle into one write to the hardware ? */ 1230507ef8aSSasha Neftin #define IGC_RX_BUFFER_WRITE 16 /* Must be power of 2 */ 1240507ef8aSSasha Neftin 1250507ef8aSSasha Neftin /* igc_test_staterr - tests bits within Rx descriptor status and error fields */ 1260507ef8aSSasha Neftin static inline __le32 igc_test_staterr(union igc_adv_rx_desc *rx_desc, 1270507ef8aSSasha Neftin const u32 stat_err_bits) 1280507ef8aSSasha Neftin { 1290507ef8aSSasha Neftin return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits); 1300507ef8aSSasha Neftin } 1310507ef8aSSasha Neftin 132c9a11c23SSasha Neftin enum igc_state_t { 133c9a11c23SSasha Neftin __IGC_TESTING, 134c9a11c23SSasha Neftin __IGC_RESETTING, 135c9a11c23SSasha Neftin __IGC_DOWN, 136c9a11c23SSasha Neftin __IGC_PTP_TX_IN_PROGRESS, 137c9a11c23SSasha Neftin }; 138c9a11c23SSasha Neftin 1390507ef8aSSasha Neftin enum igc_tx_flags { 1400507ef8aSSasha Neftin /* cmd_type flags */ 1410507ef8aSSasha Neftin IGC_TX_FLAGS_VLAN = 0x01, 1420507ef8aSSasha Neftin IGC_TX_FLAGS_TSO = 0x02, 1430507ef8aSSasha Neftin IGC_TX_FLAGS_TSTAMP = 0x04, 1440507ef8aSSasha Neftin 1450507ef8aSSasha Neftin /* olinfo flags */ 1460507ef8aSSasha Neftin IGC_TX_FLAGS_IPV4 = 0x10, 1470507ef8aSSasha Neftin IGC_TX_FLAGS_CSUM = 0x20, 1480507ef8aSSasha Neftin }; 1490507ef8aSSasha Neftin 150ab405612SSasha Neftin enum igc_boards { 151ab405612SSasha Neftin board_base, 152ab405612SSasha Neftin }; 153ab405612SSasha Neftin 1540507ef8aSSasha Neftin /* The largest size we can write to the descriptor is 65535. In order to 1550507ef8aSSasha Neftin * maintain a power of two alignment we have to limit ourselves to 32K. 1560507ef8aSSasha Neftin */ 1570507ef8aSSasha Neftin #define IGC_MAX_TXD_PWR 15 1580507ef8aSSasha Neftin #define IGC_MAX_DATA_PER_TXD BIT(IGC_MAX_TXD_PWR) 1590507ef8aSSasha Neftin 1600507ef8aSSasha Neftin /* Tx Descriptors needed, worst case */ 1610507ef8aSSasha Neftin #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IGC_MAX_DATA_PER_TXD) 1620507ef8aSSasha Neftin #define DESC_NEEDED (MAX_SKB_FRAGS + 4) 1630507ef8aSSasha Neftin 16413b5b7fdSSasha Neftin /* wrapper around a pointer to a socket buffer, 16513b5b7fdSSasha Neftin * so a DMA handle can be stored along with the buffer 16613b5b7fdSSasha Neftin */ 16713b5b7fdSSasha Neftin struct igc_tx_buffer { 16813b5b7fdSSasha Neftin union igc_adv_tx_desc *next_to_watch; 16913b5b7fdSSasha Neftin unsigned long time_stamp; 17013b5b7fdSSasha Neftin struct sk_buff *skb; 17113b5b7fdSSasha Neftin unsigned int bytecount; 17213b5b7fdSSasha Neftin u16 gso_segs; 17313b5b7fdSSasha Neftin __be16 protocol; 17413b5b7fdSSasha Neftin 17513b5b7fdSSasha Neftin DEFINE_DMA_UNMAP_ADDR(dma); 17613b5b7fdSSasha Neftin DEFINE_DMA_UNMAP_LEN(len); 17713b5b7fdSSasha Neftin u32 tx_flags; 17813b5b7fdSSasha Neftin }; 17913b5b7fdSSasha Neftin 18013b5b7fdSSasha Neftin struct igc_rx_buffer { 18113b5b7fdSSasha Neftin dma_addr_t dma; 18213b5b7fdSSasha Neftin struct page *page; 18313b5b7fdSSasha Neftin #if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536) 18413b5b7fdSSasha Neftin __u32 page_offset; 18513b5b7fdSSasha Neftin #else 18613b5b7fdSSasha Neftin __u16 page_offset; 18713b5b7fdSSasha Neftin #endif 18813b5b7fdSSasha Neftin __u16 pagecnt_bias; 18913b5b7fdSSasha Neftin }; 19013b5b7fdSSasha Neftin 1913df25e4cSSasha Neftin struct igc_tx_queue_stats { 1923df25e4cSSasha Neftin u64 packets; 1933df25e4cSSasha Neftin u64 bytes; 1943df25e4cSSasha Neftin u64 restart_queue; 1950507ef8aSSasha Neftin u64 restart_queue2; 1963df25e4cSSasha Neftin }; 1973df25e4cSSasha Neftin 1983df25e4cSSasha Neftin struct igc_rx_queue_stats { 1993df25e4cSSasha Neftin u64 packets; 2003df25e4cSSasha Neftin u64 bytes; 2013df25e4cSSasha Neftin u64 drops; 2023df25e4cSSasha Neftin u64 csum_err; 2033df25e4cSSasha Neftin u64 alloc_failed; 2043df25e4cSSasha Neftin }; 2053df25e4cSSasha Neftin 2063df25e4cSSasha Neftin struct igc_rx_packet_stats { 2073df25e4cSSasha Neftin u64 ipv4_packets; /* IPv4 headers processed */ 2083df25e4cSSasha Neftin u64 ipv4e_packets; /* IPv4E headers with extensions processed */ 2093df25e4cSSasha Neftin u64 ipv6_packets; /* IPv6 headers processed */ 2103df25e4cSSasha Neftin u64 ipv6e_packets; /* IPv6E headers with extensions processed */ 2113df25e4cSSasha Neftin u64 tcp_packets; /* TCP headers processed */ 2123df25e4cSSasha Neftin u64 udp_packets; /* UDP headers processed */ 2133df25e4cSSasha Neftin u64 sctp_packets; /* SCTP headers processed */ 2143df25e4cSSasha Neftin u64 nfs_packets; /* NFS headers processe */ 2153df25e4cSSasha Neftin u64 other_packets; 2163df25e4cSSasha Neftin }; 2173df25e4cSSasha Neftin 2183df25e4cSSasha Neftin struct igc_ring_container { 2193df25e4cSSasha Neftin struct igc_ring *ring; /* pointer to linked list of rings */ 2203df25e4cSSasha Neftin unsigned int total_bytes; /* total bytes processed this int */ 2213df25e4cSSasha Neftin unsigned int total_packets; /* total packets processed this int */ 2223df25e4cSSasha Neftin u16 work_limit; /* total work allowed per interrupt */ 2233df25e4cSSasha Neftin u8 count; /* total number of rings in vector */ 2243df25e4cSSasha Neftin u8 itr; /* current ITR setting for ring */ 2253df25e4cSSasha Neftin }; 2263df25e4cSSasha Neftin 2273df25e4cSSasha Neftin struct igc_ring { 2283df25e4cSSasha Neftin struct igc_q_vector *q_vector; /* backlink to q_vector */ 2293df25e4cSSasha Neftin struct net_device *netdev; /* back pointer to net_device */ 2303df25e4cSSasha Neftin struct device *dev; /* device for dma mapping */ 2313df25e4cSSasha Neftin union { /* array of buffer info structs */ 2323df25e4cSSasha Neftin struct igc_tx_buffer *tx_buffer_info; 2333df25e4cSSasha Neftin struct igc_rx_buffer *rx_buffer_info; 2343df25e4cSSasha Neftin }; 2353df25e4cSSasha Neftin void *desc; /* descriptor ring memory */ 2363df25e4cSSasha Neftin unsigned long flags; /* ring specific flags */ 2373df25e4cSSasha Neftin void __iomem *tail; /* pointer to ring tail register */ 2383df25e4cSSasha Neftin dma_addr_t dma; /* phys address of the ring */ 2393df25e4cSSasha Neftin unsigned int size; /* length of desc. ring in bytes */ 2403df25e4cSSasha Neftin 2413df25e4cSSasha Neftin u16 count; /* number of desc. in the ring */ 2423df25e4cSSasha Neftin u8 queue_index; /* logical index of the ring*/ 2433df25e4cSSasha Neftin u8 reg_idx; /* physical index of the ring */ 2443df25e4cSSasha Neftin 2453df25e4cSSasha Neftin /* everything past this point are written often */ 2463df25e4cSSasha Neftin u16 next_to_clean; 2473df25e4cSSasha Neftin u16 next_to_use; 2483df25e4cSSasha Neftin u16 next_to_alloc; 2493df25e4cSSasha Neftin 2503df25e4cSSasha Neftin union { 2513df25e4cSSasha Neftin /* TX */ 2523df25e4cSSasha Neftin struct { 2533df25e4cSSasha Neftin struct igc_tx_queue_stats tx_stats; 2540507ef8aSSasha Neftin struct u64_stats_sync tx_syncp; 2550507ef8aSSasha Neftin struct u64_stats_sync tx_syncp2; 2563df25e4cSSasha Neftin }; 2573df25e4cSSasha Neftin /* RX */ 2583df25e4cSSasha Neftin struct { 2593df25e4cSSasha Neftin struct igc_rx_queue_stats rx_stats; 2603df25e4cSSasha Neftin struct igc_rx_packet_stats pkt_stats; 2610507ef8aSSasha Neftin struct u64_stats_sync rx_syncp; 2623df25e4cSSasha Neftin struct sk_buff *skb; 2633df25e4cSSasha Neftin }; 2643df25e4cSSasha Neftin }; 2653df25e4cSSasha Neftin } ____cacheline_internodealigned_in_smp; 2663df25e4cSSasha Neftin 267c9a11c23SSasha Neftin struct igc_q_vector { 268c9a11c23SSasha Neftin struct igc_adapter *adapter; /* backlink */ 2693df25e4cSSasha Neftin void __iomem *itr_register; 2703df25e4cSSasha Neftin u32 eims_value; /* EIMS mask value */ 2713df25e4cSSasha Neftin 2723df25e4cSSasha Neftin u16 itr_val; 2733df25e4cSSasha Neftin u8 set_itr; 2743df25e4cSSasha Neftin 2753df25e4cSSasha Neftin struct igc_ring_container rx, tx; 276c9a11c23SSasha Neftin 277c9a11c23SSasha Neftin struct napi_struct napi; 2783df25e4cSSasha Neftin 2793df25e4cSSasha Neftin struct rcu_head rcu; /* to avoid race with update stats on free */ 2803df25e4cSSasha Neftin char name[IFNAMSIZ + 9]; 2813df25e4cSSasha Neftin struct net_device poll_dev; 2823df25e4cSSasha Neftin 2833df25e4cSSasha Neftin /* for dynamic allocation of rings associated with this q_vector */ 2843df25e4cSSasha Neftin struct igc_ring ring[0] ____cacheline_internodealigned_in_smp; 285c9a11c23SSasha Neftin }; 286c9a11c23SSasha Neftin 287c9a11c23SSasha Neftin struct igc_mac_addr { 288c9a11c23SSasha Neftin u8 addr[ETH_ALEN]; 289c9a11c23SSasha Neftin u8 queue; 290c9a11c23SSasha Neftin u8 state; /* bitmask */ 291c9a11c23SSasha Neftin }; 292c9a11c23SSasha Neftin 293c9a11c23SSasha Neftin #define IGC_MAC_STATE_DEFAULT 0x1 294c9a11c23SSasha Neftin #define IGC_MAC_STATE_MODIFIED 0x2 295c9a11c23SSasha Neftin #define IGC_MAC_STATE_IN_USE 0x4 296c9a11c23SSasha Neftin 297146740f9SSasha Neftin /* Board specific private data structure */ 298146740f9SSasha Neftin struct igc_adapter { 299c9a11c23SSasha Neftin struct net_device *netdev; 300c9a11c23SSasha Neftin 301c9a11c23SSasha Neftin unsigned long state; 302c9a11c23SSasha Neftin unsigned int flags; 303c9a11c23SSasha Neftin unsigned int num_q_vectors; 3043df25e4cSSasha Neftin 3053df25e4cSSasha Neftin struct msix_entry *msix_entries; 3063df25e4cSSasha Neftin 3073df25e4cSSasha Neftin /* TX */ 3083df25e4cSSasha Neftin u16 tx_work_limit; 309208983f0SSasha Neftin u32 tx_timeout_count; 3103df25e4cSSasha Neftin int num_tx_queues; 3113df25e4cSSasha Neftin struct igc_ring *tx_ring[IGC_MAX_TX_QUEUES]; 3123df25e4cSSasha Neftin 3133df25e4cSSasha Neftin /* RX */ 3143df25e4cSSasha Neftin int num_rx_queues; 3153df25e4cSSasha Neftin struct igc_ring *rx_ring[IGC_MAX_RX_QUEUES]; 3163df25e4cSSasha Neftin 3173df25e4cSSasha Neftin struct timer_list watchdog_timer; 3183df25e4cSSasha Neftin struct timer_list dma_err_timer; 3193df25e4cSSasha Neftin struct timer_list phy_info_timer; 3203df25e4cSSasha Neftin 321c9a11c23SSasha Neftin u16 link_speed; 322c9a11c23SSasha Neftin u16 link_duplex; 323c9a11c23SSasha Neftin 324c9a11c23SSasha Neftin u8 port_num; 325c9a11c23SSasha Neftin 326146740f9SSasha Neftin u8 __iomem *io_addr; 3273df25e4cSSasha Neftin /* Interrupt Throttle Rate */ 3283df25e4cSSasha Neftin u32 rx_itr_setting; 3293df25e4cSSasha Neftin u32 tx_itr_setting; 3303df25e4cSSasha Neftin 3313df25e4cSSasha Neftin struct work_struct reset_task; 332c9a11c23SSasha Neftin struct work_struct watchdog_task; 3333df25e4cSSasha Neftin struct work_struct dma_err_task; 3344eb80801SSasha Neftin bool fc_autoneg; 335c9a11c23SSasha Neftin 3360507ef8aSSasha Neftin u8 tx_timeout_factor; 3370507ef8aSSasha Neftin 338c9a11c23SSasha Neftin int msg_enable; 339c9a11c23SSasha Neftin u32 max_frame_size; 3400507ef8aSSasha Neftin u32 min_frame_size; 341146740f9SSasha Neftin 342146740f9SSasha Neftin /* OS defined structs */ 343146740f9SSasha Neftin struct pci_dev *pdev; 3440507ef8aSSasha Neftin /* lock for statistics */ 3450507ef8aSSasha Neftin spinlock_t stats64_lock; 3460507ef8aSSasha Neftin struct rtnl_link_stats64 stats64; 347146740f9SSasha Neftin 348146740f9SSasha Neftin /* structs defined in igc_hw.h */ 349146740f9SSasha Neftin struct igc_hw hw; 3503df25e4cSSasha Neftin struct igc_hw_stats stats; 351c9a11c23SSasha Neftin 352c9a11c23SSasha Neftin struct igc_q_vector *q_vector[MAX_Q_VECTORS]; 3533df25e4cSSasha Neftin u32 eims_enable_mask; 3543df25e4cSSasha Neftin u32 eims_other; 3553df25e4cSSasha Neftin 3563df25e4cSSasha Neftin u16 tx_ring_count; 3573df25e4cSSasha Neftin u16 rx_ring_count; 3583df25e4cSSasha Neftin 3590507ef8aSSasha Neftin u32 *shadow_vfta; 3600507ef8aSSasha Neftin 3613df25e4cSSasha Neftin u32 rss_queues; 362c9a11c23SSasha Neftin 3630507ef8aSSasha Neftin /* lock for RX network flow classification filter */ 3640507ef8aSSasha Neftin spinlock_t nfc_lock; 3650507ef8aSSasha Neftin 366c9a11c23SSasha Neftin struct igc_mac_addr *mac_table; 367ab405612SSasha Neftin 3688c5ad0daSSasha Neftin u8 rss_indir_tbl[IGC_RETA_SIZE]; 3698c5ad0daSSasha Neftin 370208983f0SSasha Neftin unsigned long link_check_timeout; 371ab405612SSasha Neftin struct igc_info ei; 372146740f9SSasha Neftin }; 373146740f9SSasha Neftin 37413b5b7fdSSasha Neftin /* igc_desc_unused - calculate if we have unused descriptors */ 37513b5b7fdSSasha Neftin static inline u16 igc_desc_unused(const struct igc_ring *ring) 37613b5b7fdSSasha Neftin { 37713b5b7fdSSasha Neftin u16 ntc = ring->next_to_clean; 37813b5b7fdSSasha Neftin u16 ntu = ring->next_to_use; 37913b5b7fdSSasha Neftin 38013b5b7fdSSasha Neftin return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1; 38113b5b7fdSSasha Neftin } 38213b5b7fdSSasha Neftin 3835586838fSSasha Neftin static inline s32 igc_get_phy_info(struct igc_hw *hw) 3845586838fSSasha Neftin { 3855586838fSSasha Neftin if (hw->phy.ops.get_phy_info) 3865586838fSSasha Neftin return hw->phy.ops.get_phy_info(hw); 3875586838fSSasha Neftin 3885586838fSSasha Neftin return 0; 3895586838fSSasha Neftin } 3905586838fSSasha Neftin 3915586838fSSasha Neftin static inline s32 igc_reset_phy(struct igc_hw *hw) 3925586838fSSasha Neftin { 3935586838fSSasha Neftin if (hw->phy.ops.reset) 3945586838fSSasha Neftin return hw->phy.ops.reset(hw); 3955586838fSSasha Neftin 3965586838fSSasha Neftin return 0; 3975586838fSSasha Neftin } 3985586838fSSasha Neftin 39913b5b7fdSSasha Neftin static inline struct netdev_queue *txring_txq(const struct igc_ring *tx_ring) 40013b5b7fdSSasha Neftin { 40113b5b7fdSSasha Neftin return netdev_get_tx_queue(tx_ring->netdev, tx_ring->queue_index); 40213b5b7fdSSasha Neftin } 40313b5b7fdSSasha Neftin 40413b5b7fdSSasha Neftin enum igc_ring_flags_t { 40513b5b7fdSSasha Neftin IGC_RING_FLAG_RX_3K_BUFFER, 40613b5b7fdSSasha Neftin IGC_RING_FLAG_RX_BUILD_SKB_ENABLED, 40713b5b7fdSSasha Neftin IGC_RING_FLAG_RX_SCTP_CSUM, 40813b5b7fdSSasha Neftin IGC_RING_FLAG_RX_LB_VLAN_BSWAP, 40913b5b7fdSSasha Neftin IGC_RING_FLAG_TX_CTX_IDX, 41013b5b7fdSSasha Neftin IGC_RING_FLAG_TX_DETECT_HANG 41113b5b7fdSSasha Neftin }; 41213b5b7fdSSasha Neftin 41313b5b7fdSSasha Neftin #define ring_uses_large_buffer(ring) \ 41413b5b7fdSSasha Neftin test_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags) 41513b5b7fdSSasha Neftin 41613b5b7fdSSasha Neftin #define ring_uses_build_skb(ring) \ 41713b5b7fdSSasha Neftin test_bit(IGC_RING_FLAG_RX_BUILD_SKB_ENABLED, &(ring)->flags) 41813b5b7fdSSasha Neftin 41913b5b7fdSSasha Neftin static inline unsigned int igc_rx_bufsz(struct igc_ring *ring) 42013b5b7fdSSasha Neftin { 42113b5b7fdSSasha Neftin #if (PAGE_SIZE < 8192) 42213b5b7fdSSasha Neftin if (ring_uses_large_buffer(ring)) 42313b5b7fdSSasha Neftin return IGC_RXBUFFER_3072; 42413b5b7fdSSasha Neftin 42513b5b7fdSSasha Neftin if (ring_uses_build_skb(ring)) 42613b5b7fdSSasha Neftin return IGC_MAX_FRAME_BUILD_SKB + IGC_TS_HDR_LEN; 42713b5b7fdSSasha Neftin #endif 42813b5b7fdSSasha Neftin return IGC_RXBUFFER_2048; 42913b5b7fdSSasha Neftin } 43013b5b7fdSSasha Neftin 43113b5b7fdSSasha Neftin static inline unsigned int igc_rx_pg_order(struct igc_ring *ring) 43213b5b7fdSSasha Neftin { 43313b5b7fdSSasha Neftin #if (PAGE_SIZE < 8192) 43413b5b7fdSSasha Neftin if (ring_uses_large_buffer(ring)) 43513b5b7fdSSasha Neftin return 1; 43613b5b7fdSSasha Neftin #endif 43713b5b7fdSSasha Neftin return 0; 43813b5b7fdSSasha Neftin } 43913b5b7fdSSasha Neftin 440208983f0SSasha Neftin static inline s32 igc_read_phy_reg(struct igc_hw *hw, u32 offset, u16 *data) 441208983f0SSasha Neftin { 442208983f0SSasha Neftin if (hw->phy.ops.read_reg) 443208983f0SSasha Neftin return hw->phy.ops.read_reg(hw, offset, data); 444208983f0SSasha Neftin 445208983f0SSasha Neftin return 0; 446208983f0SSasha Neftin } 447208983f0SSasha Neftin 4488c5ad0daSSasha Neftin /* forward declaration */ 4498c5ad0daSSasha Neftin void igc_reinit_locked(struct igc_adapter *); 4508c5ad0daSSasha Neftin 45113b5b7fdSSasha Neftin #define igc_rx_pg_size(_ring) (PAGE_SIZE << igc_rx_pg_order(_ring)) 45213b5b7fdSSasha Neftin 4530507ef8aSSasha Neftin #define IGC_TXD_DCMD (IGC_ADVTXD_DCMD_EOP | IGC_ADVTXD_DCMD_RS) 4540507ef8aSSasha Neftin 45513b5b7fdSSasha Neftin #define IGC_RX_DESC(R, i) \ 45613b5b7fdSSasha Neftin (&(((union igc_adv_rx_desc *)((R)->desc))[i])) 45713b5b7fdSSasha Neftin #define IGC_TX_DESC(R, i) \ 45813b5b7fdSSasha Neftin (&(((union igc_adv_tx_desc *)((R)->desc))[i])) 45913b5b7fdSSasha Neftin #define IGC_TX_CTXTDESC(R, i) \ 46013b5b7fdSSasha Neftin (&(((struct igc_adv_tx_context_desc *)((R)->desc))[i])) 46113b5b7fdSSasha Neftin 462d89f8841SSasha Neftin #endif /* _IGC_H_ */ 463