Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

phy: lynx-28g: make lynx_28g_set_lane_mode() more systematic

The current approach of transitioning from one SerDes protocol to
another in lynx_28g_set_lane_mode() is too poetic.

Because the driver only supports 1GbE and 10GbE, it only modifies those
registers which it knows are different between these two modes. However,
that is hardly extensible for 25GbE, 40GbE, backplane modes, etc.

We need something more systematic to make sure that all lane and
protocol converter registers are written to consistent values, no matter
what was the source lane mode.

For that, we need to introduce tables with register field values, for
each supported lane mode.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20251125114847.804961-11-vladimir.oltean@nxp.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Vladimir Oltean and committed by
Vinod Koul
444bb9a7 6af3b6d3

+496 -163
+496 -163
drivers/phy/freescale/phy-fsl-lynx-28g.c
··· 12 12 #define LYNX_28G_NUM_LANE 8 13 13 #define LYNX_28G_NUM_PLL 2 14 14 15 - #define LNa_PCC_OFFSET(lane) (4 * (LYNX_28G_NUM_LANE - (lane->id) - 1)) 16 - 17 - /* General registers per SerDes block */ 15 + /* SoC IP wrapper for protocol converters */ 18 16 #define PCC8 0x10a0 19 - #define PCC8_SGMIInCFG(lane, x) (((x) & GENMASK(2, 0)) << LNa_PCC_OFFSET(lane)) 20 - #define PCC8_SGMIInCFG_EN(lane) PCC8_SGMIInCFG(lane, 1) 21 - #define PCC8_SGMIInCFG_MSK(lane) PCC8_SGMIInCFG(lane, GENMASK(2, 0)) 22 - #define PCC8_SGMIIn_KX(lane, x) ((((x) << 3) & BIT(3)) << LNa_PCC_OFFSET(lane)) 23 - #define PCC8_SGMIIn_KX_MSK(lane) PCC8_SGMIIn_KX(lane, 1) 24 - #define PCC8_MSK(lane) PCC8_SGMIInCFG_MSK(lane) | \ 25 - PCC8_SGMIIn_KX_MSK(lane) 17 + #define PCC8_SGMIIa_KX BIT(3) 18 + #define PCC8_SGMIIa_CFG BIT(0) 26 19 27 20 #define PCCC 0x10b0 28 - #define PCCC_SXGMIInCFG(lane, x) (((x) & GENMASK(2, 0)) << LNa_PCC_OFFSET(lane)) 29 - #define PCCC_SXGMIInCFG_EN(lane) PCCC_SXGMIInCFG(lane, 1) 30 - #define PCCC_SXGMIInCFG_MSK(lane) PCCC_SXGMIInCFG(lane, GENMASK(2, 0)) 31 - #define PCCC_SXGMIInCFG_XFI(lane, x) ((((x) << 3) & BIT(3)) << LNa_PCC_OFFSET(lane)) 32 - #define PCCC_SXGMIInCFG_XFI_MSK(lane) PCCC_SXGMIInCFG_XFI(lane, 1) 33 - #define PCCC_MSK(lane) PCCC_SXGMIInCFG_MSK(lane) | \ 34 - PCCC_SXGMIInCFG_XFI_MSK(lane) 21 + #define PCCC_SXGMIIn_XFI BIT(3) 22 + #define PCCC_SXGMIIn_CFG BIT(0) 35 23 36 24 #define PCCD 0x10b4 37 - #define PCCD_E25GnCFG(lane, x) (((x) & GENMASK(2, 0)) << LNa_PCCD_OFFSET(lane)) 38 - #define PCCD_E25GnCFG_EN(lane) PCCD_E25GnCFG(lane, 1) 39 - #define PCCD_E25GnCFG_MSK(lane) PCCD_E25GnCFG(lane, GENMASK(2, 0)) 40 - #define PCCD_MSK(lane) PCCD_E25GnCFG_MSK(lane) 25 + #define PCCD_E25Gn_CFG BIT(0) 26 + 27 + #define PCCE 0x10b8 28 + #define PCCE_E40Gn_LRV BIT(3) 29 + #define PCCE_E40Gn_CFG BIT(0) 30 + #define PCCE_E50Gn_LRV BIT(3) 31 + #define PCCE_E50GnCFG BIT(0) 32 + #define PCCE_E100Gn_LRV BIT(3) 33 + #define PCCE_E100Gn_CFG BIT(0) 34 + 35 + #define SGMII_CFG(id) (28 - (id) * 4) /* Offset into PCC8 */ 36 + #define SXGMII_CFG(id) (28 - (id) * 4) /* Offset into PCCC */ 37 + #define E25G_CFG(id) (28 - (id) * 4) /* Offset into PCCD */ 38 + #define E40G_CFG(id) (28 - (id) * 4) /* Offset into PCCE */ 39 + #define E50G_CFG(id) (20 - (id) * 4) /* Offset into PCCE */ 40 + #define E100G_CFG(id) (12 - (id) * 4) /* Offset into PCCE */ 41 41 42 42 /* Per PLL registers */ 43 43 #define PLLnRSTCTL(pll) (0x400 + (pll) * 0x100 + 0x0) ··· 91 91 #define LNaTECR0_EQ_SGN_POST1Q BIT(15) 92 92 #define LNaTECR0_EQ_POST1Q GENMASK(12, 8) 93 93 #define LNaTECR0_EQ_AMP_RED GENMASK(5, 0) 94 + 95 + #define LNaTECR1(lane) (0x800 + (lane) * 0x100 + 0x34) 96 + #define LNaTECR1_EQ_ADPT_EQ_DRVR_DIS BIT(31) 97 + #define LNaTECR1_EQ_ADPT_EQ GENMASK(29, 24) 94 98 95 99 /* Lane a Rx Reset Control Register */ 96 100 #define LNaRRSTCTL(lane) (0x800 + (lane) * 0x100 + 0x40) ··· 151 147 #define LNaRECR2_EQ_BIN_DATA_AVG_TC GENMASK(5, 4) 152 148 #define LNaRECR2_SPARE_IN GENMASK(1, 0) 153 149 150 + #define LNaRECR3(lane) (0x800 + (lane) * 0x100 + 0x5c) 151 + #define LNaRECR3_EQ_SNAP_START BIT(31) 152 + #define LNaRECR3_EQ_SNAP_DONE BIT(30) 153 + #define LNaRECR3_EQ_GAINK2_HF_STAT GENMASK(28, 24) 154 + #define LNaRECR3_EQ_GAINK3_MF_STAT GENMASK(20, 16) 155 + #define LNaRECR3_SPARE_OUT GENMASK(13, 12) 156 + #define LNaRECR3_EQ_GAINK4_LF_STAT GENMASK(4, 0) 157 + 158 + #define LNaRECR4(lane) (0x800 + (lane) * 0x100 + 0x60) 159 + #define LNaRECR4_BLW_STAT GENMASK(28, 24) 160 + #define LNaRECR4_EQ_OFFSET_STAT GENMASK(21, 16) 161 + #define LNaRECR4_EQ_BIN_DATA_SEL GENMASK(15, 12) 162 + #define LNaRECR4_EQ_BIN_DATA GENMASK(8, 0) /* bit 9 is reserved */ 163 + #define LNaRECR4_EQ_BIN_DATA_SGN BIT(8) 164 + 154 165 #define LNaRSCCR0(lane) (0x800 + (lane) * 0x100 + 0x74) 155 166 #define LNaRSCCR0_SMP_OFF_EN BIT(31) 156 167 #define LNaRSCCR0_SMP_OFF_OV_EN BIT(30) ··· 180 161 #define LNaRSCCR0_SMP_AUTOZ_EG1R GENMASK(5, 4) 181 162 #define LNaRSCCR0_SMP_AUTOZ_EG1F GENMASK(1, 0) 182 163 164 + #define LNaTCSR0(lane) (0x800 + (lane) * 0x100 + 0xa0) 165 + #define LNaTCSR0_SD_STAT_OBS_EN BIT(31) 166 + #define LNaTCSR0_SD_LPBK_SEL GENMASK(29, 28) 167 + 183 168 #define LNaPSS(lane) (0x1000 + (lane) * 0x4) 184 169 #define LNaPSS_TYPE GENMASK(30, 24) 185 - #define LNaPSS_TYPE_SGMII 0x4 186 - #define LNaPSS_TYPE_XFI 0x28 170 + #define LNaPSS_TYPE_SGMII (PROTO_SEL_SGMII_BASEX_KX << 2) 171 + #define LNaPSS_TYPE_XFI (PROTO_SEL_XFI_10GBASER_KR_SXGMII << 2) 172 + #define LNaPSS_TYPE_40G ((PROTO_SEL_XFI_10GBASER_KR_SXGMII << 2) | 3) 173 + #define LNaPSS_TYPE_25G (PROTO_SEL_25G_50G_100G << 2) 174 + #define LNaPSS_TYPE_100G ((PROTO_SEL_25G_50G_100G << 2) | 2) 187 175 176 + /* MDEV_PORT is at the same bitfield address for all protocol converters */ 177 + #define MDEV_PORT GENMASK(31, 27) 178 + 179 + #define SGMIIaCR0(lane) (0x1800 + (lane) * 0x10) 188 180 #define SGMIIaCR1(lane) (0x1804 + (lane) * 0x10) 189 181 #define SGMIIaCR1_SGPCS_EN BIT(11) 182 + 183 + #define ANLTaCR0(lane) (0x1a00 + (lane) * 0x10) 184 + #define ANLTaCR1(lane) (0x1a04 + (lane) * 0x10) 185 + 186 + #define SXGMIIaCR0(lane) (0x1a80 + (lane) * 0x10) 187 + #define SXGMIIaCR0_RST BIT(31) 188 + #define SXGMIIaCR0_PD BIT(30) 189 + 190 + #define SXGMIIaCR1(lane) (0x1a84 + (lane) * 0x10) 191 + 192 + #define E25GaCR0(lane) (0x1b00 + (lane) * 0x10) 193 + #define E25GaCR0_RST BIT(31) 194 + #define E25GaCR0_PD BIT(30) 195 + 196 + #define E25GaCR1(lane) (0x1b04 + (lane) * 0x10) 197 + 198 + #define E25GaCR2(lane) (0x1b08 + (lane) * 0x10) 199 + #define E25GaCR2_FEC_ENA BIT(23) 200 + #define E25GaCR2_FEC_ERR_ENA BIT(22) 201 + #define E25GaCR2_FEC91_ENA BIT(20) 202 + 203 + #define E40GaCR0(pcvt) (0x1b40 + (pcvt) * 0x20) 204 + #define E40GaCR1(pcvt) (0x1b44 + (pcvt) * 0x20) 205 + 206 + #define E50GaCR1(pcvt) (0x1b84 + (pcvt) * 0x10) 207 + 208 + #define E100GaCR1(pcvt) (0x1c04 + (pcvt) * 0x20) 209 + 210 + #define CR(x) ((x) * 4) 190 211 191 212 enum lynx_28g_eq_type { 192 213 EQ_TYPE_NO_EQ = 0, 193 214 EQ_TYPE_2TAP = 1, 194 215 EQ_TYPE_3TAP = 2, 216 + }; 217 + 218 + enum lynx_28g_proto_sel { 219 + PROTO_SEL_PCIE = 0, 220 + PROTO_SEL_SGMII_BASEX_KX = 1, 221 + PROTO_SEL_SATA = 2, 222 + PROTO_SEL_XAUI = 4, 223 + PROTO_SEL_XFI_10GBASER_KR_SXGMII = 0xa, 224 + PROTO_SEL_25G_50G_100G = 0x1a, 225 + }; 226 + 227 + struct lynx_28g_proto_conf { 228 + /* LNaGCR0 */ 229 + int proto_sel; 230 + int if_width; 231 + /* LNaTECR0 */ 232 + int teq_type; 233 + int sgn_preq; 234 + int ratio_preq; 235 + int sgn_post1q; 236 + int ratio_post1q; 237 + int amp_red; 238 + /* LNaTECR1 */ 239 + int adpt_eq; 240 + /* LNaRGCR1 */ 241 + int enter_idle_flt_sel; 242 + int exit_idle_flt_sel; 243 + int data_lost_th_sel; 244 + /* LNaRECR0 */ 245 + int gk2ovd; 246 + int gk3ovd; 247 + int gk4ovd; 248 + int gk2ovd_en; 249 + int gk3ovd_en; 250 + int gk4ovd_en; 251 + /* LNaRECR1 ? */ 252 + int eq_offset_ovd; 253 + int eq_offset_ovd_en; 254 + /* LNaRECR2 */ 255 + int eq_offset_rng_dbl; 256 + int eq_blw_sel; 257 + int eq_boost; 258 + int spare_in; 259 + /* LNaRSCCR0 */ 260 + int smp_autoz_d1r; 261 + int smp_autoz_eg1r; 262 + }; 263 + 264 + static const struct lynx_28g_proto_conf lynx_28g_proto_conf[PHY_INTERFACE_MODE_MAX] = { 265 + [PHY_INTERFACE_MODE_SGMII] = { 266 + .proto_sel = LNaGCR0_PROTO_SEL_SGMII, 267 + .if_width = LNaGCR0_IF_WIDTH_10_BIT, 268 + .teq_type = EQ_TYPE_NO_EQ, 269 + .sgn_preq = 1, 270 + .ratio_preq = 0, 271 + .sgn_post1q = 1, 272 + .ratio_post1q = 0, 273 + .amp_red = 6, 274 + .adpt_eq = 48, 275 + .enter_idle_flt_sel = 4, 276 + .exit_idle_flt_sel = 3, 277 + .data_lost_th_sel = 1, 278 + .gk2ovd = 0x1f, 279 + .gk3ovd = 0, 280 + .gk4ovd = 0, 281 + .gk2ovd_en = 1, 282 + .gk3ovd_en = 1, 283 + .gk4ovd_en = 0, 284 + .eq_offset_ovd = 0x1f, 285 + .eq_offset_ovd_en = 0, 286 + .eq_offset_rng_dbl = 0, 287 + .eq_blw_sel = 0, 288 + .eq_boost = 0, 289 + .spare_in = 0, 290 + .smp_autoz_d1r = 0, 291 + .smp_autoz_eg1r = 0, 292 + }, 293 + [PHY_INTERFACE_MODE_1000BASEX] = { 294 + .proto_sel = LNaGCR0_PROTO_SEL_SGMII, 295 + .if_width = LNaGCR0_IF_WIDTH_10_BIT, 296 + .teq_type = EQ_TYPE_NO_EQ, 297 + .sgn_preq = 1, 298 + .ratio_preq = 0, 299 + .sgn_post1q = 1, 300 + .ratio_post1q = 0, 301 + .amp_red = 6, 302 + .adpt_eq = 48, 303 + .enter_idle_flt_sel = 4, 304 + .exit_idle_flt_sel = 3, 305 + .data_lost_th_sel = 1, 306 + .gk2ovd = 0x1f, 307 + .gk3ovd = 0, 308 + .gk4ovd = 0, 309 + .gk2ovd_en = 1, 310 + .gk3ovd_en = 1, 311 + .gk4ovd_en = 0, 312 + .eq_offset_ovd = 0x1f, 313 + .eq_offset_ovd_en = 0, 314 + .eq_offset_rng_dbl = 0, 315 + .eq_blw_sel = 0, 316 + .eq_boost = 0, 317 + .spare_in = 0, 318 + .smp_autoz_d1r = 0, 319 + .smp_autoz_eg1r = 0, 320 + }, 321 + [PHY_INTERFACE_MODE_10GBASER] = { 322 + .proto_sel = LNaGCR0_PROTO_SEL_XFI, 323 + .if_width = LNaGCR0_IF_WIDTH_20_BIT, 324 + .teq_type = EQ_TYPE_2TAP, 325 + .sgn_preq = 1, 326 + .ratio_preq = 0, 327 + .sgn_post1q = 1, 328 + .ratio_post1q = 3, 329 + .amp_red = 7, 330 + .adpt_eq = 48, 331 + .enter_idle_flt_sel = 0, 332 + .exit_idle_flt_sel = 0, 333 + .data_lost_th_sel = 0, 334 + .gk2ovd = 0, 335 + .gk3ovd = 0, 336 + .gk4ovd = 0, 337 + .gk2ovd_en = 0, 338 + .gk3ovd_en = 0, 339 + .gk4ovd_en = 0, 340 + .eq_offset_ovd = 0x1f, 341 + .eq_offset_ovd_en = 0, 342 + .eq_offset_rng_dbl = 1, 343 + .eq_blw_sel = 1, 344 + .eq_boost = 0, 345 + .spare_in = 0, 346 + .smp_autoz_d1r = 2, 347 + .smp_autoz_eg1r = 0, 348 + }, 349 + }; 350 + 351 + struct lynx_pccr { 352 + int offset; 353 + int width; 354 + int shift; 195 355 }; 196 356 197 357 struct lynx_28g_priv; ··· 416 218 iowrite32(tmp, reg); 417 219 } 418 220 221 + #define lynx_28g_read(priv, off) \ 222 + ioread32((priv)->base + (off)) 223 + #define lynx_28g_write(priv, off, val) \ 224 + iowrite32(val, (priv)->base + (off)) 419 225 #define lynx_28g_lane_rmw(lane, reg, val, mask) \ 420 226 lynx_28g_rmw((lane)->priv, reg(lane->id), val, mask) 421 227 #define lynx_28g_lane_read(lane, reg) \ ··· 528 326 } 529 327 } 530 328 531 - static void lynx_28g_cleanup_lane(struct lynx_28g_lane *lane) 532 - { 533 - struct lynx_28g_priv *priv = lane->priv; 534 - 535 - /* Cleanup the protocol configuration registers of the current protocol */ 536 - switch (lane->interface) { 537 - case PHY_INTERFACE_MODE_10GBASER: 538 - /* Cleanup the protocol configuration registers */ 539 - lynx_28g_rmw(priv, PCCC, 0, PCCC_MSK(lane)); 540 - break; 541 - case PHY_INTERFACE_MODE_SGMII: 542 - case PHY_INTERFACE_MODE_1000BASEX: 543 - /* Cleanup the protocol configuration registers */ 544 - lynx_28g_rmw(priv, PCC8, 0, PCC8_MSK(lane)); 545 - 546 - /* Disable the SGMII PCS */ 547 - lynx_28g_lane_rmw(lane, SGMIIaCR1, 0, SGMIIaCR1_SGPCS_EN); 548 - 549 - break; 550 - default: 551 - break; 552 - } 553 - } 554 - 555 - static void lynx_28g_lane_set_sgmii(struct lynx_28g_lane *lane) 556 - { 557 - struct lynx_28g_priv *priv = lane->priv; 558 - struct lynx_28g_pll *pll; 559 - 560 - lynx_28g_cleanup_lane(lane); 561 - 562 - /* Setup the lane to run in SGMII */ 563 - lynx_28g_rmw(priv, PCC8, PCC8_SGMIInCFG_EN(lane), PCC8_MSK(lane)); 564 - 565 - /* Setup the protocol select and SerDes parallel interface width */ 566 - lynx_28g_lane_rmw(lane, LNaGCR0, 567 - FIELD_PREP(LNaGCR0_PROTO_SEL, LNaGCR0_PROTO_SEL_SGMII) | 568 - FIELD_PREP(LNaGCR0_IF_WIDTH, LNaGCR0_IF_WIDTH_10_BIT), 569 - LNaGCR0_PROTO_SEL | LNaGCR0_IF_WIDTH); 570 - 571 - /* Find the PLL that works with this interface type */ 572 - pll = lynx_28g_pll_get(priv, PHY_INTERFACE_MODE_SGMII); 573 - if (unlikely(pll == NULL)) 574 - return; 575 - 576 - /* Switch to the PLL that works with this interface type */ 577 - lynx_28g_lane_set_pll(lane, pll); 578 - 579 - /* Choose the portion of clock net to be used on this lane */ 580 - lynx_28g_lane_set_nrate(lane, pll, PHY_INTERFACE_MODE_SGMII); 581 - 582 - /* Enable the SGMII PCS */ 583 - lynx_28g_lane_rmw(lane, SGMIIaCR1, SGMIIaCR1_SGPCS_EN, 584 - SGMIIaCR1_SGPCS_EN); 585 - 586 - /* Configure the appropriate equalization parameters for the protocol */ 587 - lynx_28g_lane_write(lane, LNaTECR0, 588 - LNaTECR0_EQ_SGN_PREQ | LNaTECR0_EQ_SGN_POST1Q | 589 - FIELD_PREP(LNaTECR0_EQ_AMP_RED, 6)); 590 - lynx_28g_lane_write(lane, LNaRGCR1, 591 - FIELD_PREP(LNaRGCR1_ENTER_IDLE_FLT_SEL, 4) | 592 - FIELD_PREP(LNaRGCR1_EXIT_IDLE_FLT_SEL, 3) | 593 - LNaRGCR1_DATA_LOST_FLT); 594 - lynx_28g_lane_write(lane, LNaRECR0, 595 - LNaRECR0_EQ_GAINK2_HF_OV_EN | 596 - FIELD_PREP(LNaRECR0_EQ_GAINK2_HF_OV, 31) | 597 - LNaRECR0_EQ_GAINK3_MF_OV_EN | 598 - FIELD_PREP(LNaRECR0_EQ_GAINK3_MF_OV, 0)); 599 - lynx_28g_lane_write(lane, LNaRECR1, 600 - FIELD_PREP(LNaRECR1_EQ_OFFSET_OV, 31)); 601 - lynx_28g_lane_write(lane, LNaRECR2, 0); 602 - lynx_28g_lane_write(lane, LNaRSCCR0, 0); 603 - } 604 - 605 - static void lynx_28g_lane_set_10gbaser(struct lynx_28g_lane *lane) 606 - { 607 - struct lynx_28g_priv *priv = lane->priv; 608 - struct lynx_28g_pll *pll; 609 - 610 - lynx_28g_cleanup_lane(lane); 611 - 612 - /* Enable the SXGMII lane */ 613 - lynx_28g_rmw(priv, PCCC, PCCC_SXGMIInCFG_EN(lane) | 614 - PCCC_SXGMIInCFG_XFI(lane, 1), PCCC_MSK(lane)); 615 - 616 - /* Setup the protocol select and SerDes parallel interface width */ 617 - lynx_28g_lane_rmw(lane, LNaGCR0, 618 - FIELD_PREP(LNaGCR0_PROTO_SEL, LNaGCR0_PROTO_SEL_XFI) | 619 - FIELD_PREP(LNaGCR0_IF_WIDTH, LNaGCR0_IF_WIDTH_20_BIT), 620 - LNaGCR0_PROTO_SEL | LNaGCR0_IF_WIDTH); 621 - 622 - /* Find the PLL that works with this interface type */ 623 - pll = lynx_28g_pll_get(priv, PHY_INTERFACE_MODE_10GBASER); 624 - if (unlikely(pll == NULL)) 625 - return; 626 - 627 - /* Switch to the PLL that works with this interface type */ 628 - lynx_28g_lane_set_pll(lane, pll); 629 - 630 - /* Choose the portion of clock net to be used on this lane */ 631 - lynx_28g_lane_set_nrate(lane, pll, PHY_INTERFACE_MODE_10GBASER); 632 - 633 - /* Disable the SGMII PCS */ 634 - lynx_28g_lane_rmw(lane, SGMIIaCR1, 0, SGMIIaCR1_SGPCS_EN); 635 - 636 - /* Configure the appropriate equalization parameters for the protocol */ 637 - lynx_28g_lane_write(lane, LNaTECR0, 638 - FIELD_PREP(LNaTECR0_EQ_TYPE, EQ_TYPE_2TAP) | 639 - LNaTECR0_EQ_SGN_PREQ | 640 - FIELD_PREP(LNaTECR0_EQ_PREQ, 0) | 641 - LNaTECR0_EQ_SGN_POST1Q | 642 - FIELD_PREP(LNaTECR0_EQ_POST1Q, 3) | 643 - FIELD_PREP(LNaTECR0_EQ_AMP_RED, 7)); 644 - lynx_28g_lane_write(lane, LNaRGCR1, LNaRGCR1_IDLE_CONFIG); 645 - lynx_28g_lane_write(lane, LNaRECR0, 0); 646 - lynx_28g_lane_write(lane, LNaRECR1, FIELD_PREP(LNaRECR1_EQ_OFFSET_OV, 31)); 647 - lynx_28g_lane_write(lane, LNaRECR2, 648 - LNaRECR2_EQ_OFFSET_RNG_DBL | 649 - FIELD_PREP(LNaRECR2_EQ_BLW_SEL, 1) | 650 - FIELD_PREP(LNaRECR2_EQ_BIN_DATA_AVG_TC, 2)); 651 - lynx_28g_lane_write(lane, LNaRSCCR0, 652 - FIELD_PREP(LNaRSCCR0_SMP_AUTOZ_D1R, 2)); 653 - } 654 - 655 329 static int lynx_28g_power_off(struct phy *phy) 656 330 { 657 331 struct lynx_28g_lane *lane = phy_get_drvdata(phy); ··· 580 502 return 0; 581 503 } 582 504 505 + static int lynx_28g_get_pccr(phy_interface_t interface, int lane, 506 + struct lynx_pccr *pccr) 507 + { 508 + switch (interface) { 509 + case PHY_INTERFACE_MODE_SGMII: 510 + case PHY_INTERFACE_MODE_1000BASEX: 511 + pccr->offset = PCC8; 512 + pccr->width = 4; 513 + pccr->shift = SGMII_CFG(lane); 514 + break; 515 + case PHY_INTERFACE_MODE_10GBASER: 516 + pccr->offset = PCCC; 517 + pccr->width = 4; 518 + pccr->shift = SXGMII_CFG(lane); 519 + break; 520 + default: 521 + return -EOPNOTSUPP; 522 + } 523 + 524 + return 0; 525 + } 526 + 527 + static int lynx_28g_get_pcvt_offset(int lane, phy_interface_t interface) 528 + { 529 + switch (interface) { 530 + case PHY_INTERFACE_MODE_SGMII: 531 + case PHY_INTERFACE_MODE_1000BASEX: 532 + return SGMIIaCR0(lane); 533 + case PHY_INTERFACE_MODE_10GBASER: 534 + return SXGMIIaCR0(lane); 535 + default: 536 + return -EOPNOTSUPP; 537 + } 538 + } 539 + 540 + static int lynx_pccr_write(struct lynx_28g_lane *lane, 541 + phy_interface_t interface, u32 val) 542 + { 543 + struct lynx_28g_priv *priv = lane->priv; 544 + struct lynx_pccr pccr; 545 + u32 old, tmp, mask; 546 + int err; 547 + 548 + err = lynx_28g_get_pccr(interface, lane->id, &pccr); 549 + if (err) 550 + return err; 551 + 552 + old = lynx_28g_read(priv, pccr.offset); 553 + mask = GENMASK(pccr.width - 1, 0) << pccr.shift; 554 + tmp = (old & ~mask) | (val << pccr.shift); 555 + lynx_28g_write(priv, pccr.offset, tmp); 556 + 557 + dev_dbg(&lane->phy->dev, "PCCR@0x%x: 0x%x -> 0x%x\n", 558 + pccr.offset, old, tmp); 559 + 560 + return 0; 561 + } 562 + 563 + static int lynx_pcvt_read(struct lynx_28g_lane *lane, phy_interface_t interface, 564 + int cr, u32 *val) 565 + { 566 + struct lynx_28g_priv *priv = lane->priv; 567 + int offset; 568 + 569 + offset = lynx_28g_get_pcvt_offset(lane->id, interface); 570 + if (offset < 0) 571 + return offset; 572 + 573 + *val = lynx_28g_read(priv, offset + cr); 574 + 575 + return 0; 576 + } 577 + 578 + static int lynx_pcvt_write(struct lynx_28g_lane *lane, phy_interface_t interface, 579 + int cr, u32 val) 580 + { 581 + struct lynx_28g_priv *priv = lane->priv; 582 + int offset; 583 + 584 + offset = lynx_28g_get_pcvt_offset(lane->id, interface); 585 + if (offset < 0) 586 + return offset; 587 + 588 + lynx_28g_write(priv, offset + cr, val); 589 + 590 + return 0; 591 + } 592 + 593 + static int lynx_pcvt_rmw(struct lynx_28g_lane *lane, phy_interface_t interface, 594 + int cr, u32 val, u32 mask) 595 + { 596 + int err; 597 + u32 tmp; 598 + 599 + err = lynx_pcvt_read(lane, interface, cr, &tmp); 600 + if (err) 601 + return err; 602 + 603 + tmp &= ~mask; 604 + tmp |= val; 605 + 606 + return lynx_pcvt_write(lane, interface, cr, tmp); 607 + } 608 + 609 + static void lynx_28g_lane_remap_pll(struct lynx_28g_lane *lane, 610 + phy_interface_t interface) 611 + { 612 + struct lynx_28g_priv *priv = lane->priv; 613 + struct lynx_28g_pll *pll; 614 + 615 + /* Switch to the PLL that works with this interface type */ 616 + pll = lynx_28g_pll_get(priv, interface); 617 + if (unlikely(pll == NULL)) 618 + return; 619 + 620 + lynx_28g_lane_set_pll(lane, pll); 621 + 622 + /* Choose the portion of clock net to be used on this lane */ 623 + lynx_28g_lane_set_nrate(lane, pll, interface); 624 + } 625 + 626 + static void lynx_28g_lane_change_proto_conf(struct lynx_28g_lane *lane, 627 + phy_interface_t interface) 628 + { 629 + const struct lynx_28g_proto_conf *conf = &lynx_28g_proto_conf[interface]; 630 + 631 + lynx_28g_lane_rmw(lane, LNaGCR0, 632 + FIELD_PREP(LNaGCR0_PROTO_SEL, conf->proto_sel) | 633 + FIELD_PREP(LNaGCR0_IF_WIDTH, conf->if_width), 634 + LNaGCR0_PROTO_SEL | LNaGCR0_IF_WIDTH); 635 + 636 + lynx_28g_lane_rmw(lane, LNaTECR0, 637 + FIELD_PREP(LNaTECR0_EQ_TYPE, conf->teq_type) | 638 + FIELD_PREP(LNaTECR0_EQ_SGN_PREQ, conf->sgn_preq) | 639 + FIELD_PREP(LNaTECR0_EQ_PREQ, conf->ratio_preq) | 640 + FIELD_PREP(LNaTECR0_EQ_SGN_POST1Q, conf->sgn_post1q) | 641 + FIELD_PREP(LNaTECR0_EQ_POST1Q, conf->ratio_post1q) | 642 + FIELD_PREP(LNaTECR0_EQ_AMP_RED, conf->amp_red), 643 + LNaTECR0_EQ_TYPE | 644 + LNaTECR0_EQ_SGN_PREQ | 645 + LNaTECR0_EQ_PREQ | 646 + LNaTECR0_EQ_SGN_POST1Q | 647 + LNaTECR0_EQ_POST1Q | 648 + LNaTECR0_EQ_AMP_RED); 649 + 650 + lynx_28g_lane_rmw(lane, LNaTECR1, 651 + FIELD_PREP(LNaTECR1_EQ_ADPT_EQ, conf->adpt_eq), 652 + LNaTECR1_EQ_ADPT_EQ); 653 + 654 + lynx_28g_lane_rmw(lane, LNaRGCR1, 655 + FIELD_PREP(LNaRGCR1_ENTER_IDLE_FLT_SEL, conf->enter_idle_flt_sel) | 656 + FIELD_PREP(LNaRGCR1_EXIT_IDLE_FLT_SEL, conf->exit_idle_flt_sel) | 657 + FIELD_PREP(LNaRGCR1_DATA_LOST_TH_SEL, conf->data_lost_th_sel), 658 + LNaRGCR1_ENTER_IDLE_FLT_SEL | 659 + LNaRGCR1_EXIT_IDLE_FLT_SEL | 660 + LNaRGCR1_DATA_LOST_TH_SEL); 661 + 662 + lynx_28g_lane_rmw(lane, LNaRECR0, 663 + FIELD_PREP(LNaRECR0_EQ_GAINK2_HF_OV_EN, conf->gk2ovd_en) | 664 + FIELD_PREP(LNaRECR0_EQ_GAINK3_MF_OV_EN, conf->gk3ovd_en) | 665 + FIELD_PREP(LNaRECR0_EQ_GAINK4_LF_OV_EN, conf->gk4ovd_en) | 666 + FIELD_PREP(LNaRECR0_EQ_GAINK2_HF_OV, conf->gk2ovd) | 667 + FIELD_PREP(LNaRECR0_EQ_GAINK3_MF_OV, conf->gk3ovd) | 668 + FIELD_PREP(LNaRECR0_EQ_GAINK4_LF_OV, conf->gk4ovd), 669 + LNaRECR0_EQ_GAINK2_HF_OV | 670 + LNaRECR0_EQ_GAINK3_MF_OV | 671 + LNaRECR0_EQ_GAINK4_LF_OV | 672 + LNaRECR0_EQ_GAINK2_HF_OV_EN | 673 + LNaRECR0_EQ_GAINK3_MF_OV_EN | 674 + LNaRECR0_EQ_GAINK4_LF_OV_EN); 675 + 676 + lynx_28g_lane_rmw(lane, LNaRECR1, 677 + FIELD_PREP(LNaRECR1_EQ_OFFSET_OV, conf->eq_offset_ovd) | 678 + FIELD_PREP(LNaRECR1_EQ_OFFSET_OV_EN, conf->eq_offset_ovd_en), 679 + LNaRECR1_EQ_OFFSET_OV | 680 + LNaRECR1_EQ_OFFSET_OV_EN); 681 + 682 + lynx_28g_lane_rmw(lane, LNaRECR2, 683 + FIELD_PREP(LNaRECR2_EQ_OFFSET_RNG_DBL, conf->eq_offset_rng_dbl) | 684 + FIELD_PREP(LNaRECR2_EQ_BLW_SEL, conf->eq_blw_sel) | 685 + FIELD_PREP(LNaRECR2_EQ_BOOST, conf->eq_boost) | 686 + FIELD_PREP(LNaRECR2_SPARE_IN, conf->spare_in), 687 + LNaRECR2_EQ_OFFSET_RNG_DBL | 688 + LNaRECR2_EQ_BLW_SEL | 689 + LNaRECR2_EQ_BOOST | 690 + LNaRECR2_SPARE_IN); 691 + 692 + lynx_28g_lane_rmw(lane, LNaRSCCR0, 693 + FIELD_PREP(LNaRSCCR0_SMP_AUTOZ_D1R, conf->smp_autoz_d1r) | 694 + FIELD_PREP(LNaRSCCR0_SMP_AUTOZ_EG1R, conf->smp_autoz_eg1r), 695 + LNaRSCCR0_SMP_AUTOZ_D1R | 696 + LNaRSCCR0_SMP_AUTOZ_EG1R); 697 + } 698 + 699 + static int lynx_28g_lane_disable_pcvt(struct lynx_28g_lane *lane, 700 + phy_interface_t interface) 701 + { 702 + struct lynx_28g_priv *priv = lane->priv; 703 + int err; 704 + 705 + spin_lock(&priv->pcc_lock); 706 + 707 + err = lynx_pccr_write(lane, interface, 0); 708 + if (err) 709 + goto out; 710 + 711 + switch (interface) { 712 + case PHY_INTERFACE_MODE_SGMII: 713 + case PHY_INTERFACE_MODE_1000BASEX: 714 + err = lynx_pcvt_rmw(lane, interface, CR(1), 0, 715 + SGMIIaCR1_SGPCS_EN); 716 + break; 717 + default: 718 + err = 0; 719 + } 720 + 721 + out: 722 + spin_unlock(&priv->pcc_lock); 723 + 724 + return err; 725 + } 726 + 727 + static int lynx_28g_lane_enable_pcvt(struct lynx_28g_lane *lane, 728 + phy_interface_t interface) 729 + { 730 + struct lynx_28g_priv *priv = lane->priv; 731 + u32 val; 732 + int err; 733 + 734 + spin_lock(&priv->pcc_lock); 735 + 736 + switch (interface) { 737 + case PHY_INTERFACE_MODE_SGMII: 738 + case PHY_INTERFACE_MODE_1000BASEX: 739 + err = lynx_pcvt_rmw(lane, interface, CR(1), SGMIIaCR1_SGPCS_EN, 740 + SGMIIaCR1_SGPCS_EN); 741 + break; 742 + default: 743 + err = 0; 744 + } 745 + 746 + val = 0; 747 + 748 + switch (interface) { 749 + case PHY_INTERFACE_MODE_SGMII: 750 + case PHY_INTERFACE_MODE_1000BASEX: 751 + val |= PCC8_SGMIIa_CFG; 752 + break; 753 + case PHY_INTERFACE_MODE_10GBASER: 754 + val |= PCCC_SXGMIIn_CFG | PCCC_SXGMIIn_XFI; 755 + break; 756 + default: 757 + break; 758 + } 759 + 760 + err = lynx_pccr_write(lane, interface, val); 761 + 762 + spin_unlock(&priv->pcc_lock); 763 + 764 + return err; 765 + } 766 + 583 767 static int lynx_28g_set_mode(struct phy *phy, enum phy_mode mode, int submode) 584 768 { 585 769 struct lynx_28g_lane *lane = phy_get_drvdata(phy); ··· 858 518 if (!lynx_28g_supports_interface(priv, submode)) 859 519 return -EOPNOTSUPP; 860 520 521 + if (submode == lane->interface) 522 + return 0; 523 + 861 524 /* If the lane is powered up, put the lane into the halt state while 862 525 * the reconfiguration is being done. 863 526 */ 864 527 if (powered_up) 865 528 lynx_28g_power_off(phy); 866 529 867 - spin_lock(&priv->pcc_lock); 868 - 869 - switch (submode) { 870 - case PHY_INTERFACE_MODE_SGMII: 871 - case PHY_INTERFACE_MODE_1000BASEX: 872 - lynx_28g_lane_set_sgmii(lane); 873 - break; 874 - case PHY_INTERFACE_MODE_10GBASER: 875 - lynx_28g_lane_set_10gbaser(lane); 876 - break; 877 - default: 878 - err = -EOPNOTSUPP; 530 + err = lynx_28g_lane_disable_pcvt(lane, lane->interface); 531 + if (err) 879 532 goto out; 880 - } 533 + 534 + lynx_28g_lane_change_proto_conf(lane, submode); 535 + lynx_28g_lane_remap_pll(lane, submode); 536 + WARN_ON(lynx_28g_lane_enable_pcvt(lane, submode)); 881 537 882 538 lane->interface = submode; 883 539 884 540 out: 885 - spin_unlock(&priv->pcc_lock); 886 - 887 - /* Power up the lane if necessary */ 888 541 if (powered_up) 889 542 lynx_28g_power_on(phy); 890 543