dpaa2-mac: fixup the remove path
authorIoana Ciornei <ioana.ciornei@nxp.com>
Tue, 9 Feb 2021 14:53:26 +0000 (16:53 +0200)
committerIoana Ciornei <ioana.ciornei@nxp.com>
Wed, 3 Mar 2021 10:05:04 +0000 (12:05 +0200)
On the remove path, there is a need to teardown the IRQs and disconnect
from the PHY only if the DPMAC is not in TYPE_FIXED.
Update the remove path so that we do not end up accesing an invalid MC
portal.

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h

index c50220e..61f34b1 100644 (file)
@@ -684,7 +684,13 @@ static int dpaa2_mac_probe(struct fsl_mc_device *mc_dev)
         * taken care of in the MC firmware. Thus, probe the DPMAC but do
         * nothing with it.
         */
-       if (dpaa2_mac_is_type_fixed(mc_dev, mc_dev->mc_io)) {
+       err = dpmac_get_attributes(mc_dev->mc_io, 0, mc_dev->mc_handle, &priv->attr);
+       if (err) {
+               dev_err(dev, "dpmac_get_attributes() = %d\n", err);
+               goto free_portal;
+       }
+
+       if (priv->attr.link_type == DPMAC_LINK_TYPE_FIXED) {
                fsl_mc_portal_free(mc_dev->mc_io);
                return 0;
        }
@@ -702,7 +708,6 @@ static int dpaa2_mac_probe(struct fsl_mc_device *mc_dev)
        }
 
        return 0;
-
 free_portal:
        fsl_mc_portal_free(mc_dev->mc_io);
 free_netdev:
@@ -717,9 +722,12 @@ static int dpaa2_mac_remove(struct fsl_mc_device *mc_dev)
        struct net_device *net_dev = dev_get_drvdata(dev);
        struct dpaa2_mac *priv = netdev_priv(net_dev);
 
-       dpaa2_mac_teardown_irqs(mc_dev);
-       dpaa2_mac_disconnect(priv);
-       fsl_mc_portal_free(mc_dev->mc_io);
+       if (priv->attr.link_type != DPMAC_LINK_TYPE_FIXED) {
+               dpaa2_mac_teardown_irqs(mc_dev);
+               dpaa2_mac_disconnect(priv);
+               fsl_mc_portal_free(mc_dev->mc_io);
+       }
+
        dev_set_drvdata(dev, NULL);
        free_netdev(net_dev);
 
index af6b7ed..b1d74cc 100644 (file)
@@ -17,6 +17,7 @@ struct dpaa2_mac {
        struct dpmac_link_state state;
        struct net_device *net_dev;
        struct fsl_mc_io *mc_io;
+       struct dpmac_attr attr;
 
        struct phylink_config phylink_config;
        struct phylink *phylink;