This patch adds network driver for APM X-Gene SoC ethernet.
Signed-off-by: Iyappan Subramanian <isubramanian@xxxxxxx>
Signed-off-by: Ravi Patel <rapatel@xxxxxxx>
+{
+ struct xgene_enet_pdata *pdata = netdev_priv(ndev);
+ struct phy_device *phydev;
+ unsigned char phy_id[MII_BUS_ID_SIZE+3];
+ int ret = 0;
+
+ phydev = phy_find_first(pdata->mdio_bus);
+ if (!phydev) {
+ netdev_info(ndev, "no PHY found\n");
+ ret = -1;
+ goto out;
+ }
+
+ /* attach the mac to the phy */
+ snprintf(phy_id, sizeof(phy_id), PHY_ID_FMT, pdata->mdio_bus->id,
+ pdata->phy_addr);
+ phydev = phy_connect(ndev, phy_id,
+ &xgene_enet_mdio_link_change, pdata->phy_mode);
+ if (IS_ERR(phydev)) {
+ netdev_err(ndev, "Could not attach to PHY\n");
+ ret = PTR_ERR(phydev);
+ phydev = NULL;
+ goto out;
+ }
+
+ netdev_info(ndev, "phy_id=0x%08x phy_drv=\"%s\"",
+ phydev->phy_id, phydev->drv->name);
+out:
+ pdata->phy_link = 0;
+ pdata->phy_speed = 0;
+ pdata->phy_dev = phydev;
+
+ return ret;
+}
+
+struct xgene_enet_desc {
+ u64 m0;
+ u64 m1;
+ u64 m2;
+ u64 m3;
+};
+
+struct xgene_enet_desc16 {
+ u64 m0;
+ u64 m1;
+};
+
+static inline void xgene_enet_cpu_to_le64(struct xgene_enet_desc *desc,
+ int count)
+{
+#ifdef CONFIG_CPU_BIG_ENDIAN
+ int i;
+
+ for (i = 0; i < count; i++)
+ ((u64 *)desc)[i] = cpu_to_le64(((u64 *)desc)[i]);
+#endif
+}
+
+static inline void xgene_enet_le64_to_cpu(struct xgene_enet_desc *desc,
+ int count)
+{
+#ifdef CONFIG_CPU_BIG_ENDIAN
+ int i;
+
+ for (i = 0; i < count; i++)
+ ((u64 *)desc)[i] = le64_to_cpu(((u64 *)desc)[i]);
+#endif
+}
+
+static inline void xgene_enet_desc16_to_le64(struct xgene_enet_desc *desc)
+{
+#ifdef CONFIG_CPU_BIG_ENDIAN
+ ((u64 *)desc)[1] = cpu_to_le64(((u64 *)desc)[1]);
+#endif
+}
+
+static inline void xgene_enet_le64_to_desc16(struct xgene_enet_desc *desc)
+{
+#ifdef CONFIG_CPU_BIG_ENDIAN
+ ((u64 *)desc)[1] = le64_to_cpu(((u64 *)desc)[1]);
+#endif
+}