generic: ar8216: add vtu_load_vlan field to ar8xxx_chip
[openwrt.git] / target / linux / generic / files / drivers / net / phy / ar8216.c
index 038a086..d514ec7 100644 (file)
 #define AR8X16_MAX_VLANS       128
 #define AR8X16_PROBE_RETRIES   10
 
+struct ar8216_priv;
+
 struct ar8xxx_chip {
+       int (*hw_init)(struct ar8216_priv *priv);
+       void (*init_port)(struct ar8216_priv *priv, int port);
+       void (*setup_port)(struct ar8216_priv *priv, int port, u32 egress,
+                          u32 ingress, u32 members, u32 pvid);
+       int (*atu_flush)(struct ar8216_priv *priv);
+       void (*vtu_flush)(struct ar8216_priv *priv);
+       void (*vtu_load_vlan)(struct ar8216_priv *priv, u32 vid, u32 port_mask);
 };
 
 struct ar8216_priv {
@@ -476,6 +485,33 @@ ar8216_vtu_op(struct ar8216_priv *priv, u32 op, u32 val)
 }
 
 static void
+ar8216_vtu_flush(struct ar8216_priv *priv)
+{
+       ar8216_vtu_op(priv, AR8216_VTU_OP_FLUSH, 0);
+}
+
+static void
+ar8216_vtu_load_vlan(struct ar8216_priv *priv, u32 vid, u32 port_mask)
+{
+       u32 op;
+
+       op = AR8216_VTU_OP_LOAD | (vid << AR8216_VTU_VID_S);
+       ar8216_vtu_op(priv, op, port_mask);
+}
+
+static int
+ar8216_atu_flush(struct ar8216_priv *priv)
+{
+       int ret;
+
+       ret = ar8216_wait_bit(priv, AR8216_REG_ATU, AR8216_ATU_ACTIVE, 0);
+       if (!ret)
+               priv->write(priv, AR8216_REG_ATU, AR8216_ATU_OP_FLUSH);
+
+       return ret;
+}
+
+static void
 ar8216_setup_port(struct ar8216_priv *priv, int port, u32 egress, u32 ingress,
                  u32 members, u32 pvid)
 {
@@ -534,7 +570,7 @@ ar8216_hw_apply(struct switch_dev *dev)
 
        mutex_lock(&priv->reg_mutex);
        /* flush all vlan translation unit entries */
-       ar8216_vtu_op(priv, AR8216_VTU_OP_FLUSH, 0);
+       priv->chip->vtu_flush(priv);
 
        memset(portmask, 0, sizeof(portmask));
        if (!priv->init) {
@@ -552,10 +588,8 @@ ar8216_hw_apply(struct switch_dev *dev)
                                        portmask[i] |= vp & ~mask;
                        }
 
-                       ar8216_vtu_op(priv,
-                               AR8216_VTU_OP_LOAD |
-                               (priv->vlan_id[j] << AR8216_VTU_VID_S),
-                               priv->vlan_table[j]);
+                       priv->chip->vtu_load_vlan(priv, priv->vlan_id[j],
+                                                priv->vlan_table[j]);
                }
        } else {
                /* vlan disabled:
@@ -587,12 +621,8 @@ ar8216_hw_apply(struct switch_dev *dev)
                        ingress = AR8216_IN_PORT_ONLY;
                }
 
-               if (priv->chip_type == AR8236)
-                       ar8236_setup_port(priv, i, egress, ingress, portmask[i],
-                                         pvid);
-               else
-                       ar8216_setup_port(priv, i, egress, ingress, portmask[i],
-                                         pvid);
+               priv->chip->setup_port(priv, i, egress, ingress, portmask[i],
+                                      pvid);
        }
        mutex_unlock(&priv->reg_mutex);
        return 0;
@@ -741,12 +771,30 @@ ar8216_init_port(struct ar8216_priv *priv, int port)
 }
 
 static const struct ar8xxx_chip ar8216_chip = {
+       .hw_init = ar8216_hw_init,
+       .init_port = ar8216_init_port,
+       .setup_port = ar8216_setup_port,
+       .atu_flush = ar8216_atu_flush,
+       .vtu_flush = ar8216_vtu_flush,
+       .vtu_load_vlan = ar8216_vtu_load_vlan,
 };
 
 static const struct ar8xxx_chip ar8236_chip = {
+       .hw_init = ar8236_hw_init,
+       .init_port = ar8216_init_port,
+       .setup_port = ar8236_setup_port,
+       .atu_flush = ar8216_atu_flush,
+       .vtu_flush = ar8216_vtu_flush,
+       .vtu_load_vlan = ar8216_vtu_load_vlan,
 };
 
 static const struct ar8xxx_chip ar8316_chip = {
+       .hw_init = ar8316_hw_init,
+       .init_port = ar8216_init_port,
+       .setup_port = ar8216_setup_port,
+       .atu_flush = ar8216_atu_flush,
+       .vtu_flush = ar8216_vtu_flush,
+       .vtu_load_vlan = ar8216_vtu_load_vlan,
 };
 
 static int
@@ -764,7 +812,7 @@ ar8216_reset_switch(struct switch_dev *dev)
 
        /* Configure all ports */
        for (i = 0; i < AR8216_NUM_PORTS; i++)
-               ar8216_init_port(priv, i);
+               priv->chip->init_port(priv, i);
 
        ar8216_init_globals(priv);
        mutex_unlock(&priv->reg_mutex);
@@ -943,14 +991,7 @@ ar8216_config_init(struct phy_device *pdev)
 
        priv->init = true;
 
-       ret = 0;
-       if (priv->chip_type == AR8216)
-               ret = ar8216_hw_init(priv);
-       else if (priv->chip_type == AR8236)
-               ret = ar8236_hw_init(priv);
-       else if (priv->chip_type == AR8316)
-               ret = ar8316_hw_init(priv);
-
+       ret = priv->chip->hw_init(priv);
        if (ret)
                goto err_free_priv;
 
@@ -1012,9 +1053,7 @@ ar8216_read_status(struct phy_device *phydev)
 
        /* flush the address translation unit */
        mutex_lock(&priv->reg_mutex);
-       ret = ar8216_wait_bit(priv, AR8216_REG_ATU, AR8216_ATU_ACTIVE, 0);
-       if (!ret)
-               priv->write(priv, AR8216_REG_ATU, AR8216_ATU_OP_FLUSH);
+       ret = priv->chip->atu_flush(priv);
        mutex_unlock(&priv->reg_mutex);
 
        phydev->state = PHY_RUNNING;