Skip to content

Commit f31fd0b

Browse files
committed
Merge branch 'pcs-xpcs-cleanups-batch-2'
Russell King says: ==================== net: pcs: xpcs: cleanups batch 2 This is the second cleanup series for XPCS. Patch 1 removes the enum indexing the dw_xpcs_compat array. The index is never used except to place entries in the array and to size the array. Patch 2 removes the interface arrays - each of which only contain one interface. Patch 3 makes xpcs_find_compat() take the xpcs structure rather than the ID - the previous series removed the reason for xpcs_find_compat needing to take the ID. Patch 4 provides a helper to convert xpcs structure to a regular phylink_pcs structure, which leads to patch 5. Patch 5 moves the definition of struct dw_xpcs to the private xpcs header - with patch 4 in place, nothing outside of the xpcs driver accesses the contents of the dw_xpcs structure. Patch 6 renames xpcs_get_id() to xpcs_read_id() since it's reading the ID, rather than doing anything further with it. (Prior versions of this series renamed it to xpcs_read_phys_id() since that more accurately described that it was reading the physical ID registers.) Patch 7 moves the searching of the ID list out of line as this is a separate functional block. Patch 8 converts xpcs to use the bitmap macros, which eliminates the need for _SHIFT definitions. Patch 9 adds and uses _modify() accessors as there are a large amount of read-modify-write operations in this driver. This conversion found a bug in xpcs-wx code that has been reported and already fixed. Patch 10 converts xpcs to use read_poll_timeout() rather than open coding that. Patch 11 converts all printed messages to use the dev_*() functions so the driver and devie name are always printed. Patch 12 moves DW_VR_MII_DIG_CTRL1_2G5_EN to the correct place in the header file, rather than amongst another register's definitions. Patch 13 moves the Wangxun workaround to a common location rather than duplicating it in two places. We also reformat this to fit within 80 columns. ==================== Tested-by: Serge Semin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2 parents 36efaca + bb0b8ae commit f31fd0b

File tree

6 files changed

+237
-335
lines changed

6 files changed

+237
-335
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static struct phylink_pcs *intel_mgbe_select_pcs(struct stmmac_priv *priv,
451451
* should always be an XPCS. The original code would always
452452
* return this if present.
453453
*/
454-
return &priv->hw->xpcs->pcs;
454+
return xpcs_to_phylink_pcs(priv->hw->xpcs);
455455
}
456456

457457
static int intel_mgbe_common_data(struct pci_dev *pdev,

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,26 +152,18 @@ static int nxp_sja1110_pma_config(struct dw_xpcs *xpcs,
152152
/* Enable TX and RX PLLs and circuits.
153153
* Release reset of PMA to enable data flow to/from PCS.
154154
*/
155-
ret = xpcs_read(xpcs, MDIO_MMD_VEND2, SJA1110_POWERDOWN_ENABLE);
156-
if (ret < 0)
157-
return ret;
158-
159-
val = ret & ~(SJA1110_TXPLL_PD | SJA1110_TXPD | SJA1110_RXCH_PD |
160-
SJA1110_RXBIAS_PD | SJA1110_RESET_SER_EN |
161-
SJA1110_RESET_SER | SJA1110_RESET_DES);
162-
val |= SJA1110_RXPKDETEN | SJA1110_RCVEN;
163-
164-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, SJA1110_POWERDOWN_ENABLE, val);
155+
ret = xpcs_modify(xpcs, MDIO_MMD_VEND2, SJA1110_POWERDOWN_ENABLE,
156+
SJA1110_TXPLL_PD | SJA1110_TXPD | SJA1110_RXCH_PD |
157+
SJA1110_RXBIAS_PD | SJA1110_RESET_SER_EN |
158+
SJA1110_RESET_SER | SJA1110_RESET_DES |
159+
SJA1110_RXPKDETEN | SJA1110_RCVEN,
160+
SJA1110_RXPKDETEN | SJA1110_RCVEN);
165161
if (ret < 0)
166162
return ret;
167163

168164
/* Program continuous-time linear equalizer (CTLE) settings. */
169-
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, SJA1110_RX_CDR_CTLE,
170-
rx_cdr_ctle);
171-
if (ret < 0)
172-
return ret;
173-
174-
return 0;
165+
return xpcs_write(xpcs, MDIO_MMD_VEND2, SJA1110_RX_CDR_CTLE,
166+
rx_cdr_ctle);
175167
}
176168

