This source file includes following definitions.
- xgbe_pci_init
- xgbe_pci_exit
- xgbe_debugfs_init
- xgbe_debugfs_exit
- xgbe_debugfs_rename
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 #ifndef __XGBE_H__
118 #define __XGBE_H__
119
120 #include <linux/dma-mapping.h>
121 #include <linux/netdevice.h>
122 #include <linux/workqueue.h>
123 #include <linux/phy.h>
124 #include <linux/if_vlan.h>
125 #include <linux/bitops.h>
126 #include <linux/ptp_clock_kernel.h>
127 #include <linux/timecounter.h>
128 #include <linux/net_tstamp.h>
129 #include <net/dcbnl.h>
130 #include <linux/completion.h>
131 #include <linux/cpumask.h>
132 #include <linux/interrupt.h>
133 #include <linux/dcache.h>
134 #include <linux/ethtool.h>
135 #include <linux/list.h>
136
137 #define XGBE_DRV_NAME "amd-xgbe"
138 #define XGBE_DRV_VERSION "1.0.3"
139 #define XGBE_DRV_DESC "AMD 10 Gigabit Ethernet Driver"
140
141
142 #define XGBE_TX_DESC_CNT 512
143 #define XGBE_TX_DESC_MIN_FREE (XGBE_TX_DESC_CNT >> 3)
144 #define XGBE_TX_DESC_MAX_PROC (XGBE_TX_DESC_CNT >> 1)
145 #define XGBE_RX_DESC_CNT 512
146
147 #define XGBE_TX_DESC_CNT_MIN 64
148 #define XGBE_TX_DESC_CNT_MAX 4096
149 #define XGBE_RX_DESC_CNT_MIN 64
150 #define XGBE_RX_DESC_CNT_MAX 4096
151
152 #define XGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
153
154
155 #define XGBE_TX_MAX_SPLIT ((GSO_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
156
157
158
159
160
161
162
163 #define XGBE_TX_MAX_DESCS (MAX_SKB_FRAGS + XGBE_TX_MAX_SPLIT + 2)
164
165 #define XGBE_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
166 #define XGBE_RX_BUF_ALIGN 64
167 #define XGBE_SKB_ALLOC_SIZE 256
168 #define XGBE_SPH_HDSMS_SIZE 2
169
170 #define XGBE_MAX_DMA_CHANNELS 16
171 #define XGBE_MAX_QUEUES 16
172 #define XGBE_PRIORITY_QUEUES 8
173 #define XGBE_DMA_STOP_TIMEOUT 1
174
175
176 #define XGBE_DMA_OS_ARCR 0x002b2b2b
177 #define XGBE_DMA_OS_AWCR 0x2f2f2f2f
178
179
180 #define XGBE_DMA_SYS_ARCR 0x00303030
181 #define XGBE_DMA_SYS_AWCR 0x30303030
182
183
184 #define XGBE_DMA_PCI_ARCR 0x00000003
185 #define XGBE_DMA_PCI_AWCR 0x13131313
186 #define XGBE_DMA_PCI_AWARCR 0x00000313
187
188
189 #define XGBE_IRQ_MODE_EDGE 0
190 #define XGBE_IRQ_MODE_LEVEL 1
191
192 #define XGMAC_MIN_PACKET 60
193 #define XGMAC_STD_PACKET_MTU 1500
194 #define XGMAC_MAX_STD_PACKET 1518
195 #define XGMAC_JUMBO_PACKET_MTU 9000
196 #define XGMAC_MAX_JUMBO_PACKET 9018
197 #define XGMAC_ETH_PREAMBLE (12 + 8)
198
199 #define XGMAC_PFC_DATA_LEN 46
200 #define XGMAC_PFC_DELAYS 14000
201
202 #define XGMAC_PRIO_QUEUES(_cnt) \
203 min_t(unsigned int, IEEE_8021QAZ_MAX_TCS, (_cnt))
204
205
206 #define XGBE_MAC_ADDR_PROPERTY "mac-address"
207 #define XGBE_PHY_MODE_PROPERTY "phy-mode"
208 #define XGBE_DMA_IRQS_PROPERTY "amd,per-channel-interrupt"
209 #define XGBE_SPEEDSET_PROPERTY "amd,speed-set"
210
211
212 #define XGBE_DMA_CLOCK "dma_clk"
213 #define XGBE_PTP_CLOCK "ptp_clk"
214
215
216 #define XGBE_ACPI_DMA_FREQ "amd,dma-freq"
217 #define XGBE_ACPI_PTP_FREQ "amd,ptp-freq"
218
219
220 #define XGBE_XGMAC_BAR 0
221 #define XGBE_XPCS_BAR 1
222 #define XGBE_MAC_PROP_OFFSET 0x1d000
223 #define XGBE_I2C_CTRL_OFFSET 0x1e000
224
225
226 #define XGBE_MSI_BASE_COUNT 4
227 #define XGBE_MSI_MIN_COUNT (XGBE_MSI_BASE_COUNT + 1)
228
229
230 #define XGBE_V2_DMA_CLOCK_FREQ 500000000
231 #define XGBE_V2_PTP_CLOCK_FREQ 125000000
232
233
234
235
236 #define XGBE_TSTAMP_SSINC 20
237 #define XGBE_TSTAMP_SNSINC 0
238
239
240 #define XGMAC_DRIVER_CONTEXT 1
241 #define XGMAC_IOCTL_CONTEXT 2
242
243 #define XGMAC_FIFO_MIN_ALLOC 2048
244 #define XGMAC_FIFO_UNIT 256
245 #define XGMAC_FIFO_ALIGN(_x) \
246 (((_x) + XGMAC_FIFO_UNIT - 1) & ~(XGMAC_FIFO_UNIT - 1))
247 #define XGMAC_FIFO_FC_OFF 2048
248 #define XGMAC_FIFO_FC_MIN 4096
249
250 #define XGBE_TC_MIN_QUANTUM 10
251
252
253
254
255
256
257
258 #define XGBE_GET_DESC_DATA(_ring, _idx) \
259 ((_ring)->rdata + \
260 ((_idx) & ((_ring)->rdesc_count - 1)))
261
262
263 #define XGMAC_INIT_DMA_TX_USECS 1000
264 #define XGMAC_INIT_DMA_TX_FRAMES 25
265
266 #define XGMAC_MAX_DMA_RIWT 0xff
267 #define XGMAC_INIT_DMA_RX_USECS 30
268 #define XGMAC_INIT_DMA_RX_FRAMES 25
269
270
271 #define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
272
273
274 #define XGMAC_FLOW_CONTROL_UNIT 512
275 #define XGMAC_FLOW_CONTROL_ALIGN(_x) \
276 (((_x) + XGMAC_FLOW_CONTROL_UNIT - 1) & ~(XGMAC_FLOW_CONTROL_UNIT - 1))
277 #define XGMAC_FLOW_CONTROL_VALUE(_x) \
278 (((_x) < 1024) ? 0 : ((_x) / XGMAC_FLOW_CONTROL_UNIT) - 2)
279 #define XGMAC_FLOW_CONTROL_MAX 33280
280
281
282 #define XGBE_MAC_HASH_TABLE_SIZE 8
283
284
285 #define XGBE_RSS_HASH_KEY_SIZE 40
286 #define XGBE_RSS_MAX_TABLE_SIZE 256
287 #define XGBE_RSS_LOOKUP_TABLE_TYPE 0
288 #define XGBE_RSS_HASH_KEY_TYPE 1
289
290
291 #define XGBE_AN_MS_TIMEOUT 500
292 #define XGBE_LINK_TIMEOUT 5
293
294 #define XGBE_SGMII_AN_LINK_STATUS BIT(1)
295 #define XGBE_SGMII_AN_LINK_SPEED (BIT(2) | BIT(3))
296 #define XGBE_SGMII_AN_LINK_SPEED_100 0x04
297 #define XGBE_SGMII_AN_LINK_SPEED_1000 0x08
298 #define XGBE_SGMII_AN_LINK_DUPLEX BIT(4)
299
300
301 #define XGBE_ECC_LIMIT 60
302
303
304 #define XGMAC_MAX_C22_PORT 3
305
306
307 #define XGBE_ZERO_SUP(_ls) \
308 ethtool_link_ksettings_zero_link_mode((_ls), supported)
309
310 #define XGBE_SET_SUP(_ls, _mode) \
311 ethtool_link_ksettings_add_link_mode((_ls), supported, _mode)
312
313 #define XGBE_CLR_SUP(_ls, _mode) \
314 ethtool_link_ksettings_del_link_mode((_ls), supported, _mode)
315
316 #define XGBE_IS_SUP(_ls, _mode) \
317 ethtool_link_ksettings_test_link_mode((_ls), supported, _mode)
318
319 #define XGBE_ZERO_ADV(_ls) \
320 ethtool_link_ksettings_zero_link_mode((_ls), advertising)
321
322 #define XGBE_SET_ADV(_ls, _mode) \
323 ethtool_link_ksettings_add_link_mode((_ls), advertising, _mode)
324
325 #define XGBE_CLR_ADV(_ls, _mode) \
326 ethtool_link_ksettings_del_link_mode((_ls), advertising, _mode)
327
328 #define XGBE_ADV(_ls, _mode) \
329 ethtool_link_ksettings_test_link_mode((_ls), advertising, _mode)
330
331 #define XGBE_ZERO_LP_ADV(_ls) \
332 ethtool_link_ksettings_zero_link_mode((_ls), lp_advertising)
333
334 #define XGBE_SET_LP_ADV(_ls, _mode) \
335 ethtool_link_ksettings_add_link_mode((_ls), lp_advertising, _mode)
336
337 #define XGBE_CLR_LP_ADV(_ls, _mode) \
338 ethtool_link_ksettings_del_link_mode((_ls), lp_advertising, _mode)
339
340 #define XGBE_LP_ADV(_ls, _mode) \
341 ethtool_link_ksettings_test_link_mode((_ls), lp_advertising, _mode)
342
343 #define XGBE_LM_COPY(_dst, _dname, _src, _sname) \
344 bitmap_copy((_dst)->link_modes._dname, \
345 (_src)->link_modes._sname, \
346 __ETHTOOL_LINK_MODE_MASK_NBITS)
347
348 struct xgbe_prv_data;
349
350 struct xgbe_packet_data {
351 struct sk_buff *skb;
352
353 unsigned int attributes;
354
355 unsigned int errors;
356
357 unsigned int rdesc_count;
358 unsigned int length;
359
360 unsigned int header_len;
361 unsigned int tcp_header_len;
362 unsigned int tcp_payload_len;
363 unsigned short mss;
364
365 unsigned short vlan_ctag;
366
367 u64 rx_tstamp;
368
369 u32 rss_hash;
370 enum pkt_hash_types rss_hash_type;
371
372 unsigned int tx_packets;
373 unsigned int tx_bytes;
374 };
375
376
377 struct xgbe_ring_desc {
378 __le32 desc0;
379 __le32 desc1;
380 __le32 desc2;
381 __le32 desc3;
382 };
383
384
385 struct xgbe_page_alloc {
386 struct page *pages;
387 unsigned int pages_len;
388 unsigned int pages_offset;
389
390 dma_addr_t pages_dma;
391 };
392
393
394 struct xgbe_buffer_data {
395 struct xgbe_page_alloc pa;
396 struct xgbe_page_alloc pa_unmap;
397
398 dma_addr_t dma_base;
399 unsigned long dma_off;
400 unsigned int dma_len;
401 };
402
403
404 struct xgbe_tx_ring_data {
405 unsigned int packets;
406 unsigned int bytes;
407 };
408
409
410 struct xgbe_rx_ring_data {
411 struct xgbe_buffer_data hdr;
412 struct xgbe_buffer_data buf;
413
414 unsigned short hdr_len;
415 unsigned short len;
416 };
417
418
419
420
421
422 struct xgbe_ring_data {
423 struct xgbe_ring_desc *rdesc;
424 dma_addr_t rdesc_dma;
425
426 struct sk_buff *skb;
427 dma_addr_t skb_dma;
428 unsigned int skb_dma_len;
429
430 struct xgbe_tx_ring_data tx;
431 struct xgbe_rx_ring_data rx;
432
433 unsigned int mapped_as_page;
434
435
436
437
438
439
440 unsigned int state_saved;
441 struct {
442 struct sk_buff *skb;
443 unsigned int len;
444 unsigned int error;
445 } state;
446 };
447
448 struct xgbe_ring {
449
450 spinlock_t lock;
451
452
453 struct xgbe_packet_data packet_data;
454
455
456 struct xgbe_ring_desc *rdesc;
457 dma_addr_t rdesc_dma;
458 unsigned int rdesc_count;
459
460
461
462
463 struct xgbe_ring_data *rdata;
464
465
466 struct xgbe_page_alloc rx_hdr_pa;
467 struct xgbe_page_alloc rx_buf_pa;
468 int node;
469
470
471
472
473
474
475
476 unsigned int cur;
477 unsigned int dirty;
478
479
480 unsigned int coalesce_count;
481
482 union {
483 struct {
484 unsigned int queue_stopped;
485 unsigned int xmit_more;
486 unsigned short cur_mss;
487 unsigned short cur_vlan_ctag;
488 } tx;
489 };
490 } ____cacheline_aligned;
491
492
493
494
495 struct xgbe_channel {
496 char name[16];
497
498
499 struct xgbe_prv_data *pdata;
500
501
502 unsigned int queue_index;
503 void __iomem *dma_regs;
504
505
506 int dma_irq;
507 char dma_irq_name[IFNAMSIZ + 32];
508
509
510 struct napi_struct napi;
511
512
513 unsigned int curr_ier;
514 unsigned int saved_ier;
515
516 unsigned int tx_timer_active;
517 struct timer_list tx_timer;
518
519 struct xgbe_ring *tx_ring;
520 struct xgbe_ring *rx_ring;
521
522 int node;
523 cpumask_t affinity_mask;
524 } ____cacheline_aligned;
525
526 enum xgbe_state {
527 XGBE_DOWN,
528 XGBE_LINK_INIT,
529 XGBE_LINK_ERR,
530 XGBE_STOPPED,
531 };
532
533 enum xgbe_int {
534 XGMAC_INT_DMA_CH_SR_TI,
535 XGMAC_INT_DMA_CH_SR_TPS,
536 XGMAC_INT_DMA_CH_SR_TBU,
537 XGMAC_INT_DMA_CH_SR_RI,
538 XGMAC_INT_DMA_CH_SR_RBU,
539 XGMAC_INT_DMA_CH_SR_RPS,
540 XGMAC_INT_DMA_CH_SR_TI_RI,
541 XGMAC_INT_DMA_CH_SR_FBE,
542 XGMAC_INT_DMA_ALL,
543 };
544
545 enum xgbe_int_state {
546 XGMAC_INT_STATE_SAVE,
547 XGMAC_INT_STATE_RESTORE,
548 };
549
550 enum xgbe_ecc_sec {
551 XGBE_ECC_SEC_TX,
552 XGBE_ECC_SEC_RX,
553 XGBE_ECC_SEC_DESC,
554 };
555
556 enum xgbe_speed {
557 XGBE_SPEED_1000 = 0,
558 XGBE_SPEED_2500,
559 XGBE_SPEED_10000,
560 XGBE_SPEEDS,
561 };
562
563 enum xgbe_xpcs_access {
564 XGBE_XPCS_ACCESS_V1 = 0,
565 XGBE_XPCS_ACCESS_V2,
566 };
567
568 enum xgbe_an_mode {
569 XGBE_AN_MODE_CL73 = 0,
570 XGBE_AN_MODE_CL73_REDRV,
571 XGBE_AN_MODE_CL37,
572 XGBE_AN_MODE_CL37_SGMII,
573 XGBE_AN_MODE_NONE,
574 };
575
576 enum xgbe_an {
577 XGBE_AN_READY = 0,
578 XGBE_AN_PAGE_RECEIVED,
579 XGBE_AN_INCOMPAT_LINK,
580 XGBE_AN_COMPLETE,
581 XGBE_AN_NO_LINK,
582 XGBE_AN_ERROR,
583 };
584
585 enum xgbe_rx {
586 XGBE_RX_BPA = 0,
587 XGBE_RX_XNP,
588 XGBE_RX_COMPLETE,
589 XGBE_RX_ERROR,
590 };
591
592 enum xgbe_mode {
593 XGBE_MODE_KX_1000 = 0,
594 XGBE_MODE_KX_2500,
595 XGBE_MODE_KR,
596 XGBE_MODE_X,
597 XGBE_MODE_SGMII_100,
598 XGBE_MODE_SGMII_1000,
599 XGBE_MODE_SFI,
600 XGBE_MODE_UNKNOWN,
601 };
602
603 enum xgbe_speedset {
604 XGBE_SPEEDSET_1000_10000 = 0,
605 XGBE_SPEEDSET_2500_10000,
606 };
607
608 enum xgbe_mdio_mode {
609 XGBE_MDIO_MODE_NONE = 0,
610 XGBE_MDIO_MODE_CL22,
611 XGBE_MDIO_MODE_CL45,
612 };
613
614 struct xgbe_phy {
615 struct ethtool_link_ksettings lks;
616
617 int address;
618
619 int autoneg;
620 int speed;
621 int duplex;
622
623 int link;
624
625 int pause_autoneg;
626 int tx_pause;
627 int rx_pause;
628 };
629
630 enum xgbe_i2c_cmd {
631 XGBE_I2C_CMD_READ = 0,
632 XGBE_I2C_CMD_WRITE,
633 };
634
635 struct xgbe_i2c_op {
636 enum xgbe_i2c_cmd cmd;
637
638 unsigned int target;
639
640 void *buf;
641 unsigned int len;
642 };
643
644 struct xgbe_i2c_op_state {
645 struct xgbe_i2c_op *op;
646
647 unsigned int tx_len;
648 unsigned char *tx_buf;
649
650 unsigned int rx_len;
651 unsigned char *rx_buf;
652
653 unsigned int tx_abort_source;
654
655 int ret;
656 };
657
658 struct xgbe_i2c {
659 unsigned int started;
660 unsigned int max_speed_mode;
661 unsigned int rx_fifo_size;
662 unsigned int tx_fifo_size;
663
664 struct xgbe_i2c_op_state op_state;
665 };
666
667 struct xgbe_mmc_stats {
668
669 u64 txoctetcount_gb;
670 u64 txframecount_gb;
671 u64 txbroadcastframes_g;
672 u64 txmulticastframes_g;
673 u64 tx64octets_gb;
674 u64 tx65to127octets_gb;
675 u64 tx128to255octets_gb;
676 u64 tx256to511octets_gb;
677 u64 tx512to1023octets_gb;
678 u64 tx1024tomaxoctets_gb;
679 u64 txunicastframes_gb;
680 u64 txmulticastframes_gb;
681 u64 txbroadcastframes_gb;
682 u64 txunderflowerror;
683 u64 txoctetcount_g;
684 u64 txframecount_g;
685 u64 txpauseframes;
686 u64 txvlanframes_g;
687
688
689 u64 rxframecount_gb;
690 u64 rxoctetcount_gb;
691 u64 rxoctetcount_g;
692 u64 rxbroadcastframes_g;
693 u64 rxmulticastframes_g;
694 u64 rxcrcerror;
695 u64 rxrunterror;
696 u64 rxjabbererror;
697 u64 rxundersize_g;
698 u64 rxoversize_g;
699 u64 rx64octets_gb;
700 u64 rx65to127octets_gb;
701 u64 rx128to255octets_gb;
702 u64 rx256to511octets_gb;
703 u64 rx512to1023octets_gb;
704 u64 rx1024tomaxoctets_gb;
705 u64 rxunicastframes_g;
706 u64 rxlengtherror;
707 u64 rxoutofrangetype;
708 u64 rxpauseframes;
709 u64 rxfifooverflow;
710 u64 rxvlanframes_gb;
711 u64 rxwatchdogerror;
712 };
713
714 struct xgbe_ext_stats {
715 u64 tx_tso_packets;
716 u64 rx_split_header_packets;
717 u64 rx_buffer_unavailable;
718
719 u64 txq_packets[XGBE_MAX_DMA_CHANNELS];
720 u64 txq_bytes[XGBE_MAX_DMA_CHANNELS];
721 u64 rxq_packets[XGBE_MAX_DMA_CHANNELS];
722 u64 rxq_bytes[XGBE_MAX_DMA_CHANNELS];
723
724 u64 tx_vxlan_packets;
725 u64 rx_vxlan_packets;
726 u64 rx_csum_errors;
727 u64 rx_vxlan_csum_errors;
728 };
729
730 struct xgbe_hw_if {
731 int (*tx_complete)(struct xgbe_ring_desc *);
732
733 int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
734 int (*config_rx_mode)(struct xgbe_prv_data *);
735
736 int (*enable_rx_csum)(struct xgbe_prv_data *);
737 int (*disable_rx_csum)(struct xgbe_prv_data *);
738
739 int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
740 int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
741 int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
742 int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
743 int (*update_vlan_hash_table)(struct xgbe_prv_data *);
744
745 int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
746 void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
747 int (*set_speed)(struct xgbe_prv_data *, int);
748
749 int (*set_ext_mii_mode)(struct xgbe_prv_data *, unsigned int,
750 enum xgbe_mdio_mode);
751 int (*read_ext_mii_regs)(struct xgbe_prv_data *, int, int);
752 int (*write_ext_mii_regs)(struct xgbe_prv_data *, int, int, u16);
753
754 int (*set_gpio)(struct xgbe_prv_data *, unsigned int);
755 int (*clr_gpio)(struct xgbe_prv_data *, unsigned int);
756
757 void (*enable_tx)(struct xgbe_prv_data *);
758 void (*disable_tx)(struct xgbe_prv_data *);
759 void (*enable_rx)(struct xgbe_prv_data *);
760 void (*disable_rx)(struct xgbe_prv_data *);
761
762 void (*powerup_tx)(struct xgbe_prv_data *);
763 void (*powerdown_tx)(struct xgbe_prv_data *);
764 void (*powerup_rx)(struct xgbe_prv_data *);
765 void (*powerdown_rx)(struct xgbe_prv_data *);
766
767 int (*init)(struct xgbe_prv_data *);
768 int (*exit)(struct xgbe_prv_data *);
769
770 int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
771 int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
772 void (*dev_xmit)(struct xgbe_channel *);
773 int (*dev_read)(struct xgbe_channel *);
774 void (*tx_desc_init)(struct xgbe_channel *);
775 void (*rx_desc_init)(struct xgbe_channel *);
776 void (*tx_desc_reset)(struct xgbe_ring_data *);
777 void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
778 unsigned int);
779 int (*is_last_desc)(struct xgbe_ring_desc *);
780 int (*is_context_desc)(struct xgbe_ring_desc *);
781 void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
782
783
784 int (*config_tx_flow_control)(struct xgbe_prv_data *);
785 int (*config_rx_flow_control)(struct xgbe_prv_data *);
786
787
788 int (*config_rx_coalesce)(struct xgbe_prv_data *);
789 int (*config_tx_coalesce)(struct xgbe_prv_data *);
790 unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
791 unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
792
793
794 int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
795 int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
796
797
798 int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
799 int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
800
801
802 int (*config_osp_mode)(struct xgbe_prv_data *);
803
804
805 void (*rx_mmc_int)(struct xgbe_prv_data *);
806 void (*tx_mmc_int)(struct xgbe_prv_data *);
807 void (*read_mmc_stats)(struct xgbe_prv_data *);
808
809
810 int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
811 void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
812 void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
813 unsigned int nsec);
814 u64 (*get_tstamp_time)(struct xgbe_prv_data *);
815 u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
816
817
818 void (*config_tc)(struct xgbe_prv_data *);
819 void (*config_dcb_tc)(struct xgbe_prv_data *);
820 void (*config_dcb_pfc)(struct xgbe_prv_data *);
821
822
823 int (*enable_rss)(struct xgbe_prv_data *);
824 int (*disable_rss)(struct xgbe_prv_data *);
825 int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
826 int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
827
828
829 void (*disable_ecc_ded)(struct xgbe_prv_data *);
830 void (*disable_ecc_sec)(struct xgbe_prv_data *, enum xgbe_ecc_sec);
831
832
833 void (*enable_vxlan)(struct xgbe_prv_data *);
834 void (*disable_vxlan)(struct xgbe_prv_data *);
835 void (*set_vxlan_id)(struct xgbe_prv_data *);
836 };
837
838
839
840
841
842
843
844
845 struct xgbe_phy_impl_if {
846
847 int (*init)(struct xgbe_prv_data *);
848 void (*exit)(struct xgbe_prv_data *);
849
850
851 int (*reset)(struct xgbe_prv_data *);
852 int (*start)(struct xgbe_prv_data *);
853 void (*stop)(struct xgbe_prv_data *);
854
855
856 int (*link_status)(struct xgbe_prv_data *, int *);
857
858
859 bool (*valid_speed)(struct xgbe_prv_data *, int);
860
861
862 bool (*use_mode)(struct xgbe_prv_data *, enum xgbe_mode);
863
864 void (*set_mode)(struct xgbe_prv_data *, enum xgbe_mode);
865
866 enum xgbe_mode (*get_mode)(struct xgbe_prv_data *, int);
867
868 enum xgbe_mode (*switch_mode)(struct xgbe_prv_data *);
869
870 enum xgbe_mode (*cur_mode)(struct xgbe_prv_data *);
871
872
873 enum xgbe_an_mode (*an_mode)(struct xgbe_prv_data *);
874
875
876 int (*an_config)(struct xgbe_prv_data *);
877
878
879 void (*an_advertising)(struct xgbe_prv_data *,
880 struct ethtool_link_ksettings *);
881
882
883 enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *);
884
885
886 void (*an_pre)(struct xgbe_prv_data *);
887 void (*an_post)(struct xgbe_prv_data *);
888
889
890 void (*kr_training_pre)(struct xgbe_prv_data *);
891 void (*kr_training_post)(struct xgbe_prv_data *);
892
893
894 int (*module_info)(struct xgbe_prv_data *pdata,
895 struct ethtool_modinfo *modinfo);
896 int (*module_eeprom)(struct xgbe_prv_data *pdata,
897 struct ethtool_eeprom *eeprom, u8 *data);
898 };
899
900 struct xgbe_phy_if {
901
902 int (*phy_init)(struct xgbe_prv_data *);
903 void (*phy_exit)(struct xgbe_prv_data *);
904
905
906 int (*phy_reset)(struct xgbe_prv_data *);
907 int (*phy_start)(struct xgbe_prv_data *);
908 void (*phy_stop)(struct xgbe_prv_data *);
909
910
911 void (*phy_status)(struct xgbe_prv_data *);
912 int (*phy_config_aneg)(struct xgbe_prv_data *);
913
914
915 bool (*phy_valid_speed)(struct xgbe_prv_data *, int);
916
917
918 irqreturn_t (*an_isr)(struct xgbe_prv_data *);
919
920
921 int (*module_info)(struct xgbe_prv_data *pdata,
922 struct ethtool_modinfo *modinfo);
923 int (*module_eeprom)(struct xgbe_prv_data *pdata,
924 struct ethtool_eeprom *eeprom, u8 *data);
925
926
927 struct xgbe_phy_impl_if phy_impl;
928 };
929
930 struct xgbe_i2c_if {
931
932 int (*i2c_init)(struct xgbe_prv_data *);
933
934
935 int (*i2c_start)(struct xgbe_prv_data *);
936 void (*i2c_stop)(struct xgbe_prv_data *);
937
938
939 int (*i2c_xfer)(struct xgbe_prv_data *, struct xgbe_i2c_op *);
940
941
942 irqreturn_t (*i2c_isr)(struct xgbe_prv_data *);
943 };
944
945 struct xgbe_desc_if {
946 int (*alloc_ring_resources)(struct xgbe_prv_data *);
947 void (*free_ring_resources)(struct xgbe_prv_data *);
948 int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
949 int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
950 struct xgbe_ring_data *);
951 void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
952 void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
953 void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
954 };
955
956
957
958
959 struct xgbe_hw_features {
960
961 unsigned int version;
962
963
964 unsigned int gmii;
965 unsigned int vlhash;
966 unsigned int sma;
967 unsigned int rwk;
968 unsigned int mgk;
969 unsigned int mmc;
970 unsigned int aoe;
971 unsigned int ts;
972 unsigned int eee;
973 unsigned int tx_coe;
974 unsigned int rx_coe;
975 unsigned int addn_mac;
976 unsigned int ts_src;
977 unsigned int sa_vlan_ins;
978 unsigned int vxn;
979
980
981 unsigned int rx_fifo_size;
982 unsigned int tx_fifo_size;
983 unsigned int adv_ts_hi;
984 unsigned int dma_width;
985 unsigned int dcb;
986 unsigned int sph;
987 unsigned int tso;
988 unsigned int dma_debug;
989 unsigned int rss;
990 unsigned int tc_cnt;
991 unsigned int hash_table_size;
992 unsigned int l3l4_filter_num;
993
994
995 unsigned int rx_q_cnt;
996 unsigned int tx_q_cnt;
997 unsigned int rx_ch_cnt;
998 unsigned int tx_ch_cnt;
999 unsigned int pps_out_num;
1000 unsigned int aux_snap_num;
1001 };
1002
1003 struct xgbe_version_data {
1004 void (*init_function_ptrs_phy_impl)(struct xgbe_phy_if *);
1005 enum xgbe_xpcs_access xpcs_access;
1006 unsigned int mmc_64bit;
1007 unsigned int tx_max_fifo_size;
1008 unsigned int rx_max_fifo_size;
1009 unsigned int tx_tstamp_workaround;
1010 unsigned int ecc_support;
1011 unsigned int i2c_support;
1012 unsigned int irq_reissue_support;
1013 unsigned int tx_desc_prefetch;
1014 unsigned int rx_desc_prefetch;
1015 unsigned int an_cdr_workaround;
1016 };
1017
1018 struct xgbe_vxlan_data {
1019 struct list_head list;
1020 sa_family_t sa_family;
1021 __be16 port;
1022 };
1023
1024 struct xgbe_prv_data {
1025 struct net_device *netdev;
1026 struct pci_dev *pcidev;
1027 struct platform_device *platdev;
1028 struct acpi_device *adev;
1029 struct device *dev;
1030 struct platform_device *phy_platdev;
1031 struct device *phy_dev;
1032
1033
1034 struct xgbe_version_data *vdata;
1035
1036
1037 unsigned int use_acpi;
1038
1039
1040 void __iomem *xgmac_regs;
1041 void __iomem *xpcs_regs;
1042 void __iomem *rxtx_regs;
1043 void __iomem *sir0_regs;
1044 void __iomem *sir1_regs;
1045 void __iomem *xprop_regs;
1046 void __iomem *xi2c_regs;
1047
1048
1049 unsigned int pp0;
1050 unsigned int pp1;
1051 unsigned int pp2;
1052 unsigned int pp3;
1053 unsigned int pp4;
1054
1055
1056 spinlock_t lock;
1057
1058
1059 spinlock_t xpcs_lock;
1060 unsigned int xpcs_window_def_reg;
1061 unsigned int xpcs_window_sel_reg;
1062 unsigned int xpcs_window;
1063 unsigned int xpcs_window_size;
1064 unsigned int xpcs_window_mask;
1065
1066
1067 struct mutex rss_mutex;
1068
1069
1070 unsigned long dev_state;
1071
1072
1073 unsigned long tx_sec_period;
1074 unsigned long tx_ded_period;
1075 unsigned long rx_sec_period;
1076 unsigned long rx_ded_period;
1077 unsigned long desc_sec_period;
1078 unsigned long desc_ded_period;
1079
1080 unsigned int tx_sec_count;
1081 unsigned int tx_ded_count;
1082 unsigned int rx_sec_count;
1083 unsigned int rx_ded_count;
1084 unsigned int desc_ded_count;
1085 unsigned int desc_sec_count;
1086
1087 int dev_irq;
1088 int ecc_irq;
1089 int i2c_irq;
1090 int channel_irq[XGBE_MAX_DMA_CHANNELS];
1091
1092 unsigned int per_channel_irq;
1093 unsigned int irq_count;
1094 unsigned int channel_irq_count;
1095 unsigned int channel_irq_mode;
1096
1097 char ecc_name[IFNAMSIZ + 32];
1098
1099 struct xgbe_hw_if hw_if;
1100 struct xgbe_phy_if phy_if;
1101 struct xgbe_desc_if desc_if;
1102 struct xgbe_i2c_if i2c_if;
1103
1104
1105 unsigned int coherent;
1106 unsigned int arcr;
1107 unsigned int awcr;
1108 unsigned int awarcr;
1109
1110
1111 struct workqueue_struct *dev_workqueue;
1112 struct work_struct service_work;
1113 struct timer_list service_timer;
1114
1115
1116 struct xgbe_channel *channel[XGBE_MAX_DMA_CHANNELS];
1117 unsigned int tx_max_channel_count;
1118 unsigned int rx_max_channel_count;
1119 unsigned int channel_count;
1120 unsigned int tx_ring_count;
1121 unsigned int tx_desc_count;
1122 unsigned int rx_ring_count;
1123 unsigned int rx_desc_count;
1124
1125 unsigned int new_tx_ring_count;
1126 unsigned int new_rx_ring_count;
1127
1128 unsigned int tx_max_q_count;
1129 unsigned int rx_max_q_count;
1130 unsigned int tx_q_count;
1131 unsigned int rx_q_count;
1132
1133
1134 unsigned int blen;
1135 unsigned int pbl;
1136 unsigned int aal;
1137 unsigned int rd_osr_limit;
1138 unsigned int wr_osr_limit;
1139
1140
1141 unsigned int tx_sf_mode;
1142 unsigned int tx_threshold;
1143 unsigned int tx_osp_mode;
1144 unsigned int tx_max_fifo_size;
1145
1146
1147 unsigned int rx_sf_mode;
1148 unsigned int rx_threshold;
1149 unsigned int rx_max_fifo_size;
1150
1151
1152 unsigned int tx_usecs;
1153 unsigned int tx_frames;
1154
1155
1156 unsigned int rx_riwt;
1157 unsigned int rx_usecs;
1158 unsigned int rx_frames;
1159
1160
1161 unsigned int rx_buf_size;
1162
1163
1164 unsigned int pause_autoneg;
1165 unsigned int tx_pause;
1166 unsigned int rx_pause;
1167 unsigned int rx_rfa[XGBE_MAX_QUEUES];
1168 unsigned int rx_rfd[XGBE_MAX_QUEUES];
1169
1170
1171 u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
1172 u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
1173 u32 rss_options;
1174
1175
1176 unsigned int vxlan_port_set;
1177 unsigned int vxlan_offloads_set;
1178 unsigned int vxlan_force_disable;
1179 unsigned int vxlan_port_count;
1180 struct list_head vxlan_ports;
1181 u16 vxlan_port;
1182 netdev_features_t vxlan_features;
1183
1184
1185 unsigned char mac_addr[ETH_ALEN];
1186 netdev_features_t netdev_features;
1187 struct napi_struct napi;
1188 struct xgbe_mmc_stats mmc_stats;
1189 struct xgbe_ext_stats ext_stats;
1190
1191
1192 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
1193
1194
1195 struct clk *sysclk;
1196 unsigned long sysclk_rate;
1197 struct clk *ptpclk;
1198 unsigned long ptpclk_rate;
1199
1200
1201 spinlock_t tstamp_lock;
1202 struct ptp_clock_info ptp_clock_info;
1203 struct ptp_clock *ptp_clock;
1204 struct hwtstamp_config tstamp_config;
1205 struct cyclecounter tstamp_cc;
1206 struct timecounter tstamp_tc;
1207 unsigned int tstamp_addend;
1208 struct work_struct tx_tstamp_work;
1209 struct sk_buff *tx_tstamp_skb;
1210 u64 tx_tstamp;
1211
1212
1213 struct ieee_ets *ets;
1214 struct ieee_pfc *pfc;
1215 unsigned int q2tc_map[XGBE_MAX_QUEUES];
1216 unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
1217 unsigned int pfcq[XGBE_MAX_QUEUES];
1218 unsigned int pfc_rfa;
1219 u8 num_tcs;
1220
1221
1222 struct xgbe_hw_features hw_feat;
1223
1224
1225 struct work_struct restart_work;
1226 struct work_struct stopdev_work;
1227
1228
1229 unsigned int power_down;
1230
1231
1232 u32 msg_enable;
1233
1234
1235 phy_interface_t phy_mode;
1236 int phy_link;
1237 int phy_speed;
1238
1239
1240 unsigned int phy_started;
1241 void *phy_data;
1242 struct xgbe_phy phy;
1243 int mdio_mmd;
1244 unsigned long link_check;
1245 struct completion mdio_complete;
1246
1247 unsigned int kr_redrv;
1248
1249 char an_name[IFNAMSIZ + 32];
1250 struct workqueue_struct *an_workqueue;
1251
1252 int an_irq;
1253 struct work_struct an_irq_work;
1254
1255
1256 unsigned int an_int;
1257 unsigned int an_status;
1258 struct mutex an_mutex;
1259 enum xgbe_an an_result;
1260 enum xgbe_an an_state;
1261 enum xgbe_rx kr_state;
1262 enum xgbe_rx kx_state;
1263 struct work_struct an_work;
1264 unsigned int an_again;
1265 unsigned int an_supported;
1266 unsigned int parallel_detect;
1267 unsigned int fec_ability;
1268 unsigned long an_start;
1269 enum xgbe_an_mode an_mode;
1270
1271
1272 struct xgbe_i2c i2c;
1273 struct mutex i2c_mutex;
1274 struct completion i2c_complete;
1275 char i2c_name[IFNAMSIZ + 32];
1276
1277 unsigned int lpm_ctrl;
1278
1279 unsigned int isr_as_tasklet;
1280 struct tasklet_struct tasklet_dev;
1281 struct tasklet_struct tasklet_ecc;
1282 struct tasklet_struct tasklet_i2c;
1283 struct tasklet_struct tasklet_an;
1284
1285 struct dentry *xgbe_debugfs;
1286
1287 unsigned int debugfs_xgmac_reg;
1288
1289 unsigned int debugfs_xpcs_mmd;
1290 unsigned int debugfs_xpcs_reg;
1291
1292 unsigned int debugfs_xprop_reg;
1293
1294 unsigned int debugfs_xi2c_reg;
1295
1296 bool debugfs_an_cdr_workaround;
1297 bool debugfs_an_cdr_track_early;
1298 };
1299
1300
1301 struct xgbe_prv_data *xgbe_alloc_pdata(struct device *);
1302 void xgbe_free_pdata(struct xgbe_prv_data *);
1303 void xgbe_set_counts(struct xgbe_prv_data *);
1304 int xgbe_config_netdev(struct xgbe_prv_data *);
1305 void xgbe_deconfig_netdev(struct xgbe_prv_data *);
1306
1307 int xgbe_platform_init(void);
1308 void xgbe_platform_exit(void);
1309 #ifdef CONFIG_PCI
1310 int xgbe_pci_init(void);
1311 void xgbe_pci_exit(void);
1312 #else
1313 static inline int xgbe_pci_init(void) { return 0; }
1314 static inline void xgbe_pci_exit(void) { }
1315 #endif
1316
1317 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
1318 void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
1319 void xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if *);
1320 void xgbe_init_function_ptrs_phy_v2(struct xgbe_phy_if *);
1321 void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
1322 void xgbe_init_function_ptrs_i2c(struct xgbe_i2c_if *);
1323 const struct net_device_ops *xgbe_get_netdev_ops(void);
1324 const struct ethtool_ops *xgbe_get_ethtool_ops(void);
1325
1326 #ifdef CONFIG_AMD_XGBE_DCB
1327 const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
1328 #endif
1329
1330 void xgbe_ptp_register(struct xgbe_prv_data *);
1331 void xgbe_ptp_unregister(struct xgbe_prv_data *);
1332 void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
1333 unsigned int, unsigned int, unsigned int);
1334 void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
1335 unsigned int);
1336 void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
1337 void xgbe_get_all_hw_features(struct xgbe_prv_data *);
1338 int xgbe_powerup(struct net_device *, unsigned int);
1339 int xgbe_powerdown(struct net_device *, unsigned int);
1340 void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
1341 void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
1342 void xgbe_restart_dev(struct xgbe_prv_data *pdata);
1343 void xgbe_full_restart_dev(struct xgbe_prv_data *pdata);
1344
1345 #ifdef CONFIG_DEBUG_FS
1346 void xgbe_debugfs_init(struct xgbe_prv_data *);
1347 void xgbe_debugfs_exit(struct xgbe_prv_data *);
1348 void xgbe_debugfs_rename(struct xgbe_prv_data *pdata);
1349 #else
1350 static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
1351 static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
1352 static inline void xgbe_debugfs_rename(struct xgbe_prv_data *pdata) {}
1353 #endif
1354
1355
1356 #if 0
1357 #define YDEBUG
1358 #define YDEBUG_MDIO
1359 #endif
1360
1361
1362 #ifdef YDEBUG
1363 #define DBGPR(x...) pr_alert(x)
1364 #else
1365 #define DBGPR(x...) do { } while (0)
1366 #endif
1367
1368 #ifdef YDEBUG_MDIO
1369 #define DBGPR_MDIO(x...) pr_alert(x)
1370 #else
1371 #define DBGPR_MDIO(x...) do { } while (0)
1372 #endif
1373
1374 #endif