dpaa2-mac: retrieve API version and detect features
authorIoana Ciornei <ioana.ciornei@nxp.com>
Fri, 11 Mar 2022 21:22:25 +0000 (23:22 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 14 Mar 2022 10:41:51 +0000 (10:41 +0000)
Retrieve the API version running on the firmware and based on it detect
which features are available for usage.
The first one to be listed is the capability to change the MAC protocol
at runtime.

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

index 521f036..c4a49bf 100644 (file)
 #define phylink_to_dpaa2_mac(config) \
        container_of((config), struct dpaa2_mac, phylink_config)
 
+#define DPMAC_PROTOCOL_CHANGE_VER_MAJOR                4
+#define DPMAC_PROTOCOL_CHANGE_VER_MINOR                8
+
+#define DPAA2_MAC_FEATURE_PROTOCOL_CHANGE      BIT(0)
+
+static int dpaa2_mac_cmp_ver(struct dpaa2_mac *mac,
+                            u16 ver_major, u16 ver_minor)
+{
+       if (mac->ver_major == ver_major)
+               return mac->ver_minor - ver_minor;
+       return mac->ver_major - ver_major;
+}
+
+static void dpaa2_mac_detect_features(struct dpaa2_mac *mac)
+{
+       mac->features = 0;
+
+       if (dpaa2_mac_cmp_ver(mac, DPMAC_PROTOCOL_CHANGE_VER_MAJOR,
+                             DPMAC_PROTOCOL_CHANGE_VER_MINOR) >= 0)
+               mac->features |= DPAA2_MAC_FEATURE_PROTOCOL_CHANGE;
+}
+
 static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode)
 {
        *if_mode = PHY_INTERFACE_MODE_NA;
@@ -359,6 +381,14 @@ int dpaa2_mac_open(struct dpaa2_mac *mac)
                goto err_close_dpmac;
        }
 
+       err = dpmac_get_api_version(mac->mc_io, 0, &mac->ver_major, &mac->ver_minor);
+       if (err) {
+               netdev_err(net_dev, "dpmac_get_api_version() = %d\n", err);
+               goto err_close_dpmac;
+       }
+
+       dpaa2_mac_detect_features(mac);
+
        /* Find the device node representing the MAC device and link the device
         * behind the associated netdev to it.
         */
index 1331a84..d2e51d2 100644 (file)
@@ -17,6 +17,8 @@ struct dpaa2_mac {
        struct net_device *net_dev;
        struct fsl_mc_io *mc_io;
        struct dpmac_attr attr;
+       u16 ver_major, ver_minor;
+       unsigned long features;
 
        struct phylink_config phylink_config;
        struct phylink *phylink;