1 From 9ee918eb911853c7b46cd84779d857988366e845 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Mon, 6 Jan 2020 14:30:24 +0200
4 Subject: [PATCH] Revert "net: dsa: felix: Add PCS operations for PHYLINK"
6 This reverts commit 1082a3ef9e832cc52c4b0053c7c52453376f4830.
8 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
10 drivers/net/dsa/ocelot/felix.c | 23 +--
11 drivers/net/dsa/ocelot/felix.h | 7 +-
12 drivers/net/dsa/ocelot/felix_vsc9959.c | 292 +--------------------------------
13 3 files changed, 8 insertions(+), 314 deletions(-)
15 --- a/drivers/net/dsa/ocelot/felix.c
16 +++ b/drivers/net/dsa/ocelot/felix.c
17 @@ -265,7 +265,7 @@ static int felix_get_ts_info(struct dsa_
18 static int felix_init_structs(struct felix *felix, int num_phys_ports)
20 struct ocelot *ocelot = &felix->ocelot;
21 - resource_size_t switch_base;
22 + resource_size_t base;
25 ocelot->num_phys_ports = num_phys_ports;
26 @@ -281,8 +281,7 @@ static int felix_init_structs(struct fel
27 ocelot->ops = felix->info->ops;
28 ocelot->quirks = felix->info->quirks;
30 - switch_base = pci_resource_start(felix->pdev,
31 - felix->info->switch_pci_bar);
32 + base = pci_resource_start(felix->pdev, felix->info->pci_bar);
34 for (i = 0; i < TARGET_MAX; i++) {
35 struct regmap *target;
36 @@ -293,8 +292,8 @@ static int felix_init_structs(struct fel
38 res = &felix->info->target_io_res[i];
39 res->flags = IORESOURCE_MEM;
40 - res->start += switch_base;
41 - res->end += switch_base;
45 target = ocelot_regmap_init(ocelot, res);
47 @@ -328,8 +327,8 @@ static int felix_init_structs(struct fel
49 res = &felix->info->port_io_res[port];
50 res->flags = IORESOURCE_MEM;
51 - res->start += switch_base;
52 - res->end += switch_base;
56 port_regs = devm_ioremap_resource(ocelot->dev, res);
57 if (IS_ERR(port_regs)) {
58 @@ -343,12 +342,6 @@ static int felix_init_structs(struct fel
59 ocelot->ports[port] = ocelot_port;
62 - if (felix->info->mdio_bus_alloc) {
63 - err = felix->info->mdio_bus_alloc(ocelot);
71 @@ -384,10 +377,6 @@ static int felix_setup(struct dsa_switch
72 static void felix_teardown(struct dsa_switch *ds)
74 struct ocelot *ocelot = ds->priv;
75 - struct felix *felix = ocelot_to_felix(ocelot);
78 - mdiobus_unregister(felix->imdio);
80 /* stop workqueue thread */
81 ocelot_deinit(ocelot);
82 --- a/drivers/net/dsa/ocelot/felix.h
83 +++ b/drivers/net/dsa/ocelot/felix.h
86 struct resource *target_io_res;
87 struct resource *port_io_res;
88 - struct resource *imdio_res;
89 const struct reg_field *regfields;
90 const u32 *const *map;
91 const struct ocelot_ops *ops;
92 @@ -18,10 +17,8 @@ struct felix_info {
93 const struct ocelot_stat_layout *stats_layout;
94 unsigned int num_stats;
100 - int (*mdio_bus_alloc)(struct ocelot *ocelot);
103 extern struct felix_info felix_info_vsc9959;
104 @@ -36,8 +33,6 @@ struct felix {
105 struct pci_dev *pdev;
106 struct felix_info *info;
107 struct ocelot ocelot;
108 - struct mii_bus *imdio;
109 - struct phy_device **pcs;
113 --- a/drivers/net/dsa/ocelot/felix_vsc9959.c
114 +++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
116 /* Copyright 2017 Microsemi Corporation
117 * Copyright 2018-2019 NXP Semiconductors
119 -#include <linux/fsl/enetc_mdio.h>
120 #include <soc/mscc/ocelot_sys.h>
121 #include <soc/mscc/ocelot.h>
122 #include <linux/iopoll.h>
123 @@ -391,15 +390,6 @@ static struct resource vsc9959_port_io_r
127 -/* Port MAC 0 Internal MDIO bus through which the SerDes acting as an
128 - * SGMII/QSGMII MAC PCS can be found.
130 -static struct resource vsc9959_imdio_res = {
136 static const struct reg_field vsc9959_regfields[] = {
137 [ANA_ADVLEARN_VLAN_CHK] = REG_FIELD(ANA_ADVLEARN, 6, 6),
138 [ANA_ADVLEARN_LEARN_MIRROR] = REG_FIELD(ANA_ADVLEARN, 0, 5),
139 @@ -579,291 +569,13 @@ static int vsc9959_reset(struct ocelot *
143 -void vsc9959_pcs_validate(struct ocelot *ocelot, int port,
144 - unsigned long *supported,
145 - struct phylink_link_state *state)
147 - __ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
149 - if (state->interface != PHY_INTERFACE_MODE_NA &&
150 - state->interface != PHY_INTERFACE_MODE_GMII &&
151 - state->interface != PHY_INTERFACE_MODE_SGMII &&
152 - state->interface != PHY_INTERFACE_MODE_QSGMII &&
153 - state->interface != PHY_INTERFACE_MODE_USXGMII) {
154 - bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
158 - /* No half-duplex. */
159 - phylink_set_port_modes(mask);
160 - phylink_set(mask, Autoneg);
161 - phylink_set(mask, Pause);
162 - phylink_set(mask, Asym_Pause);
163 - phylink_set(mask, 10baseT_Full);
164 - phylink_set(mask, 100baseT_Full);
165 - phylink_set(mask, 1000baseT_Full);
166 - phylink_set(mask, 1000baseX_Full);
167 - phylink_set(mask, 2500baseT_Full);
168 - phylink_set(mask, 2500baseX_Full);
169 - phylink_set(mask, 1000baseKX_Full);
171 - bitmap_and(supported, supported, mask,
172 - __ETHTOOL_LINK_MODE_MASK_NBITS);
173 - bitmap_and(state->advertising, state->advertising, mask,
174 - __ETHTOOL_LINK_MODE_MASK_NBITS);
177 -static void vsc9959_pcs_an_restart(struct ocelot *ocelot, int port)
179 - struct felix *felix = ocelot_to_felix(ocelot);
180 - struct phy_device *pcs = felix->pcs[port];
185 - phy_set_bits(pcs, MII_BMCR, BMCR_ANRESTART);
188 -static void vsc9959_pcs_init_sgmii(struct phy_device *pcs,
189 - unsigned int link_an_mode,
190 - const struct phylink_link_state *state)
192 - /* SGMII spec requires tx_config_Reg[15:0] to be exactly 0x4001
193 - * for the MAC PCS in order to acknowledge the AN.
195 - phy_write(pcs, MII_ADVERTISE, ADVERTISE_SGMII | ADVERTISE_LPACK);
197 - /* Set to SGMII mode, use AN */
198 - phy_write(pcs, ENETC_PCS_IF_MODE, ENETC_PCS_IF_MODE_SGMII_AN);
200 - /* Adjust link timer for SGMII */
201 - phy_write(pcs, ENETC_PCS_LINK_TIMER1, ENETC_PCS_LINK_TIMER1_VAL);
202 - phy_write(pcs, ENETC_PCS_LINK_TIMER2, ENETC_PCS_LINK_TIMER2_VAL);
204 - phy_write(pcs, MII_BMCR, BMCR_SPEED1000 |
209 -#define ADVERTISE_USXGMII_FDX BIT(12)
211 -static void vsc9959_pcs_init_sxgmii(struct phy_device *pcs,
212 - unsigned int link_an_mode,
213 - const struct phylink_link_state *state)
215 - /* Configure device ability for the USXGMII Replicator */
216 - phy_write_mmd(pcs, MDIO_MMD_VEND2, MII_ADVERTISE,
219 - ADVERTISE_USXGMII_FDX);
222 -static void vsc9959_pcs_init(struct ocelot *ocelot, int port,
223 - unsigned int link_an_mode,
224 - const struct phylink_link_state *state)
226 - struct felix *felix = ocelot_to_felix(ocelot);
227 - struct phy_device *pcs = felix->pcs[port];
232 - if (link_an_mode == MLO_AN_FIXED) {
233 - phydev_err(pcs, "Fixed modes are not yet supported.\n");
237 - pcs->interface = state->interface;
238 - if (pcs->interface == PHY_INTERFACE_MODE_USXGMII)
239 - pcs->is_c45 = true;
241 - pcs->is_c45 = false;
243 - /* The PCS does not implement the BMSR register fully, so capability
244 - * detection via genphy_read_abilities does not work. Since we can get
245 - * the PHY config word from the LPA register though, there is still
246 - * value in using the generic phy_resolve_aneg_linkmode function. So
247 - * populate the supported and advertising link modes manually here.
249 - linkmode_set_bit_array(phy_basic_ports_array,
250 - ARRAY_SIZE(phy_basic_ports_array),
252 - linkmode_set_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, pcs->supported);
253 - linkmode_set_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, pcs->supported);
254 - linkmode_set_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, pcs->supported);
255 - linkmode_set_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, pcs->supported);
256 - phy_advertise_supported(pcs);
258 - switch (pcs->interface) {
259 - case PHY_INTERFACE_MODE_SGMII:
260 - case PHY_INTERFACE_MODE_QSGMII:
261 - vsc9959_pcs_init_sgmii(pcs, link_an_mode, state);
263 - case PHY_INTERFACE_MODE_USXGMII:
264 - vsc9959_pcs_init_sxgmii(pcs, link_an_mode, state);
267 - dev_err(ocelot->dev, "Unsupported link mode %s\n",
268 - phy_modes(pcs->interface));
272 -static void vsc9959_pcs_link_state(struct ocelot *ocelot, int port,
273 - struct phylink_link_state *state)
275 - struct felix *felix = ocelot_to_felix(ocelot);
276 - struct phy_device *pcs = felix->pcs[port];
282 - /* Reading PCS status not yet supported for USXGMII */
288 - pcs->speed = SPEED_UNKNOWN;
289 - pcs->duplex = DUPLEX_UNKNOWN;
291 - pcs->asym_pause = 0;
293 - err = genphy_update_link(pcs);
297 - if (pcs->autoneg_complete) {
298 - u16 lpa = phy_read(pcs, MII_LPA);
300 - switch (state->interface) {
301 - case PHY_INTERFACE_MODE_SGMII:
302 - case PHY_INTERFACE_MODE_QSGMII:
303 - mii_lpa_to_linkmode_lpa_sgmii(pcs->lp_advertising, lpa);
309 - phy_resolve_aneg_linkmode(pcs);
312 - state->an_complete = pcs->autoneg_complete;
313 - state->an_enabled = pcs->autoneg;
314 - state->link = pcs->link;
315 - state->duplex = pcs->duplex;
316 - state->speed = pcs->speed;
317 - /* SGMII AN does not negotiate flow control, but that's ok,
318 - * since phylink already knows that, and does:
319 - * link_state.pause |= pl->phy_state.pause;
321 - state->pause = pcs->pause;
323 - dev_dbg(ocelot->dev,
324 - "%s: mode=%s/%s/%s adv=%*pb lpa=%*pb link=%u an_enabled=%u an_complete=%u\n",
326 - phy_modes(state->interface),
327 - phy_speed_to_str(state->speed),
328 - phy_duplex_to_str(state->duplex),
329 - __ETHTOOL_LINK_MODE_MASK_NBITS, state->advertising,
330 - __ETHTOOL_LINK_MODE_MASK_NBITS, state->lp_advertising,
331 - state->link, state->an_enabled, state->an_complete);
334 static const struct ocelot_ops vsc9959_ops = {
335 .reset = vsc9959_reset,
336 - .pcs_init = vsc9959_pcs_init,
337 - .pcs_an_restart = vsc9959_pcs_an_restart,
338 - .pcs_link_state = vsc9959_pcs_link_state,
339 - .pcs_validate = vsc9959_pcs_validate,
342 -static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
344 - struct felix *felix = ocelot_to_felix(ocelot);
345 - struct enetc_mdio_priv *mdio_priv;
346 - struct device *dev = ocelot->dev;
347 - resource_size_t imdio_base;
348 - void __iomem *imdio_regs;
349 - struct resource *res;
350 - struct enetc_hw *hw;
351 - struct mii_bus *bus;
355 - felix->pcs = devm_kcalloc(dev, felix->info->num_ports,
356 - sizeof(struct phy_device),
359 - dev_err(dev, "failed to allocate array for PCS PHYs\n");
363 - imdio_base = pci_resource_start(felix->pdev,
364 - felix->info->imdio_pci_bar);
366 - res = felix->info->imdio_res;
367 - res->flags = IORESOURCE_MEM;
368 - res->start += imdio_base;
369 - res->end += imdio_base;
371 - imdio_regs = devm_ioremap_resource(dev, res);
372 - if (IS_ERR(imdio_regs)) {
373 - dev_err(dev, "failed to map internal MDIO registers\n");
374 - return PTR_ERR(imdio_regs);
377 - hw = enetc_hw_alloc(dev, imdio_regs);
379 - dev_err(dev, "failed to allocate ENETC HW structure\n");
380 - return PTR_ERR(hw);
383 - bus = devm_mdiobus_alloc_size(dev, sizeof(*mdio_priv));
387 - bus->name = "VSC9959 internal MDIO bus";
388 - bus->read = enetc_mdio_read;
389 - bus->write = enetc_mdio_write;
391 - mdio_priv = bus->priv;
392 - mdio_priv->hw = hw;
393 - /* This gets added to imdio_regs, which already maps addresses
394 - * starting with the proper offset.
396 - mdio_priv->mdio_base = 0;
397 - snprintf(bus->id, MII_BUS_ID_SIZE, "%s-imdio", dev_name(dev));
399 - /* Needed in order to initialize the bus mutex lock */
400 - rc = mdiobus_register(bus);
402 - dev_err(dev, "failed to register MDIO bus\n");
406 - felix->imdio = bus;
408 - for (port = 0; port < felix->info->num_ports; port++) {
409 - struct phy_device *pcs;
410 - bool is_c45 = false;
412 - pcs = get_phy_device(felix->imdio, port, is_c45);
416 - felix->pcs[port] = pcs;
418 - dev_info(dev, "Found PCS at internal MDIO address %d\n", port);
424 struct felix_info felix_info_vsc9959 = {
425 .target_io_res = vsc9959_target_io_res,
426 .port_io_res = vsc9959_port_io_res,
427 - .imdio_res = &vsc9959_imdio_res,
428 .regfields = vsc9959_regfields,
429 .map = vsc9959_regmap,
431 @@ -871,8 +583,6 @@ struct felix_info felix_info_vsc9959 = {
432 .num_stats = ARRAY_SIZE(vsc9959_stats_layout),
433 .shared_queue_sz = 128 * 1024,
435 - .switch_pci_bar = 4,
436 - .imdio_pci_bar = 0,
438 .quirks = OCELOT_PCS_PERFORMS_RATE_ADAPTATION,
439 - .mdio_bus_alloc = vsc9959_mdio_bus_alloc,