Lines Matching +full:mac +full:- +full:mode
1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
5 #include <linux/pcs-lynx.h>
9 #include "dpaa2-eth.h"
10 #include "dpaa2-mac.h"
20 static int dpaa2_mac_cmp_ver(struct dpaa2_mac *mac, in dpaa2_mac_cmp_ver() argument
23 if (mac->ver_major == ver_major) in dpaa2_mac_cmp_ver()
24 return mac->ver_minor - ver_minor; in dpaa2_mac_cmp_ver()
25 return mac->ver_major - ver_major; in dpaa2_mac_cmp_ver()
28 static void dpaa2_mac_detect_features(struct dpaa2_mac *mac) in dpaa2_mac_detect_features() argument
30 mac->features = 0; in dpaa2_mac_detect_features()
32 if (dpaa2_mac_cmp_ver(mac, DPMAC_PROTOCOL_CHANGE_VER_MAJOR, in dpaa2_mac_detect_features()
34 mac->features |= DPAA2_MAC_FEATURE_PROTOCOL_CHANGE; in dpaa2_mac_detect_features()
61 return -EINVAL; in phy_mode()
100 fwnode = dev_fwnode(dev->parent); in dpaa2_mac_get_node()
114 return ERR_PTR(-EPROBE_DEFER); in dpaa2_mac_get_node()
118 err = -EINVAL; in dpaa2_mac_get_node()
155 struct dpaa2_mac *mac = phylink_to_dpaa2_mac(config); in dpaa2_mac_select_pcs() local
157 return mac->pcs; in dpaa2_mac_select_pcs()
160 static void dpaa2_mac_config(struct phylink_config *config, unsigned int mode, in dpaa2_mac_config() argument
163 struct dpaa2_mac *mac = phylink_to_dpaa2_mac(config); in dpaa2_mac_config() local
164 struct dpmac_link_state *dpmac_state = &mac->state; in dpaa2_mac_config()
168 state->advertising)) in dpaa2_mac_config()
169 dpmac_state->options |= DPMAC_LINK_OPT_AUTONEG; in dpaa2_mac_config()
171 dpmac_state->options &= ~DPMAC_LINK_OPT_AUTONEG; in dpaa2_mac_config()
173 err = dpmac_set_link_state(mac->mc_io, 0, in dpaa2_mac_config()
174 mac->mc_dev->mc_handle, dpmac_state); in dpaa2_mac_config()
176 netdev_err(mac->net_dev, "%s: dpmac_set_link_state() = %d\n", in dpaa2_mac_config()
179 if (!mac->serdes_phy) in dpaa2_mac_config()
183 err = dpmac_set_protocol(mac->mc_io, 0, mac->mc_dev->mc_handle, in dpaa2_mac_config()
184 dpmac_eth_if_mode(state->interface)); in dpaa2_mac_config()
186 netdev_err(mac->net_dev, "dpmac_set_protocol() = %d\n", err); in dpaa2_mac_config()
188 err = phy_set_mode_ext(mac->serdes_phy, PHY_MODE_ETHERNET, state->interface); in dpaa2_mac_config()
190 netdev_err(mac->net_dev, "phy_set_mode_ext() = %d\n", err); in dpaa2_mac_config()
195 unsigned int mode, phy_interface_t interface, in dpaa2_mac_link_up() argument
199 struct dpaa2_mac *mac = phylink_to_dpaa2_mac(config); in dpaa2_mac_link_up() local
200 struct dpmac_link_state *dpmac_state = &mac->state; in dpaa2_mac_link_up()
203 dpmac_state->up = 1; in dpaa2_mac_link_up()
205 dpmac_state->rate = speed; in dpaa2_mac_link_up()
208 dpmac_state->options |= DPMAC_LINK_OPT_HALF_DUPLEX; in dpaa2_mac_link_up()
210 dpmac_state->options &= ~DPMAC_LINK_OPT_HALF_DUPLEX; in dpaa2_mac_link_up()
213 dpmac_state->options |= DPMAC_LINK_OPT_PAUSE; in dpaa2_mac_link_up()
215 dpmac_state->options &= ~DPMAC_LINK_OPT_PAUSE; in dpaa2_mac_link_up()
218 dpmac_state->options |= DPMAC_LINK_OPT_ASYM_PAUSE; in dpaa2_mac_link_up()
220 dpmac_state->options &= ~DPMAC_LINK_OPT_ASYM_PAUSE; in dpaa2_mac_link_up()
222 err = dpmac_set_link_state(mac->mc_io, 0, in dpaa2_mac_link_up()
223 mac->mc_dev->mc_handle, dpmac_state); in dpaa2_mac_link_up()
225 netdev_err(mac->net_dev, "%s: dpmac_set_link_state() = %d\n", in dpaa2_mac_link_up()
230 unsigned int mode, in dpaa2_mac_link_down() argument
233 struct dpaa2_mac *mac = phylink_to_dpaa2_mac(config); in dpaa2_mac_link_down() local
234 struct dpmac_link_state *dpmac_state = &mac->state; in dpaa2_mac_link_down()
237 dpmac_state->up = 0; in dpaa2_mac_link_down()
238 err = dpmac_set_link_state(mac->mc_io, 0, in dpaa2_mac_link_down()
239 mac->mc_dev->mc_handle, dpmac_state); in dpaa2_mac_link_down()
241 netdev_err(mac->net_dev, "dpmac_set_link_state() = %d\n", err); in dpaa2_mac_link_down()
251 static int dpaa2_pcs_create(struct dpaa2_mac *mac, in dpaa2_pcs_create() argument
258 node = fwnode_find_reference(dpmac_node, "pcs-handle", 0); in dpaa2_pcs_create()
261 netdev_warn(mac->net_dev, "pcs-handle node not found\n"); in dpaa2_pcs_create()
268 if (pcs == ERR_PTR(-EPROBE_DEFER)) { in dpaa2_pcs_create()
269 netdev_dbg(mac->net_dev, "missing PCS device\n"); in dpaa2_pcs_create()
270 return -EPROBE_DEFER; in dpaa2_pcs_create()
273 if (pcs == ERR_PTR(-ENODEV)) { in dpaa2_pcs_create()
274 netdev_err(mac->net_dev, "pcs-handle node not available\n"); in dpaa2_pcs_create()
279 netdev_err(mac->net_dev, in dpaa2_pcs_create()
284 mac->pcs = pcs; in dpaa2_pcs_create()
289 static void dpaa2_pcs_destroy(struct dpaa2_mac *mac) in dpaa2_pcs_destroy() argument
291 struct phylink_pcs *phylink_pcs = mac->pcs; in dpaa2_pcs_destroy()
295 mac->pcs = NULL; in dpaa2_pcs_destroy()
299 static void dpaa2_mac_set_supported_interfaces(struct dpaa2_mac *mac) in dpaa2_mac_set_supported_interfaces() argument
303 /* We support the current interface mode, and if we have a PCS in dpaa2_mac_set_supported_interfaces()
307 __set_bit(mac->if_mode, mac->phylink_config.supported_interfaces); in dpaa2_mac_set_supported_interfaces()
308 if (mac->pcs) { in dpaa2_mac_set_supported_interfaces()
309 switch (mac->if_mode) { in dpaa2_mac_set_supported_interfaces()
313 mac->phylink_config.supported_interfaces); in dpaa2_mac_set_supported_interfaces()
315 mac->phylink_config.supported_interfaces); in dpaa2_mac_set_supported_interfaces()
323 if (!mac->serdes_phy) in dpaa2_mac_set_supported_interfaces()
334 err = phy_validate(mac->serdes_phy, PHY_MODE_ETHERNET, intf, NULL); in dpaa2_mac_set_supported_interfaces()
338 __set_bit(intf, mac->phylink_config.supported_interfaces); in dpaa2_mac_set_supported_interfaces()
342 void dpaa2_mac_start(struct dpaa2_mac *mac) in dpaa2_mac_start() argument
346 if (mac->serdes_phy) in dpaa2_mac_start()
347 phy_power_on(mac->serdes_phy); in dpaa2_mac_start()
349 phylink_start(mac->phylink); in dpaa2_mac_start()
352 void dpaa2_mac_stop(struct dpaa2_mac *mac) in dpaa2_mac_stop() argument
356 phylink_stop(mac->phylink); in dpaa2_mac_stop()
358 if (mac->serdes_phy) in dpaa2_mac_stop()
359 phy_power_off(mac->serdes_phy); in dpaa2_mac_stop()
362 int dpaa2_mac_connect(struct dpaa2_mac *mac) in dpaa2_mac_connect() argument
364 struct net_device *net_dev = mac->net_dev; in dpaa2_mac_connect()
370 mac->if_link_type = mac->attr.link_type; in dpaa2_mac_connect()
372 dpmac_node = mac->fw_node; in dpaa2_mac_connect()
374 netdev_err(net_dev, "No dpmac@%d node found.\n", mac->attr.id); in dpaa2_mac_connect()
375 return -ENODEV; in dpaa2_mac_connect()
378 err = dpaa2_mac_get_if_mode(dpmac_node, mac->attr); in dpaa2_mac_connect()
380 return -EINVAL; in dpaa2_mac_connect()
381 mac->if_mode = err; in dpaa2_mac_connect()
383 if (mac->features & DPAA2_MAC_FEATURE_PROTOCOL_CHANGE && in dpaa2_mac_connect()
384 !phy_interface_mode_is_rgmii(mac->if_mode) && in dpaa2_mac_connect()
388 if (serdes_phy == ERR_PTR(-ENODEV)) in dpaa2_mac_connect()
395 mac->serdes_phy = serdes_phy; in dpaa2_mac_connect()
397 /* The MAC does not have the capability to add RGMII delays so in dpaa2_mac_connect()
398 * error out if the interface mode requests them and there is no PHY in dpaa2_mac_connect()
402 (mac->if_mode == PHY_INTERFACE_MODE_RGMII_ID || in dpaa2_mac_connect()
403 mac->if_mode == PHY_INTERFACE_MODE_RGMII_RXID || in dpaa2_mac_connect()
404 mac->if_mode == PHY_INTERFACE_MODE_RGMII_TXID)) { in dpaa2_mac_connect()
406 return -EINVAL; in dpaa2_mac_connect()
409 if ((mac->attr.link_type == DPMAC_LINK_TYPE_PHY && in dpaa2_mac_connect()
410 mac->attr.eth_if != DPMAC_ETH_IF_RGMII) || in dpaa2_mac_connect()
411 mac->attr.link_type == DPMAC_LINK_TYPE_BACKPLANE) { in dpaa2_mac_connect()
412 err = dpaa2_pcs_create(mac, dpmac_node, mac->attr.id); in dpaa2_mac_connect()
417 memset(&mac->phylink_config, 0, sizeof(mac->phylink_config)); in dpaa2_mac_connect()
418 mac->phylink_config.dev = &net_dev->dev; in dpaa2_mac_connect()
419 mac->phylink_config.type = PHYLINK_NETDEV; in dpaa2_mac_connect()
421 mac->phylink_config.mac_capabilities = MAC_SYM_PAUSE | MAC_ASYM_PAUSE | in dpaa2_mac_connect()
425 dpaa2_mac_set_supported_interfaces(mac); in dpaa2_mac_connect()
427 phylink = phylink_create(&mac->phylink_config, in dpaa2_mac_connect()
428 dpmac_node, mac->if_mode, in dpaa2_mac_connect()
434 mac->phylink = phylink; in dpaa2_mac_connect()
437 err = phylink_fwnode_phy_connect(mac->phylink, dpmac_node, 0); in dpaa2_mac_connect()
447 phylink_destroy(mac->phylink); in dpaa2_mac_connect()
449 dpaa2_pcs_destroy(mac); in dpaa2_mac_connect()
454 void dpaa2_mac_disconnect(struct dpaa2_mac *mac) in dpaa2_mac_disconnect() argument
457 phylink_disconnect_phy(mac->phylink); in dpaa2_mac_disconnect()
460 phylink_destroy(mac->phylink); in dpaa2_mac_disconnect()
461 dpaa2_pcs_destroy(mac); in dpaa2_mac_disconnect()
462 of_phy_put(mac->serdes_phy); in dpaa2_mac_disconnect()
463 mac->serdes_phy = NULL; in dpaa2_mac_disconnect()
466 int dpaa2_mac_open(struct dpaa2_mac *mac) in dpaa2_mac_open() argument
468 struct fsl_mc_device *dpmac_dev = mac->mc_dev; in dpaa2_mac_open()
469 struct net_device *net_dev = mac->net_dev; in dpaa2_mac_open()
473 err = dpmac_open(mac->mc_io, 0, dpmac_dev->obj_desc.id, in dpaa2_mac_open()
474 &dpmac_dev->mc_handle); in dpaa2_mac_open()
475 if (err || !dpmac_dev->mc_handle) { in dpaa2_mac_open()
477 return -ENODEV; in dpaa2_mac_open()
480 err = dpmac_get_attributes(mac->mc_io, 0, dpmac_dev->mc_handle, in dpaa2_mac_open()
481 &mac->attr); in dpaa2_mac_open()
487 err = dpmac_get_api_version(mac->mc_io, 0, &mac->ver_major, &mac->ver_minor); in dpaa2_mac_open()
493 dpaa2_mac_detect_features(mac); in dpaa2_mac_open()
495 /* Find the device node representing the MAC device and link the device in dpaa2_mac_open()
498 fw_node = dpaa2_mac_get_node(&mac->mc_dev->dev, mac->attr.id); in dpaa2_mac_open()
504 mac->fw_node = fw_node; in dpaa2_mac_open()
505 net_dev->dev.of_node = to_of_node(mac->fw_node); in dpaa2_mac_open()
510 dpmac_close(mac->mc_io, 0, dpmac_dev->mc_handle); in dpaa2_mac_open()
514 void dpaa2_mac_close(struct dpaa2_mac *mac) in dpaa2_mac_close() argument
516 struct fsl_mc_device *dpmac_dev = mac->mc_dev; in dpaa2_mac_close()
518 dpmac_close(mac->mc_io, 0, dpmac_dev->mc_handle); in dpaa2_mac_close()
519 if (mac->fw_node) in dpaa2_mac_close()
520 fwnode_handle_put(mac->fw_node); in dpaa2_mac_close()
524 [DPMAC_CNT_ING_ALL_FRAME] = "[mac] rx all frames",
525 [DPMAC_CNT_ING_GOOD_FRAME] = "[mac] rx frames ok",
526 [DPMAC_CNT_ING_ERR_FRAME] = "[mac] rx frame errors",
527 [DPMAC_CNT_ING_FRAME_DISCARD] = "[mac] rx frame discards",
528 [DPMAC_CNT_ING_UCAST_FRAME] = "[mac] rx u-cast",
529 [DPMAC_CNT_ING_BCAST_FRAME] = "[mac] rx b-cast",
530 [DPMAC_CNT_ING_MCAST_FRAME] = "[mac] rx m-cast",
531 [DPMAC_CNT_ING_FRAME_64] = "[mac] rx 64 bytes",
532 [DPMAC_CNT_ING_FRAME_127] = "[mac] rx 65-127 bytes",
533 [DPMAC_CNT_ING_FRAME_255] = "[mac] rx 128-255 bytes",
534 [DPMAC_CNT_ING_FRAME_511] = "[mac] rx 256-511 bytes",
535 [DPMAC_CNT_ING_FRAME_1023] = "[mac] rx 512-1023 bytes",
536 [DPMAC_CNT_ING_FRAME_1518] = "[mac] rx 1024-1518 bytes",
537 [DPMAC_CNT_ING_FRAME_1519_MAX] = "[mac] rx 1519-max bytes",
538 [DPMAC_CNT_ING_FRAG] = "[mac] rx frags",
539 [DPMAC_CNT_ING_JABBER] = "[mac] rx jabber",
540 [DPMAC_CNT_ING_ALIGN_ERR] = "[mac] rx align errors",
541 [DPMAC_CNT_ING_OVERSIZED] = "[mac] rx oversized",
542 [DPMAC_CNT_ING_VALID_PAUSE_FRAME] = "[mac] rx pause",
543 [DPMAC_CNT_ING_BYTE] = "[mac] rx bytes",
544 [DPMAC_CNT_EGR_GOOD_FRAME] = "[mac] tx frames ok",
545 [DPMAC_CNT_EGR_UCAST_FRAME] = "[mac] tx u-cast",
546 [DPMAC_CNT_EGR_MCAST_FRAME] = "[mac] tx m-cast",
547 [DPMAC_CNT_EGR_BCAST_FRAME] = "[mac] tx b-cast",
548 [DPMAC_CNT_EGR_ERR_FRAME] = "[mac] tx frame errors",
549 [DPMAC_CNT_EGR_UNDERSIZED] = "[mac] tx undersized",
550 [DPMAC_CNT_EGR_VALID_PAUSE_FRAME] = "[mac] tx b-pause",
551 [DPMAC_CNT_EGR_BYTE] = "[mac] tx bytes",
572 void dpaa2_mac_get_ethtool_stats(struct dpaa2_mac *mac, u64 *data) in dpaa2_mac_get_ethtool_stats() argument
574 struct fsl_mc_device *dpmac_dev = mac->mc_dev; in dpaa2_mac_get_ethtool_stats()
579 err = dpmac_get_counter(mac->mc_io, 0, dpmac_dev->mc_handle, in dpaa2_mac_get_ethtool_stats()
582 netdev_err_once(mac->net_dev, in dpaa2_mac_get_ethtool_stats()