1
2
3
4#ifndef _IGC_H_
5#define _IGC_H_
6
7#include <linux/kobject.h>
8#include <linux/pci.h>
9#include <linux/netdevice.h>
10#include <linux/vmalloc.h>
11#include <linux/ethtool.h>
12#include <linux/sctp.h>
13#include <linux/ptp_clock_kernel.h>
14#include <linux/timecounter.h>
15#include <linux/net_tstamp.h>
16
17#include "igc_hw.h"
18
19
20void igc_set_ethtool_ops(struct net_device *);
21
22struct igc_adapter;
23struct igc_ring;
24
25void igc_up(struct igc_adapter *adapter);
26void igc_down(struct igc_adapter *adapter);
27int igc_setup_tx_resources(struct igc_ring *ring);
28int igc_setup_rx_resources(struct igc_ring *ring);
29void igc_free_tx_resources(struct igc_ring *ring);
30void igc_free_rx_resources(struct igc_ring *ring);
31unsigned int igc_get_max_rss_queues(struct igc_adapter *adapter);
32void igc_set_flag_queue_pairs(struct igc_adapter *adapter,
33 const u32 max_rss_queues);
34int igc_reinit_queues(struct igc_adapter *adapter);
35void igc_write_rss_indir_tbl(struct igc_adapter *adapter);
36bool igc_has_link(struct igc_adapter *adapter);
37void igc_reset(struct igc_adapter *adapter);
38int igc_set_spd_dplx(struct igc_adapter *adapter, u32 spd, u8 dplx);
39int igc_add_mac_steering_filter(struct igc_adapter *adapter,
40 const u8 *addr, u8 queue, u8 flags);
41int igc_del_mac_steering_filter(struct igc_adapter *adapter,
42 const u8 *addr, u8 queue, u8 flags);
43void igc_update_stats(struct igc_adapter *adapter);
44
45extern char igc_driver_name[];
46extern char igc_driver_version[];
47
48#define IGC_REGS_LEN 740
49#define IGC_RETA_SIZE 128
50
51
52#define IGC_PTP_ENABLED BIT(0)
53
54
55#define IGC_START_ITR 648
56#define IGC_FLAG_HAS_MSI BIT(0)
57#define IGC_FLAG_QUEUE_PAIRS BIT(3)
58#define IGC_FLAG_DMAC BIT(4)
59#define IGC_FLAG_PTP BIT(8)
60#define IGC_FLAG_NEED_LINK_UPDATE BIT(9)
61#define IGC_FLAG_MEDIA_RESET BIT(10)
62#define IGC_FLAG_MAS_ENABLE BIT(12)
63#define IGC_FLAG_HAS_MSIX BIT(13)
64#define IGC_FLAG_VLAN_PROMISC BIT(15)
65#define IGC_FLAG_RX_LEGACY BIT(16)
66
67#define IGC_FLAG_RSS_FIELD_IPV4_UDP BIT(6)
68#define IGC_FLAG_RSS_FIELD_IPV6_UDP BIT(7)
69
70#define IGC_MRQC_ENABLE_RSS_MQ 0x00000002
71#define IGC_MRQC_RSS_FIELD_IPV4_UDP 0x00400000
72#define IGC_MRQC_RSS_FIELD_IPV6_UDP 0x00800000
73
74#define IGC_START_ITR 648
75#define IGC_4K_ITR 980
76#define IGC_20K_ITR 196
77#define IGC_70K_ITR 56
78
79#define IGC_DEFAULT_ITR 3
80#define IGC_MAX_ITR_USECS 10000
81#define IGC_MIN_ITR_USECS 10
82#define NON_Q_VECTORS 1
83#define MAX_MSIX_ENTRIES 10
84
85
86#define IGC_DEFAULT_TXD 256
87#define IGC_DEFAULT_TX_WORK 128
88#define IGC_MIN_TXD 80
89#define IGC_MAX_TXD 4096
90
91#define IGC_DEFAULT_RXD 256
92#define IGC_MIN_RXD 80
93#define IGC_MAX_RXD 4096
94
95
96#define IGC_MAX_RX_QUEUES 4
97#define IGC_MAX_TX_QUEUES 4
98
99#define MAX_Q_VECTORS 8
100#define MAX_STD_JUMBO_FRAME_SIZE 9216
101
102
103#define IGC_RXBUFFER_256 256
104#define IGC_RXBUFFER_2048 2048
105#define IGC_RXBUFFER_3072 3072
106
107#define AUTO_ALL_MODES 0
108#define IGC_RX_HDR_LEN IGC_RXBUFFER_256
109
110
111
112
113
114
115#define IGC_I225_TX_LATENCY_10 9542
116#define IGC_I225_TX_LATENCY_100 1024
117#define IGC_I225_TX_LATENCY_1000 178
118#define IGC_I225_TX_LATENCY_2500 64
119#define IGC_I225_RX_LATENCY_10 20662
120#define IGC_I225_RX_LATENCY_100 2213
121#define IGC_I225_RX_LATENCY_1000 448
122#define IGC_I225_RX_LATENCY_2500 160
123
124
125
126
127
128
129
130
131
132
133
134
135#define IGC_RX_PTHRESH 8
136#define IGC_RX_HTHRESH 8
137#define IGC_TX_PTHRESH 8
138#define IGC_TX_HTHRESH 1
139#define IGC_RX_WTHRESH 4
140#define IGC_TX_WTHRESH 16
141
142#define IGC_RX_DMA_ATTR \
143 (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
144
145#define IGC_TS_HDR_LEN 16
146
147#define IGC_SKB_PAD (NET_SKB_PAD + NET_IP_ALIGN)
148
149#if (PAGE_SIZE < 8192)
150#define IGC_MAX_FRAME_BUILD_SKB \
151 (SKB_WITH_OVERHEAD(IGC_RXBUFFER_2048) - IGC_SKB_PAD - IGC_TS_HDR_LEN)
152#else
153#define IGC_MAX_FRAME_BUILD_SKB (IGC_RXBUFFER_2048 - IGC_TS_HDR_LEN)
154#endif
155
156
157#define IGC_RX_BUFFER_WRITE 16
158
159
160#define IGC_TX_FLAGS_VLAN_MASK 0xffff0000
161
162
163static inline __le32 igc_test_staterr(union igc_adv_rx_desc *rx_desc,
164 const u32 stat_err_bits)
165{
166 return rx_desc->wb.upper.status_error & cpu_to_le32(stat_err_bits);
167}
168
169enum igc_state_t {
170 __IGC_TESTING,
171 __IGC_RESETTING,
172 __IGC_DOWN,
173 __IGC_PTP_TX_IN_PROGRESS,
174};
175
176enum igc_tx_flags {
177
178 IGC_TX_FLAGS_VLAN = 0x01,
179 IGC_TX_FLAGS_TSO = 0x02,
180 IGC_TX_FLAGS_TSTAMP = 0x04,
181
182
183 IGC_TX_FLAGS_IPV4 = 0x10,
184 IGC_TX_FLAGS_CSUM = 0x20,
185};
186
187enum igc_boards {
188 board_base,
189};
190
191
192
193
194#define IGC_MAX_TXD_PWR 15
195#define IGC_MAX_DATA_PER_TXD BIT(IGC_MAX_TXD_PWR)
196
197
198#define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IGC_MAX_DATA_PER_TXD)
199#define DESC_NEEDED (MAX_SKB_FRAGS + 4)
200
201
202
203
204struct igc_tx_buffer {
205 union igc_adv_tx_desc *next_to_watch;
206 unsigned long time_stamp;
207 struct sk_buff *skb;
208 unsigned int bytecount;
209 u16 gso_segs;
210 __be16 protocol;
211
212 DEFINE_DMA_UNMAP_ADDR(dma);
213 DEFINE_DMA_UNMAP_LEN(len);
214 u32 tx_flags;
215};
216
217struct igc_rx_buffer {
218 dma_addr_t dma;
219 struct page *page;
220#if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
221 __u32 page_offset;
222#else
223 __u16 page_offset;
224#endif
225 __u16 pagecnt_bias;
226};
227
228struct igc_tx_queue_stats {
229 u64 packets;
230 u64 bytes;
231 u64 restart_queue;
232 u64 restart_queue2;
233};
234
235struct igc_rx_queue_stats {
236 u64 packets;
237 u64 bytes;
238 u64 drops;
239 u64 csum_err;
240 u64 alloc_failed;
241};
242
243struct igc_rx_packet_stats {
244 u64 ipv4_packets;
245 u64 ipv4e_packets;
246 u64 ipv6_packets;
247 u64 ipv6e_packets;
248 u64 tcp_packets;
249 u64 udp_packets;
250 u64 sctp_packets;
251 u64 nfs_packets;
252 u64 other_packets;
253};
254
255struct igc_ring_container {
256 struct igc_ring *ring;
257 unsigned int total_bytes;
258 unsigned int total_packets;
259 u16 work_limit;
260 u8 count;
261 u8 itr;
262};
263
264struct igc_ring {
265 struct igc_q_vector *q_vector;
266 struct net_device *netdev;
267 struct device *dev;
268 union {
269 struct igc_tx_buffer *tx_buffer_info;
270 struct igc_rx_buffer *rx_buffer_info;
271 };
272 void *desc;
273 unsigned long flags;
274 void __iomem *tail;
275 dma_addr_t dma;
276 unsigned int size;
277
278 u16 count;
279 u8 queue_index;
280 u8 reg_idx;
281 bool launchtime_enable;
282
283
284 u16 next_to_clean;
285 u16 next_to_use;
286 u16 next_to_alloc;
287
288 union {
289
290 struct {
291 struct igc_tx_queue_stats tx_stats;
292 struct u64_stats_sync tx_syncp;
293 struct u64_stats_sync tx_syncp2;
294 };
295
296 struct {
297 struct igc_rx_queue_stats rx_stats;
298 struct igc_rx_packet_stats pkt_stats;
299 struct u64_stats_sync rx_syncp;
300 struct sk_buff *skb;
301 };
302 };
303} ____cacheline_internodealigned_in_smp;
304
305struct igc_q_vector {
306 struct igc_adapter *adapter;
307 void __iomem *itr_register;
308 u32 eims_value;
309
310 u16 itr_val;
311 u8 set_itr;
312
313 struct igc_ring_container rx, tx;
314
315 struct napi_struct napi;
316
317 struct rcu_head rcu;
318 char name[IFNAMSIZ + 9];
319 struct net_device poll_dev;
320
321
322 struct igc_ring ring[0] ____cacheline_internodealigned_in_smp;
323};
324
325#define MAX_ETYPE_FILTER (4 - 1)
326
327enum igc_filter_match_flags {
328 IGC_FILTER_FLAG_ETHER_TYPE = 0x1,
329 IGC_FILTER_FLAG_VLAN_TCI = 0x2,
330 IGC_FILTER_FLAG_SRC_MAC_ADDR = 0x4,
331 IGC_FILTER_FLAG_DST_MAC_ADDR = 0x8,
332};
333
334
335struct igc_nfc_input {
336
337
338
339
340
341 u8 match_flags;
342 __be16 etype;
343 __be16 vlan_tci;
344 u8 src_addr[ETH_ALEN];
345 u8 dst_addr[ETH_ALEN];
346};
347
348struct igc_nfc_filter {
349 struct hlist_node nfc_node;
350 struct igc_nfc_input filter;
351 unsigned long cookie;
352 u16 etype_reg_index;
353 u16 sw_idx;
354 u16 action;
355};
356
357struct igc_mac_addr {
358 u8 addr[ETH_ALEN];
359 u8 queue;
360 u8 state;
361};
362
363#define IGC_MAC_STATE_DEFAULT 0x1
364#define IGC_MAC_STATE_IN_USE 0x2
365#define IGC_MAC_STATE_SRC_ADDR 0x4
366#define IGC_MAC_STATE_QUEUE_STEERING 0x8
367
368#define IGC_MAX_RXNFC_FILTERS 16
369
370
371struct igc_adapter {
372 struct net_device *netdev;
373
374 unsigned long state;
375 unsigned int flags;
376 unsigned int num_q_vectors;
377
378 struct msix_entry *msix_entries;
379
380
381 u16 tx_work_limit;
382 u32 tx_timeout_count;
383 int num_tx_queues;
384 struct igc_ring *tx_ring[IGC_MAX_TX_QUEUES];
385
386
387 int num_rx_queues;
388 struct igc_ring *rx_ring[IGC_MAX_RX_QUEUES];
389
390 struct timer_list watchdog_timer;
391 struct timer_list dma_err_timer;
392 struct timer_list phy_info_timer;
393
394 u32 wol;
395 u32 en_mng_pt;
396 u16 link_speed;
397 u16 link_duplex;
398
399 u8 port_num;
400
401 u8 __iomem *io_addr;
402
403 u32 rx_itr_setting;
404 u32 tx_itr_setting;
405
406 struct work_struct reset_task;
407 struct work_struct watchdog_task;
408 struct work_struct dma_err_task;
409 bool fc_autoneg;
410
411 u8 tx_timeout_factor;
412
413 int msg_enable;
414 u32 max_frame_size;
415 u32 min_frame_size;
416
417
418 struct pci_dev *pdev;
419
420 spinlock_t stats64_lock;
421 struct rtnl_link_stats64 stats64;
422
423
424 struct igc_hw hw;
425 struct igc_hw_stats stats;
426
427 struct igc_q_vector *q_vector[MAX_Q_VECTORS];
428 u32 eims_enable_mask;
429 u32 eims_other;
430
431 u16 tx_ring_count;
432 u16 rx_ring_count;
433
434 u32 tx_hwtstamp_timeouts;
435 u32 tx_hwtstamp_skipped;
436 u32 rx_hwtstamp_cleared;
437
438 u32 rss_queues;
439 u32 rss_indir_tbl_init;
440
441
442 struct hlist_head nfc_filter_list;
443 struct hlist_head cls_flower_list;
444 unsigned int nfc_filter_count;
445
446
447 spinlock_t nfc_lock;
448 bool etype_bitmap[MAX_ETYPE_FILTER];
449
450 struct igc_mac_addr *mac_table;
451
452 u8 rss_indir_tbl[IGC_RETA_SIZE];
453
454 unsigned long link_check_timeout;
455 struct igc_info ei;
456
457 struct ptp_clock *ptp_clock;
458 struct ptp_clock_info ptp_caps;
459 struct work_struct ptp_tx_work;
460 struct sk_buff *ptp_tx_skb;
461 struct hwtstamp_config tstamp_config;
462 unsigned long ptp_tx_start;
463 unsigned long last_rx_ptp_check;
464 unsigned long last_rx_timestamp;
465 unsigned int ptp_flags;
466
467 spinlock_t tmreg_lock;
468 struct cyclecounter cc;
469 struct timecounter tc;
470};
471
472
473static inline u16 igc_desc_unused(const struct igc_ring *ring)
474{
475 u16 ntc = ring->next_to_clean;
476 u16 ntu = ring->next_to_use;
477
478 return ((ntc > ntu) ? 0 : ring->count) + ntc - ntu - 1;
479}
480
481static inline s32 igc_get_phy_info(struct igc_hw *hw)
482{
483 if (hw->phy.ops.get_phy_info)
484 return hw->phy.ops.get_phy_info(hw);
485
486 return 0;
487}
488
489static inline s32 igc_reset_phy(struct igc_hw *hw)
490{
491 if (hw->phy.ops.reset)
492 return hw->phy.ops.reset(hw);
493
494 return 0;
495}
496
497static inline struct netdev_queue *txring_txq(const struct igc_ring *tx_ring)
498{
499 return netdev_get_tx_queue(tx_ring->netdev, tx_ring->queue_index);
500}
501
502enum igc_ring_flags_t {
503 IGC_RING_FLAG_RX_3K_BUFFER,
504 IGC_RING_FLAG_RX_BUILD_SKB_ENABLED,
505 IGC_RING_FLAG_RX_SCTP_CSUM,
506 IGC_RING_FLAG_RX_LB_VLAN_BSWAP,
507 IGC_RING_FLAG_TX_CTX_IDX,
508 IGC_RING_FLAG_TX_DETECT_HANG
509};
510
511#define ring_uses_large_buffer(ring) \
512 test_bit(IGC_RING_FLAG_RX_3K_BUFFER, &(ring)->flags)
513
514#define ring_uses_build_skb(ring) \
515 test_bit(IGC_RING_FLAG_RX_BUILD_SKB_ENABLED, &(ring)->flags)
516
517static inline unsigned int igc_rx_bufsz(struct igc_ring *ring)
518{
519#if (PAGE_SIZE < 8192)
520 if (ring_uses_large_buffer(ring))
521 return IGC_RXBUFFER_3072;
522
523 if (ring_uses_build_skb(ring))
524 return IGC_MAX_FRAME_BUILD_SKB + IGC_TS_HDR_LEN;
525#endif
526 return IGC_RXBUFFER_2048;
527}
528
529static inline unsigned int igc_rx_pg_order(struct igc_ring *ring)
530{
531#if (PAGE_SIZE < 8192)
532 if (ring_uses_large_buffer(ring))
533 return 1;
534#endif
535 return 0;
536}
537
538static inline s32 igc_read_phy_reg(struct igc_hw *hw, u32 offset, u16 *data)
539{
540 if (hw->phy.ops.read_reg)
541 return hw->phy.ops.read_reg(hw, offset, data);
542
543 return 0;
544}
545
546
547void igc_reinit_locked(struct igc_adapter *);
548int igc_add_filter(struct igc_adapter *adapter,
549 struct igc_nfc_filter *input);
550int igc_erase_filter(struct igc_adapter *adapter,
551 struct igc_nfc_filter *input);
552
553void igc_ptp_init(struct igc_adapter *adapter);
554void igc_ptp_reset(struct igc_adapter *adapter);
555void igc_ptp_stop(struct igc_adapter *adapter);
556void igc_ptp_rx_rgtstamp(struct igc_q_vector *q_vector, struct sk_buff *skb);
557void igc_ptp_rx_pktstamp(struct igc_q_vector *q_vector, void *va,
558 struct sk_buff *skb);
559int igc_ptp_set_ts_config(struct net_device *netdev, struct ifreq *ifr);
560int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr);
561void igc_ptp_tx_hang(struct igc_adapter *adapter);
562
563#define igc_rx_pg_size(_ring) (PAGE_SIZE << igc_rx_pg_order(_ring))
564
565#define IGC_TXD_DCMD (IGC_ADVTXD_DCMD_EOP | IGC_ADVTXD_DCMD_RS)
566
567#define IGC_RX_DESC(R, i) \
568 (&(((union igc_adv_rx_desc *)((R)->desc))[i]))
569#define IGC_TX_DESC(R, i) \
570 (&(((union igc_adv_tx_desc *)((R)->desc))[i]))
571#define IGC_TX_CTXTDESC(R, i) \
572 (&(((struct igc_adv_tx_context_desc *)((R)->desc))[i]))
573
574#endif
575