Skip to content

Commit b97b533

Browse files
elvinongbldavem330
authored andcommitted
net: pcs: add C37 SGMII AN support for intel mGbE controller
XPCS IP supports C37 SGMII AN process and it is used in intel multi-GbE controller as MAC-side SGMII. Signed-off-by: Ong Boon Leong <boon.leong.ong@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 07a4bc5 commit b97b533

2 files changed

Lines changed: 167 additions & 1 deletion

File tree

‎drivers/net/pcs/pcs-xpcs.c‎

Lines changed: 166 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define SYNOPSYS_XPCS_USXGMII_ID 0x7996ced0
1616
#define SYNOPSYS_XPCS_10GKR_ID 0x7996ced0
1717
#define SYNOPSYS_XPCS_XLGMII_ID 0x7996ced0
18+
#define SYNOPSYS_XPCS_SGMII_ID 0x7996ced0
1819
#define SYNOPSYS_XPCS_MASK 0xffffffff
1920

2021
/* Vendor regs access */
@@ -57,6 +58,34 @@
5758
#define DW_C73_2500KX BIT(0)
5859
#define DW_C73_5000KR BIT(1)
5960

61+
/* Clause 37 Defines */
62+
/* VR MII MMD registers offsets */
63+
#define DW_VR_MII_DIG_CTRL1 0x8000
64+
#define DW_VR_MII_AN_CTRL 0x8001
65+
#define DW_VR_MII_AN_INTR_STS 0x8002
66+
67+
/* VR_MII_DIG_CTRL1 */
68+
#define DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW BIT(9)
69+
70+
/* VR_MII_AN_CTRL */
71+
#define DW_VR_MII_AN_CTRL_TX_CONFIG_SHIFT 3
72+
#define DW_VR_MII_TX_CONFIG_MASK BIT(3)
73+
#define DW_VR_MII_TX_CONFIG_PHY_SIDE_SGMII 0x1
74+
#define DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII 0x0
75+
#define DW_VR_MII_AN_CTRL_PCS_MODE_SHIFT 1
76+
#define DW_VR_MII_PCS_MODE_MASK GENMASK(2, 1)
77+
#define DW_VR_MII_PCS_MODE_C37_1000BASEX 0x0
78+
#define DW_VR_MII_PCS_MODE_C37_SGMII 0x2
79+
80+
/* VR_MII_AN_INTR_STS */
81+
#define DW_VR_MII_AN_STS_C37_ANSGM_FD BIT(1)
82+
#define DW_VR_MII_AN_STS_C37_ANSGM_SP_SHIFT 2
83+
#define DW_VR_MII_AN_STS_C37_ANSGM_SP GENMASK(3, 2)
84+
#define DW_VR_MII_C37_ANSGM_SP_10 0x0
85+
#define DW_VR_MII_C37_ANSGM_SP_100 0x1
86+
#define DW_VR_MII_C37_ANSGM_SP_1000 0x2
87+
#define DW_VR_MII_C37_ANSGM_SP_LNKSTS BIT(4)
88+
6089
static const int xpcs_usxgmii_features[] = {
6190
ETHTOOL_LINK_MODE_Pause_BIT,
6291
ETHTOOL_LINK_MODE_Asym_Pause_BIT,
@@ -105,6 +134,16 @@ static const int xpcs_xlgmii_features[] = {
105134
__ETHTOOL_LINK_MODE_MASK_NBITS,
106135
};
107136

137+
static const int xpcs_sgmii_features[] = {
138+
ETHTOOL_LINK_MODE_10baseT_Half_BIT,
139+
ETHTOOL_LINK_MODE_10baseT_Full_BIT,
140+
ETHTOOL_LINK_MODE_100baseT_Half_BIT,
141+
ETHTOOL_LINK_MODE_100baseT_Full_BIT,
142+
ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
143+
ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
144+
__ETHTOOL_LINK_MODE_MASK_NBITS,
145+
};
146+
108147
static const phy_interface_t xpcs_usxgmii_interfaces[] = {
109148
PHY_INTERFACE_MODE_USXGMII,
110149
PHY_INTERFACE_MODE_MAX,
@@ -120,6 +159,11 @@ static const phy_interface_t xpcs_xlgmii_interfaces[] = {
120159
PHY_INTERFACE_MODE_MAX,
121160
};
122161

162+
static const phy_interface_t xpcs_sgmii_interfaces[] = {
163+
PHY_INTERFACE_MODE_SGMII,
164+
PHY_INTERFACE_MODE_MAX,
165+
};
166+
123167
static struct xpcs_id {
124168
u32 id;
125169
u32 mask;
@@ -145,6 +189,12 @@ static struct xpcs_id {
145189
.supported = xpcs_xlgmii_features,
146190
.interface = xpcs_xlgmii_interfaces,
147191
.an_mode = DW_AN_C73,
192+
}, {
193+
.id = SYNOPSYS_XPCS_SGMII_ID,
194+
.mask = SYNOPSYS_XPCS_MASK,
195+
.supported = xpcs_sgmii_features,
196+
.interface = xpcs_sgmii_interfaces,
197+
.an_mode = DW_AN_C37_SGMII,
148198
},
149199
};
150200

@@ -207,6 +257,9 @@ static int xpcs_soft_reset(struct mdio_xpcs_args *xpcs)
207257
case DW_AN_C73:
208258
dev = MDIO_MMD_PCS;
209259
break;
260+
case DW_AN_C37_SGMII:
261+
dev = MDIO_MMD_VEND2;
262+
break;
210263
default:
211264
return -1;
212265
}
@@ -597,6 +650,47 @@ static int xpcs_validate(struct mdio_xpcs_args *xpcs,
597650
return 0;
598651
}
599652

653+
static int xpcs_config_aneg_c37_sgmii(struct mdio_xpcs_args *xpcs)
654+
{
655+
int ret;
656+
657+
/* For AN for C37 SGMII mode, the settings are :-
658+
* 1) VR_MII_AN_CTRL Bit(2:1)[PCS_MODE] = 10b (SGMII AN)
659+
* 2) VR_MII_AN_CTRL Bit(3) [TX_CONFIG] = 0b (MAC side SGMII)
660+
* DW xPCS used with DW EQoS MAC is always MAC side SGMII.
661+
* 3) VR_MII_DIG_CTRL1 Bit(9) [MAC_AUTO_SW] = 1b (Automatic
662+
* speed/duplex mode change by HW after SGMII AN complete)
663+
*
664+
* Note: Since it is MAC side SGMII, there is no need to set
665+
* SR_MII_AN_ADV. MAC side SGMII receives AN Tx Config from
666+
* PHY about the link state change after C28 AN is completed
667+
* between PHY and Link Partner. There is also no need to
668+
* trigger AN restart for MAC-side SGMII.
669+
*/
670+
ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_CTRL);
671+
if (ret < 0)
672+
return ret;
673+
674+
ret &= ~(DW_VR_MII_PCS_MODE_MASK | DW_VR_MII_TX_CONFIG_MASK);
675+
ret |= (DW_VR_MII_PCS_MODE_C37_SGMII <<
676+
DW_VR_MII_AN_CTRL_PCS_MODE_SHIFT &
677+
DW_VR_MII_PCS_MODE_MASK);
678+
ret |= (DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII <<
679+
DW_VR_MII_AN_CTRL_TX_CONFIG_SHIFT &
680+
DW_VR_MII_TX_CONFIG_MASK);
681+
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_CTRL, ret);
682+
if (ret < 0)
683+
return ret;
684+
685+
ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1);
686+
if (ret < 0)
687+
return ret;
688+
689+
ret |= DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW;
690+
691+
return xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1, ret);
692+
}
693+
600694
static int xpcs_config(struct mdio_xpcs_args *xpcs,
601695
const struct phylink_link_state *state)
602696
{
@@ -610,6 +704,11 @@ static int xpcs_config(struct mdio_xpcs_args *xpcs,
610704
return ret;
611705
}
612706
break;
707+
case DW_AN_C37_SGMII:
708+
ret = xpcs_config_aneg_c37_sgmii(xpcs);
709+
if (ret)
710+
return ret;
711+
break;
613712
default:
614713
return -1;
615714
}
@@ -650,6 +749,47 @@ static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs,
650749
return 0;
651750
}
652751