177169
int nxp_sja1110_sgmii_pma_config(struct dw_xpcs *xpcs)

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

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,23 @@
4646
#define TXGBE_VCO_CAL_LD0 0x72
4747
#define TXGBE_VCO_CAL_REF0 0x76
4848

49-
static int txgbe_read_pma(struct dw_xpcs *xpcs, int reg)
49+
static int txgbe_write_pma(struct dw_xpcs *xpcs, int reg, u16 val)
5050
{
51-
return xpcs_read(xpcs, MDIO_MMD_PMAPMD, TXGBE_PMA_MMD + reg);
51+
return xpcs_write(xpcs, MDIO_MMD_PMAPMD, TXGBE_PMA_MMD + reg, val);
5252
}
5353

54-
static int txgbe_write_pma(struct dw_xpcs *xpcs, int reg, u16 val)
54+
static int txgbe_modify_pma(struct dw_xpcs *xpcs, int reg, u16 mask, u16 set)
5555
{
56-
return xpcs_write(xpcs, MDIO_MMD_PMAPMD, TXGBE_PMA_MMD + reg, val);
56+
return xpcs_modify(xpcs, MDIO_MMD_PMAPMD, TXGBE_PMA_MMD + reg, mask,
57+
set);
5758
}
5859

5960
static void txgbe_pma_config_10gbaser(struct dw_xpcs *xpcs)
6061
{
61-
int val;
62-
6362
txgbe_write_pma(xpcs, TXGBE_MPLLA_CTL0, 0x21);
6463
txgbe_write_pma(xpcs, TXGBE_MPLLA_CTL3, 0);
65-
val = txgbe_read_pma(xpcs, TXGBE_TX_GENCTL1);
66-
val = u16_replace_bits(val, 0x5, TXGBE_TX_GENCTL1_VBOOST_LVL);
67-
txgbe_write_pma(xpcs, TXGBE_TX_GENCTL1, val);
64+
txgbe_modify_pma(xpcs, TXGBE_TX_GENCTL1, TXGBE_TX_GENCTL1_VBOOST_LVL,
65+
FIELD_PREP(TXGBE_TX_GENCTL1_VBOOST_LVL, 0x5));
6866
txgbe_write_pma(xpcs, TXGBE_MISC_CTL0, TXGBE_MISC_CTL0_PLL |
6967
TXGBE_MISC_CTL0_CR_PARA_SEL | TXGBE_MISC_CTL0_RX_VREF(0xF));
7068
txgbe_write_pma(xpcs, TXGBE_VCO_CAL_LD0, 0x549);
@@ -78,38 +76,29 @@ static void txgbe_pma_config_10gbaser(struct dw_xpcs *xpcs)
7876

7977
txgbe_write_pma(xpcs, TXGBE_RX_EQ_CTL0, TXGBE_RX_EQ_CTL0_CTLE_POLE(2) |
8078
TXGBE_RX_EQ_CTL0_CTLE_BOOST(5));
81-
val = txgbe_read_pma(xpcs, TXGBE_RX_EQ_ATTN_CTL);
82-
val &= ~TXGBE_RX_EQ_ATTN_LVL0;
83-
txgbe_write_pma(xpcs, TXGBE_RX_EQ_ATTN_CTL, val);
79+
txgbe_modify_pma(xpcs, TXGBE_RX_EQ_ATTN_CTL, TXGBE_RX_EQ_ATTN_LVL0, 0);
8480
txgbe_write_pma(xpcs, TXGBE_DFE_TAP_CTL0, 0xBE);
85-
val = txgbe_read_pma(xpcs, TXGBE_AFE_DFE_ENABLE);
86-
val &= ~(TXGBE_DFE_EN_0 | TXGBE_AFE_EN_0);
87-
txgbe_write_pma(xpcs, TXGBE_AFE_DFE_ENABLE, val);
88-
val = txgbe_read_pma(xpcs, TXGBE_RX_EQ_CTL4);
89-
val &= ~TXGBE_RX_EQ_CTL4_CONT_ADAPT0;
90-
txgbe_write_pma(xpcs, TXGBE_RX_EQ_CTL4, val);
81+
txgbe_modify_pma(xpcs, TXGBE_AFE_DFE_ENABLE,
82+
TXGBE_DFE_EN_0 | TXGBE_AFE_EN_0, 0);
83+
txgbe_modify_pma(xpcs, TXGBE_RX_EQ_CTL4, TXGBE_RX_EQ_CTL4_CONT_ADAPT0,
84+
0);
9185
}
9286

