Lines Matching +full:lynx +full:- +full:pcs

1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * Lynx PCS MDIO helpers
8 #include <linux/pcs-lynx.h>
11 #define SGMII_CLOCK_PERIOD_NS 8 /* PCS is clocked at 125 MHz */
24 struct phylink_pcs pcs; member
35 #define phylink_pcs_to_lynx(pl_pcs) container_of((pl_pcs), struct lynx_pcs, pcs)
36 #define lynx_to_phylink_pcs(lynx) (&(lynx)->pcs) argument
38 static void lynx_pcs_get_state_usxgmii(struct mdio_device *pcs, in lynx_pcs_get_state_usxgmii() argument
41 struct mii_bus *bus = pcs->bus; in lynx_pcs_get_state_usxgmii()
42 int addr = pcs->addr; in lynx_pcs_get_state_usxgmii()
49 state->link = !!(status & MDIO_STAT1_LSTATUS); in lynx_pcs_get_state_usxgmii()
50 state->an_complete = !!(status & MDIO_AN_STAT1_COMPLETE); in lynx_pcs_get_state_usxgmii()
51 if (!state->link || !state->an_complete) in lynx_pcs_get_state_usxgmii()
61 static void lynx_pcs_get_state_2500basex(struct mdio_device *pcs, in lynx_pcs_get_state_2500basex() argument
66 bmsr = mdiodev_read(pcs, MII_BMSR); in lynx_pcs_get_state_2500basex()
68 state->link = false; in lynx_pcs_get_state_2500basex()
72 state->link = !!(bmsr & BMSR_LSTATUS); in lynx_pcs_get_state_2500basex()
73 state->an_complete = !!(bmsr & BMSR_ANEGCOMPLETE); in lynx_pcs_get_state_2500basex()
74 if (!state->link) in lynx_pcs_get_state_2500basex()
77 state->speed = SPEED_2500; in lynx_pcs_get_state_2500basex()
78 state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX; in lynx_pcs_get_state_2500basex()
79 state->duplex = DUPLEX_FULL; in lynx_pcs_get_state_2500basex()
82 static void lynx_pcs_get_state(struct phylink_pcs *pcs, in lynx_pcs_get_state() argument
85 struct lynx_pcs *lynx = phylink_pcs_to_lynx(pcs); in lynx_pcs_get_state() local
87 switch (state->interface) { in lynx_pcs_get_state()
91 phylink_mii_c22_pcs_get_state(lynx->mdio, state); in lynx_pcs_get_state()
94 lynx_pcs_get_state_2500basex(lynx->mdio, state); in lynx_pcs_get_state()
97 lynx_pcs_get_state_usxgmii(lynx->mdio, state); in lynx_pcs_get_state()
100 phylink_mii_c45_pcs_get_state(lynx->mdio, state); in lynx_pcs_get_state()
106 dev_dbg(&lynx->mdio->dev, in lynx_pcs_get_state()
108 phy_modes(state->interface), in lynx_pcs_get_state()
109 phy_speed_to_str(state->speed), in lynx_pcs_get_state()
110 phy_duplex_to_str(state->duplex), in lynx_pcs_get_state()
111 state->link, state->an_complete); in lynx_pcs_get_state()
114 static int lynx_pcs_config_giga(struct mdio_device *pcs, in lynx_pcs_config_giga() argument
128 mdiodev_write(pcs, LINK_TIMER_LO, link_timer & 0xffff); in lynx_pcs_config_giga()
129 mdiodev_write(pcs, LINK_TIMER_HI, link_timer >> 16); in lynx_pcs_config_giga()
141 err = mdiodev_modify(pcs, IF_MODE, in lynx_pcs_config_giga()
147 return phylink_mii_c22_pcs_config(pcs, interface, advertising, in lynx_pcs_config_giga()
151 static int lynx_pcs_config_usxgmii(struct mdio_device *pcs, in lynx_pcs_config_usxgmii() argument
155 struct mii_bus *bus = pcs->bus; in lynx_pcs_config_usxgmii()
156 int addr = pcs->addr; in lynx_pcs_config_usxgmii()
159 dev_err(&pcs->dev, "USXGMII only supports in-band AN for now\n"); in lynx_pcs_config_usxgmii()
160 return -EOPNOTSUPP; in lynx_pcs_config_usxgmii()
170 static int lynx_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, in lynx_pcs_config() argument
174 struct lynx_pcs *lynx = phylink_pcs_to_lynx(pcs); in lynx_pcs_config() local
180 return lynx_pcs_config_giga(lynx->mdio, ifmode, advertising, in lynx_pcs_config()
184 dev_err(&lynx->mdio->dev, in lynx_pcs_config()
186 return -EOPNOTSUPP; in lynx_pcs_config()
190 return lynx_pcs_config_usxgmii(lynx->mdio, advertising, in lynx_pcs_config()
196 return -EOPNOTSUPP; in lynx_pcs_config()
202 static void lynx_pcs_an_restart(struct phylink_pcs *pcs) in lynx_pcs_an_restart() argument
204 struct lynx_pcs *lynx = phylink_pcs_to_lynx(pcs); in lynx_pcs_an_restart() local
206 phylink_mii_c22_pcs_an_restart(lynx->mdio); in lynx_pcs_an_restart()
209 static void lynx_pcs_link_up_sgmii(struct mdio_device *pcs, in lynx_pcs_link_up_sgmii() argument
215 /* The PCS needs to be configured manually only in lynx_pcs_link_up_sgmii()
216 * when not operating on in-band mode in lynx_pcs_link_up_sgmii()
238 dev_err(&pcs->dev, "Invalid PCS speed %d\n", speed); in lynx_pcs_link_up_sgmii()
243 mdiodev_modify(pcs, IF_MODE, in lynx_pcs_link_up_sgmii()
248 /* 2500Base-X is SerDes protocol 7 on Felix and 6 on ENETC. It is a SerDes lane
250 * auto-negotiation of any link parameters. Electrically it is compatible with
254 * - Downgrading the link speed by duplicating symbols
255 * - Auto-negotiation
260 * AN, we call this PHY interface type 2500Base-X. In case a PHY negotiates a
261 * lower link speed on line side, the system-side interface remains fixed at
264 static void lynx_pcs_link_up_2500basex(struct mdio_device *pcs, in lynx_pcs_link_up_2500basex() argument
271 dev_err(&pcs->dev, "AN not supported for 2500BaseX\n"); in lynx_pcs_link_up_2500basex()
279 mdiodev_modify(pcs, IF_MODE, in lynx_pcs_link_up_2500basex()
284 static void lynx_pcs_link_up(struct phylink_pcs *pcs, unsigned int neg_mode, in lynx_pcs_link_up() argument
288 struct lynx_pcs *lynx = phylink_pcs_to_lynx(pcs); in lynx_pcs_link_up() local
293 lynx_pcs_link_up_sgmii(lynx->mdio, neg_mode, speed, duplex); in lynx_pcs_link_up()
296 lynx_pcs_link_up_2500basex(lynx->mdio, neg_mode, speed, duplex); in lynx_pcs_link_up()
299 /* At the moment, only in-band AN is supported for USXGMII in lynx_pcs_link_up()
317 struct lynx_pcs *lynx; in lynx_pcs_create() local
319 lynx = kzalloc(sizeof(*lynx), GFP_KERNEL); in lynx_pcs_create()
320 if (!lynx) in lynx_pcs_create()
321 return ERR_PTR(-ENOMEM); in lynx_pcs_create()
324 lynx->mdio = mdio; in lynx_pcs_create()
325 lynx->pcs.ops = &lynx_pcs_phylink_ops; in lynx_pcs_create()
326 lynx->pcs.neg_mode = true; in lynx_pcs_create()
327 lynx->pcs.poll = true; in lynx_pcs_create()
329 return lynx_to_phylink_pcs(lynx); in lynx_pcs_create()
335 struct phylink_pcs *pcs; in lynx_pcs_create_mdiodev() local
341 pcs = lynx_pcs_create(mdio); in lynx_pcs_create_mdiodev()
351 return pcs; in lynx_pcs_create_mdiodev()
356 * lynx_pcs_create_fwnode() creates a lynx PCS instance from the fwnode
360 * -ENODEV if the fwnode is marked unavailable
361 * -EPROBE_DEFER if we fail to find the device
362 * -ENOMEM if we fail to allocate memory
368 struct phylink_pcs *pcs; in lynx_pcs_create_fwnode() local
371 return ERR_PTR(-ENODEV); in lynx_pcs_create_fwnode()
375 return ERR_PTR(-EPROBE_DEFER); in lynx_pcs_create_fwnode()
377 pcs = lynx_pcs_create(mdio); in lynx_pcs_create_fwnode()
387 return pcs; in lynx_pcs_create_fwnode()
391 void lynx_pcs_destroy(struct phylink_pcs *pcs) in lynx_pcs_destroy() argument
393 struct lynx_pcs *lynx = phylink_pcs_to_lynx(pcs); in lynx_pcs_destroy() local
395 mdio_device_put(lynx->mdio); in lynx_pcs_destroy()
396 kfree(lynx); in lynx_pcs_destroy()
400 MODULE_DESCRIPTION("NXP Lynx PCS phylink library");