0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef __ALTERA_TSE_H__
0021 #define __ALTERA_TSE_H__
0022
0023 #define ALTERA_TSE_RESOURCE_NAME "altera_tse"
0024
0025 #include <linux/bitops.h>
0026 #include <linux/if_vlan.h>
0027 #include <linux/list.h>
0028 #include <linux/netdevice.h>
0029 #include <linux/phy.h>
0030
0031 #define ALTERA_TSE_SW_RESET_WATCHDOG_CNTR 10000
0032 #define ALTERA_TSE_MAC_FIFO_WIDTH 4
0033
0034
0035
0036 #define ALTERA_TSE_RX_SECTION_EMPTY 16
0037 #define ALTERA_TSE_RX_SECTION_FULL 0
0038 #define ALTERA_TSE_RX_ALMOST_EMPTY 8
0039 #define ALTERA_TSE_RX_ALMOST_FULL 8
0040
0041
0042 #define ALTERA_TSE_TX_SECTION_EMPTY 16
0043 #define ALTERA_TSE_TX_SECTION_FULL 0
0044 #define ALTERA_TSE_TX_ALMOST_EMPTY 8
0045 #define ALTERA_TSE_TX_ALMOST_FULL 3
0046
0047
0048 #define ALTERA_TSE_TX_IPG_LENGTH 12
0049
0050 #define ALTERA_TSE_PAUSE_QUANTA 0xffff
0051
0052 #define GET_BIT_VALUE(v, bit) (((v) >> (bit)) & 0x1)
0053
0054
0055
0056 #define MAC_CMDCFG_TX_ENA BIT(0)
0057 #define MAC_CMDCFG_RX_ENA BIT(1)
0058 #define MAC_CMDCFG_XON_GEN BIT(2)
0059 #define MAC_CMDCFG_ETH_SPEED BIT(3)
0060 #define MAC_CMDCFG_PROMIS_EN BIT(4)
0061 #define MAC_CMDCFG_PAD_EN BIT(5)
0062 #define MAC_CMDCFG_CRC_FWD BIT(6)
0063 #define MAC_CMDCFG_PAUSE_FWD BIT(7)
0064 #define MAC_CMDCFG_PAUSE_IGNORE BIT(8)
0065 #define MAC_CMDCFG_TX_ADDR_INS BIT(9)
0066 #define MAC_CMDCFG_HD_ENA BIT(10)
0067 #define MAC_CMDCFG_EXCESS_COL BIT(11)
0068 #define MAC_CMDCFG_LATE_COL BIT(12)
0069 #define MAC_CMDCFG_SW_RESET BIT(13)
0070 #define MAC_CMDCFG_MHASH_SEL BIT(14)
0071 #define MAC_CMDCFG_LOOP_ENA BIT(15)
0072 #define MAC_CMDCFG_TX_ADDR_SEL(v) (((v) & 0x7) << 16)
0073 #define MAC_CMDCFG_MAGIC_ENA BIT(19)
0074 #define MAC_CMDCFG_SLEEP BIT(20)
0075 #define MAC_CMDCFG_WAKEUP BIT(21)
0076 #define MAC_CMDCFG_XOFF_GEN BIT(22)
0077 #define MAC_CMDCFG_CNTL_FRM_ENA BIT(23)
0078 #define MAC_CMDCFG_NO_LGTH_CHECK BIT(24)
0079 #define MAC_CMDCFG_ENA_10 BIT(25)
0080 #define MAC_CMDCFG_RX_ERR_DISC BIT(26)
0081 #define MAC_CMDCFG_DISABLE_READ_TIMEOUT BIT(27)
0082 #define MAC_CMDCFG_CNT_RESET BIT(31)
0083
0084 #define MAC_CMDCFG_TX_ENA_GET(v) GET_BIT_VALUE(v, 0)
0085 #define MAC_CMDCFG_RX_ENA_GET(v) GET_BIT_VALUE(v, 1)
0086 #define MAC_CMDCFG_XON_GEN_GET(v) GET_BIT_VALUE(v, 2)
0087 #define MAC_CMDCFG_ETH_SPEED_GET(v) GET_BIT_VALUE(v, 3)
0088 #define MAC_CMDCFG_PROMIS_EN_GET(v) GET_BIT_VALUE(v, 4)
0089 #define MAC_CMDCFG_PAD_EN_GET(v) GET_BIT_VALUE(v, 5)
0090 #define MAC_CMDCFG_CRC_FWD_GET(v) GET_BIT_VALUE(v, 6)
0091 #define MAC_CMDCFG_PAUSE_FWD_GET(v) GET_BIT_VALUE(v, 7)
0092 #define MAC_CMDCFG_PAUSE_IGNORE_GET(v) GET_BIT_VALUE(v, 8)
0093 #define MAC_CMDCFG_TX_ADDR_INS_GET(v) GET_BIT_VALUE(v, 9)
0094 #define MAC_CMDCFG_HD_ENA_GET(v) GET_BIT_VALUE(v, 10)
0095 #define MAC_CMDCFG_EXCESS_COL_GET(v) GET_BIT_VALUE(v, 11)
0096 #define MAC_CMDCFG_LATE_COL_GET(v) GET_BIT_VALUE(v, 12)
0097 #define MAC_CMDCFG_SW_RESET_GET(v) GET_BIT_VALUE(v, 13)
0098 #define MAC_CMDCFG_MHASH_SEL_GET(v) GET_BIT_VALUE(v, 14)
0099 #define MAC_CMDCFG_LOOP_ENA_GET(v) GET_BIT_VALUE(v, 15)
0100 #define MAC_CMDCFG_TX_ADDR_SEL_GET(v) (((v) >> 16) & 0x7)
0101 #define MAC_CMDCFG_MAGIC_ENA_GET(v) GET_BIT_VALUE(v, 19)
0102 #define MAC_CMDCFG_SLEEP_GET(v) GET_BIT_VALUE(v, 20)
0103 #define MAC_CMDCFG_WAKEUP_GET(v) GET_BIT_VALUE(v, 21)
0104 #define MAC_CMDCFG_XOFF_GEN_GET(v) GET_BIT_VALUE(v, 22)
0105 #define MAC_CMDCFG_CNTL_FRM_ENA_GET(v) GET_BIT_VALUE(v, 23)
0106 #define MAC_CMDCFG_NO_LGTH_CHECK_GET(v) GET_BIT_VALUE(v, 24)
0107 #define MAC_CMDCFG_ENA_10_GET(v) GET_BIT_VALUE(v, 25)
0108 #define MAC_CMDCFG_RX_ERR_DISC_GET(v) GET_BIT_VALUE(v, 26)
0109 #define MAC_CMDCFG_DISABLE_READ_TIMEOUT_GET(v) GET_BIT_VALUE(v, 27)
0110 #define MAC_CMDCFG_CNT_RESET_GET(v) GET_BIT_VALUE(v, 31)
0111
0112
0113
0114 #define SGMII_PCS_SCRATCH 0x10
0115 #define SGMII_PCS_REV 0x11
0116 #define SGMII_PCS_LINK_TIMER_0 0x12
0117 #define SGMII_PCS_LINK_TIMER_1 0x13
0118 #define SGMII_PCS_IF_MODE 0x14
0119 #define SGMII_PCS_DIS_READ_TO 0x15
0120 #define SGMII_PCS_READ_TO 0x16
0121 #define SGMII_PCS_SW_RESET_TIMEOUT 100
0122
0123
0124
0125 struct altera_tse_mdio {
0126 u32 control;
0127 u32 status;
0128 u32 phy_id1;
0129 u32 phy_id2;
0130 u32 auto_negotiation_advertisement;
0131
0132
0133
0134 u32 remote_partner_base_page_ability;
0135
0136 u32 reg6;
0137 u32 reg7;
0138 u32 reg8;
0139 u32 reg9;
0140 u32 rega;
0141 u32 regb;
0142 u32 regc;
0143 u32 regd;
0144 u32 rege;
0145 u32 regf;
0146 u32 reg10;
0147 u32 reg11;
0148 u32 reg12;
0149 u32 reg13;
0150 u32 reg14;
0151 u32 reg15;
0152 u32 reg16;
0153 u32 reg17;
0154 u32 reg18;
0155 u32 reg19;
0156 u32 reg1a;
0157 u32 reg1b;
0158 u32 reg1c;
0159 u32 reg1d;
0160 u32 reg1e;
0161 u32 reg1f;
0162 };
0163
0164
0165
0166
0167
0168
0169 struct altera_tse_mac {
0170
0171
0172
0173 u32 megacore_revision;
0174
0175
0176
0177 u32 scratch_pad;
0178
0179
0180
0181 u32 command_config;
0182
0183
0184
0185 u32 mac_addr_0;
0186
0187
0188
0189 u32 mac_addr_1;
0190
0191 u32 frm_length;
0192
0193
0194
0195 u32 pause_quanta;
0196
0197 u32 rx_section_empty;
0198
0199 u32 rx_section_full;
0200
0201 u32 tx_section_empty;
0202
0203 u32 tx_section_full;
0204
0205 u32 rx_almost_empty;
0206
0207 u32 rx_almost_full;
0208
0209 u32 tx_almost_empty;
0210
0211 u32 tx_almost_full;
0212
0213 u32 mdio_phy0_addr;
0214
0215 u32 mdio_phy1_addr;
0216
0217
0218 u32 holdoff_quant;
0219
0220
0221 u32 reserved1[5];
0222
0223
0224 u32 tx_ipg_length;
0225
0226
0227
0228
0229 u32 mac_id_1;
0230 u32 mac_id_2;
0231
0232
0233 u32 frames_transmitted_ok;
0234
0235 u32 frames_received_ok;
0236
0237 u32 frames_check_sequence_errors;
0238
0239 u32 alignment_errors;
0240
0241
0242
0243 u32 octets_transmitted_ok;
0244
0245 u32 octets_received_ok;
0246
0247
0248
0249
0250 u32 tx_pause_mac_ctrl_frames;
0251
0252 u32 rx_pause_mac_ctrl_frames;
0253
0254
0255
0256
0257 u32 if_in_errors;
0258
0259 u32 if_out_errors;
0260
0261 u32 if_in_ucast_pkts;
0262
0263 u32 if_in_multicast_pkts;
0264
0265 u32 if_in_broadcast_pkts;
0266 u32 if_out_discards;
0267
0268 u32 if_out_ucast_pkts;
0269
0270
0271
0272 u32 if_out_multicast_pkts;
0273 u32 if_out_broadcast_pkts;
0274
0275
0276
0277
0278
0279
0280 u32 ether_stats_drop_events;
0281
0282 u32 ether_stats_octets;
0283
0284 u32 ether_stats_pkts;
0285
0286 u32 ether_stats_undersize_pkts;
0287
0288
0289
0290 u32 ether_stats_oversize_pkts;
0291
0292 u32 ether_stats_pkts_64_octets;
0293
0294 u32 ether_stats_pkts_65to127_octets;
0295
0296 u32 ether_stats_pkts_128to255_octets;
0297
0298 u32 ether_stats_pkts_256to511_octets;
0299
0300 u32 ether_stats_pkts_512to1023_octets;
0301
0302 u32 ether_stats_pkts_1024to1518_octets;
0303
0304
0305
0306
0307 u32 ether_stats_pkts_1519tox_octets;
0308
0309 u32 ether_stats_jabbers;
0310
0311 u32 ether_stats_fragments;
0312
0313 u32 reserved2;
0314
0315
0316 u32 tx_cmd_stat;
0317 u32 rx_cmd_stat;
0318
0319
0320 u32 msb_octets_transmitted_ok;
0321 u32 msb_octets_received_ok;
0322 u32 msb_ether_stats_octets;
0323
0324 u32 reserved3;
0325
0326
0327
0328
0329 u32 hash_table[64];
0330
0331
0332
0333
0334 struct altera_tse_mdio mdio_phy0;
0335 struct altera_tse_mdio mdio_phy1;
0336
0337
0338 u32 supp_mac_addr_0_0;
0339 u32 supp_mac_addr_0_1;
0340 u32 supp_mac_addr_1_0;
0341 u32 supp_mac_addr_1_1;
0342 u32 supp_mac_addr_2_0;
0343 u32 supp_mac_addr_2_1;
0344 u32 supp_mac_addr_3_0;
0345 u32 supp_mac_addr_3_1;
0346
0347 u32 reserved4[8];
0348
0349
0350 u32 tx_period;
0351 u32 tx_adjust_fns;
0352 u32 tx_adjust_ns;
0353 u32 rx_period;
0354 u32 rx_adjust_fns;
0355 u32 rx_adjust_ns;
0356
0357 u32 reserved5[42];
0358 };
0359
0360 #define tse_csroffs(a) (offsetof(struct altera_tse_mac, a))
0361
0362
0363
0364 #define ALTERA_TSE_TX_CMD_STAT_OMIT_CRC BIT(17)
0365 #define ALTERA_TSE_TX_CMD_STAT_TX_SHIFT16 BIT(18)
0366 #define ALTERA_TSE_RX_CMD_STAT_RX_SHIFT16 BIT(25)
0367
0368
0369
0370
0371 struct tse_buffer {
0372 struct list_head lh;
0373 struct sk_buff *skb;
0374 dma_addr_t dma_addr;
0375 u32 len;
0376 int mapped_as_page;
0377 };
0378
0379 struct altera_tse_private;
0380
0381 #define ALTERA_DTYPE_SGDMA 1
0382 #define ALTERA_DTYPE_MSGDMA 2
0383
0384
0385 struct altera_dmaops {
0386 int altera_dtype;
0387 int dmamask;
0388 void (*reset_dma)(struct altera_tse_private *);
0389 void (*enable_txirq)(struct altera_tse_private *);
0390 void (*enable_rxirq)(struct altera_tse_private *);
0391 void (*disable_txirq)(struct altera_tse_private *);
0392 void (*disable_rxirq)(struct altera_tse_private *);
0393 void (*clear_txirq)(struct altera_tse_private *);
0394 void (*clear_rxirq)(struct altera_tse_private *);
0395 int (*tx_buffer)(struct altera_tse_private *, struct tse_buffer *);
0396 u32 (*tx_completions)(struct altera_tse_private *);
0397 void (*add_rx_desc)(struct altera_tse_private *, struct tse_buffer *);
0398 u32 (*get_rx_status)(struct altera_tse_private *);
0399 int (*init_dma)(struct altera_tse_private *);
0400 void (*uninit_dma)(struct altera_tse_private *);
0401 void (*start_rxdma)(struct altera_tse_private *);
0402 };
0403
0404
0405
0406 struct altera_tse_private {
0407 struct net_device *dev;
0408 struct device *device;
0409 struct napi_struct napi;
0410
0411
0412 struct altera_tse_mac __iomem *mac_dev;
0413
0414
0415 u32 revision;
0416
0417
0418 void __iomem *rx_dma_csr;
0419 void __iomem *rx_dma_desc;
0420 void __iomem *rx_dma_resp;
0421
0422
0423 void __iomem *tx_dma_csr;
0424 void __iomem *tx_dma_desc;
0425
0426
0427 struct tse_buffer *rx_ring;
0428 u32 rx_cons;
0429 u32 rx_prod;
0430 u32 rx_ring_size;
0431 u32 rx_dma_buf_sz;
0432
0433
0434 struct tse_buffer *tx_ring;
0435 u32 tx_prod;
0436 u32 tx_cons;
0437 u32 tx_ring_size;
0438
0439
0440 u32 tx_irq;
0441 u32 rx_irq;
0442
0443
0444 u32 tx_fifo_depth;
0445 u32 rx_fifo_depth;
0446
0447
0448 u32 hash_filter;
0449 u32 added_unicast;
0450
0451
0452 u32 txdescmem;
0453 u32 rxdescmem;
0454 dma_addr_t rxdescmem_busaddr;
0455 dma_addr_t txdescmem_busaddr;
0456 u32 txctrlreg;
0457 u32 rxctrlreg;
0458 dma_addr_t rxdescphys;
0459 dma_addr_t txdescphys;
0460
0461 struct list_head txlisthd;
0462 struct list_head rxlisthd;
0463
0464
0465 spinlock_t mac_cfg_lock;
0466
0467 spinlock_t tx_lock;
0468
0469 spinlock_t rxdma_irq_lock;
0470
0471
0472 int phy_addr;
0473 phy_interface_t phy_iface;
0474 struct mii_bus *mdio;
0475 int oldspeed;
0476 int oldduplex;
0477 int oldlink;
0478
0479
0480 u32 msg_enable;
0481
0482 struct altera_dmaops *dmaops;
0483 };
0484
0485
0486
0487 void altera_tse_set_ethtool_ops(struct net_device *);
0488
0489 static inline
0490 u32 csrrd32(void __iomem *mac, size_t offs)
0491 {
0492 void __iomem *paddr = (void __iomem *)((uintptr_t)mac + offs);
0493 return readl(paddr);
0494 }
0495
0496 static inline
0497 u16 csrrd16(void __iomem *mac, size_t offs)
0498 {
0499 void __iomem *paddr = (void __iomem *)((uintptr_t)mac + offs);
0500 return readw(paddr);
0501 }
0502
0503 static inline
0504 u8 csrrd8(void __iomem *mac, size_t offs)
0505 {
0506 void __iomem *paddr = (void __iomem *)((uintptr_t)mac + offs);
0507 return readb(paddr);
0508 }
0509
0510 static inline
0511 void csrwr32(u32 val, void __iomem *mac, size_t offs)
0512 {
0513 void __iomem *paddr = (void __iomem *)((uintptr_t)mac + offs);
0514
0515 writel(val, paddr);
0516 }
0517
0518 static inline
0519 void csrwr16(u16 val, void __iomem *mac, size_t offs)
0520 {
0521 void __iomem *paddr = (void __iomem *)((uintptr_t)mac + offs);
0522
0523 writew(val, paddr);
0524 }
0525
0526 static inline
0527 void csrwr8(u8 val, void __iomem *mac, size_t offs)
0528 {
0529 void __iomem *paddr = (void __iomem *)((uintptr_t)mac + offs);
0530
0531 writeb(val, paddr);
0532 }
0533
0534 #endif