0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/delay.h>
0013 #include <linux/slab.h>
0014 #include "efx.h"
0015 #include "mdio_10g.h"
0016 #include "phy.h"
0017 #include "nic.h"
0018
0019
0020 #define TXC_REQUIRED_DEVS (MDIO_DEVS_PCS | \
0021 MDIO_DEVS_PMAPMD | \
0022 MDIO_DEVS_PHYXS)
0023
0024 #define TXC_LOOPBACKS ((1 << LOOPBACK_PCS) | \
0025 (1 << LOOPBACK_PMAPMD) | \
0026 (1 << LOOPBACK_PHYXS_WS))
0027
0028
0029
0030
0031
0032
0033
0034 #define TXCNAME "TXC43128"
0035
0036 #define TXC_MAX_RESET_TIME 500
0037
0038 #define TXC_RESET_WAIT 10
0039
0040 #define TXC_BIST_DURATION 50
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 #define TXC_GLRGS_GLCMD 0xc004
0051
0052
0053 #define TXC_GLCMD_L01PD_LBN 5
0054 #define TXC_GLCMD_L23PD_LBN 6
0055
0056
0057 #define TXC_GLCMD_LMTSWRST_LBN 14
0058
0059
0060 #define TXC_GLRGS_GSGQLCTL 0xc01a
0061
0062 #define TXC_GSGQLCT_SGQLEN_LBN 15
0063
0064 #define TXC_GSGQLCT_LNSL_LBN 13
0065 #define TXC_GSGQLCT_LNSL_WIDTH 2
0066
0067
0068 #define TXC_ALRGS_ATXCTL 0xc040
0069
0070 #define TXC_ATXCTL_TXPD3_LBN 15
0071 #define TXC_ATXCTL_TXPD2_LBN 14
0072 #define TXC_ATXCTL_TXPD1_LBN 13
0073 #define TXC_ATXCTL_TXPD0_LBN 12
0074
0075
0076 #define TXC_ALRGS_ATXAMP0 0xc041
0077
0078 #define TXC_ALRGS_ATXAMP1 0xc042
0079
0080 #define TXC_ATXAMP_LANE02_LBN 3
0081
0082 #define TXC_ATXAMP_LANE13_LBN 11
0083
0084 #define TXC_ATXAMP_1280_mV 0
0085 #define TXC_ATXAMP_1200_mV 8
0086 #define TXC_ATXAMP_1120_mV 12
0087 #define TXC_ATXAMP_1060_mV 14
0088 #define TXC_ATXAMP_0820_mV 25
0089 #define TXC_ATXAMP_0720_mV 26
0090 #define TXC_ATXAMP_0580_mV 27
0091 #define TXC_ATXAMP_0440_mV 28
0092
0093 #define TXC_ATXAMP_0820_BOTH \
0094 ((TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE02_LBN) \
0095 | (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE13_LBN))
0096
0097 #define TXC_ATXAMP_DEFAULT 0x6060
0098
0099
0100 #define TXC_ALRGS_ATXPRE0 0xc043
0101
0102 #define TXC_ALRGS_ATXPRE1 0xc044
0103
0104 #define TXC_ATXPRE_NONE 0
0105 #define TXC_ATXPRE_DEFAULT 0x1010
0106
0107 #define TXC_ALRGS_ARXCTL 0xc045
0108
0109 #define TXC_ARXCTL_RXPD3_LBN 15
0110 #define TXC_ARXCTL_RXPD2_LBN 14
0111 #define TXC_ARXCTL_RXPD1_LBN 13
0112 #define TXC_ARXCTL_RXPD0_LBN 12
0113
0114
0115 #define TXC_MRGS_CTL 0xc340
0116
0117 #define TXC_MCTL_RESET_LBN 15
0118 #define TXC_MCTL_TXLED_LBN 14
0119 #define TXC_MCTL_RXLED_LBN 13
0120
0121
0122 #define TXC_GPIO_OUTPUT 0xc346
0123 #define TXC_GPIO_DIR 0xc348
0124
0125
0126 #define TXC_BIST_CTL 0xc280
0127 #define TXC_BIST_TXFRMCNT 0xc281
0128 #define TXC_BIST_RX0FRMCNT 0xc282
0129 #define TXC_BIST_RX1FRMCNT 0xc283
0130 #define TXC_BIST_RX2FRMCNT 0xc284
0131 #define TXC_BIST_RX3FRMCNT 0xc285
0132 #define TXC_BIST_RX0ERRCNT 0xc286
0133 #define TXC_BIST_RX1ERRCNT 0xc287
0134 #define TXC_BIST_RX2ERRCNT 0xc288
0135 #define TXC_BIST_RX3ERRCNT 0xc289
0136
0137
0138 #define TXC_BIST_CTRL_TYPE_LBN 10
0139 #define TXC_BIST_CTRL_TYPE_TSD 0
0140 #define TXC_BIST_CTRL_TYPE_CRP 1
0141 #define TXC_BIST_CTRL_TYPE_CJP 2
0142 #define TXC_BIST_CTRL_TYPE_TSR 3
0143
0144 #define TXC_BIST_CTRL_B10EN_LBN 12
0145
0146 #define TXC_BIST_CTRL_ENAB_LBN 13
0147
0148 #define TXC_BIST_CTRL_STOP_LBN 14
0149
0150 #define TXC_BIST_CTRL_STRT_LBN 15
0151
0152
0153 #define TXC_MTDIABLO_CTRL 0xc34f
0154 #define TXC_MTDIABLO_CTRL_PMA_LOOP_LBN 10
0155
0156 struct txc43128_data {
0157 unsigned long bug10934_timer;
0158 enum ef4_phy_mode phy_mode;
0159 enum ef4_loopback_mode loopback_mode;
0160 };
0161
0162
0163
0164
0165 #define BUG10934_RESET_INTERVAL (5 * HZ)
0166
0167
0168 static void txc_reset_logic(struct ef4_nic *efx);
0169
0170
0171 void falcon_txc_set_gpio_val(struct ef4_nic *efx, int pin, int on)
0172 {
0173 ef4_mdio_set_flag(efx, MDIO_MMD_PHYXS, TXC_GPIO_OUTPUT, 1 << pin, on);
0174 }
0175
0176
0177 void falcon_txc_set_gpio_dir(struct ef4_nic *efx, int pin, int dir)
0178 {
0179 ef4_mdio_set_flag(efx, MDIO_MMD_PHYXS, TXC_GPIO_DIR, 1 << pin, dir);
0180 }
0181
0182
0183
0184 static int txc_reset_phy(struct ef4_nic *efx)
0185 {
0186 int rc = ef4_mdio_reset_mmd(efx, MDIO_MMD_PMAPMD,
0187 TXC_MAX_RESET_TIME / TXC_RESET_WAIT,
0188 TXC_RESET_WAIT);
0189 if (rc < 0)
0190 goto fail;
0191
0192
0193 rc = ef4_mdio_check_mmds(efx, TXC_REQUIRED_DEVS);
0194 if (rc < 0)
0195 goto fail;
0196
0197 return 0;
0198
0199 fail:
0200 netif_err(efx, hw, efx->net_dev, TXCNAME ": reset timed out!\n");
0201 return rc;
0202 }
0203
0204
0205 static int txc_bist_one(struct ef4_nic *efx, int mmd, int test)
0206 {
0207 int ctrl, bctl;
0208 int lane;
0209 int rc = 0;
0210
0211
0212 ctrl = ef4_mdio_read(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL);
0213 ctrl |= (1 << TXC_MTDIABLO_CTRL_PMA_LOOP_LBN);
0214 ef4_mdio_write(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL, ctrl);
0215
0216
0217
0218 bctl = (test << TXC_BIST_CTRL_TYPE_LBN);
0219 ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl);
0220
0221
0222 bctl |= (1 << TXC_BIST_CTRL_ENAB_LBN);
0223 ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl);
0224
0225
0226 ef4_mdio_write(efx, mmd, TXC_BIST_CTL,
0227 bctl | (1 << TXC_BIST_CTRL_STRT_LBN));
0228
0229
0230 udelay(TXC_BIST_DURATION);
0231
0232
0233 bctl |= (1 << TXC_BIST_CTRL_STOP_LBN);
0234 ef4_mdio_write(efx, mmd, TXC_BIST_CTL, bctl);
0235
0236
0237 while (bctl & (1 << TXC_BIST_CTRL_STOP_LBN))
0238 bctl = ef4_mdio_read(efx, mmd, TXC_BIST_CTL);
0239
0240
0241
0242 for (lane = 0; lane < 4; lane++) {
0243 int count = ef4_mdio_read(efx, mmd, TXC_BIST_RX0ERRCNT + lane);
0244 if (count != 0) {
0245 netif_err(efx, hw, efx->net_dev, TXCNAME": BIST error. "
0246 "Lane %d had %d errs\n", lane, count);
0247 rc = -EIO;
0248 }
0249 count = ef4_mdio_read(efx, mmd, TXC_BIST_RX0FRMCNT + lane);
0250 if (count == 0) {
0251 netif_err(efx, hw, efx->net_dev, TXCNAME": BIST error. "
0252 "Lane %d got 0 frames\n", lane);
0253 rc = -EIO;
0254 }
0255 }
0256
0257 if (rc == 0)
0258 netif_info(efx, hw, efx->net_dev, TXCNAME": BIST pass\n");
0259
0260
0261 ef4_mdio_write(efx, mmd, TXC_BIST_CTL, 0);
0262
0263
0264 ctrl &= ~(1 << TXC_MTDIABLO_CTRL_PMA_LOOP_LBN);
0265 ef4_mdio_write(efx, MDIO_MMD_PCS, TXC_MTDIABLO_CTRL, ctrl);
0266
0267 return rc;
0268 }
0269
0270 static int txc_bist(struct ef4_nic *efx)
0271 {
0272 return txc_bist_one(efx, MDIO_MMD_PCS, TXC_BIST_CTRL_TYPE_TSD);
0273 }
0274
0275
0276
0277 static void txc_apply_defaults(struct ef4_nic *efx)
0278 {
0279 int mctrl;
0280
0281
0282
0283
0284
0285
0286
0287 ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE0, TXC_ATXPRE_NONE);
0288 ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE1, TXC_ATXPRE_NONE);
0289
0290
0291 ef4_mdio_write(efx, MDIO_MMD_PHYXS,
0292 TXC_ALRGS_ATXAMP0, TXC_ATXAMP_0820_BOTH);
0293 ef4_mdio_write(efx, MDIO_MMD_PHYXS,
0294 TXC_ALRGS_ATXAMP1, TXC_ATXAMP_0820_BOTH);
0295
0296
0297
0298
0299 ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
0300 TXC_ALRGS_ATXPRE0, TXC_ATXPRE_DEFAULT);
0301 ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
0302 TXC_ALRGS_ATXPRE1, TXC_ATXPRE_DEFAULT);
0303 ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
0304 TXC_ALRGS_ATXAMP0, TXC_ATXAMP_DEFAULT);
0305 ef4_mdio_write(efx, MDIO_MMD_PMAPMD,
0306 TXC_ALRGS_ATXAMP1, TXC_ATXAMP_DEFAULT);
0307
0308
0309 mctrl = ef4_mdio_read(efx, MDIO_MMD_PHYXS, TXC_MRGS_CTL);
0310
0311
0312 mctrl &= ~((1 << TXC_MCTL_TXLED_LBN) | (1 << TXC_MCTL_RXLED_LBN));
0313 ef4_mdio_write(efx, MDIO_MMD_PHYXS, TXC_MRGS_CTL, mctrl);
0314
0315
0316 txc_reset_logic(efx);
0317
0318 falcon_board(efx)->type->init_phy(efx);
0319 }
0320
0321 static int txc43128_phy_probe(struct ef4_nic *efx)
0322 {
0323 struct txc43128_data *phy_data;
0324
0325
0326 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
0327 if (!phy_data)
0328 return -ENOMEM;
0329 efx->phy_data = phy_data;
0330 phy_data->phy_mode = efx->phy_mode;
0331
0332 efx->mdio.mmds = TXC_REQUIRED_DEVS;
0333 efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
0334
0335 efx->loopback_modes = TXC_LOOPBACKS | FALCON_XMAC_LOOPBACKS;
0336
0337 return 0;
0338 }
0339
0340
0341 static int txc43128_phy_init(struct ef4_nic *efx)
0342 {
0343 int rc;
0344
0345 rc = txc_reset_phy(efx);
0346 if (rc < 0)
0347 return rc;
0348
0349 rc = txc_bist(efx);
0350 if (rc < 0)
0351 return rc;
0352
0353 txc_apply_defaults(efx);
0354
0355 return 0;
0356 }
0357
0358
0359 static void txc_glrgs_lane_power(struct ef4_nic *efx, int mmd)
0360 {
0361 int pd = (1 << TXC_GLCMD_L01PD_LBN) | (1 << TXC_GLCMD_L23PD_LBN);
0362 int ctl = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD);
0363
0364 if (!(efx->phy_mode & PHY_MODE_LOW_POWER))
0365 ctl &= ~pd;
0366 else
0367 ctl |= pd;
0368
0369 ef4_mdio_write(efx, mmd, TXC_GLRGS_GLCMD, ctl);
0370 }
0371
0372
0373 static void txc_analog_lane_power(struct ef4_nic *efx, int mmd)
0374 {
0375 int txpd = (1 << TXC_ATXCTL_TXPD3_LBN) | (1 << TXC_ATXCTL_TXPD2_LBN)
0376 | (1 << TXC_ATXCTL_TXPD1_LBN) | (1 << TXC_ATXCTL_TXPD0_LBN);
0377 int rxpd = (1 << TXC_ARXCTL_RXPD3_LBN) | (1 << TXC_ARXCTL_RXPD2_LBN)
0378 | (1 << TXC_ARXCTL_RXPD1_LBN) | (1 << TXC_ARXCTL_RXPD0_LBN);
0379 int txctl = ef4_mdio_read(efx, mmd, TXC_ALRGS_ATXCTL);
0380 int rxctl = ef4_mdio_read(efx, mmd, TXC_ALRGS_ARXCTL);
0381
0382 if (!(efx->phy_mode & PHY_MODE_LOW_POWER)) {
0383 txctl &= ~txpd;
0384 rxctl &= ~rxpd;
0385 } else {
0386 txctl |= txpd;
0387 rxctl |= rxpd;
0388 }
0389
0390 ef4_mdio_write(efx, mmd, TXC_ALRGS_ATXCTL, txctl);
0391 ef4_mdio_write(efx, mmd, TXC_ALRGS_ARXCTL, rxctl);
0392 }
0393
0394 static void txc_set_power(struct ef4_nic *efx)
0395 {
0396
0397 ef4_mdio_set_mmds_lpower(efx,
0398 !!(efx->phy_mode & PHY_MODE_LOW_POWER),
0399 TXC_REQUIRED_DEVS);
0400
0401
0402
0403 txc_glrgs_lane_power(efx, MDIO_MMD_PCS);
0404 txc_glrgs_lane_power(efx, MDIO_MMD_PHYXS);
0405
0406
0407 txc_analog_lane_power(efx, MDIO_MMD_PMAPMD);
0408 txc_analog_lane_power(efx, MDIO_MMD_PHYXS);
0409 }
0410
0411 static void txc_reset_logic_mmd(struct ef4_nic *efx, int mmd)
0412 {
0413 int val = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD);
0414 int tries = 50;
0415
0416 val |= (1 << TXC_GLCMD_LMTSWRST_LBN);
0417 ef4_mdio_write(efx, mmd, TXC_GLRGS_GLCMD, val);
0418 while (--tries) {
0419 val = ef4_mdio_read(efx, mmd, TXC_GLRGS_GLCMD);
0420 if (!(val & (1 << TXC_GLCMD_LMTSWRST_LBN)))
0421 break;
0422 udelay(1);
0423 }
0424 if (!tries)
0425 netif_info(efx, hw, efx->net_dev,
0426 TXCNAME " Logic reset timed out!\n");
0427 }
0428
0429
0430
0431 static void txc_reset_logic(struct ef4_nic *efx)
0432 {
0433
0434
0435
0436 txc_reset_logic_mmd(efx, MDIO_MMD_PCS);
0437 }
0438
0439 static bool txc43128_phy_read_link(struct ef4_nic *efx)
0440 {
0441 return ef4_mdio_links_ok(efx, TXC_REQUIRED_DEVS);
0442 }
0443
0444 static int txc43128_phy_reconfigure(struct ef4_nic *efx)
0445 {
0446 struct txc43128_data *phy_data = efx->phy_data;
0447 enum ef4_phy_mode mode_change = efx->phy_mode ^ phy_data->phy_mode;
0448 bool loop_change = LOOPBACK_CHANGED(phy_data, efx, TXC_LOOPBACKS);
0449
0450 if (efx->phy_mode & mode_change & PHY_MODE_TX_DISABLED) {
0451 txc_reset_phy(efx);
0452 txc_apply_defaults(efx);
0453 falcon_reset_xaui(efx);
0454 mode_change &= ~PHY_MODE_TX_DISABLED;
0455 }
0456
0457 ef4_mdio_transmit_disable(efx);
0458 ef4_mdio_phy_reconfigure(efx);
0459 if (mode_change & PHY_MODE_LOW_POWER)
0460 txc_set_power(efx);
0461
0462
0463
0464
0465
0466 if (loop_change || mode_change)
0467 txc_reset_logic(efx);
0468
0469 phy_data->phy_mode = efx->phy_mode;
0470 phy_data->loopback_mode = efx->loopback_mode;
0471
0472 return 0;
0473 }
0474
0475 static void txc43128_phy_fini(struct ef4_nic *efx)
0476 {
0477
0478 ef4_mdio_write(efx, MDIO_MMD_PMAPMD, MDIO_PMA_LASI_CTRL, 0);
0479 }
0480
0481 static void txc43128_phy_remove(struct ef4_nic *efx)
0482 {
0483 kfree(efx->phy_data);
0484 efx->phy_data = NULL;
0485 }
0486
0487
0488
0489 static bool txc43128_phy_poll(struct ef4_nic *efx)
0490 {
0491 struct txc43128_data *data = efx->phy_data;
0492 bool was_up = efx->link_state.up;
0493
0494 efx->link_state.up = txc43128_phy_read_link(efx);
0495 efx->link_state.speed = 10000;
0496 efx->link_state.fd = true;
0497 efx->link_state.fc = efx->wanted_fc;
0498
0499 if (efx->link_state.up || (efx->loopback_mode != LOOPBACK_NONE)) {
0500 data->bug10934_timer = jiffies;
0501 } else {
0502 if (time_after_eq(jiffies, (data->bug10934_timer +
0503 BUG10934_RESET_INTERVAL))) {
0504 data->bug10934_timer = jiffies;
0505 txc_reset_logic(efx);
0506 }
0507 }
0508
0509 return efx->link_state.up != was_up;
0510 }
0511
0512 static const char *const txc43128_test_names[] = {
0513 "bist"
0514 };
0515
0516 static const char *txc43128_test_name(struct ef4_nic *efx, unsigned int index)
0517 {
0518 if (index < ARRAY_SIZE(txc43128_test_names))
0519 return txc43128_test_names[index];
0520 return NULL;
0521 }
0522
0523 static int txc43128_run_tests(struct ef4_nic *efx, int *results, unsigned flags)
0524 {
0525 int rc;
0526
0527 if (!(flags & ETH_TEST_FL_OFFLINE))
0528 return 0;
0529
0530 rc = txc_reset_phy(efx);
0531 if (rc < 0)
0532 return rc;
0533
0534 rc = txc_bist(efx);
0535 txc_apply_defaults(efx);
0536 results[0] = rc ? -1 : 1;
0537 return rc;
0538 }
0539
0540 static void txc43128_get_link_ksettings(struct ef4_nic *efx,
0541 struct ethtool_link_ksettings *cmd)
0542 {
0543 mdio45_ethtool_ksettings_get(&efx->mdio, cmd);
0544 }
0545
0546 const struct ef4_phy_operations falcon_txc_phy_ops = {
0547 .probe = txc43128_phy_probe,
0548 .init = txc43128_phy_init,
0549 .reconfigure = txc43128_phy_reconfigure,
0550 .poll = txc43128_phy_poll,
0551 .fini = txc43128_phy_fini,
0552 .remove = txc43128_phy_remove,
0553 .get_link_ksettings = txc43128_get_link_ksettings,
0554 .set_link_ksettings = ef4_mdio_set_link_ksettings,
0555 .test_alive = ef4_mdio_test_alive,
0556 .run_tests = txc43128_run_tests,
0557 .test_name = txc43128_test_name,
0558 };