Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Marvell Semiconductor <www.marvell.com> |
| 5 | * Written-by: Prafulla Wadaskar <prafulla@marvell.com> |
| 6 | * |
| 7 | * (C) Copyright 2003 |
| 8 | * Ingo Assmus <ingo.assmus@keymile.com> |
| 9 | * |
| 10 | * based on - Driver for MV64360X ethernet ports |
| 11 | * Copyright (C) 2002 rabeeh@galileo.co.il |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <net.h> |
| 16 | #include <malloc.h> |
| 17 | #include <miiphy.h> |
Chris Packham | 5194ed7 | 2018-06-09 20:46:16 +1200 | [diff] [blame] | 18 | #include <wait_bit.h> |
Lei Wen | a7efd71 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 19 | #include <asm/io.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 20 | #include <linux/errno.h> |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 21 | #include <asm/types.h> |
Lei Wen | a7efd71 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 22 | #include <asm/system.h> |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 23 | #include <asm/byteorder.h> |
Anatolij Gustschin | 36aaa91 | 2011-10-29 10:09:22 +0000 | [diff] [blame] | 24 | #include <asm/arch/cpu.h> |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 25 | |
| 26 | #if defined(CONFIG_KIRKWOOD) |
Stefan Roese | 3dc23f7 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 27 | #include <asm/arch/soc.h> |
Albert Aribaud | d3c9ffd | 2010-07-12 22:24:29 +0200 | [diff] [blame] | 28 | #elif defined(CONFIG_ORION5X) |
| 29 | #include <asm/arch/orion5x.h> |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 30 | #endif |
| 31 | |
Albert Aribaud | 9b6bcdc | 2010-07-12 22:24:27 +0200 | [diff] [blame] | 32 | #include "mvgbe.h" |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 33 | |
Albert Aribaud | 49fa6ed | 2010-07-05 20:15:25 +0200 | [diff] [blame] | 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
Luka Perkov | 5aa2297 | 2013-11-11 07:27:53 +0100 | [diff] [blame] | 36 | #ifndef CONFIG_MVGBE_PORTS |
| 37 | # define CONFIG_MVGBE_PORTS {0, 0} |
| 38 | #endif |
| 39 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 40 | #define MV_PHY_ADR_REQUEST 0xee |
| 41 | #define MVGBE_SMI_REG (((struct mvgbe_registers *)MVGBE0_BASE)->smi) |
Simon Kagstrom | bb1ca3b | 2009-08-20 10:12:28 +0200 | [diff] [blame] | 42 | |
Sebastian Hesselbarth | cd3ca3f | 2012-12-04 09:32:00 +0100 | [diff] [blame] | 43 | #if defined(CONFIG_PHYLIB) || defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Chris Packham | 5194ed7 | 2018-06-09 20:46:16 +1200 | [diff] [blame] | 44 | static int smi_wait_ready(struct mvgbe_device *dmvgbe) |
| 45 | { |
| 46 | int ret; |
| 47 | |
| 48 | ret = wait_for_bit_le32(&MVGBE_SMI_REG, MVGBE_PHY_SMI_BUSY_MASK, false, |
| 49 | MVGBE_PHY_SMI_TIMEOUT_MS, false); |
| 50 | if (ret) { |
| 51 | printf("Error: SMI busy timeout\n"); |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 58 | static int __mvgbe_mdio_read(struct mvgbe_device *dmvgbe, int phy_adr, |
| 59 | int devad, int reg_ofs) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 60 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 61 | struct mvgbe_registers *regs = dmvgbe->regs; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 62 | u32 smi_reg; |
Simon Kagstrom | 7b05f5e | 2009-07-08 13:03:18 +0200 | [diff] [blame] | 63 | u32 timeout; |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 64 | u16 data = 0; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 65 | |
| 66 | /* Phyadr read request */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 67 | if (phy_adr == MV_PHY_ADR_REQUEST && |
| 68 | reg_ofs == MV_PHY_ADR_REQUEST) { |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 69 | /* */ |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 70 | data = (u16) (MVGBE_REG_RD(regs->phyadr) & PHYADR_MASK); |
| 71 | return data; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 72 | } |
| 73 | /* check parameters */ |
| 74 | if (phy_adr > PHYADR_MASK) { |
| 75 | printf("Err..(%s) Invalid PHY address %d\n", |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 76 | __func__, phy_adr); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 77 | return -EFAULT; |
| 78 | } |
| 79 | if (reg_ofs > PHYREG_MASK) { |
| 80 | printf("Err..(%s) Invalid register offset %d\n", |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 81 | __func__, reg_ofs); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 82 | return -EFAULT; |
| 83 | } |
| 84 | |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 85 | /* wait till the SMI is not busy */ |
Chris Packham | 5194ed7 | 2018-06-09 20:46:16 +1200 | [diff] [blame] | 86 | if (smi_wait_ready(dmvgbe) < 0) |
| 87 | return -EFAULT; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 88 | |
| 89 | /* fill the phy address and regiser offset and read opcode */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 90 | smi_reg = (phy_adr << MVGBE_PHY_SMI_DEV_ADDR_OFFS) |
| 91 | | (reg_ofs << MVGBE_SMI_REG_ADDR_OFFS) |
| 92 | | MVGBE_PHY_SMI_OPCODE_READ; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 93 | |
| 94 | /* write the smi register */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 95 | MVGBE_REG_WR(MVGBE_SMI_REG, smi_reg); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 96 | |
| 97 | /*wait till read value is ready */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 98 | timeout = MVGBE_PHY_SMI_TIMEOUT; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 99 | |
| 100 | do { |
| 101 | /* read smi register */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 102 | smi_reg = MVGBE_REG_RD(MVGBE_SMI_REG); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 103 | if (timeout-- == 0) { |
| 104 | printf("Err..(%s) SMI read ready timeout\n", |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 105 | __func__); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 106 | return -EFAULT; |
| 107 | } |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 108 | } while (!(smi_reg & MVGBE_PHY_SMI_READ_VALID_MASK)); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 109 | |
| 110 | /* Wait for the data to update in the SMI register */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 111 | for (timeout = 0; timeout < MVGBE_PHY_SMI_TIMEOUT; timeout++) |
| 112 | ; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 113 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 114 | data = (u16) (MVGBE_REG_RD(MVGBE_SMI_REG) & MVGBE_PHY_SMI_DATA_MASK); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 115 | |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 116 | debug("%s:(adr %d, off %d) value= %04x\n", __func__, phy_adr, reg_ofs, |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 117 | data); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 118 | |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 119 | return data; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 123 | * smi_reg_read - miiphy_read callback function. |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 124 | * |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 125 | * Returns 16bit phy register value, or -EFAULT on error |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 126 | */ |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 127 | static int smi_reg_read(struct mii_dev *bus, int phy_adr, int devad, |
| 128 | int reg_ofs) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 129 | { |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 130 | struct eth_device *dev = eth_get_dev_by_name(bus->name); |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 131 | struct mvgbe_device *dmvgbe = to_mvgbe(dev); |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 132 | |
| 133 | return __mvgbe_mdio_read(dmvgbe, phy_adr, devad, reg_ofs); |
| 134 | } |
| 135 | |
| 136 | static int __mvgbe_mdio_write(struct mvgbe_device *dmvgbe, int phy_adr, |
| 137 | int devad, int reg_ofs, u16 data) |
| 138 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 139 | struct mvgbe_registers *regs = dmvgbe->regs; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 140 | u32 smi_reg; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 141 | |
| 142 | /* Phyadr write request*/ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 143 | if (phy_adr == MV_PHY_ADR_REQUEST && |
| 144 | reg_ofs == MV_PHY_ADR_REQUEST) { |
| 145 | MVGBE_REG_WR(regs->phyadr, data); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | /* check parameters */ |
| 150 | if (phy_adr > PHYADR_MASK) { |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 151 | printf("Err..(%s) Invalid phy address\n", __func__); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 152 | return -EINVAL; |
| 153 | } |
| 154 | if (reg_ofs > PHYREG_MASK) { |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 155 | printf("Err..(%s) Invalid register offset\n", __func__); |
Chris Packham | 5194ed7 | 2018-06-09 20:46:16 +1200 | [diff] [blame] | 156 | return -EFAULT; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /* wait till the SMI is not busy */ |
Chris Packham | 5194ed7 | 2018-06-09 20:46:16 +1200 | [diff] [blame] | 160 | if (smi_wait_ready(dmvgbe) < 0) |
| 161 | return -EFAULT; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 162 | |
| 163 | /* fill the phy addr and reg offset and write opcode and data */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 164 | smi_reg = (data << MVGBE_PHY_SMI_DATA_OFFS); |
| 165 | smi_reg |= (phy_adr << MVGBE_PHY_SMI_DEV_ADDR_OFFS) |
| 166 | | (reg_ofs << MVGBE_SMI_REG_ADDR_OFFS); |
| 167 | smi_reg &= ~MVGBE_PHY_SMI_OPCODE_READ; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 168 | |
| 169 | /* write the smi register */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 170 | MVGBE_REG_WR(MVGBE_SMI_REG, smi_reg); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 171 | |
| 172 | return 0; |
| 173 | } |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 174 | |
| 175 | /* |
| 176 | * smi_reg_write - miiphy_write callback function. |
| 177 | * |
| 178 | * Returns 0 if write succeed, -EFAULT on error |
| 179 | */ |
| 180 | static int smi_reg_write(struct mii_dev *bus, int phy_adr, int devad, |
| 181 | int reg_ofs, u16 data) |
| 182 | { |
| 183 | struct eth_device *dev = eth_get_dev_by_name(bus->name); |
| 184 | struct mvgbe_device *dmvgbe = to_mvgbe(dev); |
| 185 | |
| 186 | return __mvgbe_mdio_write(dmvgbe, phy_adr, devad, reg_ofs, data); |
| 187 | } |
Stefan Bigler | cc79697 | 2012-03-26 00:02:13 +0000 | [diff] [blame] | 188 | #endif |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 189 | |
| 190 | /* Stop and checks all queues */ |
| 191 | static void stop_queue(u32 * qreg) |
| 192 | { |
| 193 | u32 reg_data; |
| 194 | |
| 195 | reg_data = readl(qreg); |
| 196 | |
| 197 | if (reg_data & 0xFF) { |
| 198 | /* Issue stop command for active channels only */ |
| 199 | writel((reg_data << 8), qreg); |
| 200 | |
| 201 | /* Wait for all queue activity to terminate. */ |
| 202 | do { |
| 203 | /* |
| 204 | * Check port cause register that all queues |
| 205 | * are stopped |
| 206 | */ |
| 207 | reg_data = readl(qreg); |
| 208 | } |
| 209 | while (reg_data & 0xFF); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * set_access_control - Config address decode parameters for Ethernet unit |
| 215 | * |
| 216 | * This function configures the address decode parameters for the Gigabit |
| 217 | * Ethernet Controller according the given parameters struct. |
| 218 | * |
| 219 | * @regs Register struct pointer. |
| 220 | * @param Address decode parameter struct. |
| 221 | */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 222 | static void set_access_control(struct mvgbe_registers *regs, |
| 223 | struct mvgbe_winparam *param) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 224 | { |
| 225 | u32 access_prot_reg; |
| 226 | |
| 227 | /* Set access control register */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 228 | access_prot_reg = MVGBE_REG_RD(regs->epap); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 229 | /* clear window permission */ |
| 230 | access_prot_reg &= (~(3 << (param->win * 2))); |
| 231 | access_prot_reg |= (param->access_ctrl << (param->win * 2)); |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 232 | MVGBE_REG_WR(regs->epap, access_prot_reg); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 233 | |
| 234 | /* Set window Size reg (SR) */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 235 | MVGBE_REG_WR(regs->barsz[param->win].size, |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 236 | (((param->size / 0x10000) - 1) << 16)); |
| 237 | |
| 238 | /* Set window Base address reg (BA) */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 239 | MVGBE_REG_WR(regs->barsz[param->win].bar, |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 240 | (param->target | param->attrib | param->base_addr)); |
| 241 | /* High address remap reg (HARR) */ |
| 242 | if (param->win < 4) |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 243 | MVGBE_REG_WR(regs->ha_remap[param->win], param->high_addr); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 244 | |
| 245 | /* Base address enable reg (BARER) */ |
| 246 | if (param->enable == 1) |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 247 | MVGBE_REG_BITS_RESET(regs->bare, (1 << param->win)); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 248 | else |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 249 | MVGBE_REG_BITS_SET(regs->bare, (1 << param->win)); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 250 | } |
| 251 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 252 | static void set_dram_access(struct mvgbe_registers *regs) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 253 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 254 | struct mvgbe_winparam win_param; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 255 | int i; |
| 256 | |
| 257 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 258 | /* Set access parameters for DRAM bank i */ |
| 259 | win_param.win = i; /* Use Ethernet window i */ |
| 260 | /* Window target - DDR */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 261 | win_param.target = MVGBE_TARGET_DRAM; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 262 | /* Enable full access */ |
| 263 | win_param.access_ctrl = EWIN_ACCESS_FULL; |
| 264 | win_param.high_addr = 0; |
Albert Aribaud | 49fa6ed | 2010-07-05 20:15:25 +0200 | [diff] [blame] | 265 | /* Get bank base and size */ |
| 266 | win_param.base_addr = gd->bd->bi_dram[i].start; |
| 267 | win_param.size = gd->bd->bi_dram[i].size; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 268 | if (win_param.size == 0) |
| 269 | win_param.enable = 0; |
| 270 | else |
| 271 | win_param.enable = 1; /* Enable the access */ |
| 272 | |
| 273 | /* Enable DRAM bank */ |
| 274 | switch (i) { |
| 275 | case 0: |
| 276 | win_param.attrib = EBAR_DRAM_CS0; |
| 277 | break; |
| 278 | case 1: |
| 279 | win_param.attrib = EBAR_DRAM_CS1; |
| 280 | break; |
| 281 | case 2: |
| 282 | win_param.attrib = EBAR_DRAM_CS2; |
| 283 | break; |
| 284 | case 3: |
| 285 | win_param.attrib = EBAR_DRAM_CS3; |
| 286 | break; |
| 287 | default: |
Albert Aribaud | 49fa6ed | 2010-07-05 20:15:25 +0200 | [diff] [blame] | 288 | /* invalid bank, disable access */ |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 289 | win_param.enable = 0; |
| 290 | win_param.attrib = 0; |
| 291 | break; |
| 292 | } |
| 293 | /* Set the access control for address window(EPAPR) RD/WR */ |
| 294 | set_access_control(regs, &win_param); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables |
| 300 | * |
| 301 | * Go through all the DA filter tables (Unicast, Special Multicast & Other |
| 302 | * Multicast) and set each entry to 0. |
| 303 | */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 304 | static void port_init_mac_tables(struct mvgbe_registers *regs) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 305 | { |
| 306 | int table_index; |
| 307 | |
| 308 | /* Clear DA filter unicast table (Ex_dFUT) */ |
| 309 | for (table_index = 0; table_index < 4; ++table_index) |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 310 | MVGBE_REG_WR(regs->dfut[table_index], 0); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 311 | |
| 312 | for (table_index = 0; table_index < 64; ++table_index) { |
| 313 | /* Clear DA filter special multicast table (Ex_dFSMT) */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 314 | MVGBE_REG_WR(regs->dfsmt[table_index], 0); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 315 | /* Clear DA filter other multicast table (Ex_dFOMT) */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 316 | MVGBE_REG_WR(regs->dfomt[table_index], 0); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * port_uc_addr - This function Set the port unicast address table |
| 322 | * |
| 323 | * This function locates the proper entry in the Unicast table for the |
| 324 | * specified MAC nibble and sets its properties according to function |
| 325 | * parameters. |
| 326 | * This function add/removes MAC addresses from the port unicast address |
| 327 | * table. |
| 328 | * |
| 329 | * @uc_nibble Unicast MAC Address last nibble. |
| 330 | * @option 0 = Add, 1 = remove address. |
| 331 | * |
| 332 | * RETURN: 1 if output succeeded. 0 if option parameter is invalid. |
| 333 | */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 334 | static int port_uc_addr(struct mvgbe_registers *regs, u8 uc_nibble, |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 335 | int option) |
| 336 | { |
| 337 | u32 unicast_reg; |
| 338 | u32 tbl_offset; |
| 339 | u32 reg_offset; |
| 340 | |
| 341 | /* Locate the Unicast table entry */ |
| 342 | uc_nibble = (0xf & uc_nibble); |
| 343 | /* Register offset from unicast table base */ |
| 344 | tbl_offset = (uc_nibble / 4); |
| 345 | /* Entry offset within the above register */ |
| 346 | reg_offset = uc_nibble % 4; |
| 347 | |
| 348 | switch (option) { |
| 349 | case REJECT_MAC_ADDR: |
| 350 | /* |
| 351 | * Clear accepts frame bit at specified unicast |
| 352 | * DA table entry |
| 353 | */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 354 | unicast_reg = MVGBE_REG_RD(regs->dfut[tbl_offset]); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 355 | unicast_reg &= (0xFF << (8 * reg_offset)); |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 356 | MVGBE_REG_WR(regs->dfut[tbl_offset], unicast_reg); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 357 | break; |
| 358 | case ACCEPT_MAC_ADDR: |
| 359 | /* Set accepts frame bit at unicast DA filter table entry */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 360 | unicast_reg = MVGBE_REG_RD(regs->dfut[tbl_offset]); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 361 | unicast_reg &= (0xFF << (8 * reg_offset)); |
| 362 | unicast_reg |= ((0x01 | (RXUQ << 1)) << (8 * reg_offset)); |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 363 | MVGBE_REG_WR(regs->dfut[tbl_offset], unicast_reg); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 364 | break; |
| 365 | default: |
| 366 | return 0; |
| 367 | } |
| 368 | return 1; |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | * port_uc_addr_set - This function Set the port Unicast address. |
| 373 | */ |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 374 | static void port_uc_addr_set(struct mvgbe_device *dmvgbe, u8 *p_addr) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 375 | { |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 376 | struct mvgbe_registers *regs = dmvgbe->regs; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 377 | u32 mac_h; |
| 378 | u32 mac_l; |
| 379 | |
| 380 | mac_l = (p_addr[4] << 8) | (p_addr[5]); |
| 381 | mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) | |
| 382 | (p_addr[3] << 0); |
| 383 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 384 | MVGBE_REG_WR(regs->macal, mac_l); |
| 385 | MVGBE_REG_WR(regs->macah, mac_h); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 386 | |
| 387 | /* Accept frames of this address */ |
| 388 | port_uc_addr(regs, p_addr[5], ACCEPT_MAC_ADDR); |
| 389 | } |
| 390 | |
| 391 | /* |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 392 | * mvgbe_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory. |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 393 | */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 394 | static void mvgbe_init_rx_desc_ring(struct mvgbe_device *dmvgbe) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 395 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 396 | struct mvgbe_rxdesc *p_rx_desc; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 397 | int i; |
| 398 | |
| 399 | /* initialize the Rx descriptors ring */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 400 | p_rx_desc = dmvgbe->p_rxdesc; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 401 | for (i = 0; i < RINGSZ; i++) { |
| 402 | p_rx_desc->cmd_sts = |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 403 | MVGBE_BUFFER_OWNED_BY_DMA | MVGBE_RX_EN_INTERRUPT; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 404 | p_rx_desc->buf_size = PKTSIZE_ALIGN; |
| 405 | p_rx_desc->byte_cnt = 0; |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 406 | p_rx_desc->buf_ptr = dmvgbe->p_rxbuf + i * PKTSIZE_ALIGN; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 407 | if (i == (RINGSZ - 1)) |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 408 | p_rx_desc->nxtdesc_p = dmvgbe->p_rxdesc; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 409 | else { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 410 | p_rx_desc->nxtdesc_p = (struct mvgbe_rxdesc *) |
| 411 | ((u32) p_rx_desc + MV_RXQ_DESC_ALIGNED_SIZE); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 412 | p_rx_desc = p_rx_desc->nxtdesc_p; |
| 413 | } |
| 414 | } |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 415 | dmvgbe->p_rxdesc_curr = dmvgbe->p_rxdesc; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 416 | } |
| 417 | |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 418 | static int __mvgbe_init(struct mvgbe_device *dmvgbe) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 419 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 420 | struct mvgbe_registers *regs = dmvgbe->regs; |
Sascha Silbe | 0611c60 | 2013-08-11 17:08:23 +0200 | [diff] [blame] | 421 | #if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) && \ |
| 422 | !defined(CONFIG_PHYLIB) && \ |
| 423 | defined(CONFIG_SYS_FAULT_ECHO_LINK_DOWN) |
Simon Kagstrom | cad713b | 2009-08-20 10:13:06 +0200 | [diff] [blame] | 424 | int i; |
Prafulla Wadaskar | aba8237 | 2009-09-09 15:59:19 +0530 | [diff] [blame] | 425 | #endif |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 426 | /* setup RX rings */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 427 | mvgbe_init_rx_desc_ring(dmvgbe); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 428 | |
| 429 | /* Clear the ethernet port interrupts */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 430 | MVGBE_REG_WR(regs->ic, 0); |
| 431 | MVGBE_REG_WR(regs->ice, 0); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 432 | /* Unmask RX buffer and TX end interrupt */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 433 | MVGBE_REG_WR(regs->pim, INT_CAUSE_UNMASK_ALL); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 434 | /* Unmask phy and link status changes interrupts */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 435 | MVGBE_REG_WR(regs->peim, INT_CAUSE_UNMASK_ALL_EXT); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 436 | |
| 437 | set_dram_access(regs); |
| 438 | port_init_mac_tables(regs); |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 439 | port_uc_addr_set(dmvgbe, dmvgbe->dev.enetaddr); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 440 | |
| 441 | /* Assign port configuration and command. */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 442 | MVGBE_REG_WR(regs->pxc, PRT_CFG_VAL); |
| 443 | MVGBE_REG_WR(regs->pxcx, PORT_CFG_EXTEND_VALUE); |
| 444 | MVGBE_REG_WR(regs->psc0, PORT_SERIAL_CONTROL_VALUE); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 445 | |
| 446 | /* Assign port SDMA configuration */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 447 | MVGBE_REG_WR(regs->sdc, PORT_SDMA_CFG_VALUE); |
| 448 | MVGBE_REG_WR(regs->tqx[0].qxttbc, QTKNBKT_DEF_VAL); |
| 449 | MVGBE_REG_WR(regs->tqx[0].tqxtbc, |
| 450 | (QMTBS_DEF_VAL << 16) | QTKNRT_DEF_VAL); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 451 | /* Turn off the port/RXUQ bandwidth limitation */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 452 | MVGBE_REG_WR(regs->pmtu, 0); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 453 | |
| 454 | /* Set maximum receive buffer to 9700 bytes */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 455 | MVGBE_REG_WR(regs->psc0, MVGBE_MAX_RX_PACKET_9700BYTE |
| 456 | | (MVGBE_REG_RD(regs->psc0) & MRU_MASK)); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 457 | |
Prafulla Wadaskar | f0588fd | 2010-04-06 21:33:08 +0530 | [diff] [blame] | 458 | /* Enable port initially */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 459 | MVGBE_REG_BITS_SET(regs->psc0, MVGBE_SERIAL_PORT_EN); |
Prafulla Wadaskar | f0588fd | 2010-04-06 21:33:08 +0530 | [diff] [blame] | 460 | |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 461 | /* |
| 462 | * Set ethernet MTU for leaky bucket mechanism to 0 - this will |
| 463 | * disable the leaky bucket mechanism . |
| 464 | */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 465 | MVGBE_REG_WR(regs->pmtu, 0); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 466 | |
| 467 | /* Assignment of Rx CRDB of given RXUQ */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 468 | MVGBE_REG_WR(regs->rxcdp[RXUQ], (u32) dmvgbe->p_rxdesc_curr); |
Albert Aribaud | c19a20d | 2010-07-10 15:41:29 +0200 | [diff] [blame] | 469 | /* ensure previous write is done before enabling Rx DMA */ |
| 470 | isb(); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 471 | /* Enable port Rx. */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 472 | MVGBE_REG_WR(regs->rqc, (1 << RXUQ)); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 473 | |
Sebastian Hesselbarth | cd3ca3f | 2012-12-04 09:32:00 +0100 | [diff] [blame] | 474 | #if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) && \ |
| 475 | !defined(CONFIG_PHYLIB) && \ |
| 476 | defined(CONFIG_SYS_FAULT_ECHO_LINK_DOWN) |
Simon Kagstrom | cad713b | 2009-08-20 10:13:06 +0200 | [diff] [blame] | 477 | /* Wait up to 5s for the link status */ |
| 478 | for (i = 0; i < 5; i++) { |
| 479 | u16 phyadr; |
| 480 | |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 481 | miiphy_read(dmvgbe->dev.name, MV_PHY_ADR_REQUEST, |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 482 | MV_PHY_ADR_REQUEST, &phyadr); |
Simon Kagstrom | cad713b | 2009-08-20 10:13:06 +0200 | [diff] [blame] | 483 | /* Return if we get link up */ |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 484 | if (miiphy_link(dmvgbe->dev.name, phyadr)) |
Simon Kagstrom | cad713b | 2009-08-20 10:13:06 +0200 | [diff] [blame] | 485 | return 0; |
| 486 | udelay(1000000); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 487 | } |
Simon Kagstrom | cad713b | 2009-08-20 10:13:06 +0200 | [diff] [blame] | 488 | |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 489 | printf("No link on %s\n", dmvgbe->dev.name); |
Simon Kagstrom | cad713b | 2009-08-20 10:13:06 +0200 | [diff] [blame] | 490 | return -1; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 491 | #endif |
| 492 | return 0; |
| 493 | } |
| 494 | |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 495 | static int mvgbe_init(struct eth_device *dev) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 496 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 497 | struct mvgbe_device *dmvgbe = to_mvgbe(dev); |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 498 | |
| 499 | return __mvgbe_init(dmvgbe); |
| 500 | } |
| 501 | |
| 502 | static void __mvgbe_halt(struct mvgbe_device *dmvgbe) |
| 503 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 504 | struct mvgbe_registers *regs = dmvgbe->regs; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 505 | |
| 506 | /* Disable all gigE address decoder */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 507 | MVGBE_REG_WR(regs->bare, 0x3f); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 508 | |
| 509 | stop_queue(®s->tqc); |
| 510 | stop_queue(®s->rqc); |
| 511 | |
Prafulla Wadaskar | f0588fd | 2010-04-06 21:33:08 +0530 | [diff] [blame] | 512 | /* Disable port */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 513 | MVGBE_REG_BITS_RESET(regs->psc0, MVGBE_SERIAL_PORT_EN); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 514 | /* Set port is not reset */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 515 | MVGBE_REG_BITS_RESET(regs->psc1, 1 << 4); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 516 | #ifdef CONFIG_SYS_MII_MODE |
| 517 | /* Set MMI interface up */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 518 | MVGBE_REG_BITS_RESET(regs->psc1, 1 << 3); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 519 | #endif |
| 520 | /* Disable & mask ethernet port interrupts */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 521 | MVGBE_REG_WR(regs->ic, 0); |
| 522 | MVGBE_REG_WR(regs->ice, 0); |
| 523 | MVGBE_REG_WR(regs->pim, 0); |
| 524 | MVGBE_REG_WR(regs->peim, 0); |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 525 | } |
| 526 | |
| 527 | static int mvgbe_halt(struct eth_device *dev) |
| 528 | { |
| 529 | struct mvgbe_device *dmvgbe = to_mvgbe(dev); |
| 530 | |
| 531 | __mvgbe_halt(dmvgbe); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 536 | static int mvgbe_write_hwaddr(struct eth_device *dev) |
Prafulla Wadaskar | b5ce63e | 2010-04-06 22:21:33 +0530 | [diff] [blame] | 537 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 538 | struct mvgbe_device *dmvgbe = to_mvgbe(dev); |
Prafulla Wadaskar | b5ce63e | 2010-04-06 22:21:33 +0530 | [diff] [blame] | 539 | |
| 540 | /* Programs net device MAC address after initialization */ |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 541 | port_uc_addr_set(dmvgbe, dmvgbe->dev.enetaddr); |
Prafulla Wadaskar | b5ce63e | 2010-04-06 22:21:33 +0530 | [diff] [blame] | 542 | return 0; |
| 543 | } |
| 544 | |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 545 | static int __mvgbe_send(struct mvgbe_device *dmvgbe, void *dataptr, |
| 546 | int datasize) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 547 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 548 | struct mvgbe_registers *regs = dmvgbe->regs; |
| 549 | struct mvgbe_txdesc *p_txdesc = dmvgbe->p_txdesc; |
Simon Kagstrom | 477fa63 | 2009-08-20 10:14:11 +0200 | [diff] [blame] | 550 | void *p = (void *)dataptr; |
Simon Kagstrom | 7b05f5e | 2009-07-08 13:03:18 +0200 | [diff] [blame] | 551 | u32 cmd_sts; |
Anatolij Gustschin | e6e556c | 2011-11-19 08:59:36 +0000 | [diff] [blame] | 552 | u32 txuq0_reg_addr; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 553 | |
Simon Kagstrom | 477fa63 | 2009-08-20 10:14:11 +0200 | [diff] [blame] | 554 | /* Copy buffer if it's misaligned */ |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 555 | if ((u32) dataptr & 0x07) { |
Simon Kagstrom | 477fa63 | 2009-08-20 10:14:11 +0200 | [diff] [blame] | 556 | if (datasize > PKTSIZE_ALIGN) { |
| 557 | printf("Non-aligned data too large (%d)\n", |
| 558 | datasize); |
| 559 | return -1; |
| 560 | } |
| 561 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 562 | memcpy(dmvgbe->p_aligned_txbuf, p, datasize); |
| 563 | p = dmvgbe->p_aligned_txbuf; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 564 | } |
Simon Kagstrom | 477fa63 | 2009-08-20 10:14:11 +0200 | [diff] [blame] | 565 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 566 | p_txdesc->cmd_sts = MVGBE_ZERO_PADDING | MVGBE_GEN_CRC; |
| 567 | p_txdesc->cmd_sts |= MVGBE_TX_FIRST_DESC | MVGBE_TX_LAST_DESC; |
| 568 | p_txdesc->cmd_sts |= MVGBE_BUFFER_OWNED_BY_DMA; |
| 569 | p_txdesc->cmd_sts |= MVGBE_TX_EN_INTERRUPT; |
Simon Kagstrom | 477fa63 | 2009-08-20 10:14:11 +0200 | [diff] [blame] | 570 | p_txdesc->buf_ptr = (u8 *) p; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 571 | p_txdesc->byte_cnt = datasize; |
| 572 | |
Albert Aribaud | c19a20d | 2010-07-10 15:41:29 +0200 | [diff] [blame] | 573 | /* Set this tc desc as zeroth TXUQ */ |
Anatolij Gustschin | e6e556c | 2011-11-19 08:59:36 +0000 | [diff] [blame] | 574 | txuq0_reg_addr = (u32)®s->tcqdp[TXUQ]; |
| 575 | writel((u32) p_txdesc, txuq0_reg_addr); |
Albert Aribaud | c19a20d | 2010-07-10 15:41:29 +0200 | [diff] [blame] | 576 | |
| 577 | /* ensure tx desc writes above are performed before we start Tx DMA */ |
| 578 | isb(); |
| 579 | |
| 580 | /* Apply send command using zeroth TXUQ */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 581 | MVGBE_REG_WR(regs->tqc, (1 << TXUQ)); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 582 | |
| 583 | /* |
| 584 | * wait for packet xmit completion |
| 585 | */ |
Simon Kagstrom | 7b05f5e | 2009-07-08 13:03:18 +0200 | [diff] [blame] | 586 | cmd_sts = readl(&p_txdesc->cmd_sts); |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 587 | while (cmd_sts & MVGBE_BUFFER_OWNED_BY_DMA) { |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 588 | /* return fail if error is detected */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 589 | if ((cmd_sts & (MVGBE_ERROR_SUMMARY | MVGBE_TX_LAST_FRAME)) == |
| 590 | (MVGBE_ERROR_SUMMARY | MVGBE_TX_LAST_FRAME) && |
| 591 | cmd_sts & (MVGBE_UR_ERROR | MVGBE_RL_ERROR)) { |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 592 | printf("Err..(%s) in xmit packet\n", __func__); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 593 | return -1; |
| 594 | } |
Simon Kagstrom | 7b05f5e | 2009-07-08 13:03:18 +0200 | [diff] [blame] | 595 | cmd_sts = readl(&p_txdesc->cmd_sts); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 596 | }; |
| 597 | return 0; |
| 598 | } |
| 599 | |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 600 | static int mvgbe_send(struct eth_device *dev, void *dataptr, int datasize) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 601 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 602 | struct mvgbe_device *dmvgbe = to_mvgbe(dev); |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 603 | |
| 604 | return __mvgbe_send(dmvgbe, dataptr, datasize); |
| 605 | } |
| 606 | |
| 607 | static int __mvgbe_recv(struct mvgbe_device *dmvgbe, uchar **packetp) |
| 608 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 609 | struct mvgbe_rxdesc *p_rxdesc_curr = dmvgbe->p_rxdesc_curr; |
Simon Kagstrom | 7b05f5e | 2009-07-08 13:03:18 +0200 | [diff] [blame] | 610 | u32 cmd_sts; |
| 611 | u32 timeout = 0; |
Anatolij Gustschin | e6e556c | 2011-11-19 08:59:36 +0000 | [diff] [blame] | 612 | u32 rxdesc_curr_addr; |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 613 | unsigned char *data; |
| 614 | int rx_bytes = 0; |
| 615 | |
| 616 | *packetp = NULL; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 617 | |
| 618 | /* wait untill rx packet available or timeout */ |
| 619 | do { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 620 | if (timeout < MVGBE_PHY_SMI_TIMEOUT) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 621 | timeout++; |
| 622 | else { |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 623 | debug("%s time out...\n", __func__); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 624 | return -1; |
| 625 | } |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 626 | } while (readl(&p_rxdesc_curr->cmd_sts) & MVGBE_BUFFER_OWNED_BY_DMA); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 627 | |
| 628 | if (p_rxdesc_curr->byte_cnt != 0) { |
| 629 | debug("%s: Received %d byte Packet @ 0x%x (cmd_sts= %08x)\n", |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 630 | __func__, (u32) p_rxdesc_curr->byte_cnt, |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 631 | (u32) p_rxdesc_curr->buf_ptr, |
| 632 | (u32) p_rxdesc_curr->cmd_sts); |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * In case received a packet without first/last bits on |
| 637 | * OR the error summary bit is on, |
| 638 | * the packets needs to be dropeed. |
| 639 | */ |
Simon Kagstrom | 7b05f5e | 2009-07-08 13:03:18 +0200 | [diff] [blame] | 640 | cmd_sts = readl(&p_rxdesc_curr->cmd_sts); |
| 641 | |
| 642 | if ((cmd_sts & |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 643 | (MVGBE_RX_FIRST_DESC | MVGBE_RX_LAST_DESC)) |
| 644 | != (MVGBE_RX_FIRST_DESC | MVGBE_RX_LAST_DESC)) { |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 645 | |
| 646 | printf("Err..(%s) Dropping packet spread on" |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 647 | " multiple descriptors\n", __func__); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 648 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 649 | } else if (cmd_sts & MVGBE_ERROR_SUMMARY) { |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 650 | |
| 651 | printf("Err..(%s) Dropping packet with errors\n", |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 652 | __func__); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 653 | |
| 654 | } else { |
| 655 | /* !!! call higher layer processing */ |
| 656 | debug("%s: Sending Received packet to" |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 657 | " upper layer (net_process_received_packet)\n", |
| 658 | __func__); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 659 | |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 660 | data = (p_rxdesc_curr->buf_ptr + RX_BUF_OFFSET); |
| 661 | rx_bytes = (int)(p_rxdesc_curr->byte_cnt - |
| 662 | RX_BUF_OFFSET); |
| 663 | |
| 664 | *packetp = data; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 665 | } |
| 666 | /* |
| 667 | * free these descriptors and point next in the ring |
| 668 | */ |
| 669 | p_rxdesc_curr->cmd_sts = |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 670 | MVGBE_BUFFER_OWNED_BY_DMA | MVGBE_RX_EN_INTERRUPT; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 671 | p_rxdesc_curr->buf_size = PKTSIZE_ALIGN; |
| 672 | p_rxdesc_curr->byte_cnt = 0; |
| 673 | |
Anatolij Gustschin | e6e556c | 2011-11-19 08:59:36 +0000 | [diff] [blame] | 674 | rxdesc_curr_addr = (u32)&dmvgbe->p_rxdesc_curr; |
| 675 | writel((unsigned)p_rxdesc_curr->nxtdesc_p, rxdesc_curr_addr); |
Simon Kagstrom | 7b05f5e | 2009-07-08 13:03:18 +0200 | [diff] [blame] | 676 | |
Chris Packham | e9bf75c | 2018-07-09 21:33:59 +1200 | [diff] [blame^] | 677 | return rx_bytes; |
| 678 | } |
| 679 | |
| 680 | static int mvgbe_recv(struct eth_device *dev) |
| 681 | { |
| 682 | struct mvgbe_device *dmvgbe = to_mvgbe(dev); |
| 683 | uchar *packet; |
| 684 | int ret; |
| 685 | |
| 686 | ret = __mvgbe_recv(dmvgbe, &packet); |
| 687 | if (ret < 0) |
| 688 | return ret; |
| 689 | |
| 690 | net_process_received_packet(packet, ret); |
| 691 | |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 692 | return 0; |
| 693 | } |
| 694 | |
Sebastian Hesselbarth | cd3ca3f | 2012-12-04 09:32:00 +0100 | [diff] [blame] | 695 | #if defined(CONFIG_PHYLIB) |
| 696 | int mvgbe_phylib_init(struct eth_device *dev, int phyid) |
| 697 | { |
| 698 | struct mii_dev *bus; |
| 699 | struct phy_device *phydev; |
| 700 | int ret; |
| 701 | |
| 702 | bus = mdio_alloc(); |
| 703 | if (!bus) { |
| 704 | printf("mdio_alloc failed\n"); |
| 705 | return -ENOMEM; |
| 706 | } |
Chris Packham | 6ecf9e2 | 2016-11-01 10:48:32 +1300 | [diff] [blame] | 707 | bus->read = smi_reg_read; |
| 708 | bus->write = smi_reg_write; |
Ben Whitten | 192bc69 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 709 | strcpy(bus->name, dev->name); |
Sebastian Hesselbarth | cd3ca3f | 2012-12-04 09:32:00 +0100 | [diff] [blame] | 710 | |
| 711 | ret = mdio_register(bus); |
| 712 | if (ret) { |
| 713 | printf("mdio_register failed\n"); |
| 714 | free(bus); |
| 715 | return -ENOMEM; |
| 716 | } |
| 717 | |
| 718 | /* Set phy address of the port */ |
Chris Packham | 6ecf9e2 | 2016-11-01 10:48:32 +1300 | [diff] [blame] | 719 | smi_reg_write(bus, MV_PHY_ADR_REQUEST, 0, MV_PHY_ADR_REQUEST, phyid); |
Sebastian Hesselbarth | cd3ca3f | 2012-12-04 09:32:00 +0100 | [diff] [blame] | 720 | |
| 721 | phydev = phy_connect(bus, phyid, dev, PHY_INTERFACE_MODE_RGMII); |
| 722 | if (!phydev) { |
| 723 | printf("phy_connect failed\n"); |
| 724 | return -ENODEV; |
| 725 | } |
| 726 | |
| 727 | phy_config(phydev); |
| 728 | phy_startup(phydev); |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | #endif |
| 733 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 734 | int mvgbe_initialize(bd_t *bis) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 735 | { |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 736 | struct mvgbe_device *dmvgbe; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 737 | struct eth_device *dev; |
| 738 | int devnum; |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 739 | u8 used_ports[MAX_MVGBE_DEVS] = CONFIG_MVGBE_PORTS; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 740 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 741 | for (devnum = 0; devnum < MAX_MVGBE_DEVS; devnum++) { |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 742 | /*skip if port is configured not to use */ |
| 743 | if (used_ports[devnum] == 0) |
| 744 | continue; |
| 745 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 746 | dmvgbe = malloc(sizeof(struct mvgbe_device)); |
| 747 | |
| 748 | if (!dmvgbe) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 749 | goto error1; |
| 750 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 751 | memset(dmvgbe, 0, sizeof(struct mvgbe_device)); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 752 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 753 | dmvgbe->p_rxdesc = |
| 754 | (struct mvgbe_rxdesc *)memalign(PKTALIGN, |
| 755 | MV_RXQ_DESC_ALIGNED_SIZE*RINGSZ + 1); |
| 756 | |
| 757 | if (!dmvgbe->p_rxdesc) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 758 | goto error2; |
| 759 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 760 | dmvgbe->p_rxbuf = (u8 *) memalign(PKTALIGN, |
| 761 | RINGSZ*PKTSIZE_ALIGN + 1); |
| 762 | |
| 763 | if (!dmvgbe->p_rxbuf) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 764 | goto error3; |
| 765 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 766 | dmvgbe->p_aligned_txbuf = memalign(8, PKTSIZE_ALIGN); |
| 767 | |
| 768 | if (!dmvgbe->p_aligned_txbuf) |
Simon Kagstrom | 477fa63 | 2009-08-20 10:14:11 +0200 | [diff] [blame] | 769 | goto error4; |
| 770 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 771 | dmvgbe->p_txdesc = (struct mvgbe_txdesc *) memalign( |
| 772 | PKTALIGN, sizeof(struct mvgbe_txdesc) + 1); |
| 773 | |
| 774 | if (!dmvgbe->p_txdesc) { |
| 775 | free(dmvgbe->p_aligned_txbuf); |
| 776 | error4: |
| 777 | free(dmvgbe->p_rxbuf); |
| 778 | error3: |
| 779 | free(dmvgbe->p_rxdesc); |
| 780 | error2: |
| 781 | free(dmvgbe); |
| 782 | error1: |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 783 | printf("Err.. %s Failed to allocate memory\n", |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 784 | __func__); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 785 | return -1; |
| 786 | } |
| 787 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 788 | dev = &dmvgbe->dev; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 789 | |
Mike Frysinger | f6add13 | 2011-11-10 14:11:04 +0000 | [diff] [blame] | 790 | /* must be less than sizeof(dev->name) */ |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 791 | sprintf(dev->name, "egiga%d", devnum); |
| 792 | |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 793 | switch (devnum) { |
| 794 | case 0: |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 795 | dmvgbe->regs = (void *)MVGBE0_BASE; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 796 | break; |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 797 | #if defined(MVGBE1_BASE) |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 798 | case 1: |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 799 | dmvgbe->regs = (void *)MVGBE1_BASE; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 800 | break; |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 801 | #endif |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 802 | default: /* this should never happen */ |
| 803 | printf("Err..(%s) Invalid device number %d\n", |
Joe Hershberger | 1fd92db | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 804 | __func__, devnum); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 805 | return -1; |
| 806 | } |
| 807 | |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 808 | dev->init = (void *)mvgbe_init; |
| 809 | dev->halt = (void *)mvgbe_halt; |
| 810 | dev->send = (void *)mvgbe_send; |
| 811 | dev->recv = (void *)mvgbe_recv; |
| 812 | dev->write_hwaddr = (void *)mvgbe_write_hwaddr; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 813 | |
| 814 | eth_register(dev); |
| 815 | |
Sebastian Hesselbarth | cd3ca3f | 2012-12-04 09:32:00 +0100 | [diff] [blame] | 816 | #if defined(CONFIG_PHYLIB) |
| 817 | mvgbe_phylib_init(dev, PHY_BASE_ADR + devnum); |
| 818 | #elif defined(CONFIG_MII) || defined(CONFIG_CMD_MII) |
Joe Hershberger | 5a49f17 | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 819 | int retval; |
| 820 | struct mii_dev *mdiodev = mdio_alloc(); |
| 821 | if (!mdiodev) |
| 822 | return -ENOMEM; |
| 823 | strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN); |
| 824 | mdiodev->read = smi_reg_read; |
| 825 | mdiodev->write = smi_reg_write; |
| 826 | |
| 827 | retval = mdio_register(mdiodev); |
| 828 | if (retval < 0) |
| 829 | return retval; |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 830 | /* Set phy address of the port */ |
Albert Aribaud | d44265a | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 831 | miiphy_write(dev->name, MV_PHY_ADR_REQUEST, |
| 832 | MV_PHY_ADR_REQUEST, PHY_BASE_ADR + devnum); |
Prafulla Wadaskar | 9131589 | 2009-06-14 22:33:46 +0530 | [diff] [blame] | 833 | #endif |
| 834 | } |
| 835 | return 0; |
Prafulla Wadaskar | 0b785dd | 2009-07-01 20:34:51 +0200 | [diff] [blame] | 836 | } |