0001
0002
0003
0004
0005 #ifndef _EMAC_H_
0006 #define _EMAC_H_
0007
0008 #include <linux/irqreturn.h>
0009 #include <linux/netdevice.h>
0010 #include <linux/clk.h>
0011 #include <linux/platform_device.h>
0012 #include "emac-mac.h"
0013 #include "emac-phy.h"
0014 #include "emac-sgmii.h"
0015
0016
0017 #define EMAC_DMA_MAS_CTRL 0x1400
0018 #define EMAC_IRQ_MOD_TIM_INIT 0x1408
0019 #define EMAC_BLK_IDLE_STS 0x140c
0020 #define EMAC_PHY_LINK_DELAY 0x141c
0021 #define EMAC_SYS_ALIV_CTRL 0x1434
0022 #define EMAC_MAC_CTRL 0x1480
0023 #define EMAC_MAC_IPGIFG_CTRL 0x1484
0024 #define EMAC_MAC_STA_ADDR0 0x1488
0025 #define EMAC_MAC_STA_ADDR1 0x148c
0026 #define EMAC_HASH_TAB_REG0 0x1490
0027 #define EMAC_HASH_TAB_REG1 0x1494
0028 #define EMAC_MAC_HALF_DPLX_CTRL 0x1498
0029 #define EMAC_MAX_FRAM_LEN_CTRL 0x149c
0030 #define EMAC_WOL_CTRL0 0x14a0
0031 #define EMAC_RSS_KEY0 0x14b0
0032 #define EMAC_H1TPD_BASE_ADDR_LO 0x14e0
0033 #define EMAC_H2TPD_BASE_ADDR_LO 0x14e4
0034 #define EMAC_H3TPD_BASE_ADDR_LO 0x14e8
0035 #define EMAC_INTER_SRAM_PART9 0x1534
0036 #define EMAC_DESC_CTRL_0 0x1540
0037 #define EMAC_DESC_CTRL_1 0x1544
0038 #define EMAC_DESC_CTRL_2 0x1550
0039 #define EMAC_DESC_CTRL_10 0x1554
0040 #define EMAC_DESC_CTRL_12 0x1558
0041 #define EMAC_DESC_CTRL_13 0x155c
0042 #define EMAC_DESC_CTRL_3 0x1560
0043 #define EMAC_DESC_CTRL_4 0x1564
0044 #define EMAC_DESC_CTRL_5 0x1568
0045 #define EMAC_DESC_CTRL_14 0x156c
0046 #define EMAC_DESC_CTRL_15 0x1570
0047 #define EMAC_DESC_CTRL_16 0x1574
0048 #define EMAC_DESC_CTRL_6 0x1578
0049 #define EMAC_DESC_CTRL_8 0x1580
0050 #define EMAC_DESC_CTRL_9 0x1584
0051 #define EMAC_DESC_CTRL_11 0x1588
0052 #define EMAC_TXQ_CTRL_0 0x1590
0053 #define EMAC_TXQ_CTRL_1 0x1594
0054 #define EMAC_TXQ_CTRL_2 0x1598
0055 #define EMAC_RXQ_CTRL_0 0x15a0
0056 #define EMAC_RXQ_CTRL_1 0x15a4
0057 #define EMAC_RXQ_CTRL_2 0x15a8
0058 #define EMAC_RXQ_CTRL_3 0x15ac
0059 #define EMAC_BASE_CPU_NUMBER 0x15b8
0060 #define EMAC_DMA_CTRL 0x15c0
0061 #define EMAC_MAILBOX_0 0x15e0
0062 #define EMAC_MAILBOX_5 0x15e4
0063 #define EMAC_MAILBOX_6 0x15e8
0064 #define EMAC_MAILBOX_13 0x15ec
0065 #define EMAC_MAILBOX_2 0x15f4
0066 #define EMAC_MAILBOX_3 0x15f8
0067 #define EMAC_INT_STATUS 0x1600
0068 #define EMAC_INT_MASK 0x1604
0069 #define EMAC_MAILBOX_11 0x160c
0070 #define EMAC_AXI_MAST_CTRL 0x1610
0071 #define EMAC_MAILBOX_12 0x1614
0072 #define EMAC_MAILBOX_9 0x1618
0073 #define EMAC_MAILBOX_10 0x161c
0074 #define EMAC_ATHR_HEADER_CTRL 0x1620
0075 #define EMAC_RXMAC_STATC_REG0 0x1700
0076 #define EMAC_RXMAC_STATC_REG22 0x1758
0077 #define EMAC_TXMAC_STATC_REG0 0x1760
0078 #define EMAC_TXMAC_STATC_REG24 0x17c0
0079 #define EMAC_CLK_GATE_CTRL 0x1814
0080 #define EMAC_CORE_HW_VERSION 0x1974
0081 #define EMAC_MISC_CTRL 0x1990
0082 #define EMAC_MAILBOX_7 0x19e0
0083 #define EMAC_MAILBOX_8 0x19e4
0084 #define EMAC_IDT_TABLE0 0x1b00
0085 #define EMAC_RXMAC_STATC_REG23 0x1bc8
0086 #define EMAC_RXMAC_STATC_REG24 0x1bcc
0087 #define EMAC_TXMAC_STATC_REG25 0x1bd0
0088 #define EMAC_MAILBOX_15 0x1bd4
0089 #define EMAC_MAILBOX_16 0x1bd8
0090 #define EMAC_INT1_MASK 0x1bf0
0091 #define EMAC_INT1_STATUS 0x1bf4
0092 #define EMAC_INT2_MASK 0x1bf8
0093 #define EMAC_INT2_STATUS 0x1bfc
0094 #define EMAC_INT3_MASK 0x1c00
0095 #define EMAC_INT3_STATUS 0x1c04
0096
0097
0098 #define DEV_ID_NUM_BMSK 0x7f000000
0099 #define DEV_ID_NUM_SHFT 24
0100 #define DEV_REV_NUM_BMSK 0xff0000
0101 #define DEV_REV_NUM_SHFT 16
0102 #define INT_RD_CLR_EN 0x4000
0103 #define IRQ_MODERATOR2_EN 0x800
0104 #define IRQ_MODERATOR_EN 0x400
0105 #define LPW_CLK_SEL 0x80
0106 #define LPW_STATE 0x20
0107 #define LPW_MODE 0x10
0108 #define SOFT_RST 0x1
0109
0110
0111 #define IRQ_MODERATOR2_INIT_BMSK 0xffff0000
0112 #define IRQ_MODERATOR2_INIT_SHFT 16
0113 #define IRQ_MODERATOR_INIT_BMSK 0xffff
0114 #define IRQ_MODERATOR_INIT_SHFT 0
0115
0116
0117 #define DIS_INT BIT(31)
0118 #define PTP_INT BIT(30)
0119 #define RFD4_UR_INT BIT(29)
0120 #define TX_PKT_INT3 BIT(26)
0121 #define TX_PKT_INT2 BIT(25)
0122 #define TX_PKT_INT1 BIT(24)
0123 #define RX_PKT_INT3 BIT(19)
0124 #define RX_PKT_INT2 BIT(18)
0125 #define RX_PKT_INT1 BIT(17)
0126 #define RX_PKT_INT0 BIT(16)
0127 #define TX_PKT_INT BIT(15)
0128 #define TXQ_TO_INT BIT(14)
0129 #define GPHY_WAKEUP_INT BIT(13)
0130 #define GPHY_LINK_DOWN_INT BIT(12)
0131 #define GPHY_LINK_UP_INT BIT(11)
0132 #define DMAW_TO_INT BIT(10)
0133 #define DMAR_TO_INT BIT(9)
0134 #define TXF_UR_INT BIT(8)
0135 #define RFD3_UR_INT BIT(7)
0136 #define RFD2_UR_INT BIT(6)
0137 #define RFD1_UR_INT BIT(5)
0138 #define RFD0_UR_INT BIT(4)
0139 #define RXF_OF_INT BIT(3)
0140 #define SW_MAN_INT BIT(2)
0141
0142
0143 #define RFD2_PROC_IDX_BMSK 0xfff0000
0144 #define RFD2_PROC_IDX_SHFT 16
0145 #define RFD2_PROD_IDX_BMSK 0xfff
0146 #define RFD2_PROD_IDX_SHFT 0
0147
0148
0149 #define MAJOR_BMSK 0xf0000000
0150 #define MAJOR_SHFT 28
0151 #define MINOR_BMSK 0xfff0000
0152 #define MINOR_SHFT 16
0153 #define STEP_BMSK 0xffff
0154 #define STEP_SHFT 0
0155
0156
0157 #define TX_INDX_FIFO_SYNC_RST BIT(23)
0158 #define TX_TS_FIFO_SYNC_RST BIT(22)
0159 #define RX_TS_FIFO2_SYNC_RST BIT(21)
0160 #define RX_TS_FIFO1_SYNC_RST BIT(20)
0161 #define TX_TS_ENABLE BIT(16)
0162 #define DIS_1588_CLKS BIT(11)
0163 #define FREQ_MODE BIT(9)
0164 #define ENABLE_RRD_TIMESTAMP BIT(3)
0165
0166
0167 #define HDRIVE_BMSK 0x3000
0168 #define HDRIVE_SHFT 12
0169 #define SLB_EN BIT(9)
0170 #define PLB_EN BIT(8)
0171 #define WOL_EN BIT(3)
0172 #define PHY_RESET BIT(0)
0173
0174 #define EMAC_DEV_ID 0x0040
0175
0176
0177 #define SGMII_LN_RSM_START 0x029C
0178
0179
0180 #define SGMII_PHY_CMN_CTRL 0x0408
0181 #define SGMII_PHY_CMN_RESET_CTRL 0x0410
0182
0183
0184 #define SGMII_PHY_LN_OFFSET 0x0400
0185 #define SGMII_PHY_LN_LANE_STATUS 0x00DC
0186 #define SGMII_PHY_LN_BIST_GEN0 0x008C
0187 #define SGMII_PHY_LN_BIST_GEN1 0x0090
0188 #define SGMII_PHY_LN_BIST_GEN2 0x0094
0189 #define SGMII_PHY_LN_BIST_GEN3 0x0098
0190 #define SGMII_PHY_LN_CDR_CTRL1 0x005C
0191
0192 enum emac_clk_id {
0193 EMAC_CLK_AXI,
0194 EMAC_CLK_CFG_AHB,
0195 EMAC_CLK_HIGH_SPEED,
0196 EMAC_CLK_MDIO,
0197 EMAC_CLK_TX,
0198 EMAC_CLK_RX,
0199 EMAC_CLK_SYS,
0200 EMAC_CLK_CNT
0201 };
0202
0203 #define EMAC_LINK_SPEED_UNKNOWN 0x0
0204 #define EMAC_LINK_SPEED_10_HALF BIT(0)
0205 #define EMAC_LINK_SPEED_10_FULL BIT(1)
0206 #define EMAC_LINK_SPEED_100_HALF BIT(2)
0207 #define EMAC_LINK_SPEED_100_FULL BIT(3)
0208 #define EMAC_LINK_SPEED_1GB_FULL BIT(5)
0209
0210 #define EMAC_MAX_SETUP_LNK_CYCLE 100
0211
0212 struct emac_stats {
0213
0214 u64 rx_ok;
0215 u64 rx_bcast;
0216 u64 rx_mcast;
0217 u64 rx_pause;
0218 u64 rx_ctrl;
0219 u64 rx_fcs_err;
0220 u64 rx_len_err;
0221 u64 rx_byte_cnt;
0222 u64 rx_runt;
0223 u64 rx_frag;
0224 u64 rx_sz_64;
0225 u64 rx_sz_65_127;
0226 u64 rx_sz_128_255;
0227 u64 rx_sz_256_511;
0228 u64 rx_sz_512_1023;
0229 u64 rx_sz_1024_1518;
0230 u64 rx_sz_1519_max;
0231 u64 rx_sz_ov;
0232 u64 rx_rxf_ov;
0233 u64 rx_align_err;
0234 u64 rx_bcast_byte_cnt;
0235 u64 rx_mcast_byte_cnt;
0236 u64 rx_err_addr;
0237 u64 rx_crc_align;
0238 u64 rx_jabbers;
0239
0240
0241 u64 tx_ok;
0242 u64 tx_bcast;
0243 u64 tx_mcast;
0244 u64 tx_pause;
0245 u64 tx_exc_defer;
0246 u64 tx_ctrl;
0247 u64 tx_defer;
0248 u64 tx_byte_cnt;
0249 u64 tx_sz_64;
0250 u64 tx_sz_65_127;
0251 u64 tx_sz_128_255;
0252 u64 tx_sz_256_511;
0253 u64 tx_sz_512_1023;
0254 u64 tx_sz_1024_1518;
0255 u64 tx_sz_1519_max;
0256 u64 tx_1_col;
0257 u64 tx_2_col;
0258 u64 tx_late_col;
0259 u64 tx_abort_col;
0260 u64 tx_underrun;
0261 u64 tx_rd_eop;
0262 u64 tx_len_err;
0263 u64 tx_trunc;
0264 u64 tx_bcast_byte;
0265 u64 tx_mcast_byte;
0266 u64 tx_col;
0267
0268 spinlock_t lock;
0269 };
0270
0271
0272 #define EMAC_RSS_HSTYP_IPV4_EN 0x00000001
0273 #define EMAC_RSS_HSTYP_TCP4_EN 0x00000002
0274 #define EMAC_RSS_HSTYP_IPV6_EN 0x00000004
0275 #define EMAC_RSS_HSTYP_TCP6_EN 0x00000008
0276 #define EMAC_RSS_HSTYP_ALL_EN (\
0277 EMAC_RSS_HSTYP_IPV4_EN |\
0278 EMAC_RSS_HSTYP_TCP4_EN |\
0279 EMAC_RSS_HSTYP_IPV6_EN |\
0280 EMAC_RSS_HSTYP_TCP6_EN)
0281
0282 #define EMAC_VLAN_TO_TAG(_vlan, _tag) \
0283 (_tag = ((((_vlan) >> 8) & 0xFF) | (((_vlan) & 0xFF) << 8)))
0284
0285 #define EMAC_TAG_TO_VLAN(_tag, _vlan) \
0286 (_vlan = ((((_tag) >> 8) & 0xFF) | (((_tag) & 0xFF) << 8)))
0287
0288 #define EMAC_DEF_RX_BUF_SIZE 1536
0289 #define EMAC_MAX_JUMBO_PKT_SIZE (9 * 1024)
0290 #define EMAC_MAX_TX_OFFLOAD_THRESH (9 * 1024)
0291
0292 #define EMAC_MAX_ETH_FRAME_SIZE EMAC_MAX_JUMBO_PKT_SIZE
0293 #define EMAC_MIN_ETH_FRAME_SIZE 68
0294
0295 #define EMAC_DEF_TX_QUEUES 1
0296 #define EMAC_DEF_RX_QUEUES 1
0297
0298 #define EMAC_MIN_TX_DESCS 128
0299 #define EMAC_MIN_RX_DESCS 128
0300
0301 #define EMAC_MAX_TX_DESCS 16383
0302 #define EMAC_MAX_RX_DESCS 2047
0303
0304 #define EMAC_DEF_TX_DESCS 512
0305 #define EMAC_DEF_RX_DESCS 256
0306
0307 #define EMAC_DEF_RX_IRQ_MOD 250
0308 #define EMAC_DEF_TX_IRQ_MOD 250
0309
0310 #define EMAC_WATCHDOG_TIME (5 * HZ)
0311
0312
0313 #define EMAC_TRY_LINK_TIMEOUT (4 * HZ)
0314
0315
0316
0317
0318
0319 struct emac_irq {
0320 unsigned int irq;
0321 u32 mask;
0322 };
0323
0324
0325 struct emac_adapter {
0326 struct net_device *netdev;
0327 struct mii_bus *mii_bus;
0328 struct phy_device *phydev;
0329
0330 void __iomem *base;
0331 void __iomem *csr;
0332
0333 struct emac_sgmii phy;
0334 struct emac_stats stats;
0335
0336 struct emac_irq irq;
0337 struct clk *clk[EMAC_CLK_CNT];
0338
0339
0340 struct emac_ring_header ring_header;
0341 struct emac_tx_queue tx_q;
0342 struct emac_rx_queue rx_q;
0343 unsigned int tx_desc_cnt;
0344 unsigned int rx_desc_cnt;
0345 unsigned int rrd_size;
0346 unsigned int rfd_size;
0347 unsigned int tpd_size;
0348
0349 unsigned int rxbuf_size;
0350
0351
0352
0353
0354 bool automatic;
0355 bool tx_flow_control;
0356 bool rx_flow_control;
0357
0358
0359 bool single_pause_mode;
0360
0361
0362 u8 tpd_burst;
0363 u8 rfd_burst;
0364 unsigned int dmaw_dly_cnt;
0365 unsigned int dmar_dly_cnt;
0366 enum emac_dma_req_block dmar_block;
0367 enum emac_dma_req_block dmaw_block;
0368 enum emac_dma_order dma_order;
0369
0370 u32 irq_mod;
0371 u32 preamble;
0372
0373 struct work_struct work_thread;
0374
0375 u16 msg_enable;
0376
0377 struct mutex reset_lock;
0378 };
0379
0380 int emac_reinit_locked(struct emac_adapter *adpt);
0381 void emac_reg_update32(void __iomem *addr, u32 mask, u32 val);
0382
0383 void emac_set_ethtool_ops(struct net_device *netdev);
0384 void emac_update_hw_stats(struct emac_adapter *adpt);
0385
0386 #endif