Skip to content

Commit 3f8057c

Browse files
Sunil Gouthamdavem330
authored andcommitted
net: thunderx: Add QSGMII interface type support
This patch adds support for QSGMII interface type to the BGX driver. This type of interface is supported by 81xx SOC. Signed-off-by: Sunil Goutham <sgoutham@cavium.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 57aaf63 commit 3f8057c

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

drivers/net/ethernet/cavium/thunder/thunder_bgx.c

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,9 @@ void bgx_lmac_internal_loopback(int node, int bgx_idx,
379379
}
380380
EXPORT_SYMBOL(bgx_lmac_internal_loopback);
381381

382-
static int bgx_lmac_sgmii_init(struct bgx *bgx, int lmacid)
382+
static int bgx_lmac_sgmii_init(struct bgx *bgx, struct lmac *lmac)
383383
{
384+
int lmacid = lmac->lmacid;
384385
u64 cfg;
385386

386387
bgx_reg_modify(bgx, lmacid, BGX_GMP_GMI_TXX_THRESH, 0x30);
@@ -409,6 +410,14 @@ static int bgx_lmac_sgmii_init(struct bgx *bgx, int lmacid)
409410
cfg |= (PCS_MRX_CTL_RST_AN | PCS_MRX_CTL_AN_EN);
410411
bgx_reg_write(bgx, lmacid, BGX_GMP_PCS_MRX_CTL, cfg);
411412

413+
if (lmac->lmac_type == BGX_MODE_QSGMII) {
414+
/* Disable disparity check for QSGMII */
415+
cfg = bgx_reg_read(bgx, lmacid, BGX_GMP_PCS_MISCX_CTL);
416+
cfg &= ~PCS_MISC_CTL_DISP_EN;
417+
bgx_reg_write(bgx, lmacid, BGX_GMP_PCS_MISCX_CTL, cfg);
418+
return 0;
419+
}
420+
412421
if (bgx_poll_reg(bgx, lmacid, BGX_GMP_PCS_MRX_STATUS,
413422
PCS_MRX_STATUS_AN_CPT, false)) {
414423
dev_err(&bgx->pdev->dev, "BGX AN_CPT not completed\n");
@@ -650,6 +659,14 @@ static void bgx_poll_for_link(struct work_struct *work)
650659
queue_delayed_work(lmac->check_link, &lmac->dwork, HZ * 2);
651660
}
652661

662+
static int phy_interface_mode(u8 lmac_type)
663+
{
664+
if (lmac_type == BGX_MODE_QSGMII)
665+
return PHY_INTERFACE_MODE_QSGMII;
666+
667+
return PHY_INTERFACE_MODE_SGMII;
668+
}
669+
653670
static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid)
654671
{
655672
struct lmac *lmac;
@@ -658,9 +675,10 @@ static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid)
658675
lmac = &bgx->lmac[lmacid];
659676
lmac->bgx = bgx;
660677

661-
if (lmac->lmac_type == BGX_MODE_SGMII) {
678+
if ((lmac->lmac_type == BGX_MODE_SGMII) ||
679+
(lmac->lmac_type == BGX_MODE_QSGMII)) {
662680
lmac->is_sgmii = 1;
663-
if (bgx_lmac_sgmii_init(bgx, lmacid))
681+
if (bgx_lmac_sgmii_init(bgx, lmac))
664682
return -1;
665683
} else {
666684
lmac->is_sgmii = 0;
@@ -697,7 +715,7 @@ static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid)
697715

698716
if (phy_connect_direct(&lmac->netdev, lmac->phydev,
699717
bgx_lmac_handler,
700-
PHY_INTERFACE_MODE_SGMII))
718+
phy_interface_mode(lmac->lmac_type)))
701719
return -ENODEV;
702720

703721
phy_start_aneg(lmac->phydev);
@@ -799,6 +817,11 @@ static void bgx_init_hw(struct bgx *bgx)
799817
bgx_reg_write(bgx, 0, BGX_CMR_RX_STREERING + (i * 8), 0x00);
800818
}
801819

820+
static u8 bgx_get_lane2sds_cfg(struct bgx *bgx, struct lmac *lmac)
821+
{
822+
return (u8)(bgx_reg_read(bgx, lmac->lmacid, BGX_CMRX_CFG) & 0xFF);
823+
}
824+
802825
static void bgx_print_qlm_mode(struct bgx *bgx, u8 lmacid)
803826
{
804827
struct device *dev = &bgx->pdev->dev;
@@ -838,12 +861,22 @@ static void bgx_print_qlm_mode(struct bgx *bgx, u8 lmacid)
838861
else
839862
dev_info(dev, "%s: 40G_KR4\n", (char *)str);
840863
break;
841-
default:
842-
dev_info(dev, "%s: INVALID\n", (char *)str);
864+
case BGX_MODE_QSGMII:
865+
if ((lmacid == 0) &&
866+
(bgx_get_lane2sds_cfg(bgx, lmac) != lmacid))
867+
return;
868+
if ((lmacid == 2) &&
869+
(bgx_get_lane2sds_cfg(bgx, lmac) == lmacid))
870+
return;
871+
dev_info(dev, "%s: QSGMII\n", (char *)str);
872+
break;
873+
case BGX_MODE_INVALID:
874+
/* Nothing to do */
875+
break;
843876
}
844877
}
845878

