Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2014-2020 Broadcom
0004  */
0005 
0006 #ifndef __BCMGENET_H__
0007 #define __BCMGENET_H__
0008 
0009 #include <linux/skbuff.h>
0010 #include <linux/netdevice.h>
0011 #include <linux/spinlock.h>
0012 #include <linux/clk.h>
0013 #include <linux/mii.h>
0014 #include <linux/if_vlan.h>
0015 #include <linux/phy.h>
0016 #include <linux/dim.h>
0017 #include <linux/ethtool.h>
0018 
0019 #include "../unimac.h"
0020 
0021 /* total number of Buffer Descriptors, same for Rx/Tx */
0022 #define TOTAL_DESC              256
0023 
0024 /* which ring is descriptor based */
0025 #define DESC_INDEX              16
0026 
0027 /* Body(1500) + EH_SIZE(14) + VLANTAG(4) + BRCMTAG(6) + FCS(4) = 1528.
0028  * 1536 is multiple of 256 bytes
0029  */
0030 #define ENET_BRCM_TAG_LEN   6
0031 #define ENET_PAD        8
0032 #define ENET_MAX_MTU_SIZE   (ETH_DATA_LEN + ETH_HLEN + VLAN_HLEN + \
0033                  ENET_BRCM_TAG_LEN + ETH_FCS_LEN + ENET_PAD)
0034 #define DMA_MAX_BURST_LENGTH    0x10
0035 
0036 /* misc. configuration */
0037 #define MAX_NUM_OF_FS_RULES     16
0038 #define CLEAR_ALL_HFB           0xFF
0039 #define DMA_FC_THRESH_HI        (TOTAL_DESC >> 4)
0040 #define DMA_FC_THRESH_LO        5
0041 
0042 /* 64B receive/transmit status block */
0043 struct status_64 {
0044     u32 length_status;      /* length and peripheral status */
0045     u32 ext_status;     /* Extended status*/
0046     u32 rx_csum;        /* partial rx checksum */
0047     u32 unused1[9];     /* unused */
0048     u32 tx_csum_info;       /* Tx checksum info. */
0049     u32 unused2[3];     /* unused */
0050 };
0051 
0052 /* Rx status bits */
0053 #define STATUS_RX_EXT_MASK      0x1FFFFF
0054 #define STATUS_RX_CSUM_MASK     0xFFFF
0055 #define STATUS_RX_CSUM_OK       0x10000
0056 #define STATUS_RX_CSUM_FR       0x20000
0057 #define STATUS_RX_PROTO_TCP     0
0058 #define STATUS_RX_PROTO_UDP     1
0059 #define STATUS_RX_PROTO_ICMP        2
0060 #define STATUS_RX_PROTO_OTHER       3
0061 #define STATUS_RX_PROTO_MASK        3
0062 #define STATUS_RX_PROTO_SHIFT       18
0063 #define STATUS_FILTER_INDEX_MASK    0xFFFF
0064 /* Tx status bits */
0065 #define STATUS_TX_CSUM_START_MASK   0X7FFF
0066 #define STATUS_TX_CSUM_START_SHIFT  16
0067 #define STATUS_TX_CSUM_PROTO_UDP    0x8000
0068 #define STATUS_TX_CSUM_OFFSET_MASK  0x7FFF
0069 #define STATUS_TX_CSUM_LV       0x80000000
0070 
0071 /* DMA Descriptor */
0072 #define DMA_DESC_LENGTH_STATUS  0x00    /* in bytes of data in buffer */
0073 #define DMA_DESC_ADDRESS_LO 0x04    /* lower bits of PA */
0074 #define DMA_DESC_ADDRESS_HI 0x08    /* upper 32 bits of PA, GENETv4+ */
0075 
0076 /* Rx/Tx common counter group */
0077 struct bcmgenet_pkt_counters {
0078     u32 cnt_64;     /* RO Received/Transmited 64 bytes packet */
0079     u32 cnt_127;    /* RO Rx/Tx 127 bytes packet */
0080     u32 cnt_255;    /* RO Rx/Tx 65-255 bytes packet */
0081     u32 cnt_511;    /* RO Rx/Tx 256-511 bytes packet */
0082     u32 cnt_1023;   /* RO Rx/Tx 512-1023 bytes packet */
0083     u32 cnt_1518;   /* RO Rx/Tx 1024-1518 bytes packet */
0084     u32 cnt_mgv;    /* RO Rx/Tx 1519-1522 good VLAN packet */
0085     u32 cnt_2047;   /* RO Rx/Tx 1522-2047 bytes packet*/
0086     u32 cnt_4095;   /* RO Rx/Tx 2048-4095 bytes packet*/
0087     u32 cnt_9216;   /* RO Rx/Tx 4096-9216 bytes packet*/
0088 };
0089 
0090 /* RSV, Receive Status Vector */
0091 struct bcmgenet_rx_counters {
0092     struct  bcmgenet_pkt_counters pkt_cnt;
0093     u32 pkt;        /* RO (0x428) Received pkt count*/
0094     u32 bytes;      /* RO Received byte count */
0095     u32 mca;        /* RO # of Received multicast pkt */
0096     u32 bca;        /* RO # of Receive broadcast pkt */
0097     u32 fcs;        /* RO # of Received FCS error  */
0098     u32 cf;     /* RO # of Received control frame pkt*/
0099     u32 pf;     /* RO # of Received pause frame pkt */
0100     u32 uo;     /* RO # of unknown op code pkt */
0101     u32 aln;        /* RO # of alignment error count */
0102     u32 flr;        /* RO # of frame length out of range count */
0103     u32 cde;        /* RO # of code error pkt */
0104     u32 fcr;        /* RO # of carrier sense error pkt */
0105     u32 ovr;        /* RO # of oversize pkt*/
0106     u32 jbr;        /* RO # of jabber count */
0107     u32 mtue;       /* RO # of MTU error pkt*/
0108     u32 pok;        /* RO # of Received good pkt */
0109     u32 uc;     /* RO # of unicast pkt */
0110     u32 ppp;        /* RO # of PPP pkt */
0111     u32 rcrc;       /* RO (0x470),# of CRC match pkt */
0112 };
0113 
0114 /* TSV, Transmit Status Vector */
0115 struct bcmgenet_tx_counters {
0116     struct bcmgenet_pkt_counters pkt_cnt;
0117     u32 pkts;       /* RO (0x4a8) Transmited pkt */
0118     u32 mca;        /* RO # of xmited multicast pkt */
0119     u32 bca;        /* RO # of xmited broadcast pkt */
0120     u32 pf;     /* RO # of xmited pause frame count */
0121     u32 cf;     /* RO # of xmited control frame count */
0122     u32 fcs;        /* RO # of xmited FCS error count */
0123     u32 ovr;        /* RO # of xmited oversize pkt */
0124     u32 drf;        /* RO # of xmited deferral pkt */
0125     u32 edf;        /* RO # of xmited Excessive deferral pkt*/
0126     u32 scl;        /* RO # of xmited single collision pkt */
0127     u32 mcl;        /* RO # of xmited multiple collision pkt*/
0128     u32 lcl;        /* RO # of xmited late collision pkt */
0129     u32 ecl;        /* RO # of xmited excessive collision pkt*/
0130     u32 frg;        /* RO # of xmited fragments pkt*/
0131     u32 ncl;        /* RO # of xmited total collision count */
0132     u32 jbr;        /* RO # of xmited jabber count*/
0133     u32 bytes;      /* RO # of xmited byte count */
0134     u32 pok;        /* RO # of xmited good pkt */
0135     u32 uc;     /* RO (0x0x4f0)# of xmited unitcast pkt */
0136 };
0137 
0138 struct bcmgenet_mib_counters {
0139     struct bcmgenet_rx_counters rx;
0140     struct bcmgenet_tx_counters tx;
0141     u32 rx_runt_cnt;
0142     u32 rx_runt_fcs;
0143     u32 rx_runt_fcs_align;
0144     u32 rx_runt_bytes;
0145     u32 rbuf_ovflow_cnt;
0146     u32 rbuf_err_cnt;
0147     u32 mdf_err_cnt;
0148     u32 alloc_rx_buff_failed;
0149     u32 rx_dma_failed;
0150     u32 tx_dma_failed;
0151     u32 tx_realloc_tsb;
0152     u32 tx_realloc_tsb_failed;
0153 };
0154 
0155 #define UMAC_MIB_START          0x400
0156 
0157 #define UMAC_MDIO_CMD           0x614
0158 #define  MDIO_START_BUSY        (1 << 29)
0159 #define  MDIO_READ_FAIL         (1 << 28)
0160 #define  MDIO_RD            (2 << 26)
0161 #define  MDIO_WR            (1 << 26)
0162 #define  MDIO_PMD_SHIFT         21
0163 #define  MDIO_PMD_MASK          0x1F
0164 #define  MDIO_REG_SHIFT         16
0165 #define  MDIO_REG_MASK          0x1F
0166 
0167 #define UMAC_RBUF_OVFL_CNT_V1       0x61C
0168 #define RBUF_OVFL_CNT_V2        0x80
0169 #define RBUF_OVFL_CNT_V3PLUS        0x94
0170 
0171 #define UMAC_MPD_CTRL           0x620
0172 #define  MPD_EN             (1 << 0)
0173 #define  MPD_PW_EN          (1 << 27)
0174 #define  MPD_MSEQ_LEN_SHIFT     16
0175 #define  MPD_MSEQ_LEN_MASK      0xFF
0176 
0177 #define UMAC_MPD_PW_MS          0x624
0178 #define UMAC_MPD_PW_LS          0x628
0179 #define UMAC_RBUF_ERR_CNT_V1        0x634
0180 #define RBUF_ERR_CNT_V2         0x84
0181 #define RBUF_ERR_CNT_V3PLUS     0x98
0182 #define UMAC_MDF_ERR_CNT        0x638
0183 #define UMAC_MDF_CTRL           0x650
0184 #define UMAC_MDF_ADDR           0x654
0185 #define UMAC_MIB_CTRL           0x580
0186 #define  MIB_RESET_RX           (1 << 0)
0187 #define  MIB_RESET_RUNT         (1 << 1)
0188 #define  MIB_RESET_TX           (1 << 2)
0189 
0190 #define RBUF_CTRL           0x00
0191 #define  RBUF_64B_EN            (1 << 0)
0192 #define  RBUF_ALIGN_2B          (1 << 1)
0193 #define  RBUF_BAD_DIS           (1 << 2)
0194 
0195 #define RBUF_STATUS         0x0C
0196 #define  RBUF_STATUS_WOL        (1 << 0)
0197 #define  RBUF_STATUS_MPD_INTR_ACTIVE    (1 << 1)
0198 #define  RBUF_STATUS_ACPI_INTR_ACTIVE   (1 << 2)
0199 
0200 #define RBUF_CHK_CTRL           0x14
0201 #define  RBUF_RXCHK_EN          (1 << 0)
0202 #define  RBUF_SKIP_FCS          (1 << 4)
0203 #define  RBUF_L3_PARSE_DIS      (1 << 5)
0204 
0205 #define RBUF_ENERGY_CTRL        0x9c
0206 #define  RBUF_EEE_EN            (1 << 0)
0207 #define  RBUF_PM_EN         (1 << 1)
0208 
0209 #define RBUF_TBUF_SIZE_CTRL     0xb4
0210 
0211 #define RBUF_HFB_CTRL_V1        0x38
0212 #define  RBUF_HFB_FILTER_EN_SHIFT   16
0213 #define  RBUF_HFB_FILTER_EN_MASK    0xffff0000
0214 #define  RBUF_HFB_EN            (1 << 0)
0215 #define  RBUF_HFB_256B          (1 << 1)
0216 #define  RBUF_ACPI_EN           (1 << 2)
0217 
0218 #define RBUF_HFB_LEN_V1         0x3C
0219 #define  RBUF_FLTR_LEN_MASK     0xFF
0220 #define  RBUF_FLTR_LEN_SHIFT        8
0221 
0222 #define TBUF_CTRL           0x00
0223 #define  TBUF_64B_EN            (1 << 0)
0224 #define TBUF_BP_MC          0x0C
0225 #define TBUF_ENERGY_CTRL        0x14
0226 #define  TBUF_EEE_EN            (1 << 0)
0227 #define  TBUF_PM_EN         (1 << 1)
0228 
0229 #define TBUF_CTRL_V1            0x80
0230 #define TBUF_BP_MC_V1           0xA0
0231 
0232 #define HFB_CTRL            0x00
0233 #define HFB_FLT_ENABLE_V3PLUS       0x04
0234 #define HFB_FLT_LEN_V2          0x04
0235 #define HFB_FLT_LEN_V3PLUS      0x1C
0236 
0237 /* uniMac intrl2 registers */
0238 #define INTRL2_CPU_STAT         0x00
0239 #define INTRL2_CPU_SET          0x04
0240 #define INTRL2_CPU_CLEAR        0x08
0241 #define INTRL2_CPU_MASK_STATUS      0x0C
0242 #define INTRL2_CPU_MASK_SET     0x10
0243 #define INTRL2_CPU_MASK_CLEAR       0x14
0244 
0245 /* INTRL2 instance 0 definitions */
0246 #define UMAC_IRQ_SCB            (1 << 0)
0247 #define UMAC_IRQ_EPHY           (1 << 1)
0248 #define UMAC_IRQ_PHY_DET_R      (1 << 2)
0249 #define UMAC_IRQ_PHY_DET_F      (1 << 3)
0250 #define UMAC_IRQ_LINK_UP        (1 << 4)
0251 #define UMAC_IRQ_LINK_DOWN      (1 << 5)
0252 #define UMAC_IRQ_LINK_EVENT     (UMAC_IRQ_LINK_UP | UMAC_IRQ_LINK_DOWN)
0253 #define UMAC_IRQ_UMAC           (1 << 6)
0254 #define UMAC_IRQ_UMAC_TSV       (1 << 7)
0255 #define UMAC_IRQ_TBUF_UNDERRUN      (1 << 8)
0256 #define UMAC_IRQ_RBUF_OVERFLOW      (1 << 9)
0257 #define UMAC_IRQ_HFB_SM         (1 << 10)
0258 #define UMAC_IRQ_HFB_MM         (1 << 11)
0259 #define UMAC_IRQ_MPD_R          (1 << 12)
0260 #define UMAC_IRQ_WAKE_EVENT     (UMAC_IRQ_HFB_SM | UMAC_IRQ_HFB_MM | \
0261                      UMAC_IRQ_MPD_R)
0262 #define UMAC_IRQ_RXDMA_MBDONE       (1 << 13)
0263 #define UMAC_IRQ_RXDMA_PDONE        (1 << 14)
0264 #define UMAC_IRQ_RXDMA_BDONE        (1 << 15)
0265 #define UMAC_IRQ_RXDMA_DONE     UMAC_IRQ_RXDMA_MBDONE
0266 #define UMAC_IRQ_TXDMA_MBDONE       (1 << 16)
0267 #define UMAC_IRQ_TXDMA_PDONE        (1 << 17)
0268 #define UMAC_IRQ_TXDMA_BDONE        (1 << 18)
0269 #define UMAC_IRQ_TXDMA_DONE     UMAC_IRQ_TXDMA_MBDONE
0270 
0271 /* Only valid for GENETv3+ */
0272 #define UMAC_IRQ_MDIO_DONE      (1 << 23)
0273 #define UMAC_IRQ_MDIO_ERROR     (1 << 24)
0274 
0275 /* INTRL2 instance 1 definitions */
0276 #define UMAC_IRQ1_TX_INTR_MASK      0xFFFF
0277 #define UMAC_IRQ1_RX_INTR_MASK      0xFFFF
0278 #define UMAC_IRQ1_RX_INTR_SHIFT     16
0279 
0280 /* Register block offsets */
0281 #define GENET_SYS_OFF           0x0000
0282 #define GENET_GR_BRIDGE_OFF     0x0040
0283 #define GENET_EXT_OFF           0x0080
0284 #define GENET_INTRL2_0_OFF      0x0200
0285 #define GENET_INTRL2_1_OFF      0x0240
0286 #define GENET_RBUF_OFF          0x0300
0287 #define GENET_UMAC_OFF          0x0800
0288 
0289 /* SYS block offsets and register definitions */
0290 #define SYS_REV_CTRL            0x00
0291 #define SYS_PORT_CTRL           0x04
0292 #define  PORT_MODE_INT_EPHY     0
0293 #define  PORT_MODE_INT_GPHY     1
0294 #define  PORT_MODE_EXT_EPHY     2
0295 #define  PORT_MODE_EXT_GPHY     3
0296 #define  PORT_MODE_EXT_RVMII_25     (4 | BIT(4))
0297 #define  PORT_MODE_EXT_RVMII_50     4
0298 #define  LED_ACT_SOURCE_MAC     (1 << 9)
0299 
0300 #define SYS_RBUF_FLUSH_CTRL     0x08
0301 #define SYS_TBUF_FLUSH_CTRL     0x0C
0302 #define RBUF_FLUSH_CTRL_V1      0x04
0303 
0304 /* Ext block register offsets and definitions */
0305 #define EXT_EXT_PWR_MGMT        0x00
0306 #define  EXT_PWR_DOWN_BIAS      (1 << 0)
0307 #define  EXT_PWR_DOWN_DLL       (1 << 1)
0308 #define  EXT_PWR_DOWN_PHY       (1 << 2)
0309 #define  EXT_PWR_DN_EN_LD       (1 << 3)
0310 #define  EXT_ENERGY_DET         (1 << 4)
0311 #define  EXT_IDDQ_FROM_PHY      (1 << 5)
0312 #define  EXT_IDDQ_GLBL_PWR      (1 << 7)
0313 #define  EXT_PHY_RESET          (1 << 8)
0314 #define  EXT_ENERGY_DET_MASK        (1 << 12)
0315 #define  EXT_PWR_DOWN_PHY_TX        (1 << 16)
0316 #define  EXT_PWR_DOWN_PHY_RX        (1 << 17)
0317 #define  EXT_PWR_DOWN_PHY_SD        (1 << 18)
0318 #define  EXT_PWR_DOWN_PHY_RD        (1 << 19)
0319 #define  EXT_PWR_DOWN_PHY_EN        (1 << 20)
0320 
0321 #define EXT_RGMII_OOB_CTRL      0x0C
0322 #define  RGMII_MODE_EN_V123     (1 << 0)
0323 #define  RGMII_LINK         (1 << 4)
0324 #define  OOB_DISABLE            (1 << 5)
0325 #define  RGMII_MODE_EN          (1 << 6)
0326 #define  ID_MODE_DIS            (1 << 16)
0327 
0328 #define EXT_GPHY_CTRL           0x1C
0329 #define  EXT_CFG_IDDQ_BIAS      (1 << 0)
0330 #define  EXT_CFG_PWR_DOWN       (1 << 1)
0331 #define  EXT_CK25_DIS           (1 << 4)
0332 #define  EXT_CFG_IDDQ_GLOBAL_PWR    (1 << 3)
0333 #define  EXT_GPHY_RESET         (1 << 5)
0334 
0335 /* DMA rings size */
0336 #define DMA_RING_SIZE           (0x40)
0337 #define DMA_RINGS_SIZE          (DMA_RING_SIZE * (DESC_INDEX + 1))
0338 
0339 /* DMA registers common definitions */
0340 #define DMA_RW_POINTER_MASK     0x1FF
0341 #define DMA_P_INDEX_DISCARD_CNT_MASK    0xFFFF
0342 #define DMA_P_INDEX_DISCARD_CNT_SHIFT   16
0343 #define DMA_BUFFER_DONE_CNT_MASK    0xFFFF
0344 #define DMA_BUFFER_DONE_CNT_SHIFT   16
0345 #define DMA_P_INDEX_MASK        0xFFFF
0346 #define DMA_C_INDEX_MASK        0xFFFF
0347 
0348 /* DMA ring size register */
0349 #define DMA_RING_SIZE_MASK      0xFFFF
0350 #define DMA_RING_SIZE_SHIFT     16
0351 #define DMA_RING_BUFFER_SIZE_MASK   0xFFFF
0352 
0353 /* DMA interrupt threshold register */
0354 #define DMA_INTR_THRESHOLD_MASK     0x01FF
0355 
0356 /* DMA XON/XOFF register */
0357 #define DMA_XON_THREHOLD_MASK       0xFFFF
0358 #define DMA_XOFF_THRESHOLD_MASK     0xFFFF
0359 #define DMA_XOFF_THRESHOLD_SHIFT    16
0360 
0361 /* DMA flow period register */
0362 #define DMA_FLOW_PERIOD_MASK        0xFFFF
0363 #define DMA_MAX_PKT_SIZE_MASK       0xFFFF
0364 #define DMA_MAX_PKT_SIZE_SHIFT      16
0365 
0366 
0367 /* DMA control register */
0368 #define DMA_EN              (1 << 0)
0369 #define DMA_RING_BUF_EN_SHIFT       0x01
0370 #define DMA_RING_BUF_EN_MASK        0xFFFF
0371 #define DMA_TSB_SWAP_EN         (1 << 20)
0372 
0373 /* DMA status register */
0374 #define DMA_DISABLED            (1 << 0)
0375 #define DMA_DESC_RAM_INIT_BUSY      (1 << 1)
0376 
0377 /* DMA SCB burst size register */
0378 #define DMA_SCB_BURST_SIZE_MASK     0x1F
0379 
0380 /* DMA activity vector register */
0381 #define DMA_ACTIVITY_VECTOR_MASK    0x1FFFF
0382 
0383 /* DMA backpressure mask register */
0384 #define DMA_BACKPRESSURE_MASK       0x1FFFF
0385 #define DMA_PFC_ENABLE          (1 << 31)
0386 
0387 /* DMA backpressure status register */
0388 #define DMA_BACKPRESSURE_STATUS_MASK    0x1FFFF
0389 
0390 /* DMA override register */
0391 #define DMA_LITTLE_ENDIAN_MODE      (1 << 0)
0392 #define DMA_REGISTER_MODE       (1 << 1)
0393 
0394 /* DMA timeout register */
0395 #define DMA_TIMEOUT_MASK        0xFFFF
0396 #define DMA_TIMEOUT_VAL         5000    /* micro seconds */
0397 
0398 /* TDMA rate limiting control register */
0399 #define DMA_RATE_LIMIT_EN_MASK      0xFFFF
0400 
0401 /* TDMA arbitration control register */
0402 #define DMA_ARBITER_MODE_MASK       0x03
0403 #define DMA_RING_BUF_PRIORITY_MASK  0x1F
0404 #define DMA_RING_BUF_PRIORITY_SHIFT 5
0405 #define DMA_PRIO_REG_INDEX(q)       ((q) / 6)
0406 #define DMA_PRIO_REG_SHIFT(q)       (((q) % 6) * DMA_RING_BUF_PRIORITY_SHIFT)
0407 #define DMA_RATE_ADJ_MASK       0xFF
0408 
0409 /* Tx/Rx Dma Descriptor common bits*/
0410 #define DMA_BUFLENGTH_MASK      0x0fff
0411 #define DMA_BUFLENGTH_SHIFT     16
0412 #define DMA_OWN             0x8000
0413 #define DMA_EOP             0x4000
0414 #define DMA_SOP             0x2000
0415 #define DMA_WRAP            0x1000
0416 /* Tx specific Dma descriptor bits */
0417 #define DMA_TX_UNDERRUN         0x0200
0418 #define DMA_TX_APPEND_CRC       0x0040
0419 #define DMA_TX_OW_CRC           0x0020
0420 #define DMA_TX_DO_CSUM          0x0010
0421 #define DMA_TX_QTAG_SHIFT       7
0422 
0423 /* Rx Specific Dma descriptor bits */
0424 #define DMA_RX_CHK_V3PLUS       0x8000
0425 #define DMA_RX_CHK_V12          0x1000
0426 #define DMA_RX_BRDCAST          0x0040
0427 #define DMA_RX_MULT         0x0020
0428 #define DMA_RX_LG           0x0010
0429 #define DMA_RX_NO           0x0008
0430 #define DMA_RX_RXER         0x0004
0431 #define DMA_RX_CRC_ERROR        0x0002
0432 #define DMA_RX_OV           0x0001
0433 #define DMA_RX_FI_MASK          0x001F
0434 #define DMA_RX_FI_SHIFT         0x0007
0435 #define DMA_DESC_ALLOC_MASK     0x00FF
0436 
0437 #define DMA_ARBITER_RR          0x00
0438 #define DMA_ARBITER_WRR         0x01
0439 #define DMA_ARBITER_SP          0x02
0440 
0441 struct enet_cb {
0442     struct sk_buff      *skb;
0443     void __iomem *bd_addr;
0444     DEFINE_DMA_UNMAP_ADDR(dma_addr);
0445     DEFINE_DMA_UNMAP_LEN(dma_len);
0446 };
0447 
0448 /* power management mode */
0449 enum bcmgenet_power_mode {
0450     GENET_POWER_CABLE_SENSE = 0,
0451     GENET_POWER_PASSIVE,
0452     GENET_POWER_WOL_MAGIC,
0453 };
0454 
0455 struct bcmgenet_priv;
0456 
0457 /* We support both runtime GENET detection and compile-time
0458  * to optimize code-paths for a given hardware
0459  */
0460 enum bcmgenet_version {
0461     GENET_V1 = 1,
0462     GENET_V2,
0463     GENET_V3,
0464     GENET_V4,
0465     GENET_V5
0466 };
0467 
0468 #define GENET_IS_V1(p)  ((p)->version == GENET_V1)
0469 #define GENET_IS_V2(p)  ((p)->version == GENET_V2)
0470 #define GENET_IS_V3(p)  ((p)->version == GENET_V3)
0471 #define GENET_IS_V4(p)  ((p)->version == GENET_V4)
0472 #define GENET_IS_V5(p)  ((p)->version == GENET_V5)
0473 
0474 /* Hardware flags */
0475 #define GENET_HAS_40BITS    (1 << 0)
0476 #define GENET_HAS_EXT       (1 << 1)
0477 #define GENET_HAS_MDIO_INTR (1 << 2)
0478 #define GENET_HAS_MOCA_LINK_DET (1 << 3)
0479 
0480 /* BCMGENET hardware parameters, keep this structure nicely aligned
0481  * since it is going to be used in hot paths
0482  */
0483 struct bcmgenet_hw_params {
0484     u8      tx_queues;
0485     u8      tx_bds_per_q;
0486     u8      rx_queues;
0487     u8      rx_bds_per_q;
0488     u8      bp_in_en_shift;
0489     u32     bp_in_mask;
0490     u8      hfb_filter_cnt;
0491     u8      hfb_filter_size;
0492     u8      qtag_mask;
0493     u16     tbuf_offset;
0494     u32     hfb_offset;
0495     u32     hfb_reg_offset;
0496     u32     rdma_offset;
0497     u32     tdma_offset;
0498     u32     words_per_bd;
0499     u32     flags;
0500 };
0501 
0502 struct bcmgenet_skb_cb {
0503     struct enet_cb *first_cb;   /* First control block of SKB */
0504     struct enet_cb *last_cb;    /* Last control block of SKB */
0505     unsigned int bytes_sent;    /* bytes on the wire (no TSB) */
0506 };
0507 
0508 #define GENET_CB(skb)   ((struct bcmgenet_skb_cb *)((skb)->cb))
0509 
0510 struct bcmgenet_tx_ring {
0511     spinlock_t  lock;       /* ring lock */
0512     struct napi_struct napi;    /* NAPI per tx queue */
0513     unsigned long   packets;
0514     unsigned long   bytes;
0515     unsigned int    index;      /* ring index */
0516     unsigned int    queue;      /* queue index */
0517     struct enet_cb  *cbs;       /* tx ring buffer control block*/
0518     unsigned int    size;       /* size of each tx ring */
0519     unsigned int    clean_ptr;      /* Tx ring clean pointer */
0520     unsigned int    c_index;    /* last consumer index of each ring*/
0521     unsigned int    free_bds;   /* # of free bds for each ring */
0522     unsigned int    write_ptr;  /* Tx ring write pointer SW copy */
0523     unsigned int    prod_index; /* Tx ring producer index SW copy */
0524     unsigned int    cb_ptr;     /* Tx ring initial CB ptr */
0525     unsigned int    end_ptr;    /* Tx ring end CB ptr */
0526     void (*int_enable)(struct bcmgenet_tx_ring *);
0527     void (*int_disable)(struct bcmgenet_tx_ring *);
0528     struct bcmgenet_priv *priv;
0529 };
0530 
0531 struct bcmgenet_net_dim {
0532     u16     use_dim;
0533     u16     event_ctr;
0534     unsigned long   packets;
0535     unsigned long   bytes;
0536     struct dim  dim;
0537 };
0538 
0539 struct bcmgenet_rx_ring {
0540     struct napi_struct napi;    /* Rx NAPI struct */
0541     unsigned long   bytes;
0542     unsigned long   packets;
0543     unsigned long   errors;
0544     unsigned long   dropped;
0545     unsigned int    index;      /* Rx ring index */
0546     struct enet_cb  *cbs;       /* Rx ring buffer control block */
0547     unsigned int    size;       /* Rx ring size */
0548     unsigned int    c_index;    /* Rx last consumer index */
0549     unsigned int    read_ptr;   /* Rx ring read pointer */
0550     unsigned int    cb_ptr;     /* Rx ring initial CB ptr */
0551     unsigned int    end_ptr;    /* Rx ring end CB ptr */
0552     unsigned int    old_discards;
0553     struct bcmgenet_net_dim dim;
0554     u32     rx_max_coalesced_frames;
0555     u32     rx_coalesce_usecs;
0556     void (*int_enable)(struct bcmgenet_rx_ring *);
0557     void (*int_disable)(struct bcmgenet_rx_ring *);
0558     struct bcmgenet_priv *priv;
0559 };
0560 
0561 enum bcmgenet_rxnfc_state {
0562     BCMGENET_RXNFC_STATE_UNUSED = 0,
0563     BCMGENET_RXNFC_STATE_DISABLED,
0564     BCMGENET_RXNFC_STATE_ENABLED
0565 };
0566 
0567 struct bcmgenet_rxnfc_rule {
0568     struct  list_head list;
0569     struct ethtool_rx_flow_spec fs;
0570     enum bcmgenet_rxnfc_state state;
0571 };
0572 
0573 /* device context */
0574 struct bcmgenet_priv {
0575     void __iomem *base;
0576     enum bcmgenet_version version;
0577     struct net_device *dev;
0578 
0579     /* transmit variables */
0580     void __iomem *tx_bds;
0581     struct enet_cb *tx_cbs;
0582     unsigned int num_tx_bds;
0583 
0584     struct bcmgenet_tx_ring tx_rings[DESC_INDEX + 1];
0585 
0586     /* receive variables */
0587     void __iomem *rx_bds;
0588     struct enet_cb *rx_cbs;
0589     unsigned int num_rx_bds;
0590     unsigned int rx_buf_len;
0591     struct bcmgenet_rxnfc_rule rxnfc_rules[MAX_NUM_OF_FS_RULES];
0592     struct list_head rxnfc_list;
0593 
0594     struct bcmgenet_rx_ring rx_rings[DESC_INDEX + 1];
0595 
0596     /* other misc variables */
0597     struct bcmgenet_hw_params *hw_params;
0598     unsigned autoneg_pause:1;
0599     unsigned tx_pause:1;
0600     unsigned rx_pause:1;
0601 
0602     /* MDIO bus variables */
0603     wait_queue_head_t wq;
0604     bool internal_phy;
0605     struct device_node *phy_dn;
0606     struct device_node *mdio_dn;
0607     struct mii_bus *mii_bus;
0608     u16 gphy_rev;
0609     struct clk *clk_eee;
0610     bool clk_eee_enabled;
0611 
0612     /* PHY device variables */
0613     phy_interface_t phy_interface;
0614     int phy_addr;
0615     int ext_phy;
0616     bool ephy_16nm;
0617 
0618     /* Interrupt variables */
0619     struct work_struct bcmgenet_irq_work;
0620     int irq0;
0621     int irq1;
0622     int wol_irq;
0623     bool wol_irq_disabled;
0624 
0625     /* shared status */
0626     spinlock_t lock;
0627     unsigned int irq0_stat;
0628 
0629     /* HW descriptors/checksum variables */
0630     bool crc_fwd_en;
0631 
0632     u32 dma_max_burst_length;
0633 
0634     u32 msg_enable;
0635 
0636     struct clk *clk;
0637     struct platform_device *pdev;
0638     struct platform_device *mii_pdev;
0639 
0640     /* WOL */
0641     struct clk *clk_wol;
0642     u32 wolopts;
0643     u8 sopass[SOPASS_MAX];
0644     bool wol_active;
0645 
0646     struct bcmgenet_mib_counters mib;
0647 
0648     struct ethtool_eee eee;
0649 };
0650 
0651 #define GENET_IO_MACRO(name, offset)                    \
0652 static inline u32 bcmgenet_##name##_readl(struct bcmgenet_priv *priv,   \
0653                     u32 off)            \
0654 {                                   \
0655     /* MIPS chips strapped for BE will automagically configure the  \
0656      * peripheral registers for CPU-native byte order.      \
0657      */                             \
0658     if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) \
0659         return __raw_readl(priv->base + offset + off);      \
0660     else                                \
0661         return readl_relaxed(priv->base + offset + off);    \
0662 }                                   \
0663 static inline void bcmgenet_##name##_writel(struct bcmgenet_priv *priv, \
0664                     u32 val, u32 off)       \
0665 {                                   \
0666     if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) \
0667         __raw_writel(val, priv->base + offset + off);       \
0668     else                                \
0669         writel_relaxed(val, priv->base + offset + off);     \
0670 }
0671 
0672 GENET_IO_MACRO(ext, GENET_EXT_OFF);
0673 GENET_IO_MACRO(umac, GENET_UMAC_OFF);
0674 GENET_IO_MACRO(sys, GENET_SYS_OFF);
0675 
0676 /* interrupt l2 registers accessors */
0677 GENET_IO_MACRO(intrl2_0, GENET_INTRL2_0_OFF);
0678 GENET_IO_MACRO(intrl2_1, GENET_INTRL2_1_OFF);
0679 
0680 /* HFB register accessors  */
0681 GENET_IO_MACRO(hfb, priv->hw_params->hfb_offset);
0682 
0683 /* GENET v2+ HFB control and filter len helpers */
0684 GENET_IO_MACRO(hfb_reg, priv->hw_params->hfb_reg_offset);
0685 
0686 /* RBUF register accessors */
0687 GENET_IO_MACRO(rbuf, GENET_RBUF_OFF);
0688 
0689 /* MDIO routines */
0690 int bcmgenet_mii_init(struct net_device *dev);
0691 int bcmgenet_mii_config(struct net_device *dev, bool init);
0692 int bcmgenet_mii_probe(struct net_device *dev);
0693 void bcmgenet_mii_exit(struct net_device *dev);
0694 void bcmgenet_phy_pause_set(struct net_device *dev, bool rx, bool tx);
0695 void bcmgenet_phy_power_set(struct net_device *dev, bool enable);
0696 void bcmgenet_mii_setup(struct net_device *dev);
0697 
0698 /* Wake-on-LAN routines */
0699 void bcmgenet_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol);
0700 int bcmgenet_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol);
0701 int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv,
0702                 enum bcmgenet_power_mode mode);
0703 void bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv,
0704                    enum bcmgenet_power_mode mode);
0705 
0706 #endif /* __BCMGENET_H__ */