9387
static void txgbe_pma_config_1g(struct dw_xpcs *xpcs)
9488
{
95-
int val;
96-
97-
val = txgbe_read_pma(xpcs, TXGBE_TX_GENCTL1);
98-
val = u16_replace_bits(val, 0x5, TXGBE_TX_GENCTL1_VBOOST_LVL);
99-
val &= ~TXGBE_TX_GENCTL1_VBOOST_EN0;
100-
txgbe_write_pma(xpcs, TXGBE_TX_GENCTL1, val);
89+
txgbe_modify_pma(xpcs, TXGBE_TX_GENCTL1,
90+
TXGBE_TX_GENCTL1_VBOOST_LVL |
91+
TXGBE_TX_GENCTL1_VBOOST_EN0,
92+
FIELD_PREP(TXGBE_TX_GENCTL1_VBOOST_LVL, 0x5));
10193
txgbe_write_pma(xpcs, TXGBE_MISC_CTL0, TXGBE_MISC_CTL0_PLL |
10294
TXGBE_MISC_CTL0_CR_PARA_SEL | TXGBE_MISC_CTL0_RX_VREF(0xF));
10395

10496
txgbe_write_pma(xpcs, TXGBE_RX_EQ_CTL0, TXGBE_RX_EQ_CTL0_VGA1_GAIN(7) |
10597
TXGBE_RX_EQ_CTL0_VGA2_GAIN(7) | TXGBE_RX_EQ_CTL0_CTLE_BOOST(6));
106-
val = txgbe_read_pma(xpcs, TXGBE_RX_EQ_ATTN_CTL);
107-
val &= ~TXGBE_RX_EQ_ATTN_LVL0;
108-
txgbe_write_pma(xpcs, TXGBE_RX_EQ_ATTN_CTL, val);
98+
txgbe_modify_pma(xpcs, TXGBE_RX_EQ_ATTN_CTL, TXGBE_RX_EQ_ATTN_LVL0, 0);
10999
txgbe_write_pma(xpcs, TXGBE_DFE_TAP_CTL0, 0);
110-
val = txgbe_read_pma(xpcs, TXGBE_RX_GEN_CTL3);
111-
val = u16_replace_bits(val, 0x4, TXGBE_RX_GEN_CTL3_LOS_TRSHLD0);
112-
txgbe_write_pma(xpcs, TXGBE_RX_GEN_CTL3, val);
100+
txgbe_modify_pma(xpcs, TXGBE_RX_GEN_CTL3, TXGBE_RX_GEN_CTL3_LOS_TRSHLD0,
101+
FIELD_PREP(TXGBE_RX_GEN_CTL3_LOS_TRSHLD0, 0x4));
113102

114103
txgbe_write_pma(xpcs, TXGBE_MPLLA_CTL0, 0x20);
115104
txgbe_write_pma(xpcs, TXGBE_MPLLA_CTL3, 0x46);
@@ -172,7 +161,7 @@ static bool txgbe_xpcs_mode_quirk(struct dw_xpcs *xpcs)
172161

173162
int txgbe_xpcs_switch_mode(struct dw_xpcs *xpcs, phy_interface_t interface)
174163
{
175-
int val, ret;
164+
int ret;
176165

177166
switch (interface) {
178167
case PHY_INTERFACE_MODE_10GBASER:
@@ -194,9 +183,8 @@ int txgbe_xpcs_switch_mode(struct dw_xpcs *xpcs, phy_interface_t interface)
194183

195184
if (interface == PHY_INTERFACE_MODE_10GBASER) {
196185
xpcs_write(xpcs, MDIO_MMD_PCS, MDIO_CTRL2, MDIO_PCS_CTRL2_10GBR);
197-
val = xpcs_read(xpcs, MDIO_MMD_PMAPMD, MDIO_CTRL1);
198-
val |= MDIO_CTRL1_SPEED10G;
199-
xpcs_write(xpcs, MDIO_MMD_PMAPMD, MDIO_CTRL1, val);
186+
xpcs_modify(xpcs, MDIO_MMD_PMAPMD, MDIO_CTRL1,
187+
MDIO_CTRL1_SPEED10G, MDIO_CTRL1_SPEED10G);
200188
txgbe_pma_config_10gbaser(xpcs);
201189
} else {
202190
xpcs_write(xpcs, MDIO_MMD_PCS, MDIO_CTRL2, MDIO_PCS_CTRL2_10GBX);

0 commit comments

Comments
 (0)