0001
0002
0003
0004 #include <linux/bitops.h>
0005
0006
0007 #define ENETC_DEV_ID_PF 0xe100
0008 #define ENETC_DEV_ID_VF 0xef00
0009 #define ENETC_DEV_ID_PTP 0xee02
0010
0011
0012 #define ENETC_BAR_REGS 0
0013
0014
0015 #define ENETC_SIMR 0
0016 #define ENETC_SIMR_EN BIT(31)
0017 #define ENETC_SIMR_RSSE BIT(0)
0018 #define ENETC_SICTR0 0x18
0019 #define ENETC_SICTR1 0x1c
0020 #define ENETC_SIPCAPR0 0x20
0021 #define ENETC_SIPCAPR0_QBV BIT(4)
0022 #define ENETC_SIPCAPR0_PSFP BIT(9)
0023 #define ENETC_SIPCAPR0_RSS BIT(8)
0024 #define ENETC_SIPCAPR1 0x24
0025 #define ENETC_SITGTGR 0x30
0026 #define ENETC_SIRBGCR 0x38
0027
0028 #define ENETC_SICAR0 0x40
0029 #define ENETC_SICAR1 0x44
0030 #define ENETC_SICAR2 0x48
0031
0032
0033
0034
0035 #define ENETC_SICAR_RD_COHERENT 0x2b2b0000
0036 #define ENETC_SICAR_WR_COHERENT 0x00006727
0037 #define ENETC_SICAR_MSI 0x00300030
0038
0039 #define ENETC_SIPMAR0 0x80
0040 #define ENETC_SIPMAR1 0x84
0041
0042
0043 #define ENETC_DEFAULT_MSG_SIZE 1024
0044
0045 static inline u32 enetc_vsi_set_msize(u32 size)
0046 {
0047 return size < ENETC_DEFAULT_MSG_SIZE ? size >> 5 : 0;
0048 }
0049
0050 #define ENETC_PSIMSGRR 0x204
0051 #define ENETC_PSIMSGRR_MR_MASK GENMASK(2, 1)
0052 #define ENETC_PSIMSGRR_MR(n) BIT((n) + 1)
0053 #define ENETC_PSIVMSGRCVAR0(n) (0x210 + (n) * 0x8)
0054 #define ENETC_PSIVMSGRCVAR1(n) (0x214 + (n) * 0x8)
0055
0056 #define ENETC_VSIMSGSR 0x204
0057 #define ENETC_VSIMSGSR_MB BIT(0)
0058 #define ENETC_VSIMSGSR_MS BIT(1)
0059 #define ENETC_VSIMSGSNDAR0 0x210
0060 #define ENETC_VSIMSGSNDAR1 0x214
0061
0062 #define ENETC_SIMSGSR_SET_MC(val) ((val) << 16)
0063 #define ENETC_SIMSGSR_GET_MC(val) ((val) >> 16)
0064
0065
0066 #define ENETC_SIROCT 0x300
0067 #define ENETC_SIRFRM 0x308
0068 #define ENETC_SIRUCA 0x310
0069 #define ENETC_SIRMCA 0x318
0070 #define ENETC_SITOCT 0x320
0071 #define ENETC_SITFRM 0x328
0072 #define ENETC_SITUCA 0x330
0073 #define ENETC_SITMCA 0x338
0074 #define ENETC_RBDCR(n) (0x8180 + (n) * 0x200)
0075
0076
0077 #define ENETC_SICBDRMR 0x800
0078 #define ENETC_SICBDRSR 0x804
0079 #define ENETC_SICBDRBAR0 0x810
0080 #define ENETC_SICBDRBAR1 0x814
0081 #define ENETC_SICBDRPIR 0x818
0082 #define ENETC_SICBDRCIR 0x81c
0083 #define ENETC_SICBDRLENR 0x820
0084
0085 #define ENETC_SICAPR0 0x900
0086 #define ENETC_SICAPR1 0x904
0087
0088 #define ENETC_PSIIER 0xa00
0089 #define ENETC_PSIIER_MR_MASK GENMASK(2, 1)
0090 #define ENETC_PSIIDR 0xa08
0091 #define ENETC_SITXIDR 0xa18
0092 #define ENETC_SIRXIDR 0xa28
0093 #define ENETC_SIMSIVR 0xa30
0094
0095 #define ENETC_SIMSITRV(n) (0xB00 + (n) * 0x4)
0096 #define ENETC_SIMSIRRV(n) (0xB80 + (n) * 0x4)
0097
0098 #define ENETC_SIUEFDCR 0xe28
0099
0100 #define ENETC_SIRFSCAPR 0x1200
0101 #define ENETC_SIRFSCAPR_GET_NUM_RFS(val) ((val) & 0x7f)
0102 #define ENETC_SIRSSCAPR 0x1600
0103 #define ENETC_SIRSSCAPR_GET_NUM_RSS(val) (BIT((val) & 0xf) * 32)
0104
0105
0106 enum enetc_bdr_type {TX, RX};
0107 #define ENETC_BDR_OFF(i) ((i) * 0x200)
0108 #define ENETC_BDR(t, i, r) (0x8000 + (t) * 0x100 + ENETC_BDR_OFF(i) + (r))
0109
0110 #define ENETC_RBMR 0
0111 #define ENETC_RBMR_BDS BIT(2)
0112 #define ENETC_RBMR_CM BIT(4)
0113 #define ENETC_RBMR_VTE BIT(5)
0114 #define ENETC_RBMR_EN BIT(31)
0115 #define ENETC_RBSR 0x4
0116 #define ENETC_RBBSR 0x8
0117 #define ENETC_RBCIR 0xc
0118 #define ENETC_RBBAR0 0x10
0119 #define ENETC_RBBAR1 0x14
0120 #define ENETC_RBPIR 0x18
0121 #define ENETC_RBLENR 0x20
0122 #define ENETC_RBIER 0xa0
0123 #define ENETC_RBIER_RXTIE BIT(0)
0124 #define ENETC_RBIDR 0xa4
0125 #define ENETC_RBICR0 0xa8
0126 #define ENETC_RBICR0_ICEN BIT(31)
0127 #define ENETC_RBICR0_ICPT_MASK 0x1ff
0128 #define ENETC_RBICR0_SET_ICPT(n) ((n) & ENETC_RBICR0_ICPT_MASK)
0129 #define ENETC_RBICR1 0xac
0130
0131
0132 #define ENETC_TBMR 0
0133 #define ENETC_TBSR_BUSY BIT(0)
0134 #define ENETC_TBMR_VIH BIT(9)
0135 #define ENETC_TBMR_PRIO_MASK GENMASK(2, 0)
0136 #define ENETC_TBMR_SET_PRIO(val) ((val) & ENETC_TBMR_PRIO_MASK)
0137 #define ENETC_TBMR_EN BIT(31)
0138 #define ENETC_TBSR 0x4
0139 #define ENETC_TBBAR0 0x10
0140 #define ENETC_TBBAR1 0x14
0141 #define ENETC_TBPIR 0x18
0142 #define ENETC_TBCIR 0x1c
0143 #define ENETC_TBCIR_IDX_MASK 0xffff
0144 #define ENETC_TBLENR 0x20
0145 #define ENETC_TBIER 0xa0
0146 #define ENETC_TBIER_TXTIE BIT(0)
0147 #define ENETC_TBIDR 0xa4
0148 #define ENETC_TBICR0 0xa8
0149 #define ENETC_TBICR0_ICEN BIT(31)
0150 #define ENETC_TBICR0_ICPT_MASK 0xf
0151 #define ENETC_TBICR0_SET_ICPT(n) ((ilog2(n) + 1) & ENETC_TBICR0_ICPT_MASK)
0152 #define ENETC_TBICR1 0xac
0153
0154 #define ENETC_RTBLENR_LEN(n) ((n) & ~0x7)
0155
0156
0157 #define ENETC_PORT_BASE 0x10000
0158 #define ENETC_PMR 0x0000
0159 #define ENETC_PMR_EN GENMASK(18, 16)
0160 #define ENETC_PMR_PSPEED_MASK GENMASK(11, 8)
0161 #define ENETC_PMR_PSPEED_10M 0
0162 #define ENETC_PMR_PSPEED_100M BIT(8)
0163 #define ENETC_PMR_PSPEED_1000M BIT(9)
0164 #define ENETC_PMR_PSPEED_2500M BIT(10)
0165 #define ENETC_PSR 0x0004
0166 #define ENETC_PSIPMR 0x0018
0167 #define ENETC_PSIPMR_SET_UP(n) BIT(n)
0168 #define ENETC_PSIPMR_SET_MP(n) BIT((n) + 16)
0169 #define ENETC_PSIPVMR 0x001c
0170 #define ENETC_VLAN_PROMISC_MAP_ALL 0x7
0171 #define ENETC_PSIPVMR_SET_VP(simap) ((simap) & 0x7)
0172 #define ENETC_PSIPVMR_SET_VUTA(simap) (((simap) & 0x7) << 16)
0173 #define ENETC_PSIPMAR0(n) (0x0100 + (n) * 0x8)
0174 #define ENETC_PSIPMAR1(n) (0x0104 + (n) * 0x8)
0175 #define ENETC_PVCLCTR 0x0208
0176 #define ENETC_PCVLANR1 0x0210
0177 #define ENETC_PCVLANR2 0x0214
0178 #define ENETC_VLAN_TYPE_C BIT(0)
0179 #define ENETC_VLAN_TYPE_S BIT(1)
0180 #define ENETC_PVCLCTR_OVTPIDL(bmp) ((bmp) & 0xff)
0181 #define ENETC_PSIVLANR(n) (0x0240 + (n) * 4)
0182 #define ENETC_PSIVLAN_EN BIT(31)
0183 #define ENETC_PSIVLAN_SET_QOS(val) ((u32)(val) << 12)
0184 #define ENETC_PPAUONTR 0x0410
0185 #define ENETC_PPAUOFFTR 0x0414
0186 #define ENETC_PTXMBAR 0x0608
0187 #define ENETC_PCAPR0 0x0900
0188 #define ENETC_PCAPR0_RXBDR(val) ((val) >> 24)
0189 #define ENETC_PCAPR0_TXBDR(val) (((val) >> 16) & 0xff)
0190 #define ENETC_PCAPR1 0x0904
0191 #define ENETC_PSICFGR0(n) (0x0940 + (n) * 0xc)
0192 #define ENETC_PSICFGR0_SET_TXBDR(val) ((val) & 0xff)
0193 #define ENETC_PSICFGR0_SET_RXBDR(val) (((val) & 0xff) << 16)
0194 #define ENETC_PSICFGR0_VTE BIT(12)
0195 #define ENETC_PSICFGR0_SIVIE BIT(14)
0196 #define ENETC_PSICFGR0_ASE BIT(15)
0197 #define ENETC_PSICFGR0_SIVC(bmp) (((bmp) & 0xff) << 24)
0198
0199 #define ENETC_PTCCBSR0(n) (0x1110 + (n) * 8)
0200 #define ENETC_CBSE BIT(31)
0201 #define ENETC_CBS_BW_MASK GENMASK(6, 0)
0202 #define ENETC_PTCCBSR1(n) (0x1114 + (n) * 8)
0203 #define ENETC_RSSHASH_KEY_SIZE 40
0204 #define ENETC_PRSSCAPR 0x1404
0205 #define ENETC_PRSSCAPR_GET_NUM_RSS(val) (BIT((val) & 0xf) * 32)
0206 #define ENETC_PRSSK(n) (0x1410 + (n) * 4)
0207 #define ENETC_PSIVLANFMR 0x1700
0208 #define ENETC_PSIVLANFMR_VS BIT(0)
0209 #define ENETC_PRFSMR 0x1800
0210 #define ENETC_PRFSMR_RFSE BIT(31)
0211 #define ENETC_PRFSCAPR 0x1804
0212 #define ENETC_PRFSCAPR_GET_NUM_RFS(val) ((((val) & 0xf) + 1) * 16)
0213 #define ENETC_PSIRFSCFGR(n) (0x1814 + (n) * 4)
0214 #define ENETC_PFPMR 0x1900
0215 #define ENETC_PFPMR_PMACE BIT(1)
0216 #define ENETC_PFPMR_MWLM BIT(0)
0217 #define ENETC_EMDIO_BASE 0x1c00
0218 #define ENETC_PSIUMHFR0(n, err) (((err) ? 0x1d08 : 0x1d00) + (n) * 0x10)
0219 #define ENETC_PSIUMHFR1(n) (0x1d04 + (n) * 0x10)
0220 #define ENETC_PSIMMHFR0(n, err) (((err) ? 0x1d00 : 0x1d08) + (n) * 0x10)
0221 #define ENETC_PSIMMHFR1(n) (0x1d0c + (n) * 0x10)
0222 #define ENETC_PSIVHFR0(n) (0x1e00 + (n) * 8)
0223 #define ENETC_PSIVHFR1(n) (0x1e04 + (n) * 8)
0224 #define ENETC_MMCSR 0x1f00
0225 #define ENETC_MMCSR_ME BIT(16)
0226 #define ENETC_PTCMSDUR(n) (0x2020 + (n) * 4)
0227
0228 #define ENETC_PM0_CMD_CFG 0x8008
0229 #define ENETC_PM1_CMD_CFG 0x9008
0230 #define ENETC_PM0_TX_EN BIT(0)
0231 #define ENETC_PM0_RX_EN BIT(1)
0232 #define ENETC_PM0_PROMISC BIT(4)
0233 #define ENETC_PM0_PAUSE_IGN BIT(8)
0234 #define ENETC_PM0_CMD_XGLP BIT(10)
0235 #define ENETC_PM0_CMD_TXP BIT(11)
0236 #define ENETC_PM0_CMD_PHY_TX_EN BIT(15)
0237 #define ENETC_PM0_CMD_SFD BIT(21)
0238 #define ENETC_PM0_MAXFRM 0x8014
0239 #define ENETC_SET_TX_MTU(val) ((val) << 16)
0240 #define ENETC_SET_MAXFRM(val) ((val) & 0xffff)
0241 #define ENETC_PM0_RX_FIFO 0x801c
0242 #define ENETC_PM0_RX_FIFO_VAL 1
0243
0244 #define ENETC_PM_IMDIO_BASE 0x8030
0245
0246 #define ENETC_PM0_PAUSE_QUANTA 0x8054
0247 #define ENETC_PM0_PAUSE_THRESH 0x8064
0248 #define ENETC_PM1_PAUSE_QUANTA 0x9054
0249 #define ENETC_PM1_PAUSE_THRESH 0x9064
0250
0251 #define ENETC_PM0_SINGLE_STEP 0x80c0
0252 #define ENETC_PM1_SINGLE_STEP 0x90c0
0253 #define ENETC_PM0_SINGLE_STEP_CH BIT(7)
0254 #define ENETC_PM0_SINGLE_STEP_EN BIT(31)
0255 #define ENETC_SET_SINGLE_STEP_OFFSET(v) (((v) & 0xff) << 8)
0256
0257 #define ENETC_PM0_IF_MODE 0x8300
0258 #define ENETC_PM0_IFM_RG BIT(2)
0259 #define ENETC_PM0_IFM_RLP (BIT(5) | BIT(11))
0260 #define ENETC_PM0_IFM_EN_AUTO BIT(15)
0261 #define ENETC_PM0_IFM_SSP_MASK GENMASK(14, 13)
0262 #define ENETC_PM0_IFM_SSP_1000 (2 << 13)
0263 #define ENETC_PM0_IFM_SSP_100 (0 << 13)
0264 #define ENETC_PM0_IFM_SSP_10 (1 << 13)
0265 #define ENETC_PM0_IFM_FULL_DPX BIT(12)
0266 #define ENETC_PM0_IFM_IFMODE_MASK GENMASK(1, 0)
0267 #define ENETC_PM0_IFM_IFMODE_XGMII 0
0268 #define ENETC_PM0_IFM_IFMODE_GMII 2
0269 #define ENETC_PSIDCAPR 0x1b08
0270 #define ENETC_PSIDCAPR_MSK GENMASK(15, 0)
0271 #define ENETC_PSFCAPR 0x1b18
0272 #define ENETC_PSFCAPR_MSK GENMASK(15, 0)
0273 #define ENETC_PSGCAPR 0x1b28
0274 #define ENETC_PSGCAPR_GCL_MSK GENMASK(18, 16)
0275 #define ENETC_PSGCAPR_SGIT_MSK GENMASK(15, 0)
0276 #define ENETC_PFMCAPR 0x1b38
0277 #define ENETC_PFMCAPR_MSK GENMASK(15, 0)
0278
0279
0280 #define ENETC_PM0_REOCT 0x8100
0281 #define ENETC_PM0_RALN 0x8110
0282 #define ENETC_PM0_RXPF 0x8118
0283 #define ENETC_PM0_RFRM 0x8120
0284 #define ENETC_PM0_RFCS 0x8128
0285 #define ENETC_PM0_RVLAN 0x8130
0286 #define ENETC_PM0_RERR 0x8138
0287 #define ENETC_PM0_RUCA 0x8140
0288 #define ENETC_PM0_RMCA 0x8148
0289 #define ENETC_PM0_RBCA 0x8150
0290 #define ENETC_PM0_RDRP 0x8158
0291 #define ENETC_PM0_RPKT 0x8160
0292 #define ENETC_PM0_RUND 0x8168
0293 #define ENETC_PM0_R64 0x8170
0294 #define ENETC_PM0_R127 0x8178
0295 #define ENETC_PM0_R255 0x8180
0296 #define ENETC_PM0_R511 0x8188
0297 #define ENETC_PM0_R1023 0x8190
0298 #define ENETC_PM0_R1522 0x8198
0299 #define ENETC_PM0_R1523X 0x81A0
0300 #define ENETC_PM0_ROVR 0x81A8
0301 #define ENETC_PM0_RJBR 0x81B0
0302 #define ENETC_PM0_RFRG 0x81B8
0303 #define ENETC_PM0_RCNP 0x81C0
0304 #define ENETC_PM0_RDRNTP 0x81C8
0305 #define ENETC_PM0_TEOCT 0x8200
0306 #define ENETC_PM0_TOCT 0x8208
0307 #define ENETC_PM0_TCRSE 0x8210
0308 #define ENETC_PM0_TXPF 0x8218
0309 #define ENETC_PM0_TFRM 0x8220
0310 #define ENETC_PM0_TFCS 0x8228
0311 #define ENETC_PM0_TVLAN 0x8230
0312 #define ENETC_PM0_TERR 0x8238
0313 #define ENETC_PM0_TUCA 0x8240
0314 #define ENETC_PM0_TMCA 0x8248
0315 #define ENETC_PM0_TBCA 0x8250
0316 #define ENETC_PM0_TPKT 0x8260
0317 #define ENETC_PM0_TUND 0x8268
0318 #define ENETC_PM0_T64 0x8270
0319 #define ENETC_PM0_T127 0x8278
0320 #define ENETC_PM0_T255 0x8280
0321 #define ENETC_PM0_T511 0x8288
0322 #define ENETC_PM0_T1023 0x8290
0323 #define ENETC_PM0_T1522 0x8298
0324 #define ENETC_PM0_T1523X 0x82A0
0325 #define ENETC_PM0_TCNP 0x82C0
0326 #define ENETC_PM0_TDFR 0x82D0
0327 #define ENETC_PM0_TMCOL 0x82D8
0328 #define ENETC_PM0_TSCOL 0x82E0
0329 #define ENETC_PM0_TLCOL 0x82E8
0330 #define ENETC_PM0_TECOL 0x82F0
0331
0332
0333 #define ENETC_PICDR(n) (0x0700 + (n) * 8)
0334 #define ENETC_PBFDSIR 0x0810
0335 #define ENETC_PFDMSAPR 0x0814
0336 #define ENETC_UFDMF 0x1680
0337 #define ENETC_MFDMF 0x1684
0338 #define ENETC_PUFDVFR 0x1780
0339 #define ENETC_PMFDVFR 0x1784
0340 #define ENETC_PBFDVFR 0x1788
0341
0342
0343 #define ENETC_GLOBAL_BASE 0x20000
0344 #define ENETC_G_EIPBRR0 0x0bf8
0345 #define ENETC_G_EIPBRR1 0x0bfc
0346 #define ENETC_G_EPFBLPR(n) (0xd00 + 4 * (n))
0347 #define ENETC_G_EPFBLPR1_XGMII 0x80000000
0348
0349
0350 struct enetc_hw {
0351
0352 void __iomem *reg;
0353
0354 void __iomem *port;
0355
0356 void __iomem *global;
0357 };
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371 extern rwlock_t enetc_mdio_lock;
0372
0373
0374
0375
0376
0377 static inline void enetc_lock_mdio(void)
0378 {
0379 read_lock(&enetc_mdio_lock);
0380 }
0381
0382 static inline void enetc_unlock_mdio(void)
0383 {
0384 read_unlock(&enetc_mdio_lock);
0385 }
0386
0387
0388
0389
0390
0391 static inline u32 enetc_rd_reg_hot(void __iomem *reg)
0392 {
0393 lockdep_assert_held(&enetc_mdio_lock);
0394
0395 return ioread32(reg);
0396 }
0397
0398 static inline void enetc_wr_reg_hot(void __iomem *reg, u32 val)
0399 {
0400 lockdep_assert_held(&enetc_mdio_lock);
0401
0402 iowrite32(val, reg);
0403 }
0404
0405
0406 static inline u32 _enetc_rd_reg_wa(void __iomem *reg)
0407 {
0408 u32 val;
0409
0410 enetc_lock_mdio();
0411 val = ioread32(reg);
0412 enetc_unlock_mdio();
0413
0414 return val;
0415 }
0416
0417 static inline void _enetc_wr_reg_wa(void __iomem *reg, u32 val)
0418 {
0419 enetc_lock_mdio();
0420 iowrite32(val, reg);
0421 enetc_unlock_mdio();
0422 }
0423
0424 static inline u32 _enetc_rd_mdio_reg_wa(void __iomem *reg)
0425 {
0426 unsigned long flags;
0427 u32 val;
0428
0429 write_lock_irqsave(&enetc_mdio_lock, flags);
0430 val = ioread32(reg);
0431 write_unlock_irqrestore(&enetc_mdio_lock, flags);
0432
0433 return val;
0434 }
0435
0436 static inline void _enetc_wr_mdio_reg_wa(void __iomem *reg, u32 val)
0437 {
0438 unsigned long flags;
0439
0440 write_lock_irqsave(&enetc_mdio_lock, flags);
0441 iowrite32(val, reg);
0442 write_unlock_irqrestore(&enetc_mdio_lock, flags);
0443 }
0444
0445 #ifdef ioread64
0446 static inline u64 _enetc_rd_reg64(void __iomem *reg)
0447 {
0448 return ioread64(reg);
0449 }
0450 #else
0451
0452 static inline u64 _enetc_rd_reg64(void __iomem *reg)
0453 {
0454 u32 low, high, tmp;
0455
0456 do {
0457 high = ioread32(reg + 4);
0458 low = ioread32(reg);
0459 tmp = ioread32(reg + 4);
0460 } while (high != tmp);
0461
0462 return le64_to_cpu((__le64)high << 32 | low);
0463 }
0464 #endif
0465
0466 static inline u64 _enetc_rd_reg64_wa(void __iomem *reg)
0467 {
0468 u64 val;
0469
0470 enetc_lock_mdio();
0471 val = _enetc_rd_reg64(reg);
0472 enetc_unlock_mdio();
0473
0474 return val;
0475 }
0476
0477
0478 #define enetc_rd_reg(reg) _enetc_rd_reg_wa((reg))
0479 #define enetc_wr_reg(reg, val) _enetc_wr_reg_wa((reg), (val))
0480 #define enetc_rd(hw, off) enetc_rd_reg((hw)->reg + (off))
0481 #define enetc_wr(hw, off, val) enetc_wr_reg((hw)->reg + (off), val)
0482 #define enetc_rd_hot(hw, off) enetc_rd_reg_hot((hw)->reg + (off))
0483 #define enetc_wr_hot(hw, off, val) enetc_wr_reg_hot((hw)->reg + (off), val)
0484 #define enetc_rd64(hw, off) _enetc_rd_reg64_wa((hw)->reg + (off))
0485
0486 #define enetc_port_rd(hw, off) enetc_rd_reg((hw)->port + (off))
0487 #define enetc_port_wr(hw, off, val) enetc_wr_reg((hw)->port + (off), val)
0488 #define enetc_port_rd_mdio(hw, off) _enetc_rd_mdio_reg_wa((hw)->port + (off))
0489 #define enetc_port_wr_mdio(hw, off, val) _enetc_wr_mdio_reg_wa(\
0490 (hw)->port + (off), val)
0491
0492 #define enetc_global_rd(hw, off) enetc_rd_reg((hw)->global + (off))
0493 #define enetc_global_wr(hw, off, val) enetc_wr_reg((hw)->global + (off), val)
0494
0495 #define enetc_bdr_rd(hw, t, n, off) \
0496 enetc_rd(hw, ENETC_BDR(t, n, off))
0497 #define enetc_bdr_wr(hw, t, n, off, val) \
0498 enetc_wr(hw, ENETC_BDR(t, n, off), val)
0499 #define enetc_txbdr_rd(hw, n, off) enetc_bdr_rd(hw, TX, n, off)
0500 #define enetc_rxbdr_rd(hw, n, off) enetc_bdr_rd(hw, RX, n, off)
0501 #define enetc_txbdr_wr(hw, n, off, val) \
0502 enetc_bdr_wr(hw, TX, n, off, val)
0503 #define enetc_rxbdr_wr(hw, n, off, val) \
0504 enetc_bdr_wr(hw, RX, n, off, val)
0505
0506
0507 union enetc_tx_bd {
0508 struct {
0509 __le64 addr;
0510 __le16 buf_len;
0511 __le16 frm_len;
0512 union {
0513 struct {
0514 u8 reserved[3];
0515 u8 flags;
0516 };
0517 __le32 txstart;
0518 __le32 lstatus;
0519 };
0520 };
0521 struct {
0522 __le32 tstamp;
0523 __le16 tpid;
0524 __le16 vid;
0525 u8 reserved[6];
0526 u8 e_flags;
0527 u8 flags;
0528 } ext;
0529 struct {
0530 __le32 tstamp;
0531 u8 reserved[10];
0532 u8 status;
0533 u8 flags;
0534 } wb;
0535 };
0536
0537 enum enetc_txbd_flags {
0538 ENETC_TXBD_FLAGS_RES0 = BIT(0),
0539 ENETC_TXBD_FLAGS_TSE = BIT(1),
0540 ENETC_TXBD_FLAGS_W = BIT(2),
0541 ENETC_TXBD_FLAGS_RES3 = BIT(3),
0542 ENETC_TXBD_FLAGS_TXSTART = BIT(4),
0543 ENETC_TXBD_FLAGS_EX = BIT(6),
0544 ENETC_TXBD_FLAGS_F = BIT(7)
0545 };
0546 #define ENETC_TXBD_STATS_WIN BIT(7)
0547 #define ENETC_TXBD_TXSTART_MASK GENMASK(24, 0)
0548 #define ENETC_TXBD_FLAGS_OFFSET 24
0549
0550 static inline __le32 enetc_txbd_set_tx_start(u64 tx_start, u8 flags)
0551 {
0552 u32 temp;
0553
0554 temp = (tx_start >> 5 & ENETC_TXBD_TXSTART_MASK) |
0555 (flags << ENETC_TXBD_FLAGS_OFFSET);
0556
0557 return cpu_to_le32(temp);
0558 }
0559
0560 static inline void enetc_clear_tx_bd(union enetc_tx_bd *txbd)
0561 {
0562 memset(txbd, 0, sizeof(*txbd));
0563 }
0564
0565
0566 #define ENETC_TXBD_E_FLAGS_VLAN_INS BIT(0)
0567 #define ENETC_TXBD_E_FLAGS_ONE_STEP_PTP BIT(1)
0568 #define ENETC_TXBD_E_FLAGS_TWO_STEP_PTP BIT(2)
0569
0570 union enetc_rx_bd {
0571 struct {
0572 __le64 addr;
0573 u8 reserved[8];
0574 } w;
0575 struct {
0576 __le16 inet_csum;
0577 __le16 parse_summary;
0578 __le32 rss_hash;
0579 __le16 buf_len;
0580 __le16 vlan_opt;
0581 union {
0582 struct {
0583 __le16 flags;
0584 __le16 error;
0585 };
0586 __le32 lstatus;
0587 };
0588 } r;
0589 struct {
0590 __le32 tstamp;
0591 u8 reserved[12];
0592 } ext;
0593 };
0594
0595 #define ENETC_RXBD_LSTATUS_R BIT(30)
0596 #define ENETC_RXBD_LSTATUS_F BIT(31)
0597 #define ENETC_RXBD_ERR_MASK 0xff
0598 #define ENETC_RXBD_LSTATUS(flags) ((flags) << 16)
0599 #define ENETC_RXBD_FLAG_VLAN BIT(9)
0600 #define ENETC_RXBD_FLAG_TSTMP BIT(10)
0601 #define ENETC_RXBD_FLAG_TPID GENMASK(1, 0)
0602
0603 #define ENETC_MAC_ADDR_FILT_CNT 8
0604 #define EMETC_MAC_ADDR_FILT_RES 3
0605 #define ENETC_MAX_NUM_VFS 2
0606
0607 #define ENETC_CBD_FLAGS_SF BIT(7)
0608 #define ENETC_CBD_STATUS_MASK 0xf
0609
0610 struct enetc_cmd_rfse {
0611 u8 smac_h[6];
0612 u8 smac_m[6];
0613 u8 dmac_h[6];
0614 u8 dmac_m[6];
0615 __be32 sip_h[4];
0616 __be32 sip_m[4];
0617 __be32 dip_h[4];
0618 __be32 dip_m[4];
0619 u16 ethtype_h;
0620 u16 ethtype_m;
0621 u16 ethtype4_h;
0622 u16 ethtype4_m;
0623 u16 sport_h;
0624 u16 sport_m;
0625 u16 dport_h;
0626 u16 dport_m;
0627 u16 vlan_h;
0628 u16 vlan_m;
0629 u8 proto_h;
0630 u8 proto_m;
0631 u16 flags;
0632 u16 result;
0633 u16 mode;
0634 };
0635
0636 #define ENETC_RFSE_EN BIT(15)
0637 #define ENETC_RFSE_MODE_BD 2
0638
0639 static inline void enetc_load_primary_mac_addr(struct enetc_hw *hw,
0640 struct net_device *ndev)
0641 {
0642 u8 addr[ETH_ALEN] __aligned(4);
0643
0644 *(u32 *)addr = __raw_readl(hw->reg + ENETC_SIPMAR0);
0645 *(u16 *)(addr + 4) = __raw_readw(hw->reg + ENETC_SIPMAR1);
0646 eth_hw_addr_set(ndev, addr);
0647 }
0648
0649 #define ENETC_SI_INT_IDX 0
0650
0651 #define ENETC_BDR_INT_BASE_IDX 1
0652
0653
0654
0655
0656 enum enetc_msg_cmd_status {
0657 ENETC_MSG_CMD_STATUS_OK,
0658 ENETC_MSG_CMD_STATUS_FAIL
0659 };
0660
0661
0662 enum enetc_msg_cmd_type {
0663 ENETC_MSG_CMD_MNG_MAC = 1,
0664 ENETC_MSG_CMD_MNG_RX_MAC_FILTER,
0665 ENETC_MSG_CMD_MNG_RX_VLAN_FILTER
0666 };
0667
0668
0669 enum enetc_msg_cmd_action_type {
0670 ENETC_MSG_CMD_MNG_ADD = 1,
0671 ENETC_MSG_CMD_MNG_REMOVE
0672 };
0673
0674
0675 struct enetc_msg_cmd_header {
0676 u16 type;
0677 u16 id;
0678 };
0679
0680
0681
0682 static inline void enetc_bdr_enable_rxvlan(struct enetc_hw *hw, int idx,
0683 bool en)
0684 {
0685 u32 val = enetc_rxbdr_rd(hw, idx, ENETC_RBMR);
0686
0687 val = (val & ~ENETC_RBMR_VTE) | (en ? ENETC_RBMR_VTE : 0);
0688 enetc_rxbdr_wr(hw, idx, ENETC_RBMR, val);
0689 }
0690
0691 static inline void enetc_bdr_enable_txvlan(struct enetc_hw *hw, int idx,
0692 bool en)
0693 {
0694 u32 val = enetc_txbdr_rd(hw, idx, ENETC_TBMR);
0695
0696 val = (val & ~ENETC_TBMR_VIH) | (en ? ENETC_TBMR_VIH : 0);
0697 enetc_txbdr_wr(hw, idx, ENETC_TBMR, val);
0698 }
0699
0700 static inline void enetc_set_bdr_prio(struct enetc_hw *hw, int bdr_idx,
0701 int prio)
0702 {
0703 u32 val = enetc_txbdr_rd(hw, bdr_idx, ENETC_TBMR);
0704
0705 val &= ~ENETC_TBMR_PRIO_MASK;
0706 val |= ENETC_TBMR_SET_PRIO(prio);
0707 enetc_txbdr_wr(hw, bdr_idx, ENETC_TBMR, val);
0708 }
0709
0710 enum bdcr_cmd_class {
0711 BDCR_CMD_UNSPEC = 0,
0712 BDCR_CMD_MAC_FILTER,
0713 BDCR_CMD_VLAN_FILTER,
0714 BDCR_CMD_RSS,
0715 BDCR_CMD_RFS,
0716 BDCR_CMD_PORT_GCL,
0717 BDCR_CMD_RECV_CLASSIFIER,
0718 BDCR_CMD_STREAM_IDENTIFY,
0719 BDCR_CMD_STREAM_FILTER,
0720 BDCR_CMD_STREAM_GCL,
0721 BDCR_CMD_FLOW_METER,
0722 __BDCR_CMD_MAX_LEN,
0723 BDCR_CMD_MAX_LEN = __BDCR_CMD_MAX_LEN - 1,
0724 };
0725
0726
0727 struct tgs_gcl_conf {
0728 u8 atc;
0729 u8 res[7];
0730 struct {
0731 u8 res1[4];
0732 __le16 acl_len;
0733 u8 res2[2];
0734 };
0735 };
0736
0737
0738 struct gce {
0739 __le32 period;
0740 u8 gate;
0741 u8 res[3];
0742 };
0743
0744
0745 struct tgs_gcl_data {
0746 __le32 btl;
0747 __le32 bth;
0748 __le32 ct;
0749 __le32 cte;
0750 struct gce entry[];
0751 };
0752
0753
0754 struct streamid_conf {
0755 __le32 stream_handle;
0756 __le32 iports;
0757 u8 id_type;
0758 u8 oui[3];
0759 u8 res[3];
0760 u8 en;
0761 };
0762
0763 #define ENETC_CBDR_SID_VID_MASK 0xfff
0764 #define ENETC_CBDR_SID_VIDM BIT(12)
0765 #define ENETC_CBDR_SID_TG_MASK 0xc000
0766
0767 struct streamid_data {
0768 union {
0769 u8 dmac[6];
0770 u8 smac[6];
0771 };
0772 u16 vid_vidm_tg;
0773 };
0774
0775 #define ENETC_CBDR_SFI_PRI_MASK 0x7
0776 #define ENETC_CBDR_SFI_PRIM BIT(3)
0777 #define ENETC_CBDR_SFI_BLOV BIT(4)
0778 #define ENETC_CBDR_SFI_BLEN BIT(5)
0779 #define ENETC_CBDR_SFI_MSDUEN BIT(6)
0780 #define ENETC_CBDR_SFI_FMITEN BIT(7)
0781 #define ENETC_CBDR_SFI_ENABLE BIT(7)
0782
0783 struct sfi_conf {
0784 __le32 stream_handle;
0785 u8 multi;
0786 u8 res[2];
0787 u8 sthm;
0788
0789
0790
0791
0792
0793
0794
0795 __le16 fm_inst_table_index;
0796 __le16 msdu;
0797 __le16 sg_inst_table_index;
0798 u8 res1[2];
0799 __le32 input_ports;
0800 u8 res2[3];
0801 u8 en;
0802 };
0803
0804
0805
0806
0807
0808 struct sfi_counter_data {
0809 u32 matchl;
0810 u32 matchh;
0811 u32 msdu_dropl;
0812 u32 msdu_droph;
0813 u32 stream_gate_dropl;
0814 u32 stream_gate_droph;
0815 u32 flow_meter_dropl;
0816 u32 flow_meter_droph;
0817 };
0818
0819 #define ENETC_CBDR_SGI_OIPV_MASK 0x7
0820 #define ENETC_CBDR_SGI_OIPV_EN BIT(3)
0821 #define ENETC_CBDR_SGI_CGTST BIT(6)
0822 #define ENETC_CBDR_SGI_OGTST BIT(7)
0823 #define ENETC_CBDR_SGI_CFG_CHG BIT(1)
0824 #define ENETC_CBDR_SGI_CFG_PND BIT(2)
0825 #define ENETC_CBDR_SGI_OEX BIT(4)
0826 #define ENETC_CBDR_SGI_OEXEN BIT(5)
0827 #define ENETC_CBDR_SGI_IRX BIT(6)
0828 #define ENETC_CBDR_SGI_IRXEN BIT(7)
0829 #define ENETC_CBDR_SGI_ACLLEN_MASK 0x3
0830 #define ENETC_CBDR_SGI_OCLLEN_MASK 0xc
0831 #define ENETC_CBDR_SGI_EN BIT(7)
0832
0833
0834
0835
0836 struct sgi_table {
0837 u8 res[8];
0838 u8 oipv;
0839 u8 res0[2];
0840 u8 ocgtst;
0841 u8 res1[7];
0842 u8 gset;
0843 u8 oacl_len;
0844 u8 res2[2];
0845 u8 en;
0846 };
0847
0848 #define ENETC_CBDR_SGI_AIPV_MASK 0x7
0849 #define ENETC_CBDR_SGI_AIPV_EN BIT(3)
0850 #define ENETC_CBDR_SGI_AGTST BIT(7)
0851
0852
0853 struct sgcl_conf {
0854 u8 aipv;
0855 u8 res[2];
0856 u8 agtst;
0857 u8 res1[4];
0858 union {
0859 struct {
0860 u8 res2[4];
0861 u8 acl_len;
0862 u8 res3[3];
0863 };
0864 u8 cct[8];
0865 };
0866 };
0867
0868 #define ENETC_CBDR_SGL_IOMEN BIT(0)
0869 #define ENETC_CBDR_SGL_IPVEN BIT(3)
0870 #define ENETC_CBDR_SGL_GTST BIT(4)
0871 #define ENETC_CBDR_SGL_IPV_MASK 0xe
0872
0873 struct sgce {
0874 u32 interval;
0875 u8 msdu[3];
0876 u8 multi;
0877 };
0878
0879
0880 struct sgcl_data {
0881 u32 btl;
0882 u32 bth;
0883 u32 ct;
0884 u32 cte;
0885 struct sgce sgcl[];
0886 };
0887
0888 #define ENETC_CBDR_FMI_MR BIT(0)
0889 #define ENETC_CBDR_FMI_MREN BIT(1)
0890 #define ENETC_CBDR_FMI_DOY BIT(2)
0891 #define ENETC_CBDR_FMI_CM BIT(3)
0892 #define ENETC_CBDR_FMI_CF BIT(4)
0893 #define ENETC_CBDR_FMI_NDOR BIT(5)
0894 #define ENETC_CBDR_FMI_OALEN BIT(6)
0895 #define ENETC_CBDR_FMI_IRFPP_MASK GENMASK(4, 0)
0896
0897
0898 struct fmi_conf {
0899 __le32 cir;
0900 __le32 cbs;
0901 __le32 eir;
0902 __le32 ebs;
0903 u8 conf;
0904 u8 res1;
0905 u8 ir_fpp;
0906 u8 res2[4];
0907 u8 en;
0908 };
0909
0910 struct enetc_cbd {
0911 union{
0912 struct sfi_conf sfi_conf;
0913 struct sgi_table sgi_table;
0914 struct fmi_conf fmi_conf;
0915 struct {
0916 __le32 addr[2];
0917 union {
0918 __le32 opt[4];
0919 struct tgs_gcl_conf gcl_conf;
0920 struct streamid_conf sid_set;
0921 struct sgcl_conf sgcl_conf;
0922 };
0923 };
0924 __le32 data[6];
0925 };
0926 __le16 index;
0927 __le16 length;
0928 u8 cmd;
0929 u8 cls;
0930 u8 _res;
0931 u8 status_flags;
0932 };
0933
0934 #define ENETC_CLK 400000000ULL
0935 static inline u32 enetc_cycles_to_usecs(u32 cycles)
0936 {
0937 return (u32)div_u64(cycles * 1000000ULL, ENETC_CLK);
0938 }
0939
0940 static inline u32 enetc_usecs_to_cycles(u32 usecs)
0941 {
0942 return (u32)div_u64(usecs * ENETC_CLK, 1000000ULL);
0943 }
0944
0945
0946 #define ENETC_QBV_PTGCR_OFFSET 0x11a00
0947 #define ENETC_QBV_TGE BIT(31)
0948 #define ENETC_QBV_TGPE BIT(30)
0949
0950
0951 #define ENETC_QBV_PTGCAPR_OFFSET 0x11a08
0952 #define ENETC_QBV_MAX_GCL_LEN_MASK GENMASK(15, 0)
0953
0954
0955 #define ENETC_PTCTSDR(n) (0x1210 + 4 * (n))
0956 #define ENETC_TSDE BIT(31)
0957
0958
0959 #define ENETC_PPSFPMR 0x11b00
0960 #define ENETC_PPSFPMR_PSFPEN BIT(0)
0961 #define ENETC_PPSFPMR_VS BIT(1)
0962 #define ENETC_PPSFPMR_PVC BIT(2)
0963 #define ENETC_PPSFPMR_PVZC BIT(3)