1*0dd07709SNoam Camus /* 2*0dd07709SNoam Camus * Copyright(c) 2015 EZchip Technologies. 3*0dd07709SNoam Camus * 4*0dd07709SNoam Camus * This program is free software; you can redistribute it and/or modify it 5*0dd07709SNoam Camus * under the terms and conditions of the GNU General Public License, 6*0dd07709SNoam Camus * version 2, as published by the Free Software Foundation. 7*0dd07709SNoam Camus * 8*0dd07709SNoam Camus * This program is distributed in the hope it will be useful, but WITHOUT 9*0dd07709SNoam Camus * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10*0dd07709SNoam Camus * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11*0dd07709SNoam Camus * more details. 12*0dd07709SNoam Camus * 13*0dd07709SNoam Camus * The full GNU General Public License is included in this distribution in 14*0dd07709SNoam Camus * the file called "COPYING". 15*0dd07709SNoam Camus */ 16*0dd07709SNoam Camus 17*0dd07709SNoam Camus #ifndef _NPS_ENET_H 18*0dd07709SNoam Camus #define _NPS_ENET_H 19*0dd07709SNoam Camus 20*0dd07709SNoam Camus /* default values */ 21*0dd07709SNoam Camus #define NPS_ENET_NAPI_POLL_WEIGHT 0x2 22*0dd07709SNoam Camus #define NPS_ENET_MAX_FRAME_LENGTH 0x3FFF 23*0dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_0_TX_FC_RETR 0x7 24*0dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_0_RX_IFG 0x5 25*0dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_0_TX_IFG 0xC 26*0dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_0_TX_PR_LEN 0x7 27*0dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_2_STAT_EN 0x3 28*0dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_3_RX_IFG_TH 0x14 29*0dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_3_MAX_LEN 0x3FFC 30*0dd07709SNoam Camus #define NPS_ENET_ENABLE 1 31*0dd07709SNoam Camus #define NPS_ENET_DISABLE 0 32*0dd07709SNoam Camus 33*0dd07709SNoam Camus /* register definitions */ 34*0dd07709SNoam Camus #define NPS_ENET_REG_TX_CTL 0x800 35*0dd07709SNoam Camus #define NPS_ENET_REG_TX_BUF 0x808 36*0dd07709SNoam Camus #define NPS_ENET_REG_RX_CTL 0x810 37*0dd07709SNoam Camus #define NPS_ENET_REG_RX_BUF 0x818 38*0dd07709SNoam Camus #define NPS_ENET_REG_BUF_INT_ENABLE 0x8C0 39*0dd07709SNoam Camus #define NPS_ENET_REG_BUF_INT_CAUSE 0x8C4 40*0dd07709SNoam Camus #define NPS_ENET_REG_GE_MAC_CFG_0 0x1000 41*0dd07709SNoam Camus #define NPS_ENET_REG_GE_MAC_CFG_1 0x1004 42*0dd07709SNoam Camus #define NPS_ENET_REG_GE_MAC_CFG_2 0x1008 43*0dd07709SNoam Camus #define NPS_ENET_REG_GE_MAC_CFG_3 0x100C 44*0dd07709SNoam Camus #define NPS_ENET_REG_GE_RST 0x1400 45*0dd07709SNoam Camus #define NPS_ENET_REG_PHASE_FIFO_CTL 0x1404 46*0dd07709SNoam Camus 47*0dd07709SNoam Camus /* Tx control register */ 48*0dd07709SNoam Camus struct nps_enet_tx_ctl { 49*0dd07709SNoam Camus union { 50*0dd07709SNoam Camus /* ct: SW sets to indicate frame ready in Tx buffer for 51*0dd07709SNoam Camus * transmission. HW resets to when transmission done 52*0dd07709SNoam Camus * et: Transmit error 53*0dd07709SNoam Camus * nt: Length in bytes of Tx frame loaded to Tx buffer 54*0dd07709SNoam Camus */ 55*0dd07709SNoam Camus struct { 56*0dd07709SNoam Camus u32 57*0dd07709SNoam Camus __reserved_1:16, 58*0dd07709SNoam Camus ct:1, 59*0dd07709SNoam Camus et:1, 60*0dd07709SNoam Camus __reserved_2:3, 61*0dd07709SNoam Camus nt:11; 62*0dd07709SNoam Camus }; 63*0dd07709SNoam Camus 64*0dd07709SNoam Camus u32 value; 65*0dd07709SNoam Camus }; 66*0dd07709SNoam Camus }; 67*0dd07709SNoam Camus 68*0dd07709SNoam Camus /* Rx control register */ 69*0dd07709SNoam Camus struct nps_enet_rx_ctl { 70*0dd07709SNoam Camus union { 71*0dd07709SNoam Camus /* cr: HW sets to indicate frame ready in Rx buffer. 72*0dd07709SNoam Camus * SW resets to indicate host read received frame 73*0dd07709SNoam Camus * and new frames can be written to Rx buffer 74*0dd07709SNoam Camus * er: Rx error indication 75*0dd07709SNoam Camus * crc: Rx CRC error indication 76*0dd07709SNoam Camus * nr: Length in bytes of Rx frame loaded by MAC to Rx buffer 77*0dd07709SNoam Camus */ 78*0dd07709SNoam Camus struct { 79*0dd07709SNoam Camus u32 80*0dd07709SNoam Camus __reserved_1:16, 81*0dd07709SNoam Camus cr:1, 82*0dd07709SNoam Camus er:1, 83*0dd07709SNoam Camus crc:1, 84*0dd07709SNoam Camus __reserved_2:2, 85*0dd07709SNoam Camus nr:11; 86*0dd07709SNoam Camus }; 87*0dd07709SNoam Camus 88*0dd07709SNoam Camus u32 value; 89*0dd07709SNoam Camus }; 90*0dd07709SNoam Camus }; 91*0dd07709SNoam Camus 92*0dd07709SNoam Camus /* Interrupt enable for data buffer events register */ 93*0dd07709SNoam Camus struct nps_enet_buf_int_enable { 94*0dd07709SNoam Camus union { 95*0dd07709SNoam Camus /* tx_done: Interrupt generation in the case when new frame 96*0dd07709SNoam Camus * is ready in Rx buffer 97*0dd07709SNoam Camus * rx_rdy: Interrupt generation in the case when current frame 98*0dd07709SNoam Camus * was read from TX buffer 99*0dd07709SNoam Camus */ 100*0dd07709SNoam Camus struct { 101*0dd07709SNoam Camus u32 102*0dd07709SNoam Camus __reserved:30, 103*0dd07709SNoam Camus tx_done:1, 104*0dd07709SNoam Camus rx_rdy:1; 105*0dd07709SNoam Camus }; 106*0dd07709SNoam Camus 107*0dd07709SNoam Camus u32 value; 108*0dd07709SNoam Camus }; 109*0dd07709SNoam Camus }; 110*0dd07709SNoam Camus 111*0dd07709SNoam Camus /* Interrupt cause for data buffer events register */ 112*0dd07709SNoam Camus struct nps_enet_buf_int_cause { 113*0dd07709SNoam Camus union { 114*0dd07709SNoam Camus /* tx_done: Interrupt in the case when current frame was 115*0dd07709SNoam Camus * read from TX buffer. 116*0dd07709SNoam Camus * rx_rdy: Interrupt in the case when new frame is ready 117*0dd07709SNoam Camus * in RX buffer. 118*0dd07709SNoam Camus */ 119*0dd07709SNoam Camus struct { 120*0dd07709SNoam Camus u32 121*0dd07709SNoam Camus __reserved:30, 122*0dd07709SNoam Camus tx_done:1, 123*0dd07709SNoam Camus rx_rdy:1; 124*0dd07709SNoam Camus }; 125*0dd07709SNoam Camus 126*0dd07709SNoam Camus u32 value; 127*0dd07709SNoam Camus }; 128*0dd07709SNoam Camus }; 129*0dd07709SNoam Camus 130*0dd07709SNoam Camus /* Gbps Eth MAC Configuration 0 register */ 131*0dd07709SNoam Camus struct nps_enet_ge_mac_cfg_0 { 132*0dd07709SNoam Camus union { 133*0dd07709SNoam Camus /* tx_pr_len: Transmit preamble length in bytes 134*0dd07709SNoam Camus * tx_ifg_nib: Tx idle pattern 135*0dd07709SNoam Camus * nib_mode: Nibble (4-bit) Mode 136*0dd07709SNoam Camus * rx_pr_check_en: Receive preamble Check Enable 137*0dd07709SNoam Camus * tx_ifg: Transmit inter-Frame Gap 138*0dd07709SNoam Camus * rx_ifg: Receive inter-Frame Gap 139*0dd07709SNoam Camus * tx_fc_retr: Transmit Flow Control Retransmit Mode 140*0dd07709SNoam Camus * rx_length_check_en: Receive Length Check Enable 141*0dd07709SNoam Camus * rx_crc_ignore: Results of the CRC check are ignored 142*0dd07709SNoam Camus * rx_crc_strip: MAC strips the CRC from received frames 143*0dd07709SNoam Camus * rx_fc_en: Receive Flow Control Enable 144*0dd07709SNoam Camus * tx_crc_en: Transmit CRC Enabled 145*0dd07709SNoam Camus * tx_pad_en: Transmit Padding Enable 146*0dd07709SNoam Camus * tx_cf_en: Transmit Flow Control Enable 147*0dd07709SNoam Camus * tx_en: Transmit Enable 148*0dd07709SNoam Camus * rx_en: Receive Enable 149*0dd07709SNoam Camus */ 150*0dd07709SNoam Camus struct { 151*0dd07709SNoam Camus u32 152*0dd07709SNoam Camus tx_pr_len:4, 153*0dd07709SNoam Camus tx_ifg_nib:4, 154*0dd07709SNoam Camus nib_mode:1, 155*0dd07709SNoam Camus rx_pr_check_en:1, 156*0dd07709SNoam Camus tx_ifg:6, 157*0dd07709SNoam Camus rx_ifg:4, 158*0dd07709SNoam Camus tx_fc_retr:3, 159*0dd07709SNoam Camus rx_length_check_en:1, 160*0dd07709SNoam Camus rx_crc_ignore:1, 161*0dd07709SNoam Camus rx_crc_strip:1, 162*0dd07709SNoam Camus rx_fc_en:1, 163*0dd07709SNoam Camus tx_crc_en:1, 164*0dd07709SNoam Camus tx_pad_en:1, 165*0dd07709SNoam Camus tx_fc_en:1, 166*0dd07709SNoam Camus tx_en:1, 167*0dd07709SNoam Camus rx_en:1; 168*0dd07709SNoam Camus }; 169*0dd07709SNoam Camus 170*0dd07709SNoam Camus u32 value; 171*0dd07709SNoam Camus }; 172*0dd07709SNoam Camus }; 173*0dd07709SNoam Camus 174*0dd07709SNoam Camus /* Gbps Eth MAC Configuration 1 register */ 175*0dd07709SNoam Camus struct nps_enet_ge_mac_cfg_1 { 176*0dd07709SNoam Camus union { 177*0dd07709SNoam Camus /* octet_3: MAC address octet 3 178*0dd07709SNoam Camus * octet_2: MAC address octet 2 179*0dd07709SNoam Camus * octet_1: MAC address octet 1 180*0dd07709SNoam Camus * octet_0: MAC address octet 0 181*0dd07709SNoam Camus */ 182*0dd07709SNoam Camus struct { 183*0dd07709SNoam Camus u32 184*0dd07709SNoam Camus octet_3:8, 185*0dd07709SNoam Camus octet_2:8, 186*0dd07709SNoam Camus octet_1:8, 187*0dd07709SNoam Camus octet_0:8; 188*0dd07709SNoam Camus }; 189*0dd07709SNoam Camus 190*0dd07709SNoam Camus u32 value; 191*0dd07709SNoam Camus }; 192*0dd07709SNoam Camus }; 193*0dd07709SNoam Camus 194*0dd07709SNoam Camus /* Gbps Eth MAC Configuration 2 register */ 195*0dd07709SNoam Camus struct nps_enet_ge_mac_cfg_2 { 196*0dd07709SNoam Camus union { 197*0dd07709SNoam Camus /* transmit_flush_en: MAC flush enable 198*0dd07709SNoam Camus * stat_en: RMON statistics interface enable 199*0dd07709SNoam Camus * disc_da: Discard frames with DA different 200*0dd07709SNoam Camus * from MAC address 201*0dd07709SNoam Camus * disc_bc: Discard broadcast frames 202*0dd07709SNoam Camus * disc_mc: Discard multicast frames 203*0dd07709SNoam Camus * octet_5: MAC address octet 5 204*0dd07709SNoam Camus * octet_4: MAC address octet 4 205*0dd07709SNoam Camus */ 206*0dd07709SNoam Camus struct { 207*0dd07709SNoam Camus u32 208*0dd07709SNoam Camus transmit_flush_en:1, 209*0dd07709SNoam Camus __reserved_1:5, 210*0dd07709SNoam Camus stat_en:2, 211*0dd07709SNoam Camus __reserved_2:1, 212*0dd07709SNoam Camus disc_da:1, 213*0dd07709SNoam Camus disc_bc:1, 214*0dd07709SNoam Camus disc_mc:1, 215*0dd07709SNoam Camus __reserved_3:4, 216*0dd07709SNoam Camus octet_5:8, 217*0dd07709SNoam Camus octet_4:8; 218*0dd07709SNoam Camus }; 219*0dd07709SNoam Camus 220*0dd07709SNoam Camus u32 value; 221*0dd07709SNoam Camus }; 222*0dd07709SNoam Camus }; 223*0dd07709SNoam Camus 224*0dd07709SNoam Camus /* Gbps Eth MAC Configuration 3 register */ 225*0dd07709SNoam Camus struct nps_enet_ge_mac_cfg_3 { 226*0dd07709SNoam Camus union { 227*0dd07709SNoam Camus /* ext_oob_cbfc_sel: Selects one of the 4 profiles for 228*0dd07709SNoam Camus * extended OOB in-flow-control indication 229*0dd07709SNoam Camus * max_len: Maximum receive frame length in bytes 230*0dd07709SNoam Camus * tx_cbfc_en: Enable transmission of class-based 231*0dd07709SNoam Camus * flow control packets 232*0dd07709SNoam Camus * rx_ifg_th: Threshold for IFG status reporting via OOB 233*0dd07709SNoam Camus * cf_timeout: Configurable time to decrement FC counters 234*0dd07709SNoam Camus * cf_drop: Drop control frames 235*0dd07709SNoam Camus * redirect_cbfc_sel: Selects one of CBFC redirect profiles 236*0dd07709SNoam Camus * rx_cbfc_redir_en: Enable Rx class-based flow 237*0dd07709SNoam Camus * control redirect 238*0dd07709SNoam Camus * rx_cbfc_en: Enable Rx class-based flow control 239*0dd07709SNoam Camus * tm_hd_mode: TM header mode 240*0dd07709SNoam Camus */ 241*0dd07709SNoam Camus struct { 242*0dd07709SNoam Camus u32 243*0dd07709SNoam Camus ext_oob_cbfc_sel:2, 244*0dd07709SNoam Camus max_len:14, 245*0dd07709SNoam Camus tx_cbfc_en:1, 246*0dd07709SNoam Camus rx_ifg_th:5, 247*0dd07709SNoam Camus cf_timeout:4, 248*0dd07709SNoam Camus cf_drop:1, 249*0dd07709SNoam Camus redirect_cbfc_sel:2, 250*0dd07709SNoam Camus rx_cbfc_redir_en:1, 251*0dd07709SNoam Camus rx_cbfc_en:1, 252*0dd07709SNoam Camus tm_hd_mode:1; 253*0dd07709SNoam Camus }; 254*0dd07709SNoam Camus 255*0dd07709SNoam Camus u32 value; 256*0dd07709SNoam Camus }; 257*0dd07709SNoam Camus }; 258*0dd07709SNoam Camus 259*0dd07709SNoam Camus /* GE MAC, PCS reset control register */ 260*0dd07709SNoam Camus struct nps_enet_ge_rst { 261*0dd07709SNoam Camus union { 262*0dd07709SNoam Camus /* gmac_0: GE MAC reset 263*0dd07709SNoam Camus * spcs_0: SGMII PCS reset 264*0dd07709SNoam Camus */ 265*0dd07709SNoam Camus struct { 266*0dd07709SNoam Camus u32 267*0dd07709SNoam Camus __reserved_1:23, 268*0dd07709SNoam Camus gmac_0:1, 269*0dd07709SNoam Camus __reserved_2:7, 270*0dd07709SNoam Camus spcs_0:1; 271*0dd07709SNoam Camus }; 272*0dd07709SNoam Camus 273*0dd07709SNoam Camus u32 value; 274*0dd07709SNoam Camus }; 275*0dd07709SNoam Camus }; 276*0dd07709SNoam Camus 277*0dd07709SNoam Camus /* Tx phase sync FIFO control register */ 278*0dd07709SNoam Camus struct nps_enet_phase_fifo_ctl { 279*0dd07709SNoam Camus union { 280*0dd07709SNoam Camus /* init: initialize serdes TX phase sync FIFO pointers 281*0dd07709SNoam Camus * rst: reset serdes TX phase sync FIFO 282*0dd07709SNoam Camus */ 283*0dd07709SNoam Camus struct { 284*0dd07709SNoam Camus u32 285*0dd07709SNoam Camus __reserved:30, 286*0dd07709SNoam Camus init:1, 287*0dd07709SNoam Camus rst:1; 288*0dd07709SNoam Camus }; 289*0dd07709SNoam Camus 290*0dd07709SNoam Camus u32 value; 291*0dd07709SNoam Camus }; 292*0dd07709SNoam Camus }; 293*0dd07709SNoam Camus 294*0dd07709SNoam Camus /** 295*0dd07709SNoam Camus * struct nps_enet_priv - Storage of ENET's private information. 296*0dd07709SNoam Camus * @regs_base: Base address of ENET memory-mapped control registers. 297*0dd07709SNoam Camus * @irq: For RX/TX IRQ number. 298*0dd07709SNoam Camus * @tx_packet_sent: SW indication if frame is being sent. 299*0dd07709SNoam Camus * @tx_skb: socket buffer of sent frame. 300*0dd07709SNoam Camus * @napi: Structure for NAPI. 301*0dd07709SNoam Camus */ 302*0dd07709SNoam Camus struct nps_enet_priv { 303*0dd07709SNoam Camus void __iomem *regs_base; 304*0dd07709SNoam Camus s32 irq; 305*0dd07709SNoam Camus bool tx_packet_sent; 306*0dd07709SNoam Camus struct sk_buff *tx_skb; 307*0dd07709SNoam Camus struct napi_struct napi; 308*0dd07709SNoam Camus struct nps_enet_ge_mac_cfg_2 ge_mac_cfg_2; 309*0dd07709SNoam Camus struct nps_enet_ge_mac_cfg_3 ge_mac_cfg_3; 310*0dd07709SNoam Camus }; 311*0dd07709SNoam Camus 312*0dd07709SNoam Camus /** 313*0dd07709SNoam Camus * nps_reg_set - Sets ENET register with provided value. 314*0dd07709SNoam Camus * @priv: Pointer to EZchip ENET private data structure. 315*0dd07709SNoam Camus * @reg: Register offset from base address. 316*0dd07709SNoam Camus * @value: Value to set in register. 317*0dd07709SNoam Camus */ 318*0dd07709SNoam Camus static inline void nps_enet_reg_set(struct nps_enet_priv *priv, 319*0dd07709SNoam Camus s32 reg, s32 value) 320*0dd07709SNoam Camus { 321*0dd07709SNoam Camus iowrite32be(value, priv->regs_base + reg); 322*0dd07709SNoam Camus } 323*0dd07709SNoam Camus 324*0dd07709SNoam Camus /** 325*0dd07709SNoam Camus * nps_reg_get - Gets value of specified ENET register. 326*0dd07709SNoam Camus * @priv: Pointer to EZchip ENET private data structure. 327*0dd07709SNoam Camus * @reg: Register offset from base address. 328*0dd07709SNoam Camus * 329*0dd07709SNoam Camus * returns: Value of requested register. 330*0dd07709SNoam Camus */ 331*0dd07709SNoam Camus static inline u32 nps_enet_reg_get(struct nps_enet_priv *priv, s32 reg) 332*0dd07709SNoam Camus { 333*0dd07709SNoam Camus return ioread32be(priv->regs_base + reg); 334*0dd07709SNoam Camus } 335*0dd07709SNoam Camus 336*0dd07709SNoam Camus #endif /* _NPS_ENET_H */ 337