1 From 50ba3c63dc3f4fbeac32fc5675a00756723d786d Mon Sep 17 00:00:00 2001
2 From: Bogdan Purcareata <bogdan.purcareata@nxp.com>
3 Date: Wed, 12 Apr 2017 12:42:07 +0000
4 Subject: [PATCH] staging: fsl-dpaa2/mac: Add Freescale DPAA2 mac driver
6 Introduce the DPAA2 mac driver, which manages Datapath
7 Media Access Control (DPMAC) objects discovered on the
10 This driver works as a proxy between phylib including phy
11 drivers and the Management Complex firmware. It receives
12 updates on link state changes from PHY lib and forwards
13 them to the Management Complex and receives interrupts
14 from the Management Complex whenever a request is made to
15 change the link state.
17 This is a squashed commit containing contributions of the
19 Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
20 Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
21 Signed-off-by: Bogdan Hamciuc <bogdan.hamciuc@nxp.com>
22 Signed-off-by: Razvan Stefanescu <razvan.stefanescu@nxp.com>
23 Signed-off-by: Stuart Yoder <stuart.yoder@freescale.com>
24 Signed-off-by: J. German Rivera <German.Rivera@freescale.com>
25 Signed-off-by: Itai Katz <itai.katz@freescale.com>
27 Signed-off-by: Bogdan Purcareata <bogdan.purcareata@nxp.com>
29 drivers/staging/fsl-dpaa2/Kconfig | 2 +
30 drivers/staging/fsl-dpaa2/Makefile | 1 +
31 drivers/staging/fsl-dpaa2/mac/Kconfig | 23 ++
32 drivers/staging/fsl-dpaa2/mac/Makefile | 10 +
33 drivers/staging/fsl-dpaa2/mac/mac.c | 670 +++++++++++++++++++++++++++++++++
34 5 files changed, 706 insertions(+)
35 create mode 100644 drivers/staging/fsl-dpaa2/mac/Kconfig
36 create mode 100644 drivers/staging/fsl-dpaa2/mac/Makefile
37 create mode 100644 drivers/staging/fsl-dpaa2/mac/mac.c
39 --- a/drivers/staging/fsl-dpaa2/Kconfig
40 +++ b/drivers/staging/fsl-dpaa2/Kconfig
41 @@ -17,3 +17,5 @@ config FSL_DPAA2_ETHSW
43 Driver for Freescale DPAA2 Ethernet Switch. Select
44 BRIDGE to have support for bridge tools.
46 +source "drivers/staging/fsl-dpaa2/mac/Kconfig"
47 --- a/drivers/staging/fsl-dpaa2/Makefile
48 +++ b/drivers/staging/fsl-dpaa2/Makefile
52 obj-$(CONFIG_FSL_DPAA2_ETHSW) += ethsw/
53 +obj-$(CONFIG_FSL_DPAA2_MAC) += mac/
55 +++ b/drivers/staging/fsl-dpaa2/mac/Kconfig
58 + tristate "DPAA2 MAC / PHY interface"
59 + depends on FSL_MC_BUS && FSL_DPAA2
60 + select MDIO_BUS_MUX_MMIOREG
61 + select FSL_XGMAC_MDIO
64 + Prototype driver for DPAA2 MAC / PHY interface object.
65 + This driver works as a proxy between phylib including phy drivers and
66 + the MC firmware. It receives updates on link state changes from PHY
67 + lib and forwards them to MC and receives interrupt from MC whenever
68 + a request is made to change the link state.
71 +config FSL_DPAA2_MAC_NETDEVS
72 + bool "Expose net interfaces for PHYs"
74 + depends on FSL_DPAA2_MAC
76 + Exposes macX net interfaces which allow direct control over MACs and
79 + Leave disabled if unsure.
81 +++ b/drivers/staging/fsl-dpaa2/mac/Makefile
84 +obj-$(CONFIG_FSL_DPAA2_MAC) += dpaa2-mac.o
86 +dpaa2-mac-objs := mac.o dpmac.o
89 + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
92 + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
94 +++ b/drivers/staging/fsl-dpaa2/mac/mac.c
96 +/* Copyright 2015 Freescale Semiconductor Inc.
98 + * Redistribution and use in source and binary forms, with or without
99 + * modification, are permitted provided that the following conditions are met:
100 + * * Redistributions of source code must retain the above copyright
101 + * notice, this list of conditions and the following disclaimer.
102 + * * Redistributions in binary form must reproduce the above copyright
103 + * notice, this list of conditions and the following disclaimer in the
104 + * documentation and/or other materials provided with the distribution.
105 + * * Neither the name of Freescale Semiconductor nor the
106 + * names of its contributors may be used to endorse or promote products
107 + * derived from this software without specific prior written permission.
110 + * ALTERNATIVELY, this software may be distributed under the terms of the
111 + * GNU General Public License ("GPL") as published by the Free Software
112 + * Foundation, either version 2 of that License or (at your option) any
115 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
116 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
117 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
118 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
119 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
120 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
121 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
122 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
123 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
124 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
127 +#include <linux/module.h>
129 +#include <linux/netdevice.h>
130 +#include <linux/etherdevice.h>
131 +#include <linux/msi.h>
132 +#include <linux/rtnetlink.h>
133 +#include <linux/if_vlan.h>
135 +#include <uapi/linux/if_bridge.h>
136 +#include <net/netlink.h>
138 +#include <linux/of.h>
139 +#include <linux/of_mdio.h>
140 +#include <linux/of_net.h>
141 +#include <linux/phy.h>
142 +#include <linux/phy_fixed.h>
144 +#include "../../fsl-mc/include/mc.h"
145 +#include "../../fsl-mc/include/mc-sys.h"
148 +#include "dpmac-cmd.h"
150 +struct dpaa2_mac_priv {
151 + struct net_device *netdev;
152 + struct fsl_mc_device *mc_dev;
153 + struct dpmac_attr attr;
154 + struct dpmac_link_state old_state;
157 +/* TODO: fix the 10G modes, mapping can't be right:
159 + * XAUI is serial, using 8b/10b encoding
160 + * XFI is also serial but using 64b/66b encoding
161 + * they can't all map to XGMII...
163 + * This must be kept in sync with enum dpmac_eth_if.
165 +static phy_interface_t dpaa2_mac_iface_mode[] = {
166 + PHY_INTERFACE_MODE_MII, /* DPMAC_ETH_IF_MII */
167 + PHY_INTERFACE_MODE_RMII, /* DPMAC_ETH_IF_RMII */
168 + PHY_INTERFACE_MODE_SMII, /* DPMAC_ETH_IF_SMII */
169 + PHY_INTERFACE_MODE_GMII, /* DPMAC_ETH_IF_GMII */
170 + PHY_INTERFACE_MODE_RGMII, /* DPMAC_ETH_IF_RGMII */
171 + PHY_INTERFACE_MODE_SGMII, /* DPMAC_ETH_IF_SGMII */
172 + PHY_INTERFACE_MODE_QSGMII, /* DPMAC_ETH_IF_QSGMII */
173 + PHY_INTERFACE_MODE_XGMII, /* DPMAC_ETH_IF_XAUI */
174 + PHY_INTERFACE_MODE_XGMII, /* DPMAC_ETH_IF_XFI */
177 +static void dpaa2_mac_link_changed(struct net_device *netdev)
179 + struct phy_device *phydev;
180 + struct dpmac_link_state state = { 0 };
181 + struct dpaa2_mac_priv *priv = netdev_priv(netdev);
184 + /* the PHY just notified us of link state change */
185 + phydev = netdev->phydev;
187 + state.up = !!phydev->link;
188 + if (phydev->link) {
189 + state.rate = phydev->speed;
191 + if (!phydev->duplex)
192 + state.options |= DPMAC_LINK_OPT_HALF_DUPLEX;
193 + if (phydev->autoneg)
194 + state.options |= DPMAC_LINK_OPT_AUTONEG;
196 + netif_carrier_on(netdev);
198 + netif_carrier_off(netdev);
201 + if (priv->old_state.up != state.up ||
202 + priv->old_state.rate != state.rate ||
203 + priv->old_state.options != state.options) {
204 + priv->old_state = state;
205 + phy_print_status(phydev);
208 + /* We must interrogate MC at all times, because we don't know
209 + * when and whether a potential DPNI may have read the link state.
211 + err = dpmac_set_link_state(priv->mc_dev->mc_io, 0,
212 + priv->mc_dev->mc_handle, &state);
214 + dev_err(&priv->mc_dev->dev, "dpmac_set_link_state: %d\n", err);
217 +#ifdef CONFIG_FSL_DPAA2_MAC_NETDEVS
218 +static netdev_tx_t dpaa2_mac_drop_frame(struct sk_buff *skb,
219 + struct net_device *dev)
221 + /* we don't support I/O for now, drop the frame */
222 + dev_kfree_skb_any(skb);
223 + return NETDEV_TX_OK;
226 +static int dpaa2_mac_open(struct net_device *netdev)
228 + /* start PHY state machine */
229 + phy_start(netdev->phydev);
234 +static int dpaa2_mac_stop(struct net_device *netdev)
236 + if (!netdev->phydev)
239 + /* stop PHY state machine */
240 + phy_stop(netdev->phydev);
242 + /* signal link down to firmware */
243 + netdev->phydev->link = 0;
244 + dpaa2_mac_link_changed(netdev);
250 +static int dpaa2_mac_get_settings(struct net_device *netdev,
251 + struct ethtool_cmd *cmd)
253 + return phy_ethtool_gset(netdev->phydev, cmd);
256 +static int dpaa2_mac_set_settings(struct net_device *netdev,
257 + struct ethtool_cmd *cmd)
259 + return phy_ethtool_sset(netdev->phydev, cmd);
262 +static void dpaa2_mac_get_stats(struct net_device *netdev,
263 + struct rtnl_link_stats64 *storage)
265 + struct dpaa2_mac_priv *priv = netdev_priv(netdev);
269 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
270 + DPMAC_CNT_EGR_MCAST_FRAME,
271 + &storage->tx_packets);
274 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
275 + DPMAC_CNT_EGR_BCAST_FRAME, &tmp);
278 + storage->tx_packets += tmp;
279 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
280 + DPMAC_CNT_EGR_UCAST_FRAME, &tmp);
283 + storage->tx_packets += tmp;
285 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
286 + DPMAC_CNT_EGR_UNDERSIZED, &storage->tx_dropped);
289 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
290 + DPMAC_CNT_EGR_BYTE, &storage->tx_bytes);
293 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
294 + DPMAC_CNT_EGR_ERR_FRAME, &storage->tx_errors);
298 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
299 + DPMAC_CNT_ING_ALL_FRAME, &storage->rx_packets);
302 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
303 + DPMAC_CNT_ING_MCAST_FRAME, &storage->multicast);
306 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
307 + DPMAC_CNT_ING_FRAME_DISCARD,
308 + &storage->rx_dropped);
311 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
312 + DPMAC_CNT_ING_ALIGN_ERR, &storage->rx_errors);
315 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
316 + DPMAC_CNT_ING_OVERSIZED, &tmp);
319 + storage->rx_errors += tmp;
320 + err = dpmac_get_counter(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle,
321 + DPMAC_CNT_ING_BYTE, &storage->rx_bytes);
327 + netdev_err(netdev, "dpmac_get_counter err %d\n", err);
331 + enum dpmac_counter id;
332 + char name[ETH_GSTRING_LEN];
333 +} dpaa2_mac_counters[] = {
334 + {DPMAC_CNT_ING_ALL_FRAME, "rx all frames"},
335 + {DPMAC_CNT_ING_GOOD_FRAME, "rx frames ok"},
336 + {DPMAC_CNT_ING_ERR_FRAME, "rx frame errors"},
337 + {DPMAC_CNT_ING_FRAME_DISCARD, "rx frame discards"},
338 + {DPMAC_CNT_ING_UCAST_FRAME, "rx u-cast"},
339 + {DPMAC_CNT_ING_BCAST_FRAME, "rx b-cast"},
340 + {DPMAC_CNT_ING_MCAST_FRAME, "rx m-cast"},
341 + {DPMAC_CNT_ING_FRAME_64, "rx 64 bytes"},
342 + {DPMAC_CNT_ING_FRAME_127, "rx 65-127 bytes"},
343 + {DPMAC_CNT_ING_FRAME_255, "rx 128-255 bytes"},
344 + {DPMAC_CNT_ING_FRAME_511, "rx 256-511 bytes"},
345 + {DPMAC_CNT_ING_FRAME_1023, "rx 512-1023 bytes"},
346 + {DPMAC_CNT_ING_FRAME_1518, "rx 1024-1518 bytes"},
347 + {DPMAC_CNT_ING_FRAME_1519_MAX, "rx 1519-max bytes"},
348 + {DPMAC_CNT_ING_FRAG, "rx frags"},
349 + {DPMAC_CNT_ING_JABBER, "rx jabber"},
350 + {DPMAC_CNT_ING_ALIGN_ERR, "rx align errors"},
351 + {DPMAC_CNT_ING_OVERSIZED, "rx oversized"},
352 + {DPMAC_CNT_ING_VALID_PAUSE_FRAME, "rx pause"},
353 + {DPMAC_CNT_ING_BYTE, "rx bytes"},
354 + {DPMAC_CNT_ENG_GOOD_FRAME, "tx frames ok"},
355 + {DPMAC_CNT_EGR_UCAST_FRAME, "tx u-cast"},
356 + {DPMAC_CNT_EGR_MCAST_FRAME, "tx m-cast"},
357 + {DPMAC_CNT_EGR_BCAST_FRAME, "tx b-cast"},
358 + {DPMAC_CNT_EGR_ERR_FRAME, "tx frame errors"},
359 + {DPMAC_CNT_EGR_UNDERSIZED, "tx undersized"},
360 + {DPMAC_CNT_EGR_VALID_PAUSE_FRAME, "tx b-pause"},
361 + {DPMAC_CNT_EGR_BYTE, "tx bytes"},
365 +static void dpaa2_mac_get_strings(struct net_device *netdev,
366 + u32 stringset, u8 *data)
370 + switch (stringset) {
372 + for (i = 0; i < ARRAY_SIZE(dpaa2_mac_counters); i++)
373 + memcpy(data + i * ETH_GSTRING_LEN,
374 + dpaa2_mac_counters[i].name,
380 +static void dpaa2_mac_get_ethtool_stats(struct net_device *netdev,
381 + struct ethtool_stats *stats,
384 + struct dpaa2_mac_priv *priv = netdev_priv(netdev);
388 + for (i = 0; i < ARRAY_SIZE(dpaa2_mac_counters); i++) {
389 + err = dpmac_get_counter(priv->mc_dev->mc_io,
391 + priv->mc_dev->mc_handle,
392 + dpaa2_mac_counters[i].id, &data[i]);
394 + netdev_err(netdev, "dpmac_get_counter[%s] err %d\n",
395 + dpaa2_mac_counters[i].name, err);
399 +static int dpaa2_mac_get_sset_count(struct net_device *dev, int sset)
403 + return ARRAY_SIZE(dpaa2_mac_counters);
405 + return -EOPNOTSUPP;
409 +static const struct net_device_ops dpaa2_mac_ndo_ops = {
410 + .ndo_start_xmit = &dpaa2_mac_drop_frame,
411 + .ndo_open = &dpaa2_mac_open,
412 + .ndo_stop = &dpaa2_mac_stop,
413 + .ndo_get_stats64 = &dpaa2_mac_get_stats,
416 +static const struct ethtool_ops dpaa2_mac_ethtool_ops = {
417 + .get_settings = &dpaa2_mac_get_settings,
418 + .set_settings = &dpaa2_mac_set_settings,
419 + .get_strings = &dpaa2_mac_get_strings,
420 + .get_ethtool_stats = &dpaa2_mac_get_ethtool_stats,
421 + .get_sset_count = &dpaa2_mac_get_sset_count,
423 +#endif /* CONFIG_FSL_DPAA2_MAC_NETDEVS */
425 +static void configure_link(struct dpaa2_mac_priv *priv,
426 + struct dpmac_link_cfg *cfg)
428 + struct phy_device *phydev = priv->netdev->phydev;
430 + if (unlikely(!phydev))
433 + phydev->speed = cfg->rate;
434 + phydev->duplex = !!(cfg->options & DPMAC_LINK_OPT_HALF_DUPLEX);
436 + if (cfg->options & DPMAC_LINK_OPT_AUTONEG) {
437 + phydev->autoneg = 1;
438 + phydev->advertising |= ADVERTISED_Autoneg;
440 + phydev->autoneg = 0;
441 + phydev->advertising &= ~ADVERTISED_Autoneg;
444 + phy_start_aneg(phydev);
447 +static irqreturn_t dpaa2_mac_irq_handler(int irq_num, void *arg)
449 + struct device *dev = (struct device *)arg;
450 + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
451 + struct dpaa2_mac_priv *priv = dev_get_drvdata(dev);
452 + struct dpmac_link_cfg link_cfg;
456 + err = dpmac_get_irq_status(mc_dev->mc_io, 0, mc_dev->mc_handle,
457 + DPMAC_IRQ_INDEX, &status);
458 + if (unlikely(err || !status))
461 + /* DPNI-initiated link configuration; 'ifconfig up' also calls this */
462 + if (status & DPMAC_IRQ_EVENT_LINK_CFG_REQ) {
463 + err = dpmac_get_link_cfg(mc_dev->mc_io, 0, mc_dev->mc_handle,
468 + configure_link(priv, &link_cfg);
472 + dpmac_clear_irq_status(mc_dev->mc_io, 0, mc_dev->mc_handle,
473 + DPMAC_IRQ_INDEX, status);
475 + return IRQ_HANDLED;
478 +static int setup_irqs(struct fsl_mc_device *mc_dev)
481 + struct fsl_mc_device_irq *irq;
483 + err = fsl_mc_allocate_irqs(mc_dev);
485 + dev_err(&mc_dev->dev, "fsl_mc_allocate_irqs err %d\n", err);
489 + irq = mc_dev->irqs[0];
490 + err = devm_request_threaded_irq(&mc_dev->dev, irq->msi_desc->irq,
491 + NULL, &dpaa2_mac_irq_handler,
492 + IRQF_NO_SUSPEND | IRQF_ONESHOT,
493 + dev_name(&mc_dev->dev), &mc_dev->dev);
495 + dev_err(&mc_dev->dev, "devm_request_threaded_irq err %d\n",
500 + err = dpmac_set_irq_mask(mc_dev->mc_io, 0, mc_dev->mc_handle,
501 + DPMAC_IRQ_INDEX, DPMAC_IRQ_EVENT_LINK_CFG_REQ);
503 + dev_err(&mc_dev->dev, "dpmac_set_irq_mask err %d\n", err);
506 + err = dpmac_set_irq_enable(mc_dev->mc_io, 0, mc_dev->mc_handle,
507 + DPMAC_IRQ_INDEX, 1);
509 + dev_err(&mc_dev->dev, "dpmac_set_irq_enable err %d\n", err);
516 + fsl_mc_free_irqs(mc_dev);
521 +static void teardown_irqs(struct fsl_mc_device *mc_dev)
525 + err = dpmac_set_irq_enable(mc_dev->mc_io, 0, mc_dev->mc_handle,
526 + DPMAC_IRQ_INDEX, 0);
528 + dev_err(&mc_dev->dev, "dpmac_set_irq_enable err %d\n", err);
530 + fsl_mc_free_irqs(mc_dev);
533 +static struct device_node *find_dpmac_node(struct device *dev, u16 dpmac_id)
535 + struct device_node *dpmacs, *dpmac = NULL;
536 + struct device_node *mc_node = dev->of_node;
540 + dpmacs = of_find_node_by_name(mc_node, "dpmacs");
542 + dev_err(dev, "No dpmacs subnode in device-tree\n");
546 + while ((dpmac = of_get_next_child(dpmacs, dpmac))) {
547 + err = of_property_read_u32(dpmac, "reg", &id);
550 + if (id == dpmac_id)
557 +static int dpaa2_mac_probe(struct fsl_mc_device *mc_dev)
559 + struct device *dev;
560 + struct dpaa2_mac_priv *priv = NULL;
561 + struct device_node *phy_node, *dpmac_node;
562 + struct net_device *netdev;
563 + phy_interface_t if_mode;
566 + dev = &mc_dev->dev;
568 + /* prepare a net_dev structure to make the phy lib API happy */
569 + netdev = alloc_etherdev(sizeof(*priv));
571 + dev_err(dev, "alloc_etherdev error\n");
575 + priv = netdev_priv(netdev);
576 + priv->mc_dev = mc_dev;
577 + priv->netdev = netdev;
579 + SET_NETDEV_DEV(netdev, dev);
581 +#ifdef CONFIG_FSL_DPAA2_MAC_NETDEVS
582 + snprintf(netdev->name, IFNAMSIZ, "mac%d", mc_dev->obj_desc.id);
585 + dev_set_drvdata(dev, priv);
587 + err = fsl_mc_portal_allocate(mc_dev, 0, &mc_dev->mc_io);
588 + if (err || !mc_dev->mc_io) {
589 + dev_err(dev, "fsl_mc_portal_allocate error: %d\n", err);
591 + goto err_free_netdev;
594 + err = dpmac_open(mc_dev->mc_io, 0, mc_dev->obj_desc.id,
595 + &mc_dev->mc_handle);
596 + if (err || !mc_dev->mc_handle) {
597 + dev_err(dev, "dpmac_open error: %d\n", err);
602 + err = dpmac_get_attributes(mc_dev->mc_io, 0,
603 + mc_dev->mc_handle, &priv->attr);
605 + dev_err(dev, "dpmac_get_attributes err %d\n", err);
610 + /* Look up the DPMAC node in the device-tree. */
611 + dpmac_node = find_dpmac_node(dev, priv->attr.id);
613 + dev_err(dev, "No dpmac@%d subnode found.\n", priv->attr.id);
618 + err = setup_irqs(mc_dev);
624 +#ifdef CONFIG_FSL_DPAA2_MAC_NETDEVS
625 + /* OPTIONAL, register netdev just to make it visible to the user */
626 + netdev->netdev_ops = &dpaa2_mac_ndo_ops;
627 + netdev->ethtool_ops = &dpaa2_mac_ethtool_ops;
629 + /* phy starts up enabled so netdev should be up too */
630 + netdev->flags |= IFF_UP;
632 + err = register_netdev(priv->netdev);
634 + dev_err(dev, "register_netdev error %d\n", err);
638 +#endif /* CONFIG_FSL_DPAA2_MAC_NETDEVS */
640 + /* probe the PHY as a fixed-link if the link type declared in DPC
641 + * explicitly mandates this
643 + if (priv->attr.link_type == DPMAC_LINK_TYPE_FIXED)
644 + goto probe_fixed_link;
646 + if (priv->attr.eth_if < ARRAY_SIZE(dpaa2_mac_iface_mode)) {
647 + if_mode = dpaa2_mac_iface_mode[priv->attr.eth_if];
648 + dev_dbg(dev, "\tusing if mode %s for eth_if %d\n",
649 + phy_modes(if_mode), priv->attr.eth_if);
651 + dev_warn(dev, "Unexpected interface mode %d, will probe as fixed link\n",
652 + priv->attr.eth_if);
653 + goto probe_fixed_link;
656 + /* try to connect to the PHY */
657 + phy_node = of_parse_phandle(dpmac_node, "phy-handle", 0);
660 + dev_err(dev, "dpmac node has no phy-handle property\n");
665 + netdev->phydev = of_phy_connect(netdev, phy_node,
666 + &dpaa2_mac_link_changed, 0, if_mode);
667 + if (!netdev->phydev) {
668 + /* No need for dev_err(); the kernel's loud enough as it is. */
669 + dev_dbg(dev, "Can't of_phy_connect() now.\n");
670 + /* We might be waiting for the MDIO MUX to probe, so defer
673 + err = -EPROBE_DEFER;
676 + dev_info(dev, "Connected to %s PHY.\n", phy_modes(if_mode));
679 + if (!netdev->phydev) {
680 + struct fixed_phy_status status = {
682 + /* fixed-phys don't support 10Gbps speed for now */
687 + /* try to register a fixed link phy */
688 + netdev->phydev = fixed_phy_register(PHY_POLL, &status, NULL);
689 + if (!netdev->phydev || IS_ERR(netdev->phydev)) {
690 + dev_err(dev, "error trying to register fixed PHY\n");
691 + /* So we don't crash unregister_netdev() later on */
692 + netdev->phydev = NULL;
696 + dev_info(dev, "Registered fixed PHY.\n");
699 + /* start PHY state machine */
700 +#ifdef CONFIG_FSL_DPAA2_MAC_NETDEVS
701 + dpaa2_mac_open(netdev);
702 +#else /* CONFIG_FSL_DPAA2_MAC_NETDEVS */
703 + phy_start(netdev->phydev);
704 +#endif /* CONFIG_FSL_DPAA2_MAC_NETDEVS */
709 +#ifdef CONFIG_FSL_DPAA2_MAC_NETDEVS
710 + unregister_netdev(netdev);
713 + teardown_irqs(mc_dev);
715 + dpmac_close(mc_dev->mc_io, 0, mc_dev->mc_handle);
717 + fsl_mc_portal_free(mc_dev->mc_io);
719 + free_netdev(netdev);
724 +static int dpaa2_mac_remove(struct fsl_mc_device *mc_dev)
726 + struct device *dev = &mc_dev->dev;
727 + struct dpaa2_mac_priv *priv = dev_get_drvdata(dev);
729 +#ifdef CONFIG_FSL_DPAA2_MAC_NETDEVS
730 + unregister_netdev(priv->netdev);
732 + teardown_irqs(priv->mc_dev);
733 + dpmac_close(priv->mc_dev->mc_io, 0, priv->mc_dev->mc_handle);
734 + fsl_mc_portal_free(priv->mc_dev->mc_io);
735 + free_netdev(priv->netdev);
737 + dev_set_drvdata(dev, NULL);
743 +static const struct fsl_mc_device_id dpaa2_mac_match_id_table[] = {
745 + .vendor = FSL_MC_VENDOR_FREESCALE,
746 + .obj_type = "dpmac",
750 +MODULE_DEVICE_TABLE(fslmc, dpaa2_mac_match_id_table);
752 +static struct fsl_mc_driver dpaa2_mac_drv = {
754 + .name = KBUILD_MODNAME,
755 + .owner = THIS_MODULE,
757 + .probe = dpaa2_mac_probe,
758 + .remove = dpaa2_mac_remove,
759 + .match_id_table = dpaa2_mac_match_id_table,
762 +module_fsl_mc_driver(dpaa2_mac_drv);
764 +MODULE_LICENSE("GPL");
765 +MODULE_DESCRIPTION("DPAA2 PHY proxy interface driver");