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> 135f295805SVinicius Costa Gomes #include <linux/ptp_clock_kernel.h> 145f295805SVinicius Costa Gomes #include <linux/timecounter.h> 155f295805SVinicius Costa Gomes #include <linux/net_tstamp.h> 16d89f8841SSasha Neftin 17146740f9SSasha Neftin #include "igc_hw.h" 18146740f9SSasha Neftin 197df76bd1SAndre Guedes void igc_ethtool_set_ops(struct net_device *); 208c5ad0daSSasha Neftin 2189d35511SSasha Neftin /* Transmit and receive queues */ 2289d35511SSasha Neftin #define IGC_MAX_RX_QUEUES 4 2389d35511SSasha Neftin #define IGC_MAX_TX_QUEUES 4 2489d35511SSasha Neftin 2589d35511SSasha Neftin #define MAX_Q_VECTORS 8 2689d35511SSasha Neftin #define MAX_STD_JUMBO_FRAME_SIZE 9216 2789d35511SSasha Neftin 28b4d48d96SAndre Guedes #define MAX_ETYPE_FILTER 8 2989d35511SSasha Neftin #define IGC_RETA_SIZE 128 3089d35511SSasha Neftin 3187938851SEderson de Souza /* SDP support */ 3287938851SEderson de Souza #define IGC_N_EXTTS 2 3387938851SEderson de Souza #define IGC_N_PEROUT 2 3487938851SEderson de Souza #define IGC_N_SDP 4 3587938851SEderson de Souza 366574631bSKurt Kanzenbach #define MAX_FLEX_FILTER 32 376574631bSKurt Kanzenbach 38750433d0SAndre Guedes enum igc_mac_filter_type { 39750433d0SAndre Guedes IGC_MAC_FILTER_TYPE_DST = 0, 40750433d0SAndre Guedes IGC_MAC_FILTER_TYPE_SRC 41750433d0SAndre Guedes }; 42750433d0SAndre Guedes 4389d35511SSasha Neftin struct igc_tx_queue_stats { 4489d35511SSasha Neftin u64 packets; 4589d35511SSasha Neftin u64 bytes; 4689d35511SSasha Neftin u64 restart_queue; 4789d35511SSasha Neftin u64 restart_queue2; 4889d35511SSasha Neftin }; 4989d35511SSasha Neftin 5089d35511SSasha Neftin struct igc_rx_queue_stats { 5189d35511SSasha Neftin u64 packets; 5289d35511SSasha Neftin u64 bytes; 5389d35511SSasha Neftin u64 drops; 5489d35511SSasha Neftin u64 csum_err; 5589d35511SSasha Neftin u64 alloc_failed; 5689d35511SSasha Neftin }; 5789d35511SSasha Neftin 5889d35511SSasha Neftin struct igc_rx_packet_stats { 5989d35511SSasha Neftin u64 ipv4_packets; /* IPv4 headers processed */ 6089d35511SSasha Neftin u64 ipv4e_packets; /* IPv4E headers with extensions processed */ 6189d35511SSasha Neftin u64 ipv6_packets; /* IPv6 headers processed */ 6289d35511SSasha Neftin u64 ipv6e_packets; /* IPv6E headers with extensions processed */ 6389d35511SSasha Neftin u64 tcp_packets; /* TCP headers processed */ 6489d35511SSasha Neftin u64 udp_packets; /* UDP headers processed */ 6589d35511SSasha Neftin u64 sctp_packets; /* SCTP headers processed */ 6689d35511SSasha Neftin u64 nfs_packets; /* NFS headers processe */ 6789d35511SSasha Neftin u64 other_packets; 6889d35511SSasha Neftin }; 6989d35511SSasha Neftin 7089d35511SSasha Neftin struct igc_ring_container { 7189d35511SSasha Neftin struct igc_ring *ring; /* pointer to linked list of rings */ 7289d35511SSasha Neftin unsigned int total_bytes; /* total bytes processed this int */ 7389d35511SSasha Neftin unsigned int total_packets; /* total packets processed this int */ 7489d35511SSasha Neftin u16 work_limit; /* total work allowed per interrupt */ 7589d35511SSasha Neftin u8 count; /* total number of rings in vector */ 7689d35511SSasha Neftin u8 itr; /* current ITR setting for ring */ 7789d35511SSasha Neftin }; 7889d35511SSasha Neftin 7989d35511SSasha Neftin struct igc_ring { 8089d35511SSasha Neftin struct igc_q_vector *q_vector; /* backlink to q_vector */ 8189d35511SSasha Neftin struct net_device *netdev; /* back pointer to net_device */ 8289d35511SSasha Neftin struct device *dev; /* device for dma mapping */ 8389d35511SSasha Neftin union { /* array of buffer info structs */ 8489d35511SSasha Neftin struct igc_tx_buffer *tx_buffer_info; 8589d35511SSasha Neftin struct igc_rx_buffer *rx_buffer_info; 8689d35511SSasha Neftin }; 8789d35511SSasha Neftin void *desc; /* descriptor ring memory */ 8889d35511SSasha Neftin unsigned long flags; /* ring specific flags */ 8989d35511SSasha Neftin void __iomem *tail; /* pointer to ring tail register */ 9089d35511SSasha Neftin dma_addr_t dma; /* phys address of the ring */ 9189d35511SSasha Neftin unsigned int size; /* length of desc. ring in bytes */ 9289d35511SSasha Neftin 9389d35511SSasha Neftin u16 count; /* number of desc. in the ring */ 9489d35511SSasha Neftin u8 queue_index; /* logical index of the ring*/ 9589d35511SSasha Neftin u8 reg_idx; /* physical index of the ring */ 9689d35511SSasha Neftin bool launchtime_enable; /* true if LaunchTime is enabled */ 97*db0b124fSVinicius Costa Gomes ktime_t last_tx_cycle; /* end of the cycle with a launchtime transmission */ 98*db0b124fSVinicius Costa Gomes ktime_t last_ff_cycle; /* Last cycle with an active first flag */ 9989d35511SSasha Neftin 10089d35511SSasha Neftin u32 start_time; 10189d35511SSasha Neftin u32 end_time; 10289d35511SSasha Neftin 1031ab011b0SAravindhan Gunasekaran /* CBS parameters */ 1041ab011b0SAravindhan Gunasekaran bool cbs_enable; /* indicates if CBS is enabled */ 1051ab011b0SAravindhan Gunasekaran s32 idleslope; /* idleSlope in kbps */ 1061ab011b0SAravindhan Gunasekaran s32 sendslope; /* sendSlope in kbps */ 1071ab011b0SAravindhan Gunasekaran s32 hicredit; /* hiCredit in bytes */ 1081ab011b0SAravindhan Gunasekaran s32 locredit; /* loCredit in bytes */ 1091ab011b0SAravindhan Gunasekaran 11089d35511SSasha Neftin /* everything past this point are written often */ 11189d35511SSasha Neftin u16 next_to_clean; 11289d35511SSasha Neftin u16 next_to_use; 11389d35511SSasha Neftin u16 next_to_alloc; 11489d35511SSasha Neftin 11589d35511SSasha Neftin union { 11689d35511SSasha Neftin /* TX */ 11789d35511SSasha Neftin struct { 11889d35511SSasha Neftin struct igc_tx_queue_stats tx_stats; 11989d35511SSasha Neftin struct u64_stats_sync tx_syncp; 12089d35511SSasha Neftin struct u64_stats_sync tx_syncp2; 12189d35511SSasha Neftin }; 12289d35511SSasha Neftin /* RX */ 12389d35511SSasha Neftin struct { 12489d35511SSasha Neftin struct igc_rx_queue_stats rx_stats; 12589d35511SSasha Neftin struct igc_rx_packet_stats pkt_stats; 12689d35511SSasha Neftin struct u64_stats_sync rx_syncp; 12789d35511SSasha Neftin struct sk_buff *skb; 12889d35511SSasha Neftin }; 12989d35511SSasha Neftin }; 13073f1071cSAndre Guedes 13173f1071cSAndre Guedes struct xdp_rxq_info xdp_rxq; 132fc9df2a0SAndre Guedes struct xsk_buff_pool *xsk_pool; 13389d35511SSasha Neftin } ____cacheline_internodealigned_in_smp; 13489d35511SSasha Neftin 13589d35511SSasha Neftin /* Board specific private data structure */ 13689d35511SSasha Neftin struct igc_adapter { 13789d35511SSasha Neftin struct net_device *netdev; 13889d35511SSasha Neftin 13993ec439aSSasha Neftin struct ethtool_eee eee; 14093ec439aSSasha Neftin u16 eee_advert; 14193ec439aSSasha Neftin 14289d35511SSasha Neftin unsigned long state; 14389d35511SSasha Neftin unsigned int flags; 14489d35511SSasha Neftin unsigned int num_q_vectors; 14589d35511SSasha Neftin 14689d35511SSasha Neftin struct msix_entry *msix_entries; 14789d35511SSasha Neftin 14889d35511SSasha Neftin /* TX */ 14989d35511SSasha Neftin u16 tx_work_limit; 15089d35511SSasha Neftin u32 tx_timeout_count; 15189d35511SSasha Neftin int num_tx_queues; 15289d35511SSasha Neftin struct igc_ring *tx_ring[IGC_MAX_TX_QUEUES]; 15389d35511SSasha Neftin 15489d35511SSasha Neftin /* RX */ 15589d35511SSasha Neftin int num_rx_queues; 15689d35511SSasha Neftin struct igc_ring *rx_ring[IGC_MAX_RX_QUEUES]; 15789d35511SSasha Neftin 15889d35511SSasha Neftin struct timer_list watchdog_timer; 15989d35511SSasha Neftin struct timer_list dma_err_timer; 16089d35511SSasha Neftin struct timer_list phy_info_timer; 16189d35511SSasha Neftin 16289d35511SSasha Neftin u32 wol; 16389d35511SSasha Neftin u32 en_mng_pt; 16489d35511SSasha Neftin u16 link_speed; 16589d35511SSasha Neftin u16 link_duplex; 16689d35511SSasha Neftin 16789d35511SSasha Neftin u8 port_num; 16889d35511SSasha Neftin 16989d35511SSasha Neftin u8 __iomem *io_addr; 17089d35511SSasha Neftin /* Interrupt Throttle Rate */ 17189d35511SSasha Neftin u32 rx_itr_setting; 17289d35511SSasha Neftin u32 tx_itr_setting; 17389d35511SSasha Neftin 17489d35511SSasha Neftin struct work_struct reset_task; 17589d35511SSasha Neftin struct work_struct watchdog_task; 17689d35511SSasha Neftin struct work_struct dma_err_task; 17789d35511SSasha Neftin bool fc_autoneg; 17889d35511SSasha Neftin 17989d35511SSasha Neftin u8 tx_timeout_factor; 18089d35511SSasha Neftin 18189d35511SSasha Neftin int msg_enable; 18289d35511SSasha Neftin u32 max_frame_size; 18389d35511SSasha Neftin u32 min_frame_size; 18489d35511SSasha Neftin 18589d35511SSasha Neftin ktime_t base_time; 18689d35511SSasha Neftin ktime_t cycle_time; 18789d35511SSasha Neftin 18889d35511SSasha Neftin /* OS defined structs */ 18989d35511SSasha Neftin struct pci_dev *pdev; 19089d35511SSasha Neftin /* lock for statistics */ 19189d35511SSasha Neftin spinlock_t stats64_lock; 19289d35511SSasha Neftin struct rtnl_link_stats64 stats64; 19389d35511SSasha Neftin 19489d35511SSasha Neftin /* structs defined in igc_hw.h */ 19589d35511SSasha Neftin struct igc_hw hw; 19689d35511SSasha Neftin struct igc_hw_stats stats; 19789d35511SSasha Neftin 19889d35511SSasha Neftin struct igc_q_vector *q_vector[MAX_Q_VECTORS]; 19989d35511SSasha Neftin u32 eims_enable_mask; 20089d35511SSasha Neftin u32 eims_other; 20189d35511SSasha Neftin 20289d35511SSasha Neftin u16 tx_ring_count; 20389d35511SSasha Neftin u16 rx_ring_count; 20489d35511SSasha Neftin 20589d35511SSasha Neftin u32 tx_hwtstamp_timeouts; 20689d35511SSasha Neftin u32 tx_hwtstamp_skipped; 20789d35511SSasha Neftin u32 rx_hwtstamp_cleared; 20889d35511SSasha Neftin 20989d35511SSasha Neftin u32 rss_queues; 21089d35511SSasha Neftin u32 rss_indir_tbl_init; 21189d35511SSasha Neftin 21297700bc8SAndre Guedes /* Any access to elements in nfc_rule_list is protected by the 21397700bc8SAndre Guedes * nfc_rule_lock. 21497700bc8SAndre Guedes */ 21542fc5dc0SAndre Guedes struct mutex nfc_rule_lock; 216d957c601SAndre Guedes struct list_head nfc_rule_list; 21797700bc8SAndre Guedes unsigned int nfc_rule_count; 21889d35511SSasha Neftin 21989d35511SSasha Neftin u8 rss_indir_tbl[IGC_RETA_SIZE]; 22089d35511SSasha Neftin 22189d35511SSasha Neftin unsigned long link_check_timeout; 22289d35511SSasha Neftin struct igc_info ei; 22389d35511SSasha Neftin 224f026d8caSVitaly Lifshits u32 test_icr; 225f026d8caSVitaly Lifshits 22689d35511SSasha Neftin struct ptp_clock *ptp_clock; 22789d35511SSasha Neftin struct ptp_clock_info ptp_caps; 22889d35511SSasha Neftin struct work_struct ptp_tx_work; 22989d35511SSasha Neftin struct sk_buff *ptp_tx_skb; 23089d35511SSasha Neftin struct hwtstamp_config tstamp_config; 23189d35511SSasha Neftin unsigned long ptp_tx_start; 23289d35511SSasha Neftin unsigned int ptp_flags; 23389d35511SSasha Neftin /* System time value lock */ 23489d35511SSasha Neftin spinlock_t tmreg_lock; 23589d35511SSasha Neftin struct cyclecounter cc; 23689d35511SSasha Neftin struct timecounter tc; 237b03c49cdSVinicius Costa Gomes struct timespec64 prev_ptp_time; /* Pre-reset PTP clock */ 238b03c49cdSVinicius Costa Gomes ktime_t ptp_reset_start; /* Reset time in clock mono */ 239a90ec848SVinicius Costa Gomes struct system_time_snapshot snapshot; 24001bb6129SSasha Neftin 24194f794d1SSasha Neftin char fw_version[32]; 24226575105SAndre Guedes 24326575105SAndre Guedes struct bpf_prog *xdp_prog; 24464433e5bSEderson de Souza 24564433e5bSEderson de Souza bool pps_sys_wrap_on; 24687938851SEderson de Souza 24787938851SEderson de Souza struct ptp_pin_desc sdp_config[IGC_N_SDP]; 24887938851SEderson de Souza struct { 24987938851SEderson de Souza struct timespec64 start; 25087938851SEderson de Souza struct timespec64 period; 25187938851SEderson de Souza } perout[IGC_N_PEROUT]; 25289d35511SSasha Neftin }; 2538c5ad0daSSasha Neftin 2548c5ad0daSSasha Neftin void igc_up(struct igc_adapter *adapter); 2558c5ad0daSSasha Neftin void igc_down(struct igc_adapter *adapter); 256f026d8caSVitaly Lifshits int igc_open(struct net_device *netdev); 257f026d8caSVitaly Lifshits int igc_close(struct net_device *netdev); 2588c5ad0daSSasha Neftin int igc_setup_tx_resources(struct igc_ring *ring); 2598c5ad0daSSasha Neftin int igc_setup_rx_resources(struct igc_ring *ring); 2608c5ad0daSSasha Neftin void igc_free_tx_resources(struct igc_ring *ring); 2618c5ad0daSSasha Neftin void igc_free_rx_resources(struct igc_ring *ring); 2628c5ad0daSSasha Neftin unsigned int igc_get_max_rss_queues(struct igc_adapter *adapter); 2638c5ad0daSSasha Neftin void igc_set_flag_queue_pairs(struct igc_adapter *adapter, 2648c5ad0daSSasha Neftin const u32 max_rss_queues); 2658c5ad0daSSasha Neftin int igc_reinit_queues(struct igc_adapter *adapter); 2662121c271SSasha Neftin void igc_write_rss_indir_tbl(struct igc_adapter *adapter); 2678c5ad0daSSasha Neftin bool igc_has_link(struct igc_adapter *adapter); 2688c5ad0daSSasha Neftin void igc_reset(struct igc_adapter *adapter); 26936b9fea6SSasha Neftin void igc_update_stats(struct igc_adapter *adapter); 270fc9df2a0SAndre Guedes void igc_disable_rx_ring(struct igc_ring *ring); 271fc9df2a0SAndre Guedes void igc_enable_rx_ring(struct igc_ring *ring); 2729acf59a7SAndre Guedes void igc_disable_tx_ring(struct igc_ring *ring); 2739acf59a7SAndre Guedes void igc_enable_tx_ring(struct igc_ring *ring); 274fc9df2a0SAndre Guedes int igc_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags); 2758c5ad0daSSasha Neftin 2769c384ee3SSasha Neftin /* igc_dump declarations */ 2779c384ee3SSasha Neftin void igc_rings_dump(struct igc_adapter *adapter); 2789c384ee3SSasha Neftin void igc_regs_dump(struct igc_adapter *adapter); 2799c384ee3SSasha Neftin 280d89f8841SSasha Neftin extern char igc_driver_name[]; 281d89f8841SSasha Neftin 2828c5ad0daSSasha Neftin #define IGC_REGS_LEN 740 2838c5ad0daSSasha Neftin 2845f295805SVinicius Costa Gomes /* flags controlling PTP/1588 function */ 2855f295805SVinicius Costa Gomes #define IGC_PTP_ENABLED BIT(0) 2865f295805SVinicius Costa Gomes 28767082b53SSasha Neftin /* Flags definitions */ 2883df25e4cSSasha Neftin #define IGC_FLAG_HAS_MSI BIT(0) 2898c5ad0daSSasha Neftin #define IGC_FLAG_QUEUE_PAIRS BIT(3) 2908c5ad0daSSasha Neftin #define IGC_FLAG_DMAC BIT(4) 2915f295805SVinicius Costa Gomes #define IGC_FLAG_PTP BIT(8) 292e055600dSSasha Neftin #define IGC_FLAG_WOL_SUPPORTED BIT(8) 2930507ef8aSSasha Neftin #define IGC_FLAG_NEED_LINK_UPDATE BIT(9) 294208983f0SSasha Neftin #define IGC_FLAG_MEDIA_RESET BIT(10) 295208983f0SSasha Neftin #define IGC_FLAG_MAS_ENABLE BIT(12) 2963df25e4cSSasha Neftin #define IGC_FLAG_HAS_MSIX BIT(13) 29793ec439aSSasha Neftin #define IGC_FLAG_EEE BIT(14) 2980507ef8aSSasha Neftin #define IGC_FLAG_VLAN_PROMISC BIT(15) 2998c5ad0daSSasha Neftin #define IGC_FLAG_RX_LEGACY BIT(16) 300ec50a9d4SVinicius Costa Gomes #define IGC_FLAG_TSN_QBV_ENABLED BIT(17) 3011ab011b0SAravindhan Gunasekaran #define IGC_FLAG_TSN_QAV_ENABLED BIT(18) 3023df25e4cSSasha Neftin 3031ab011b0SAravindhan Gunasekaran #define IGC_FLAG_TSN_ANY_ENABLED \ 3041ab011b0SAravindhan Gunasekaran (IGC_FLAG_TSN_QBV_ENABLED | IGC_FLAG_TSN_QAV_ENABLED) 30561572d5fSVinicius Costa Gomes 3062121c271SSasha Neftin #define IGC_FLAG_RSS_FIELD_IPV4_UDP BIT(6) 3072121c271SSasha Neftin #define IGC_FLAG_RSS_FIELD_IPV6_UDP BIT(7) 3082121c271SSasha Neftin 3092121c271SSasha Neftin #define IGC_MRQC_ENABLE_RSS_MQ 0x00000002 3102121c271SSasha Neftin #define IGC_MRQC_RSS_FIELD_IPV4_UDP 0x00400000 3112121c271SSasha Neftin #define IGC_MRQC_RSS_FIELD_IPV6_UDP 0x00800000 3122121c271SSasha Neftin 31364900e8fSSasha Neftin /* Interrupt defines */ 3143df25e4cSSasha Neftin #define IGC_START_ITR 648 /* ~6000 ints/sec */ 3153df25e4cSSasha Neftin #define IGC_4K_ITR 980 3163df25e4cSSasha Neftin #define IGC_20K_ITR 196 3173df25e4cSSasha Neftin #define IGC_70K_ITR 56 3183df25e4cSSasha Neftin 3190507ef8aSSasha Neftin #define IGC_DEFAULT_ITR 3 /* dynamic */ 3200507ef8aSSasha Neftin #define IGC_MAX_ITR_USECS 10000 3210507ef8aSSasha Neftin #define IGC_MIN_ITR_USECS 10 3220507ef8aSSasha Neftin #define NON_Q_VECTORS 1 3230507ef8aSSasha Neftin #define MAX_MSIX_ENTRIES 10 3240507ef8aSSasha Neftin 3250507ef8aSSasha Neftin /* TX/RX descriptor defines */ 3260507ef8aSSasha Neftin #define IGC_DEFAULT_TXD 256 3270507ef8aSSasha Neftin #define IGC_DEFAULT_TX_WORK 128 3280507ef8aSSasha Neftin #define IGC_MIN_TXD 80 3290507ef8aSSasha Neftin #define IGC_MAX_TXD 4096 3300507ef8aSSasha Neftin 3310507ef8aSSasha Neftin #define IGC_DEFAULT_RXD 256 3320507ef8aSSasha Neftin #define IGC_MIN_RXD 80 3330507ef8aSSasha Neftin #define IGC_MAX_RXD 4096 3340507ef8aSSasha Neftin 33513b5b7fdSSasha Neftin /* Supported Rx Buffer Sizes */ 33613b5b7fdSSasha Neftin #define IGC_RXBUFFER_256 256 33713b5b7fdSSasha Neftin #define IGC_RXBUFFER_2048 2048 33813b5b7fdSSasha Neftin #define IGC_RXBUFFER_3072 3072 33913b5b7fdSSasha Neftin 3408c5ad0daSSasha Neftin #define AUTO_ALL_MODES 0 34113b5b7fdSSasha Neftin #define IGC_RX_HDR_LEN IGC_RXBUFFER_256 34213b5b7fdSSasha Neftin 34381b05520SVinicius Costa Gomes /* Transmit and receive latency (for PTP timestamps) */ 344f03369b9SVinicius Costa Gomes #define IGC_I225_TX_LATENCY_10 240 345f03369b9SVinicius Costa Gomes #define IGC_I225_TX_LATENCY_100 58 346f03369b9SVinicius Costa Gomes #define IGC_I225_TX_LATENCY_1000 80 347f03369b9SVinicius Costa Gomes #define IGC_I225_TX_LATENCY_2500 1325 348f03369b9SVinicius Costa Gomes #define IGC_I225_RX_LATENCY_10 6450 349f03369b9SVinicius Costa Gomes #define IGC_I225_RX_LATENCY_100 185 350f03369b9SVinicius Costa Gomes #define IGC_I225_RX_LATENCY_1000 300 351f03369b9SVinicius Costa Gomes #define IGC_I225_RX_LATENCY_2500 1485 35281b05520SVinicius Costa Gomes 35313b5b7fdSSasha Neftin /* RX and TX descriptor control thresholds. 35413b5b7fdSSasha Neftin * PTHRESH - MAC will consider prefetch if it has fewer than this number of 35513b5b7fdSSasha Neftin * descriptors available in its onboard memory. 35613b5b7fdSSasha Neftin * Setting this to 0 disables RX descriptor prefetch. 35713b5b7fdSSasha Neftin * HTHRESH - MAC will only prefetch if there are at least this many descriptors 35813b5b7fdSSasha Neftin * available in host memory. 35913b5b7fdSSasha Neftin * If PTHRESH is 0, this should also be 0. 36013b5b7fdSSasha Neftin * WTHRESH - RX descriptor writeback threshold - MAC will delay writing back 36113b5b7fdSSasha Neftin * descriptors until either it has this many to write back, or the 36213b5b7fdSSasha Neftin * ITR timer expires. 36313b5b7fdSSasha Neftin */ 36413b5b7fdSSasha Neftin #define IGC_RX_PTHRESH 8 36513b5b7fdSSasha Neftin #define IGC_RX_HTHRESH 8 36613b5b7fdSSasha Neftin #define IGC_TX_PTHRESH 8 36713b5b7fdSSasha Neftin #define IGC_TX_HTHRESH 1 36813b5b7fdSSasha Neftin #define IGC_RX_WTHRESH 4 36913b5b7fdSSasha Neftin #define IGC_TX_WTHRESH 16 37013b5b7fdSSasha Neftin 37113b5b7fdSSasha Neftin #define IGC_RX_DMA_ATTR \ 37213b5b7fdSSasha Neftin (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING) 37313b5b7fdSSasha Neftin 37413b5b7fdSSasha Neftin #define IGC_TS_HDR_LEN 16 37513b5b7fdSSasha Neftin 37613b5b7fdSSasha Neftin #define IGC_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN) 37713b5b7fdSSasha Neftin 37813b5b7fdSSasha Neftin #if (PAGE_SIZE < 8192) 37913b5b7fdSSasha Neftin #define IGC_MAX_FRAME_BUILD_SKB \ 38013b5b7fdSSasha Neftin (SKB_WITH_OVERHEAD(IGC_RXBUFFER_2048) - IGC_SKB_PAD - IGC_TS_HDR_LEN) 38113b5b7fdSSasha Neftin #else 38213b5b7fdSSasha Neftin #define IGC_MAX_FRAME_BUILD_SKB (IGC_RXBUFFER_2048 - IGC_TS_HDR_LEN) 38313b5b7fdSSasha Neftin #endif 38413b5b7fdSSasha Neftin 3850507ef8aSSasha Neftin /* How many Rx Buffers do we bundle into one write to the hardware ? */ 3860507ef8aSSasha Neftin #define IGC_RX_BUFFER_WRITE 16 /* Must be power of 2 */ 3870507ef8aSSasha Neftin 388d3ae3cfbSSasha Neftin /* VLAN info */ 389d3ae3cfbSSasha Neftin #define IGC_TX_FLAGS_VLAN_MASK 0xffff0000 3908d744963SMuhammad Husaini Zulkifli #define IGC_TX_FLAGS_VLAN_SHIFT 16 391d3ae3cfbSSasha Neftin 3920507ef8aSSasha Neftin /* igc_test_staterr - tests bits within Rx descriptor status and error fields */ 3930507ef8aSSasha Neftin static inline __le32 igc_test_staterr(union igc_adv_rx_desc *rx_desc, 3940507ef8aSSasha Neftin const u32 stat_err_bits) 3950507ef8aSSasha Neftin { 3960507ef8aSSasha Neftin return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits); 3970507ef8aSSasha Neftin } 3980507ef8aSSasha Neftin 399c9a11c23SSasha Neftin enum igc_state_t { 400c9a11c23SSasha Neftin __IGC_TESTING, 401c9a11c23SSasha Neftin __IGC_RESETTING, 402c9a11c23SSasha Neftin __IGC_DOWN, 403c9a11c23SSasha Neftin __IGC_PTP_TX_IN_PROGRESS, 404c9a11c23SSasha Neftin }; 405c9a11c23SSasha Neftin 4060507ef8aSSasha Neftin enum igc_tx_flags { 4070507ef8aSSasha Neftin /* cmd_type flags */ 4080507ef8aSSasha Neftin IGC_TX_FLAGS_VLAN = 0x01, 4090507ef8aSSasha Neftin IGC_TX_FLAGS_TSO = 0x02, 4100507ef8aSSasha Neftin IGC_TX_FLAGS_TSTAMP = 0x04, 4110507ef8aSSasha Neftin 4120507ef8aSSasha Neftin /* olinfo flags */ 4130507ef8aSSasha Neftin IGC_TX_FLAGS_IPV4 = 0x10, 4140507ef8aSSasha Neftin IGC_TX_FLAGS_CSUM = 0x20, 4150507ef8aSSasha Neftin }; 4160507ef8aSSasha Neftin 417ab405612SSasha Neftin enum igc_boards { 418ab405612SSasha Neftin board_base, 419ab405612SSasha Neftin }; 420ab405612SSasha Neftin 4210507ef8aSSasha Neftin /* The largest size we can write to the descriptor is 65535. In order to 4220507ef8aSSasha Neftin * maintain a power of two alignment we have to limit ourselves to 32K. 4230507ef8aSSasha Neftin */ 4240507ef8aSSasha Neftin #define IGC_MAX_TXD_PWR 15 4250507ef8aSSasha Neftin #define IGC_MAX_DATA_PER_TXD BIT(IGC_MAX_TXD_PWR) 4260507ef8aSSasha Neftin 4270507ef8aSSasha Neftin /* Tx Descriptors needed, worst case */ 4280507ef8aSSasha Neftin #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IGC_MAX_DATA_PER_TXD) 4290507ef8aSSasha Neftin #define DESC_NEEDED (MAX_SKB_FRAGS + 4) 4300507ef8aSSasha Neftin 431859b4dfaSAndre Guedes enum igc_tx_buffer_type { 432859b4dfaSAndre Guedes IGC_TX_BUFFER_TYPE_SKB, 433859b4dfaSAndre Guedes IGC_TX_BUFFER_TYPE_XDP, 4349acf59a7SAndre Guedes IGC_TX_BUFFER_TYPE_XSK, 435859b4dfaSAndre Guedes }; 436859b4dfaSAndre Guedes 43713b5b7fdSSasha Neftin /* wrapper around a pointer to a socket buffer, 43813b5b7fdSSasha Neftin * so a DMA handle can be stored along with the buffer 43913b5b7fdSSasha Neftin */ 44013b5b7fdSSasha Neftin struct igc_tx_buffer { 44113b5b7fdSSasha Neftin union igc_adv_tx_desc *next_to_watch; 44213b5b7fdSSasha Neftin unsigned long time_stamp; 443859b4dfaSAndre Guedes enum igc_tx_buffer_type type; 44473f1071cSAndre Guedes union { 44513b5b7fdSSasha Neftin struct sk_buff *skb; 44673f1071cSAndre Guedes struct xdp_frame *xdpf; 44773f1071cSAndre Guedes }; 44813b5b7fdSSasha Neftin unsigned int bytecount; 44913b5b7fdSSasha Neftin u16 gso_segs; 45013b5b7fdSSasha Neftin __be16 protocol; 45113b5b7fdSSasha Neftin 45213b5b7fdSSasha Neftin DEFINE_DMA_UNMAP_ADDR(dma); 45313b5b7fdSSasha Neftin DEFINE_DMA_UNMAP_LEN(len); 45413b5b7fdSSasha Neftin u32 tx_flags; 45513b5b7fdSSasha Neftin }; 45613b5b7fdSSasha Neftin 45713b5b7fdSSasha Neftin struct igc_rx_buffer { 458fc9df2a0SAndre Guedes union { 459fc9df2a0SAndre Guedes struct { 46013b5b7fdSSasha Neftin dma_addr_t dma; 46113b5b7fdSSasha Neftin struct page *page; 46213b5b7fdSSasha Neftin #if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536) 46313b5b7fdSSasha Neftin __u32 page_offset; 46413b5b7fdSSasha Neftin #else 46513b5b7fdSSasha Neftin __u16 page_offset; 46613b5b7fdSSasha Neftin #endif 46713b5b7fdSSasha Neftin __u16 pagecnt_bias; 46813b5b7fdSSasha Neftin }; 469fc9df2a0SAndre Guedes struct xdp_buff *xdp; 470fc9df2a0SAndre Guedes }; 471fc9df2a0SAndre Guedes }; 47213b5b7fdSSasha Neftin 473c9a11c23SSasha Neftin struct igc_q_vector { 474c9a11c23SSasha Neftin struct igc_adapter *adapter; /* backlink */ 4753df25e4cSSasha Neftin void __iomem *itr_register; 4763df25e4cSSasha Neftin u32 eims_value; /* EIMS mask value */ 4773df25e4cSSasha Neftin 4783df25e4cSSasha Neftin u16 itr_val; 4793df25e4cSSasha Neftin u8 set_itr; 4803df25e4cSSasha Neftin 4813df25e4cSSasha Neftin struct igc_ring_container rx, tx; 482c9a11c23SSasha Neftin 483c9a11c23SSasha Neftin struct napi_struct napi; 4843df25e4cSSasha Neftin 4853df25e4cSSasha Neftin struct rcu_head rcu; /* to avoid race with update stats on free */ 4863df25e4cSSasha Neftin char name[IFNAMSIZ + 9]; 4873df25e4cSSasha Neftin struct net_device poll_dev; 4883df25e4cSSasha Neftin 4893df25e4cSSasha Neftin /* for dynamic allocation of rings associated with this q_vector */ 490040efdb1SGustavo A. R. Silva struct igc_ring ring[] ____cacheline_internodealigned_in_smp; 491c9a11c23SSasha Neftin }; 492c9a11c23SSasha Neftin 4936245c848SSasha Neftin enum igc_filter_match_flags { 4942b477d05SKurt Kanzenbach IGC_FILTER_FLAG_ETHER_TYPE = BIT(0), 4952b477d05SKurt Kanzenbach IGC_FILTER_FLAG_VLAN_TCI = BIT(1), 4962b477d05SKurt Kanzenbach IGC_FILTER_FLAG_SRC_MAC_ADDR = BIT(2), 4972b477d05SKurt Kanzenbach IGC_FILTER_FLAG_DST_MAC_ADDR = BIT(3), 4982b477d05SKurt Kanzenbach IGC_FILTER_FLAG_USER_DATA = BIT(4), 4992b477d05SKurt Kanzenbach IGC_FILTER_FLAG_VLAN_ETYPE = BIT(5), 5006245c848SSasha Neftin }; 5016245c848SSasha Neftin 50297700bc8SAndre Guedes struct igc_nfc_filter { 5036245c848SSasha Neftin u8 match_flags; 504c983e327SAndre Guedes u16 etype; 5052b477d05SKurt Kanzenbach __be16 vlan_etype; 506c983e327SAndre Guedes u16 vlan_tci; 5076245c848SSasha Neftin u8 src_addr[ETH_ALEN]; 5086245c848SSasha Neftin u8 dst_addr[ETH_ALEN]; 5092b477d05SKurt Kanzenbach u8 user_data[8]; 5102b477d05SKurt Kanzenbach u8 user_mask[8]; 5112b477d05SKurt Kanzenbach u8 flex_index; 5122b477d05SKurt Kanzenbach u8 rx_queue; 5132b477d05SKurt Kanzenbach u8 prio; 5142b477d05SKurt Kanzenbach u8 immediate_irq; 5152b477d05SKurt Kanzenbach u8 drop; 5166245c848SSasha Neftin }; 5176245c848SSasha Neftin 51897700bc8SAndre Guedes struct igc_nfc_rule { 519d957c601SAndre Guedes struct list_head list; 52097700bc8SAndre Guedes struct igc_nfc_filter filter; 521d3ba9e6fSAndre Guedes u32 location; 5226245c848SSasha Neftin u16 action; 52373744262SKurt Kanzenbach bool flex; 5246245c848SSasha Neftin }; 5256245c848SSasha Neftin 5262b477d05SKurt Kanzenbach /* IGC supports a total of 32 NFC rules: 16 MAC address based, 8 VLAN priority 5272b477d05SKurt Kanzenbach * based, 8 ethertype based and 32 Flex filter based rules. 528e087d3bbSAndre Guedes */ 5292b477d05SKurt Kanzenbach #define IGC_MAX_RXNFC_RULES 64 530c9a11c23SSasha Neftin 5316574631bSKurt Kanzenbach struct igc_flex_filter { 5326574631bSKurt Kanzenbach u8 index; 5336574631bSKurt Kanzenbach u8 data[128]; 5346574631bSKurt Kanzenbach u8 mask[16]; 5356574631bSKurt Kanzenbach u8 length; 5366574631bSKurt Kanzenbach u8 rx_queue; 5376574631bSKurt Kanzenbach u8 prio; 5386574631bSKurt Kanzenbach u8 immediate_irq; 5396574631bSKurt Kanzenbach u8 drop; 5406574631bSKurt Kanzenbach }; 5416574631bSKurt Kanzenbach 54213b5b7fdSSasha Neftin /* igc_desc_unused - calculate if we have unused descriptors */ 54313b5b7fdSSasha Neftin static inline u16 igc_desc_unused(const struct igc_ring *ring) 54413b5b7fdSSasha Neftin { 54513b5b7fdSSasha Neftin u16 ntc = ring->next_to_clean; 54613b5b7fdSSasha Neftin u16 ntu = ring->next_to_use; 54713b5b7fdSSasha Neftin 54813b5b7fdSSasha Neftin return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1; 54913b5b7fdSSasha Neftin } 55013b5b7fdSSasha Neftin 5515586838fSSasha Neftin static inline s32 igc_get_phy_info(struct igc_hw *hw) 5525586838fSSasha Neftin { 5535586838fSSasha Neftin if (hw->phy.ops.get_phy_info) 5545586838fSSasha Neftin return hw->phy.ops.get_phy_info(hw); 5555586838fSSasha Neftin 5565586838fSSasha Neftin return 0; 5575586838fSSasha Neftin } 5585586838fSSasha Neftin 5595586838fSSasha Neftin static inline s32 igc_reset_phy(struct igc_hw *hw) 5605586838fSSasha Neftin { 5615586838fSSasha Neftin if (hw->phy.ops.reset) 5625586838fSSasha Neftin return hw->phy.ops.reset(hw); 5635586838fSSasha Neftin 5645586838fSSasha Neftin return 0; 5655586838fSSasha Neftin } 5665586838fSSasha Neftin 56713b5b7fdSSasha Neftin static inline struct netdev_queue *txring_txq(const struct igc_ring *tx_ring) 56813b5b7fdSSasha Neftin { 56913b5b7fdSSasha Neftin return netdev_get_tx_queue(tx_ring->netdev, tx_ring->queue_index); 57013b5b7fdSSasha Neftin } 57113b5b7fdSSasha Neftin 57213b5b7fdSSasha Neftin enum igc_ring_flags_t { 57313b5b7fdSSasha Neftin IGC_RING_FLAG_RX_3K_BUFFER, 57413b5b7fdSSasha Neftin IGC_RING_FLAG_RX_BUILD_SKB_ENABLED, 57513b5b7fdSSasha Neftin IGC_RING_FLAG_RX_SCTP_CSUM, 57613b5b7fdSSasha Neftin IGC_RING_FLAG_RX_LB_VLAN_BSWAP, 57713b5b7fdSSasha Neftin IGC_RING_FLAG_TX_CTX_IDX, 578fc9df2a0SAndre Guedes IGC_RING_FLAG_TX_DETECT_HANG, 579fc9df2a0SAndre Guedes IGC_RING_FLAG_AF_XDP_ZC, 58013b5b7fdSSasha Neftin }; 58113b5b7fdSSasha Neftin 58213b5b7fdSSasha Neftin #define ring_uses_large_buffer(ring) \ 58313b5b7fdSSasha Neftin test_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags) 5841bf33f71SAndre Guedes #define set_ring_uses_large_buffer(ring) \ 5851bf33f71SAndre Guedes set_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags) 5861bf33f71SAndre Guedes #define clear_ring_uses_large_buffer(ring) \ 5871bf33f71SAndre Guedes clear_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags) 58813b5b7fdSSasha Neftin 58913b5b7fdSSasha Neftin #define ring_uses_build_skb(ring) \ 59013b5b7fdSSasha Neftin test_bit(IGC_RING_FLAG_RX_BUILD_SKB_ENABLED, &(ring)->flags) 59113b5b7fdSSasha Neftin 59213b5b7fdSSasha Neftin static inline unsigned int igc_rx_bufsz(struct igc_ring *ring) 59313b5b7fdSSasha Neftin { 59413b5b7fdSSasha Neftin #if (PAGE_SIZE < 8192) 59513b5b7fdSSasha Neftin if (ring_uses_large_buffer(ring)) 59613b5b7fdSSasha Neftin return IGC_RXBUFFER_3072; 59713b5b7fdSSasha Neftin 59813b5b7fdSSasha Neftin if (ring_uses_build_skb(ring)) 59913b5b7fdSSasha Neftin return IGC_MAX_FRAME_BUILD_SKB + IGC_TS_HDR_LEN; 60013b5b7fdSSasha Neftin #endif 60113b5b7fdSSasha Neftin return IGC_RXBUFFER_2048; 60213b5b7fdSSasha Neftin } 60313b5b7fdSSasha Neftin 60413b5b7fdSSasha Neftin static inline unsigned int igc_rx_pg_order(struct igc_ring *ring) 60513b5b7fdSSasha Neftin { 60613b5b7fdSSasha Neftin #if (PAGE_SIZE < 8192) 60713b5b7fdSSasha Neftin if (ring_uses_large_buffer(ring)) 60813b5b7fdSSasha Neftin return 1; 60913b5b7fdSSasha Neftin #endif 61013b5b7fdSSasha Neftin return 0; 61113b5b7fdSSasha Neftin } 61213b5b7fdSSasha Neftin 613208983f0SSasha Neftin static inline s32 igc_read_phy_reg(struct igc_hw *hw, u32 offset, u16 *data) 614208983f0SSasha Neftin { 615208983f0SSasha Neftin if (hw->phy.ops.read_reg) 616208983f0SSasha Neftin return hw->phy.ops.read_reg(hw, offset, data); 617208983f0SSasha Neftin 61805682a0aSTom Rix return -EOPNOTSUPP; 619208983f0SSasha Neftin } 620208983f0SSasha Neftin 6218c5ad0daSSasha Neftin void igc_reinit_locked(struct igc_adapter *); 62236fa2152SAndre Guedes struct igc_nfc_rule *igc_get_nfc_rule(struct igc_adapter *adapter, 62336fa2152SAndre Guedes u32 location); 62436fa2152SAndre Guedes int igc_add_nfc_rule(struct igc_adapter *adapter, struct igc_nfc_rule *rule); 62536fa2152SAndre Guedes void igc_del_nfc_rule(struct igc_adapter *adapter, struct igc_nfc_rule *rule); 6268c5ad0daSSasha Neftin 6275f295805SVinicius Costa Gomes void igc_ptp_init(struct igc_adapter *adapter); 6285f295805SVinicius Costa Gomes void igc_ptp_reset(struct igc_adapter *adapter); 629a5136f76SSasha Neftin void igc_ptp_suspend(struct igc_adapter *adapter); 6305f295805SVinicius Costa Gomes void igc_ptp_stop(struct igc_adapter *adapter); 631e1ed4f92SAndre Guedes ktime_t igc_ptp_rx_pktstamp(struct igc_adapter *adapter, __le32 *buf); 6325f295805SVinicius Costa Gomes int igc_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr); 6335f295805SVinicius Costa Gomes int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr); 6342c344ae2SVinicius Costa Gomes void igc_ptp_tx_hang(struct igc_adapter *adapter); 635fec49eb4SVinicius Costa Gomes void igc_ptp_read(struct igc_adapter *adapter, struct timespec64 *ts); 6362c344ae2SVinicius Costa Gomes 63713b5b7fdSSasha Neftin #define igc_rx_pg_size(_ring) (PAGE_SIZE << igc_rx_pg_order(_ring)) 63813b5b7fdSSasha Neftin 6390507ef8aSSasha Neftin #define IGC_TXD_DCMD (IGC_ADVTXD_DCMD_EOP | IGC_ADVTXD_DCMD_RS) 6400507ef8aSSasha Neftin 64113b5b7fdSSasha Neftin #define IGC_RX_DESC(R, i) \ 64213b5b7fdSSasha Neftin (&(((union igc_adv_rx_desc *)((R)->desc))[i])) 64313b5b7fdSSasha Neftin #define IGC_TX_DESC(R, i) \ 64413b5b7fdSSasha Neftin (&(((union igc_adv_tx_desc *)((R)->desc))[i])) 64513b5b7fdSSasha Neftin #define IGC_TX_CTXTDESC(R, i) \ 64613b5b7fdSSasha Neftin (&(((struct igc_adv_tx_context_desc *)((R)->desc))[i])) 64713b5b7fdSSasha Neftin 648d89f8841SSasha Neftin #endif /* _IGC_H_ */ 649