0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 #ifndef __XGBE_H__
0118 #define __XGBE_H__
0119
0120 #include <linux/dma-mapping.h>
0121 #include <linux/netdevice.h>
0122 #include <linux/workqueue.h>
0123 #include <linux/phy.h>
0124 #include <linux/if_vlan.h>
0125 #include <linux/bitops.h>
0126 #include <linux/ptp_clock_kernel.h>
0127 #include <linux/timecounter.h>
0128 #include <linux/net_tstamp.h>
0129 #include <net/dcbnl.h>
0130 #include <linux/completion.h>
0131 #include <linux/cpumask.h>
0132 #include <linux/interrupt.h>
0133 #include <linux/dcache.h>
0134 #include <linux/ethtool.h>
0135 #include <linux/list.h>
0136
0137 #define XGBE_DRV_NAME "amd-xgbe"
0138 #define XGBE_DRV_DESC "AMD 10 Gigabit Ethernet Driver"
0139
0140
0141 #define XGBE_TX_DESC_CNT 512
0142 #define XGBE_TX_DESC_MIN_FREE (XGBE_TX_DESC_CNT >> 3)
0143 #define XGBE_TX_DESC_MAX_PROC (XGBE_TX_DESC_CNT >> 1)
0144 #define XGBE_RX_DESC_CNT 512
0145
0146 #define XGBE_TX_DESC_CNT_MIN 64
0147 #define XGBE_TX_DESC_CNT_MAX 4096
0148 #define XGBE_RX_DESC_CNT_MIN 64
0149 #define XGBE_RX_DESC_CNT_MAX 4096
0150
0151 #define XGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
0152
0153
0154 #define XGBE_TX_MAX_SPLIT \
0155 ((GSO_LEGACY_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
0156
0157
0158
0159
0160
0161
0162
0163 #define XGBE_TX_MAX_DESCS (MAX_SKB_FRAGS + XGBE_TX_MAX_SPLIT + 2)
0164
0165 #define XGBE_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
0166 #define XGBE_RX_BUF_ALIGN 64
0167 #define XGBE_SKB_ALLOC_SIZE 256
0168 #define XGBE_SPH_HDSMS_SIZE 2
0169
0170 #define XGBE_MAX_DMA_CHANNELS 16
0171 #define XGBE_MAX_QUEUES 16
0172 #define XGBE_PRIORITY_QUEUES 8
0173 #define XGBE_DMA_STOP_TIMEOUT 1
0174
0175
0176 #define XGBE_DMA_OS_ARCR 0x002b2b2b
0177 #define XGBE_DMA_OS_AWCR 0x2f2f2f2f
0178
0179
0180 #define XGBE_DMA_SYS_ARCR 0x00303030
0181 #define XGBE_DMA_SYS_AWCR 0x30303030
0182
0183
0184 #define XGBE_DMA_PCI_ARCR 0x000f0f0f
0185 #define XGBE_DMA_PCI_AWCR 0x0f0f0f0f
0186 #define XGBE_DMA_PCI_AWARCR 0x00000f0f
0187
0188
0189 #define XGBE_IRQ_MODE_EDGE 0
0190 #define XGBE_IRQ_MODE_LEVEL 1
0191
0192 #define XGMAC_MIN_PACKET 60
0193 #define XGMAC_STD_PACKET_MTU 1500
0194 #define XGMAC_MAX_STD_PACKET 1518
0195 #define XGMAC_JUMBO_PACKET_MTU 9000
0196 #define XGMAC_MAX_JUMBO_PACKET 9018
0197 #define XGMAC_ETH_PREAMBLE (12 + 8)
0198
0199 #define XGMAC_PFC_DATA_LEN 46
0200 #define XGMAC_PFC_DELAYS 14000
0201
0202 #define XGMAC_PRIO_QUEUES(_cnt) \
0203 min_t(unsigned int, IEEE_8021QAZ_MAX_TCS, (_cnt))
0204
0205
0206 #define XGBE_MAC_ADDR_PROPERTY "mac-address"
0207 #define XGBE_PHY_MODE_PROPERTY "phy-mode"
0208 #define XGBE_DMA_IRQS_PROPERTY "amd,per-channel-interrupt"
0209 #define XGBE_SPEEDSET_PROPERTY "amd,speed-set"
0210
0211
0212 #define XGBE_DMA_CLOCK "dma_clk"
0213 #define XGBE_PTP_CLOCK "ptp_clk"
0214
0215
0216 #define XGBE_ACPI_DMA_FREQ "amd,dma-freq"
0217 #define XGBE_ACPI_PTP_FREQ "amd,ptp-freq"
0218
0219
0220 #define XGBE_XGMAC_BAR 0
0221 #define XGBE_XPCS_BAR 1
0222 #define XGBE_MAC_PROP_OFFSET 0x1d000
0223 #define XGBE_I2C_CTRL_OFFSET 0x1e000
0224
0225
0226 #define XGBE_MSI_BASE_COUNT 4
0227 #define XGBE_MSI_MIN_COUNT (XGBE_MSI_BASE_COUNT + 1)
0228
0229
0230 #define XGBE_V2_DMA_CLOCK_FREQ 500000000
0231 #define XGBE_V2_PTP_CLOCK_FREQ 125000000
0232
0233
0234
0235
0236 #define XGBE_TSTAMP_SSINC 20
0237 #define XGBE_TSTAMP_SNSINC 0
0238
0239
0240 #define XGMAC_DRIVER_CONTEXT 1
0241 #define XGMAC_IOCTL_CONTEXT 2
0242
0243 #define XGMAC_FIFO_MIN_ALLOC 2048
0244 #define XGMAC_FIFO_UNIT 256
0245 #define XGMAC_FIFO_ALIGN(_x) \
0246 (((_x) + XGMAC_FIFO_UNIT - 1) & ~(XGMAC_FIFO_UNIT - 1))
0247 #define XGMAC_FIFO_FC_OFF 2048
0248 #define XGMAC_FIFO_FC_MIN 4096
0249
0250 #define XGBE_TC_MIN_QUANTUM 10
0251
0252
0253
0254
0255
0256
0257
0258 #define XGBE_GET_DESC_DATA(_ring, _idx) \
0259 ((_ring)->rdata + \
0260 ((_idx) & ((_ring)->rdesc_count - 1)))
0261
0262
0263 #define XGMAC_INIT_DMA_TX_USECS 1000
0264 #define XGMAC_INIT_DMA_TX_FRAMES 25
0265
0266 #define XGMAC_MAX_DMA_RIWT 0xff
0267 #define XGMAC_INIT_DMA_RX_USECS 30
0268 #define XGMAC_INIT_DMA_RX_FRAMES 25
0269
0270
0271 #define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
0272
0273
0274 #define XGMAC_FLOW_CONTROL_UNIT 512
0275 #define XGMAC_FLOW_CONTROL_ALIGN(_x) \
0276 (((_x) + XGMAC_FLOW_CONTROL_UNIT - 1) & ~(XGMAC_FLOW_CONTROL_UNIT - 1))
0277 #define XGMAC_FLOW_CONTROL_VALUE(_x) \
0278 (((_x) < 1024) ? 0 : ((_x) / XGMAC_FLOW_CONTROL_UNIT) - 2)
0279 #define XGMAC_FLOW_CONTROL_MAX 33280
0280
0281
0282 #define XGBE_MAC_HASH_TABLE_SIZE 8
0283
0284
0285 #define XGBE_RSS_HASH_KEY_SIZE 40
0286 #define XGBE_RSS_MAX_TABLE_SIZE 256
0287 #define XGBE_RSS_LOOKUP_TABLE_TYPE 0
0288 #define XGBE_RSS_HASH_KEY_TYPE 1
0289
0290
0291 #define XGBE_AN_MS_TIMEOUT 500
0292 #define XGBE_LINK_TIMEOUT 5
0293
0294 #define XGBE_SGMII_AN_LINK_STATUS BIT(1)
0295 #define XGBE_SGMII_AN_LINK_SPEED (BIT(2) | BIT(3))
0296 #define XGBE_SGMII_AN_LINK_SPEED_100 0x04
0297 #define XGBE_SGMII_AN_LINK_SPEED_1000 0x08
0298 #define XGBE_SGMII_AN_LINK_DUPLEX BIT(4)
0299
0300
0301 #define XGBE_ECC_LIMIT 60
0302
0303
0304 #define XGMAC_MAX_C22_PORT 3
0305
0306
0307 #define XGBE_ZERO_SUP(_ls) \
0308 ethtool_link_ksettings_zero_link_mode((_ls), supported)
0309
0310 #define XGBE_SET_SUP(_ls, _mode) \
0311 ethtool_link_ksettings_add_link_mode((_ls), supported, _mode)
0312
0313 #define XGBE_CLR_SUP(_ls, _mode) \
0314 ethtool_link_ksettings_del_link_mode((_ls), supported, _mode)
0315
0316 #define XGBE_IS_SUP(_ls, _mode) \
0317 ethtool_link_ksettings_test_link_mode((_ls), supported, _mode)
0318
0319 #define XGBE_ZERO_ADV(_ls) \
0320 ethtool_link_ksettings_zero_link_mode((_ls), advertising)
0321
0322 #define XGBE_SET_ADV(_ls, _mode) \
0323 ethtool_link_ksettings_add_link_mode((_ls), advertising, _mode)
0324
0325 #define XGBE_CLR_ADV(_ls, _mode) \
0326 ethtool_link_ksettings_del_link_mode((_ls), advertising, _mode)
0327
0328 #define XGBE_ADV(_ls, _mode) \
0329 ethtool_link_ksettings_test_link_mode((_ls), advertising, _mode)
0330
0331 #define XGBE_ZERO_LP_ADV(_ls) \
0332 ethtool_link_ksettings_zero_link_mode((_ls), lp_advertising)
0333
0334 #define XGBE_SET_LP_ADV(_ls, _mode) \
0335 ethtool_link_ksettings_add_link_mode((_ls), lp_advertising, _mode)
0336
0337 #define XGBE_CLR_LP_ADV(_ls, _mode) \
0338 ethtool_link_ksettings_del_link_mode((_ls), lp_advertising, _mode)
0339
0340 #define XGBE_LP_ADV(_ls, _mode) \
0341 ethtool_link_ksettings_test_link_mode((_ls), lp_advertising, _mode)
0342
0343 #define XGBE_LM_COPY(_dst, _dname, _src, _sname) \
0344 bitmap_copy((_dst)->link_modes._dname, \
0345 (_src)->link_modes._sname, \
0346 __ETHTOOL_LINK_MODE_MASK_NBITS)
0347
0348 struct xgbe_prv_data;
0349
0350 struct xgbe_packet_data {
0351 struct sk_buff *skb;
0352
0353 unsigned int attributes;
0354
0355 unsigned int errors;
0356
0357 unsigned int rdesc_count;
0358 unsigned int length;
0359
0360 unsigned int header_len;
0361 unsigned int tcp_header_len;
0362 unsigned int tcp_payload_len;
0363 unsigned short mss;
0364
0365 unsigned short vlan_ctag;
0366
0367 u64 rx_tstamp;
0368
0369 u32 rss_hash;
0370 enum pkt_hash_types rss_hash_type;
0371
0372 unsigned int tx_packets;
0373 unsigned int tx_bytes;
0374 };
0375
0376
0377 struct xgbe_ring_desc {
0378 __le32 desc0;
0379 __le32 desc1;
0380 __le32 desc2;
0381 __le32 desc3;
0382 };
0383
0384
0385 struct xgbe_page_alloc {
0386 struct page *pages;
0387 unsigned int pages_len;
0388 unsigned int pages_offset;
0389
0390 dma_addr_t pages_dma;
0391 };
0392
0393
0394 struct xgbe_buffer_data {
0395 struct xgbe_page_alloc pa;
0396 struct xgbe_page_alloc pa_unmap;
0397
0398 dma_addr_t dma_base;
0399 unsigned long dma_off;
0400 unsigned int dma_len;
0401 };
0402
0403
0404 struct xgbe_tx_ring_data {
0405 unsigned int packets;
0406 unsigned int bytes;
0407 };
0408
0409
0410 struct xgbe_rx_ring_data {
0411 struct xgbe_buffer_data hdr;
0412 struct xgbe_buffer_data buf;
0413
0414 unsigned short hdr_len;
0415 unsigned short len;
0416 };
0417
0418
0419
0420
0421
0422 struct xgbe_ring_data {
0423 struct xgbe_ring_desc *rdesc;
0424 dma_addr_t rdesc_dma;
0425
0426 struct sk_buff *skb;
0427 dma_addr_t skb_dma;
0428 unsigned int skb_dma_len;
0429
0430 struct xgbe_tx_ring_data tx;
0431 struct xgbe_rx_ring_data rx;
0432
0433 unsigned int mapped_as_page;
0434
0435
0436
0437
0438
0439
0440 unsigned int state_saved;
0441 struct {
0442 struct sk_buff *skb;
0443 unsigned int len;
0444 unsigned int error;
0445 } state;
0446 };
0447
0448 struct xgbe_ring {
0449
0450 spinlock_t lock;
0451
0452
0453 struct xgbe_packet_data packet_data;
0454
0455
0456 struct xgbe_ring_desc *rdesc;
0457 dma_addr_t rdesc_dma;
0458 unsigned int rdesc_count;
0459
0460
0461
0462
0463 struct xgbe_ring_data *rdata;
0464
0465
0466 struct xgbe_page_alloc rx_hdr_pa;
0467 struct xgbe_page_alloc rx_buf_pa;
0468 int node;
0469
0470
0471
0472
0473
0474
0475
0476 unsigned int cur;
0477 unsigned int dirty;
0478
0479
0480 unsigned int coalesce_count;
0481
0482 union {
0483 struct {
0484 unsigned int queue_stopped;
0485 unsigned int xmit_more;
0486 unsigned short cur_mss;
0487 unsigned short cur_vlan_ctag;
0488 } tx;
0489 };
0490 } ____cacheline_aligned;
0491
0492
0493
0494
0495 struct xgbe_channel {
0496 char name[16];
0497
0498
0499 struct xgbe_prv_data *pdata;
0500
0501
0502 unsigned int queue_index;
0503 void __iomem *dma_regs;
0504
0505
0506 int dma_irq;
0507 char dma_irq_name[IFNAMSIZ + 32];
0508
0509
0510 struct napi_struct napi;
0511
0512
0513 unsigned int curr_ier;
0514 unsigned int saved_ier;
0515
0516 unsigned int tx_timer_active;
0517 struct timer_list tx_timer;
0518
0519 struct xgbe_ring *tx_ring;
0520 struct xgbe_ring *rx_ring;
0521
0522 int node;
0523 cpumask_t affinity_mask;
0524 } ____cacheline_aligned;
0525
0526 enum xgbe_state {
0527 XGBE_DOWN,
0528 XGBE_LINK_INIT,
0529 XGBE_LINK_ERR,
0530 XGBE_STOPPED,
0531 };
0532
0533 enum xgbe_int {
0534 XGMAC_INT_DMA_CH_SR_TI,
0535 XGMAC_INT_DMA_CH_SR_TPS,
0536 XGMAC_INT_DMA_CH_SR_TBU,
0537 XGMAC_INT_DMA_CH_SR_RI,
0538 XGMAC_INT_DMA_CH_SR_RBU,
0539 XGMAC_INT_DMA_CH_SR_RPS,
0540 XGMAC_INT_DMA_CH_SR_TI_RI,
0541 XGMAC_INT_DMA_CH_SR_FBE,
0542 XGMAC_INT_DMA_ALL,
0543 };
0544
0545 enum xgbe_int_state {
0546 XGMAC_INT_STATE_SAVE,
0547 XGMAC_INT_STATE_RESTORE,
0548 };
0549
0550 enum xgbe_ecc_sec {
0551 XGBE_ECC_SEC_TX,
0552 XGBE_ECC_SEC_RX,
0553 XGBE_ECC_SEC_DESC,
0554 };
0555
0556 enum xgbe_speed {
0557 XGBE_SPEED_1000 = 0,
0558 XGBE_SPEED_2500,
0559 XGBE_SPEED_10000,
0560 XGBE_SPEEDS,
0561 };
0562
0563 enum xgbe_xpcs_access {
0564 XGBE_XPCS_ACCESS_V1 = 0,
0565 XGBE_XPCS_ACCESS_V2,
0566 };
0567
0568 enum xgbe_an_mode {
0569 XGBE_AN_MODE_CL73 = 0,
0570 XGBE_AN_MODE_CL73_REDRV,
0571 XGBE_AN_MODE_CL37,
0572 XGBE_AN_MODE_CL37_SGMII,
0573 XGBE_AN_MODE_NONE,
0574 };
0575
0576 enum xgbe_an {
0577 XGBE_AN_READY = 0,
0578 XGBE_AN_PAGE_RECEIVED,
0579 XGBE_AN_INCOMPAT_LINK,
0580 XGBE_AN_COMPLETE,
0581 XGBE_AN_NO_LINK,
0582 XGBE_AN_ERROR,
0583 };
0584
0585 enum xgbe_rx {
0586 XGBE_RX_BPA = 0,
0587 XGBE_RX_XNP,
0588 XGBE_RX_COMPLETE,
0589 XGBE_RX_ERROR,
0590 };
0591
0592 enum xgbe_mode {
0593 XGBE_MODE_KX_1000 = 0,
0594 XGBE_MODE_KX_2500,
0595 XGBE_MODE_KR,
0596 XGBE_MODE_X,
0597 XGBE_MODE_SGMII_100,
0598 XGBE_MODE_SGMII_1000,
0599 XGBE_MODE_SFI,
0600 XGBE_MODE_UNKNOWN,
0601 };
0602
0603 enum xgbe_speedset {
0604 XGBE_SPEEDSET_1000_10000 = 0,
0605 XGBE_SPEEDSET_2500_10000,
0606 };
0607
0608 enum xgbe_mdio_mode {
0609 XGBE_MDIO_MODE_NONE = 0,
0610 XGBE_MDIO_MODE_CL22,
0611 XGBE_MDIO_MODE_CL45,
0612 };
0613
0614 struct xgbe_phy {
0615 struct ethtool_link_ksettings lks;
0616
0617 int address;
0618
0619 int autoneg;
0620 int speed;
0621 int duplex;
0622
0623 int link;
0624
0625 int pause_autoneg;
0626 int tx_pause;
0627 int rx_pause;
0628 };
0629
0630 enum xgbe_i2c_cmd {
0631 XGBE_I2C_CMD_READ = 0,
0632 XGBE_I2C_CMD_WRITE,
0633 };
0634
0635 struct xgbe_i2c_op {
0636 enum xgbe_i2c_cmd cmd;
0637
0638 unsigned int target;
0639
0640 void *buf;
0641 unsigned int len;
0642 };
0643
0644 struct xgbe_i2c_op_state {
0645 struct xgbe_i2c_op *op;
0646
0647 unsigned int tx_len;
0648 unsigned char *tx_buf;
0649
0650 unsigned int rx_len;
0651 unsigned char *rx_buf;
0652
0653 unsigned int tx_abort_source;
0654
0655 int ret;
0656 };
0657
0658 struct xgbe_i2c {
0659 unsigned int started;
0660 unsigned int max_speed_mode;
0661 unsigned int rx_fifo_size;
0662 unsigned int tx_fifo_size;
0663
0664 struct xgbe_i2c_op_state op_state;
0665 };
0666
0667 struct xgbe_mmc_stats {
0668
0669 u64 txoctetcount_gb;
0670 u64 txframecount_gb;
0671 u64 txbroadcastframes_g;
0672 u64 txmulticastframes_g;
0673 u64 tx64octets_gb;
0674 u64 tx65to127octets_gb;
0675 u64 tx128to255octets_gb;
0676 u64 tx256to511octets_gb;
0677 u64 tx512to1023octets_gb;
0678 u64 tx1024tomaxoctets_gb;
0679 u64 txunicastframes_gb;
0680 u64 txmulticastframes_gb;
0681 u64 txbroadcastframes_gb;
0682 u64 txunderflowerror;
0683 u64 txoctetcount_g;
0684 u64 txframecount_g;
0685 u64 txpauseframes;
0686 u64 txvlanframes_g;
0687
0688
0689 u64 rxframecount_gb;
0690 u64 rxoctetcount_gb;
0691 u64 rxoctetcount_g;
0692 u64 rxbroadcastframes_g;
0693 u64 rxmulticastframes_g;
0694 u64 rxcrcerror;
0695 u64 rxrunterror;
0696 u64 rxjabbererror;
0697 u64 rxundersize_g;
0698 u64 rxoversize_g;
0699 u64 rx64octets_gb;
0700 u64 rx65to127octets_gb;
0701 u64 rx128to255octets_gb;
0702 u64 rx256to511octets_gb;
0703 u64 rx512to1023octets_gb;
0704 u64 rx1024tomaxoctets_gb;
0705 u64 rxunicastframes_g;
0706 u64 rxlengtherror;
0707 u64 rxoutofrangetype;
0708 u64 rxpauseframes;
0709 u64 rxfifooverflow;
0710 u64 rxvlanframes_gb;
0711 u64 rxwatchdogerror;
0712 };
0713
0714 struct xgbe_ext_stats {
0715 u64 tx_tso_packets;
0716 u64 rx_split_header_packets;
0717 u64 rx_buffer_unavailable;
0718
0719 u64 txq_packets[XGBE_MAX_DMA_CHANNELS];
0720 u64 txq_bytes[XGBE_MAX_DMA_CHANNELS];
0721 u64 rxq_packets[XGBE_MAX_DMA_CHANNELS];
0722 u64 rxq_bytes[XGBE_MAX_DMA_CHANNELS];
0723
0724 u64 tx_vxlan_packets;
0725 u64 rx_vxlan_packets;
0726 u64 rx_csum_errors;
0727 u64 rx_vxlan_csum_errors;
0728 };
0729
0730 struct xgbe_hw_if {
0731 int (*tx_complete)(struct xgbe_ring_desc *);
0732
0733 int (*set_mac_address)(struct xgbe_prv_data *, const u8 *addr);
0734 int (*config_rx_mode)(struct xgbe_prv_data *);
0735
0736 int (*enable_rx_csum)(struct xgbe_prv_data *);
0737 int (*disable_rx_csum)(struct xgbe_prv_data *);
0738
0739 int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
0740 int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
0741 int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
0742 int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
0743 int (*update_vlan_hash_table)(struct xgbe_prv_data *);
0744
0745 int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
0746 void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
0747 int (*set_speed)(struct xgbe_prv_data *, int);
0748
0749 int (*set_ext_mii_mode)(struct xgbe_prv_data *, unsigned int,
0750 enum xgbe_mdio_mode);
0751 int (*read_ext_mii_regs)(struct xgbe_prv_data *, int, int);
0752 int (*write_ext_mii_regs)(struct xgbe_prv_data *, int, int, u16);
0753
0754 int (*set_gpio)(struct xgbe_prv_data *, unsigned int);
0755 int (*clr_gpio)(struct xgbe_prv_data *, unsigned int);
0756
0757 void (*enable_tx)(struct xgbe_prv_data *);
0758 void (*disable_tx)(struct xgbe_prv_data *);
0759 void (*enable_rx)(struct xgbe_prv_data *);
0760 void (*disable_rx)(struct xgbe_prv_data *);
0761
0762 void (*powerup_tx)(struct xgbe_prv_data *);
0763 void (*powerdown_tx)(struct xgbe_prv_data *);
0764 void (*powerup_rx)(struct xgbe_prv_data *);
0765 void (*powerdown_rx)(struct xgbe_prv_data *);
0766
0767 int (*init)(struct xgbe_prv_data *);
0768 int (*exit)(struct xgbe_prv_data *);
0769
0770 int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
0771 int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
0772 void (*dev_xmit)(struct xgbe_channel *);
0773 int (*dev_read)(struct xgbe_channel *);
0774 void (*tx_desc_init)(struct xgbe_channel *);
0775 void (*rx_desc_init)(struct xgbe_channel *);
0776 void (*tx_desc_reset)(struct xgbe_ring_data *);
0777 void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
0778 unsigned int);
0779 int (*is_last_desc)(struct xgbe_ring_desc *);
0780 int (*is_context_desc)(struct xgbe_ring_desc *);
0781 void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
0782
0783
0784 int (*config_tx_flow_control)(struct xgbe_prv_data *);
0785 int (*config_rx_flow_control)(struct xgbe_prv_data *);
0786
0787
0788 int (*config_rx_coalesce)(struct xgbe_prv_data *);
0789 int (*config_tx_coalesce)(struct xgbe_prv_data *);
0790 unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
0791 unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
0792
0793
0794 int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
0795 int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
0796
0797
0798 int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
0799 int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
0800
0801
0802 int (*config_osp_mode)(struct xgbe_prv_data *);
0803
0804
0805 void (*rx_mmc_int)(struct xgbe_prv_data *);
0806 void (*tx_mmc_int)(struct xgbe_prv_data *);
0807 void (*read_mmc_stats)(struct xgbe_prv_data *);
0808
0809
0810 int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
0811 void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
0812 void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
0813 unsigned int nsec);
0814 u64 (*get_tstamp_time)(struct xgbe_prv_data *);
0815 u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
0816
0817
0818 void (*config_tc)(struct xgbe_prv_data *);
0819 void (*config_dcb_tc)(struct xgbe_prv_data *);
0820 void (*config_dcb_pfc)(struct xgbe_prv_data *);
0821
0822
0823 int (*enable_rss)(struct xgbe_prv_data *);
0824 int (*disable_rss)(struct xgbe_prv_data *);
0825 int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
0826 int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
0827
0828
0829 void (*disable_ecc_ded)(struct xgbe_prv_data *);
0830 void (*disable_ecc_sec)(struct xgbe_prv_data *, enum xgbe_ecc_sec);
0831
0832
0833 void (*enable_vxlan)(struct xgbe_prv_data *);
0834 void (*disable_vxlan)(struct xgbe_prv_data *);
0835 void (*set_vxlan_id)(struct xgbe_prv_data *);
0836 };
0837
0838
0839
0840
0841
0842
0843
0844
0845 struct xgbe_phy_impl_if {
0846
0847 int (*init)(struct xgbe_prv_data *);
0848 void (*exit)(struct xgbe_prv_data *);
0849
0850
0851 int (*reset)(struct xgbe_prv_data *);
0852 int (*start)(struct xgbe_prv_data *);
0853 void (*stop)(struct xgbe_prv_data *);
0854
0855
0856 int (*link_status)(struct xgbe_prv_data *, int *);
0857
0858
0859 bool (*valid_speed)(struct xgbe_prv_data *, int);
0860
0861
0862 bool (*use_mode)(struct xgbe_prv_data *, enum xgbe_mode);
0863
0864 void (*set_mode)(struct xgbe_prv_data *, enum xgbe_mode);
0865
0866 enum xgbe_mode (*get_mode)(struct xgbe_prv_data *, int);
0867
0868 enum xgbe_mode (*switch_mode)(struct xgbe_prv_data *);
0869
0870 enum xgbe_mode (*cur_mode)(struct xgbe_prv_data *);
0871
0872
0873 enum xgbe_an_mode (*an_mode)(struct xgbe_prv_data *);
0874
0875
0876 int (*an_config)(struct xgbe_prv_data *);
0877
0878
0879 void (*an_advertising)(struct xgbe_prv_data *,
0880 struct ethtool_link_ksettings *);
0881
0882
0883 enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *);
0884
0885
0886 void (*an_pre)(struct xgbe_prv_data *);
0887 void (*an_post)(struct xgbe_prv_data *);
0888
0889
0890 void (*kr_training_pre)(struct xgbe_prv_data *);
0891 void (*kr_training_post)(struct xgbe_prv_data *);
0892
0893
0894 int (*module_info)(struct xgbe_prv_data *pdata,
0895 struct ethtool_modinfo *modinfo);
0896 int (*module_eeprom)(struct xgbe_prv_data *pdata,
0897 struct ethtool_eeprom *eeprom, u8 *data);
0898 };
0899
0900 struct xgbe_phy_if {
0901
0902 int (*phy_init)(struct xgbe_prv_data *);
0903 void (*phy_exit)(struct xgbe_prv_data *);
0904
0905
0906 int (*phy_reset)(struct xgbe_prv_data *);
0907 int (*phy_start)(struct xgbe_prv_data *);
0908 void (*phy_stop)(struct xgbe_prv_data *);
0909
0910
0911 void (*phy_status)(struct xgbe_prv_data *);
0912 int (*phy_config_aneg)(struct xgbe_prv_data *);
0913
0914
0915 bool (*phy_valid_speed)(struct xgbe_prv_data *, int);
0916
0917
0918 irqreturn_t (*an_isr)(struct xgbe_prv_data *);
0919
0920
0921 int (*module_info)(struct xgbe_prv_data *pdata,
0922 struct ethtool_modinfo *modinfo);
0923 int (*module_eeprom)(struct xgbe_prv_data *pdata,
0924 struct ethtool_eeprom *eeprom, u8 *data);
0925
0926
0927 struct xgbe_phy_impl_if phy_impl;
0928 };
0929
0930 struct xgbe_i2c_if {
0931
0932 int (*i2c_init)(struct xgbe_prv_data *);
0933
0934
0935 int (*i2c_start)(struct xgbe_prv_data *);
0936 void (*i2c_stop)(struct xgbe_prv_data *);
0937
0938
0939 int (*i2c_xfer)(struct xgbe_prv_data *, struct xgbe_i2c_op *);
0940
0941
0942 irqreturn_t (*i2c_isr)(struct xgbe_prv_data *);
0943 };
0944
0945 struct xgbe_desc_if {
0946 int (*alloc_ring_resources)(struct xgbe_prv_data *);
0947 void (*free_ring_resources)(struct xgbe_prv_data *);
0948 int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
0949 int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
0950 struct xgbe_ring_data *);
0951 void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
0952 void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
0953 void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
0954 };
0955
0956
0957
0958
0959 struct xgbe_hw_features {
0960
0961 unsigned int version;
0962
0963
0964 unsigned int gmii;
0965 unsigned int vlhash;
0966 unsigned int sma;
0967 unsigned int rwk;
0968 unsigned int mgk;
0969 unsigned int mmc;
0970 unsigned int aoe;
0971 unsigned int ts;
0972 unsigned int eee;
0973 unsigned int tx_coe;
0974 unsigned int rx_coe;
0975 unsigned int addn_mac;
0976 unsigned int ts_src;
0977 unsigned int sa_vlan_ins;
0978 unsigned int vxn;
0979
0980
0981 unsigned int rx_fifo_size;
0982 unsigned int tx_fifo_size;
0983 unsigned int adv_ts_hi;
0984 unsigned int dma_width;
0985 unsigned int dcb;
0986 unsigned int sph;
0987 unsigned int tso;
0988 unsigned int dma_debug;
0989 unsigned int rss;
0990 unsigned int tc_cnt;
0991 unsigned int hash_table_size;
0992 unsigned int l3l4_filter_num;
0993
0994
0995 unsigned int rx_q_cnt;
0996 unsigned int tx_q_cnt;
0997 unsigned int rx_ch_cnt;
0998 unsigned int tx_ch_cnt;
0999 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_prv_data {
1019 struct net_device *netdev;
1020 struct pci_dev *pcidev;
1021 struct platform_device *platdev;
1022 struct acpi_device *adev;
1023 struct device *dev;
1024 struct platform_device *phy_platdev;
1025 struct device *phy_dev;
1026
1027
1028 struct xgbe_version_data *vdata;
1029
1030
1031 unsigned int use_acpi;
1032
1033
1034 void __iomem *xgmac_regs;
1035 void __iomem *xpcs_regs;
1036 void __iomem *rxtx_regs;
1037 void __iomem *sir0_regs;
1038 void __iomem *sir1_regs;
1039 void __iomem *xprop_regs;
1040 void __iomem *xi2c_regs;
1041
1042
1043 unsigned int pp0;
1044 unsigned int pp1;
1045 unsigned int pp2;
1046 unsigned int pp3;
1047 unsigned int pp4;
1048
1049
1050 spinlock_t lock;
1051
1052
1053 spinlock_t xpcs_lock;
1054 unsigned int xpcs_window_def_reg;
1055 unsigned int xpcs_window_sel_reg;
1056 unsigned int xpcs_window;
1057 unsigned int xpcs_window_size;
1058 unsigned int xpcs_window_mask;
1059
1060
1061 struct mutex rss_mutex;
1062
1063
1064 unsigned long dev_state;
1065
1066
1067 unsigned long tx_sec_period;
1068 unsigned long tx_ded_period;
1069 unsigned long rx_sec_period;
1070 unsigned long rx_ded_period;
1071 unsigned long desc_sec_period;
1072 unsigned long desc_ded_period;
1073
1074 unsigned int tx_sec_count;
1075 unsigned int tx_ded_count;
1076 unsigned int rx_sec_count;
1077 unsigned int rx_ded_count;
1078 unsigned int desc_ded_count;
1079 unsigned int desc_sec_count;
1080
1081 int dev_irq;
1082 int ecc_irq;
1083 int i2c_irq;
1084 int channel_irq[XGBE_MAX_DMA_CHANNELS];
1085
1086 unsigned int per_channel_irq;
1087 unsigned int irq_count;
1088 unsigned int channel_irq_count;
1089 unsigned int channel_irq_mode;
1090
1091 char ecc_name[IFNAMSIZ + 32];
1092
1093 struct xgbe_hw_if hw_if;
1094 struct xgbe_phy_if phy_if;
1095 struct xgbe_desc_if desc_if;
1096 struct xgbe_i2c_if i2c_if;
1097
1098
1099 unsigned int coherent;
1100 unsigned int arcr;
1101 unsigned int awcr;
1102 unsigned int awarcr;
1103
1104
1105 struct workqueue_struct *dev_workqueue;
1106 struct work_struct service_work;
1107 struct timer_list service_timer;
1108
1109
1110 struct xgbe_channel *channel[XGBE_MAX_DMA_CHANNELS];
1111 unsigned int tx_max_channel_count;
1112 unsigned int rx_max_channel_count;
1113 unsigned int channel_count;
1114 unsigned int tx_ring_count;
1115 unsigned int tx_desc_count;
1116 unsigned int rx_ring_count;
1117 unsigned int rx_desc_count;
1118
1119 unsigned int new_tx_ring_count;
1120 unsigned int new_rx_ring_count;
1121
1122 unsigned int tx_max_q_count;
1123 unsigned int rx_max_q_count;
1124 unsigned int tx_q_count;
1125 unsigned int rx_q_count;
1126
1127
1128 unsigned int blen;
1129 unsigned int pbl;
1130 unsigned int aal;
1131 unsigned int rd_osr_limit;
1132 unsigned int wr_osr_limit;
1133
1134
1135 unsigned int tx_sf_mode;
1136 unsigned int tx_threshold;
1137 unsigned int tx_osp_mode;
1138 unsigned int tx_max_fifo_size;
1139
1140
1141 unsigned int rx_sf_mode;
1142 unsigned int rx_threshold;
1143 unsigned int rx_max_fifo_size;
1144
1145
1146 unsigned int tx_usecs;
1147 unsigned int tx_frames;
1148
1149
1150 unsigned int rx_riwt;
1151 unsigned int rx_usecs;
1152 unsigned int rx_frames;
1153
1154
1155 unsigned int rx_buf_size;
1156
1157
1158 unsigned int pause_autoneg;
1159 unsigned int tx_pause;
1160 unsigned int rx_pause;
1161 unsigned int rx_rfa[XGBE_MAX_QUEUES];
1162 unsigned int rx_rfd[XGBE_MAX_QUEUES];
1163
1164
1165 u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
1166 u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
1167 u32 rss_options;
1168
1169
1170 u16 vxlan_port;
1171
1172
1173 unsigned char mac_addr[ETH_ALEN];
1174 netdev_features_t netdev_features;
1175 struct napi_struct napi;
1176 struct xgbe_mmc_stats mmc_stats;
1177 struct xgbe_ext_stats ext_stats;
1178
1179
1180 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
1181
1182
1183 struct clk *sysclk;
1184 unsigned long sysclk_rate;
1185 struct clk *ptpclk;
1186 unsigned long ptpclk_rate;
1187
1188
1189 spinlock_t tstamp_lock;
1190 struct ptp_clock_info ptp_clock_info;
1191 struct ptp_clock *ptp_clock;
1192 struct hwtstamp_config tstamp_config;
1193 struct cyclecounter tstamp_cc;
1194 struct timecounter tstamp_tc;
1195 unsigned int tstamp_addend;
1196 struct work_struct tx_tstamp_work;
1197 struct sk_buff *tx_tstamp_skb;
1198 u64 tx_tstamp;
1199
1200
1201 struct ieee_ets *ets;
1202 struct ieee_pfc *pfc;
1203 unsigned int q2tc_map[XGBE_MAX_QUEUES];
1204 unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
1205 unsigned int pfcq[XGBE_MAX_QUEUES];
1206 unsigned int pfc_rfa;
1207 u8 num_tcs;
1208
1209
1210 struct xgbe_hw_features hw_feat;
1211
1212
1213 struct work_struct restart_work;
1214 struct work_struct stopdev_work;
1215
1216
1217 unsigned int power_down;
1218
1219
1220 u32 msg_enable;
1221
1222
1223 phy_interface_t phy_mode;
1224 int phy_link;
1225 int phy_speed;
1226
1227
1228 unsigned int phy_started;
1229 void *phy_data;
1230 struct xgbe_phy phy;
1231 int mdio_mmd;
1232 unsigned long link_check;
1233 struct completion mdio_complete;
1234
1235 unsigned int kr_redrv;
1236
1237 char an_name[IFNAMSIZ + 32];
1238 struct workqueue_struct *an_workqueue;
1239
1240 int an_irq;
1241 struct work_struct an_irq_work;
1242
1243
1244 unsigned int an_int;
1245 unsigned int an_status;
1246 struct mutex an_mutex;
1247 enum xgbe_an an_result;
1248 enum xgbe_an an_state;
1249 enum xgbe_rx kr_state;
1250 enum xgbe_rx kx_state;
1251 struct work_struct an_work;
1252 unsigned int an_again;
1253 unsigned int an_supported;
1254 unsigned int parallel_detect;
1255 unsigned int fec_ability;
1256 unsigned long an_start;
1257 enum xgbe_an_mode an_mode;
1258
1259
1260 struct xgbe_i2c i2c;
1261 struct mutex i2c_mutex;
1262 struct completion i2c_complete;
1263 char i2c_name[IFNAMSIZ + 32];
1264
1265 unsigned int lpm_ctrl;
1266
1267 unsigned int isr_as_tasklet;
1268 struct tasklet_struct tasklet_dev;
1269 struct tasklet_struct tasklet_ecc;
1270 struct tasklet_struct tasklet_i2c;
1271 struct tasklet_struct tasklet_an;
1272
1273 struct dentry *xgbe_debugfs;
1274
1275 unsigned int debugfs_xgmac_reg;
1276
1277 unsigned int debugfs_xpcs_mmd;
1278 unsigned int debugfs_xpcs_reg;
1279
1280 unsigned int debugfs_xprop_reg;
1281
1282 unsigned int debugfs_xi2c_reg;
1283
1284 bool debugfs_an_cdr_workaround;
1285 bool debugfs_an_cdr_track_early;
1286 };
1287
1288
1289 struct xgbe_prv_data *xgbe_alloc_pdata(struct device *);
1290 void xgbe_free_pdata(struct xgbe_prv_data *);
1291 void xgbe_set_counts(struct xgbe_prv_data *);
1292 int xgbe_config_netdev(struct xgbe_prv_data *);
1293 void xgbe_deconfig_netdev(struct xgbe_prv_data *);
1294
1295 int xgbe_platform_init(void);
1296 void xgbe_platform_exit(void);
1297 #ifdef CONFIG_PCI
1298 int xgbe_pci_init(void);
1299 void xgbe_pci_exit(void);
1300 #else
1301 static inline int xgbe_pci_init(void) { return 0; }
1302 static inline void xgbe_pci_exit(void) { }
1303 #endif
1304
1305 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
1306 void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
1307 void xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if *);
1308 void xgbe_init_function_ptrs_phy_v2(struct xgbe_phy_if *);
1309 void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
1310 void xgbe_init_function_ptrs_i2c(struct xgbe_i2c_if *);
1311 const struct net_device_ops *xgbe_get_netdev_ops(void);
1312 const struct ethtool_ops *xgbe_get_ethtool_ops(void);
1313 const struct udp_tunnel_nic_info *xgbe_get_udp_tunnel_info(void);
1314
1315 #ifdef CONFIG_AMD_XGBE_DCB
1316 const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
1317 #endif
1318
1319 void xgbe_ptp_register(struct xgbe_prv_data *);
1320 void xgbe_ptp_unregister(struct xgbe_prv_data *);
1321 void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
1322 unsigned int, unsigned int, unsigned int);
1323 void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
1324 unsigned int);
1325 void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
1326 void xgbe_get_all_hw_features(struct xgbe_prv_data *);
1327 int xgbe_powerup(struct net_device *, unsigned int);
1328 int xgbe_powerdown(struct net_device *, unsigned int);
1329 void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
1330 void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
1331 void xgbe_restart_dev(struct xgbe_prv_data *pdata);
1332 void xgbe_full_restart_dev(struct xgbe_prv_data *pdata);
1333
1334 #ifdef CONFIG_DEBUG_FS
1335 void xgbe_debugfs_init(struct xgbe_prv_data *);
1336 void xgbe_debugfs_exit(struct xgbe_prv_data *);
1337 void xgbe_debugfs_rename(struct xgbe_prv_data *pdata);
1338 #else
1339 static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
1340 static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
1341 static inline void xgbe_debugfs_rename(struct xgbe_prv_data *pdata) {}
1342 #endif
1343
1344
1345 #if 0
1346 #define YDEBUG
1347 #define YDEBUG_MDIO
1348 #endif
1349
1350
1351 #ifdef YDEBUG
1352 #define DBGPR(x...) pr_alert(x)
1353 #else
1354 #define DBGPR(x...) do { } while (0)
1355 #endif
1356
1357 #ifdef YDEBUG_MDIO
1358 #define DBGPR_MDIO(x...) pr_alert(x)
1359 #else
1360 #define DBGPR_MDIO(x...) do { } while (0)
1361 #endif
1362
1363 #endif