]> git.sur5r.net Git - u-boot/blobdiff - drivers/net/mvpp2.c
net: mvpp2: Add MDIO support for PPv2.2
[u-boot] / drivers / net / mvpp2.c
index b56af82f92d7b57624d6056787dcbf1c574bc6bc..8751ee85e38846d3217b17250adda59fffa10be2 100644 (file)
@@ -228,7 +228,21 @@ do {                                                                       \
 
 /* Interrupt Cause and Mask registers */
 #define MVPP2_ISR_RX_THRESHOLD_REG(rxq)                (0x5200 + 4 * (rxq))
-#define MVPP2_ISR_RXQ_GROUP_REG(rxq)           (0x5400 + 4 * (rxq))
+#define MVPP21_ISR_RXQ_GROUP_REG(rxq)          (0x5400 + 4 * (rxq))
+
+#define MVPP22_ISR_RXQ_GROUP_INDEX_REG          0x5400
+#define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf
+#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK   0x380
+#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET 7
+
+#define MVPP22_ISR_RXQ_GROUP_INDEX_SUBGROUP_MASK 0xf
+#define MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_MASK   0x380
+
+#define MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG     0x5404
+#define MVPP22_ISR_RXQ_SUB_GROUP_STARTQ_MASK    0x1f
+#define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_MASK      0xf00
+#define MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET    8
+
 #define MVPP2_ISR_ENABLE_REG(port)             (0x5420 + 4 * (port))
 #define     MVPP2_ISR_ENABLE_INTERRUPT(mask)   ((mask) & 0xffff)
 #define     MVPP2_ISR_DISABLE_INTERRUPT(mask)  (((mask) << 16) & 0xffff0000)
@@ -383,7 +397,9 @@ do {                                                                        \
        (((index) < (q)->last_desc) ? ((index) + 1) : 0)
 
 /* SMI: 0xc0054 -> offset 0x54 to lms_base */
-#define MVPP2_SMI                              0x0054
+#define MVPP21_SMI                             0x0054
+/* PP2.2: SMI: 0x12a200 -> offset 0x1200 to iface_base */
+#define MVPP22_SMI                             0x1200
 #define     MVPP2_PHY_REG_MASK                 0x1f
 /* SMI register fields */
 #define     MVPP2_SMI_DATA_OFFS                        0       /* Data */
@@ -440,9 +456,6 @@ do {                                                                        \
 /* Maximum number of TXQs used by single port */
 #define MVPP2_MAX_TXQ                  8
 
-/* Maximum number of RXQs used by single port */
-#define MVPP2_MAX_RXQ                  8
-
 /* Default number of TXQs in use */
 #define MVPP2_DEFAULT_TXQ              1
 
@@ -450,9 +463,6 @@ do {                                                                        \
 #define MVPP2_DEFAULT_RXQ              1
 #define CONFIG_MV_ETH_RXQ              8       /* increment by 8 */
 
-/* Total number of RXQs available to all ports */
-#define MVPP2_RXQ_TOTAL_NUM            (MVPP2_MAX_PORTS * MVPP2_MAX_RXQ)
-
 /* Max number of Rx descriptors */
 #define MVPP2_MAX_RXD                  16
 
@@ -737,6 +747,7 @@ struct mvpp2 {
        void __iomem *base;
        void __iomem *lms_base;
        void __iomem *iface_base;
+       void __iomem *mdio_base;
 
        /* List of pointers to port structures */
        struct mvpp2_port **port_list;
@@ -758,6 +769,9 @@ struct mvpp2 {
        /* HW version */
        enum { MVPP21, MVPP22 } hw_version;
 
+       /* Maximum number of RXQs per port */
+       unsigned int max_port_rxqs;
+
        struct mii_dev *bus;
 };
 
@@ -3686,7 +3700,8 @@ static int mvpp2_port_init(struct udevice *dev, struct mvpp2_port *port)
        struct mvpp2_txq_pcpu *txq_pcpu;
        int queue, cpu, err;
 
-       if (port->first_rxq + rxq_number > MVPP2_RXQ_TOTAL_NUM)
+       if (port->first_rxq + rxq_number >
+           MVPP2_MAX_PORTS * priv->max_port_rxqs)
                return -EINVAL;
 
        /* Disable port */
@@ -3747,7 +3762,19 @@ static int mvpp2_port_init(struct udevice *dev, struct mvpp2_port *port)
        }
 
        /* Configure Rx queue group interrupt for this port */
-       mvpp2_write(priv, MVPP2_ISR_RXQ_GROUP_REG(port->id), CONFIG_MV_ETH_RXQ);
+       if (priv->hw_version == MVPP21) {
+               mvpp2_write(priv, MVPP21_ISR_RXQ_GROUP_REG(port->id),
+                           CONFIG_MV_ETH_RXQ);
+       } else {
+               u32 val;
+
+               val = (port->id << MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET);
+               mvpp2_write(priv, MVPP22_ISR_RXQ_GROUP_INDEX_REG, val);
+
+               val = (CONFIG_MV_ETH_RXQ <<
+                      MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET);
+               mvpp2_write(priv, MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG, val);
+       }
 
        /* Create Rx descriptor rings */
        for (queue = 0; queue < rxq_number; queue++) {
@@ -3782,8 +3809,7 @@ static int mvpp2_port_init(struct udevice *dev, struct mvpp2_port *port)
 static int mvpp2_port_probe(struct udevice *dev,
                            struct mvpp2_port *port,
                            int port_node,
-                           struct mvpp2 *priv,
-                           int *next_first_rxq)
+                           struct mvpp2 *priv)
 {
        int phy_node;
        u32 id;
@@ -3817,7 +3843,10 @@ static int mvpp2_port_probe(struct udevice *dev,
 
        port->priv = priv;
        port->id = id;
-       port->first_rxq = *next_first_rxq;
+       if (priv->hw_version == MVPP21)
+               port->first_rxq = port->id * rxq_number;
+       else
+               port->first_rxq = port->id * priv->max_port_rxqs;
        port->phy_node = phy_node;
        port->phy_interface = phy_mode;
        port->phyaddr = phyaddr;
@@ -3851,8 +3880,6 @@ static int mvpp2_port_probe(struct udevice *dev,
        }
        mvpp2_port_power_up(port);
 
-       /* Increment the first Rx queue number to be used by the next port */
-       *next_first_rxq += CONFIG_MV_ETH_RXQ;
        priv->port_list[id] = port;
        return 0;
 }
@@ -3969,7 +3996,8 @@ static int mvpp2_init(struct udevice *dev, struct mvpp2 *priv)
        u32 val;
 
        /* Checks for hardware constraints (U-Boot uses only one rxq) */
-       if ((rxq_number > MVPP2_MAX_RXQ) || (txq_number > MVPP2_MAX_TXQ)) {
+       if ((rxq_number > priv->max_port_rxqs) ||
+           (txq_number > MVPP2_MAX_TXQ)) {
                dev_err(&pdev->dev, "invalid queue size parameter\n");
                return -EINVAL;
        }
@@ -4013,9 +4041,23 @@ static int mvpp2_init(struct udevice *dev, struct mvpp2 *priv)
        mvpp2_rx_fifo_init(priv);
 
        /* Reset Rx queue group interrupt configuration */
-       for (i = 0; i < MVPP2_MAX_PORTS; i++)
-               mvpp2_write(priv, MVPP2_ISR_RXQ_GROUP_REG(i),
-                           CONFIG_MV_ETH_RXQ);
+       for (i = 0; i < MVPP2_MAX_PORTS; i++) {
+               if (priv->hw_version == MVPP21) {
+                       mvpp2_write(priv, MVPP21_ISR_RXQ_GROUP_REG(i),
+                                   CONFIG_MV_ETH_RXQ);
+                       continue;
+               } else {
+                       u32 val;
+
+                       val = (i << MVPP22_ISR_RXQ_GROUP_INDEX_GROUP_OFFSET);
+                       mvpp2_write(priv, MVPP22_ISR_RXQ_GROUP_INDEX_REG, val);
+
+                       val = (CONFIG_MV_ETH_RXQ <<
+                              MVPP22_ISR_RXQ_SUB_GROUP_SIZE_OFFSET);
+                       mvpp2_write(priv,
+                                   MVPP22_ISR_RXQ_SUB_GROUP_CONFIG_REG, val);
+               }
+       }
 
        if (priv->hw_version == MVPP21)
                writel(MVPP2_EXT_GLOBAL_CTRL_DEFAULT,
@@ -4050,7 +4092,7 @@ static int smi_wait_ready(struct mvpp2 *priv)
        /* wait till the SMI is not busy */
        do {
                /* read smi register */
-               smi_reg = readl(priv->lms_base + MVPP2_SMI);
+               smi_reg = readl(priv->mdio_base);
                if (timeout-- == 0) {
                        printf("Error: SMI busy timeout\n");
                        return -EFAULT;
@@ -4092,14 +4134,14 @@ static int mpp2_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
                | MVPP2_SMI_OPCODE_READ;
 
        /* write the smi register */
-       writel(smi_reg, priv->lms_base + MVPP2_SMI);
+       writel(smi_reg, priv->mdio_base);
 
        /* wait till read value is ready */
        timeout = MVPP2_SMI_TIMEOUT;
 
        do {
                /* read smi register */
-               smi_reg = readl(priv->lms_base + MVPP2_SMI);
+               smi_reg = readl(priv->mdio_base);
                if (timeout-- == 0) {
                        printf("Err: SMI read ready timeout\n");
                        return -EFAULT;
@@ -4110,7 +4152,7 @@ static int mpp2_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
        for (timeout = 0; timeout < MVPP2_SMI_TIMEOUT; timeout++)
                ;
 
-       return readl(priv->lms_base + MVPP2_SMI) & MVPP2_SMI_DATA_MASK;
+       return readl(priv->mdio_base) & MVPP2_SMI_DATA_MASK;
 }
 
 /*
@@ -4147,7 +4189,7 @@ static int mpp2_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
        smi_reg &= ~MVPP2_SMI_OPCODE_READ;
 
        /* write the smi register */
-       writel(smi_reg, priv->lms_base + MVPP2_SMI);
+       writel(smi_reg, priv->mdio_base);
 
        return 0;
 }
@@ -4348,8 +4390,7 @@ static int mvpp2_probe(struct udevice *dev)
                return err;
        }
 
-       return mvpp2_port_probe(dev, port, dev_of_offset(dev), priv,
-                               &buffer_loc.first_rxq);
+       return mvpp2_port_probe(dev, port, dev_of_offset(dev), priv);
 }
 
 static const struct eth_ops mvpp2_ops = {
@@ -4431,12 +4472,21 @@ static int mvpp2_base_probe(struct udevice *dev)
                priv->lms_base = (void *)dev_get_addr_index(dev, 1);
                if (IS_ERR(priv->lms_base))
                        return PTR_ERR(priv->lms_base);
+
+               priv->mdio_base = priv->lms_base + MVPP21_SMI;
        } else {
                priv->iface_base = (void *)dev_get_addr_index(dev, 1);
                if (IS_ERR(priv->iface_base))
                        return PTR_ERR(priv->iface_base);
+
+               priv->mdio_base = priv->iface_base + MVPP22_SMI;
        }
 
+       if (priv->hw_version == MVPP21)
+               priv->max_port_rxqs = 8;
+       else
+               priv->max_port_rxqs = 32;
+
        /* Finally create and register the MDIO bus driver */
        bus = mdio_alloc();
        if (!bus) {
@@ -4498,6 +4548,10 @@ static const struct udevice_id mvpp2_ids[] = {
                .compatible = "marvell,armada-375-pp2",
                .data = MVPP21,
        },
+       {
+               .compatible = "marvell,armada-7k-pp22",
+               .data = MVPP22,
+       },
        { }
 };