752+
static int xpcs_get_state_c37_sgmii(struct mdio_xpcs_args *xpcs,
753+
struct phylink_link_state *state)
754+
{
755+
int ret;
756+
757+
/* Reset link_state */
758+
state->link = false;
759+
state->speed = SPEED_UNKNOWN;
760+
state->duplex = DUPLEX_UNKNOWN;
761+
state->pause = 0;
762+
763+
/* For C37 SGMII mode, we check DW_VR_MII_AN_INTR_STS for link
764+
* status, speed and duplex.
765+
*/
766+
ret = xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS);
767+
if (ret < 0)
768+
return false;
769+
770+
if (ret & DW_VR_MII_C37_ANSGM_SP_LNKSTS) {
771+
int speed_value;
772+
773+
state->link = true;
774+
775+
speed_value = (ret & DW_VR_MII_AN_STS_C37_ANSGM_SP) >>
776+
DW_VR_MII_AN_STS_C37_ANSGM_SP_SHIFT;
777+
if (speed_value == DW_VR_MII_C37_ANSGM_SP_1000)
778+
state->speed = SPEED_1000;
779+
else if (speed_value == DW_VR_MII_C37_ANSGM_SP_100)
780+
state->speed = SPEED_100;
781+
else
782+
state->speed = SPEED_10;
783+
784+
if (ret & DW_VR_MII_AN_STS_C37_ANSGM_FD)
785+
state->duplex = DUPLEX_FULL;
786+
else
787+
state->duplex = DUPLEX_HALF;
788+
}
789+
790+
return 0;
791+
}
792+
653793
static int xpcs_get_state(struct mdio_xpcs_args *xpcs,
654794
struct phylink_link_state *state)
655795
{
@@ -661,6 +801,11 @@ static int xpcs_get_state(struct mdio_xpcs_args *xpcs,
661801
if (ret)
662802
return ret;
663803
break;
804+
case DW_AN_C37_SGMII:
805+
ret = xpcs_get_state_c37_sgmii(xpcs, state);
806+
if (ret)
807+
return ret;
808+
break;
664809
default:
665810
return -1;
666811
}
@@ -682,6 +827,7 @@ static u32 xpcs_get_id(struct mdio_xpcs_args *xpcs)
682827
int ret;
683828
u32 id;
684829

830+
/* First, search C73 PCS using PCS MMD */
685831
ret = xpcs_read(xpcs, MDIO_MMD_PCS, MII_PHYSID1);
686832
if (ret < 0)
687833
return 0xffffffff;
@@ -692,7 +838,26 @@ static u32 xpcs_get_id(struct mdio_xpcs_args *xpcs)
692838
if (ret < 0)
693839
return 0xffffffff;
694840

695-
return id | ret;
841+
/* If Device IDs are not all zeros, we found C73 AN-type device */
842+
if (id | ret)
843+
return id | ret;
844+
845+
/* Next, search C37 PCS using Vendor-Specific MII MMD */
846+
ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_PHYSID1);
847+
if (ret < 0)
848+
return 0xffffffff;
849+
850+
id = ret << 16;
851+
852+
ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_PHYSID2);
853+
if (ret < 0)
854+
return 0xffffffff;
855+
856+
/* If Device IDs are not all zeros, we found C37 AN-type device */
857+
if (id | ret)
858+
return id | ret;
859+
860+
return 0xffffffff;
696861
}
697862

698863
static bool xpcs_check_features(struct mdio_xpcs_args *xpcs,

‎include/linux/pcs/pcs-xpcs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/* AN mode */
1414
#define DW_AN_C73 1
15+
#define DW_AN_C37_SGMII 2
1516

1617
struct mdio_xpcs_args {
1718
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);

0 commit comments

Comments
 (0)