846-
static void lmac_set_lane2sds(struct lmac *lmac)
879+
static void lmac_set_lane2sds(struct bgx *bgx, struct lmac *lmac)
847880
{
848881
switch (lmac->lmac_type) {
849882
case BGX_MODE_SGMII:
@@ -857,6 +890,14 @@ static void lmac_set_lane2sds(struct lmac *lmac)
857890
case BGX_MODE_RXAUI:
858891
lmac->lane_to_sds = (lmac->lmacid) ? 0xE : 0x4;
859892
break;
893+
case BGX_MODE_QSGMII:
894+
/* There is no way to determine if DLM0/2 is QSGMII or
895+
* DLM1/3 is configured to QSGMII as bootloader will
896+
* configure all LMACs, so take whatever is configured
897+
* by low level firmware.
898+
*/
899+
lmac->lane_to_sds = bgx_get_lane2sds_cfg(bgx, lmac);
900+
break;
860901
default:
861902
lmac->lane_to_sds = 0;
862903
break;
@@ -882,7 +923,7 @@ static void bgx_set_lmac_config(struct bgx *bgx, u8 idx)
882923
lmac->use_training =
883924
bgx_reg_read(bgx, 0, BGX_SPUX_BR_PMD_CRTL) &
884925
SPU_PMD_CRTL_TRAIN_EN;
885-
lmac_set_lane2sds(lmac);
926+
lmac_set_lane2sds(bgx, lmac);
886927
return;
887928
}
888929

@@ -901,15 +942,15 @@ static void bgx_set_lmac_config(struct bgx *bgx, u8 idx)
901942
lmac->use_training =
902943
bgx_reg_read(bgx, idx, BGX_SPUX_BR_PMD_CRTL) &
903944
SPU_PMD_CRTL_TRAIN_EN;
904-
lmac_set_lane2sds(lmac);
945+
lmac_set_lane2sds(bgx, lmac);
905946

906947
/* Set LMAC type of other lmac on same DLM i.e LMAC 1/3 */
907948
olmac = &bgx->lmac[idx + 1];
908949
olmac->lmac_type = lmac->lmac_type;
909950
olmac->use_training =
910951
bgx_reg_read(bgx, idx + 1, BGX_SPUX_BR_PMD_CRTL) &
911952
SPU_PMD_CRTL_TRAIN_EN;
912-
lmac_set_lane2sds(olmac);
953+
lmac_set_lane2sds(bgx, olmac);
913954
}
914955
}
915956

@@ -920,7 +961,7 @@ static bool is_dlm0_in_bgx_mode(struct bgx *bgx)
920961
if (!bgx->is_81xx)
921962
return true;
922963

923-
lmac = &bgx->lmac[1];
964+
lmac = &bgx->lmac[0];
924965
if (lmac->lmac_type == BGX_MODE_INVALID)
925966
return false;
926967

@@ -946,7 +987,7 @@ static void bgx_get_qlm_mode(struct bgx *bgx)
946987
if (bgx->lmac_count > MAX_LMAC_PER_BGX)
947988
bgx->lmac_count = MAX_LMAC_PER_BGX;
948989

949-
for (idx = 0; idx < bgx->lmac_count; idx++)
990+
for (idx = 0; idx < MAX_LMAC_PER_BGX; idx++)
950991
bgx_set_lmac_config(bgx, idx);
951992

952993
if (!bgx->is_81xx) {

drivers/net/ethernet/cavium/thunder/thunder_bgx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
#define BGX_GMP_PCS_ANX_AN_RESULTS 0x30020
147147
#define BGX_GMP_PCS_SGM_AN_ADV 0x30068
148148
#define BGX_GMP_PCS_MISCX_CTL 0x30078
149+
#define PCS_MISC_CTL_DISP_EN BIT_ULL(13)
149150
#define PCS_MISC_CTL_GMX_ENO BIT_ULL(11)
150151
#define PCS_MISC_CTL_SAMP_PT_MASK 0x7Full
151152
#define BGX_GMP_GMI_PRTX_CFG 0x38020

0 commit comments

Comments
 (0)