3 * Marvell Semiconductor <www.marvell.com>
4 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
7 * Ingo Assmus <ingo.assmus@keymile.com>
9 * based on - Driver for MV64360X ethernet ports
10 * Copyright (C) 2002 rabeeh@galileo.co.il
12 * See file CREDITS for list of people who contributed to this
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
36 #include <asm/errno.h>
37 #include <asm/types.h>
38 #include <asm/system.h>
39 #include <asm/byteorder.h>
40 #include <asm/arch/cpu.h>
42 #if defined(CONFIG_KIRKWOOD)
43 #include <asm/arch/kirkwood.h>
44 #elif defined(CONFIG_ORION5X)
45 #include <asm/arch/orion5x.h>
46 #elif defined(CONFIG_DOVE)
47 #include <asm/arch/dove.h>
52 DECLARE_GLOBAL_DATA_PTR;
54 #define MV_PHY_ADR_REQUEST 0xee
55 #define MVGBE_SMI_REG (((struct mvgbe_registers *)MVGBE0_BASE)->smi)
57 #if defined(CONFIG_PHYLIB) || defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
59 * smi_reg_read - miiphy_read callback function.
61 * Returns 16bit phy register value, or 0xffff on error
63 static int smi_reg_read(const char *devname, u8 phy_adr, u8 reg_ofs, u16 * data)
65 struct eth_device *dev = eth_get_dev_by_name(devname);
66 struct mvgbe_device *dmvgbe = to_mvgbe(dev);
67 struct mvgbe_registers *regs = dmvgbe->regs;
71 /* Phyadr read request */
72 if (phy_adr == MV_PHY_ADR_REQUEST &&
73 reg_ofs == MV_PHY_ADR_REQUEST) {
75 *data = (u16) (MVGBE_REG_RD(regs->phyadr) & PHYADR_MASK);
78 /* check parameters */
79 if (phy_adr > PHYADR_MASK) {
80 printf("Err..(%s) Invalid PHY address %d\n",
81 __FUNCTION__, phy_adr);
84 if (reg_ofs > PHYREG_MASK) {
85 printf("Err..(%s) Invalid register offset %d\n",
86 __FUNCTION__, reg_ofs);
90 timeout = MVGBE_PHY_SMI_TIMEOUT;
91 /* wait till the SMI is not busy */
93 /* read smi register */
94 smi_reg = MVGBE_REG_RD(MVGBE_SMI_REG);
96 printf("Err..(%s) SMI busy timeout\n", __FUNCTION__);
99 } while (smi_reg & MVGBE_PHY_SMI_BUSY_MASK);
101 /* fill the phy address and regiser offset and read opcode */
102 smi_reg = (phy_adr << MVGBE_PHY_SMI_DEV_ADDR_OFFS)
103 | (reg_ofs << MVGBE_SMI_REG_ADDR_OFFS)
104 | MVGBE_PHY_SMI_OPCODE_READ;
106 /* write the smi register */
107 MVGBE_REG_WR(MVGBE_SMI_REG, smi_reg);
109 /*wait till read value is ready */
110 timeout = MVGBE_PHY_SMI_TIMEOUT;
113 /* read smi register */
114 smi_reg = MVGBE_REG_RD(MVGBE_SMI_REG);
115 if (timeout-- == 0) {
116 printf("Err..(%s) SMI read ready timeout\n",
120 } while (!(smi_reg & MVGBE_PHY_SMI_READ_VALID_MASK));
122 /* Wait for the data to update in the SMI register */
123 for (timeout = 0; timeout < MVGBE_PHY_SMI_TIMEOUT; timeout++)
126 *data = (u16) (MVGBE_REG_RD(MVGBE_SMI_REG) & MVGBE_PHY_SMI_DATA_MASK);
128 debug("%s:(adr %d, off %d) value= %04x\n", __FUNCTION__, phy_adr,
135 * smi_reg_write - imiiphy_write callback function.
137 * Returns 0 if write succeed, -EINVAL on bad parameters
140 static int smi_reg_write(const char *devname, u8 phy_adr, u8 reg_ofs, u16 data)
142 struct eth_device *dev = eth_get_dev_by_name(devname);
143 struct mvgbe_device *dmvgbe = to_mvgbe(dev);
144 struct mvgbe_registers *regs = dmvgbe->regs;
148 /* Phyadr write request*/
149 if (phy_adr == MV_PHY_ADR_REQUEST &&
150 reg_ofs == MV_PHY_ADR_REQUEST) {
151 MVGBE_REG_WR(regs->phyadr, data);
155 /* check parameters */
156 if (phy_adr > PHYADR_MASK) {
157 printf("Err..(%s) Invalid phy address\n", __FUNCTION__);
160 if (reg_ofs > PHYREG_MASK) {
161 printf("Err..(%s) Invalid register offset\n", __FUNCTION__);
165 /* wait till the SMI is not busy */
166 timeout = MVGBE_PHY_SMI_TIMEOUT;
168 /* read smi register */
169 smi_reg = MVGBE_REG_RD(MVGBE_SMI_REG);
170 if (timeout-- == 0) {
171 printf("Err..(%s) SMI busy timeout\n", __FUNCTION__);
174 } while (smi_reg & MVGBE_PHY_SMI_BUSY_MASK);
176 /* fill the phy addr and reg offset and write opcode and data */
177 smi_reg = (data << MVGBE_PHY_SMI_DATA_OFFS);
178 smi_reg |= (phy_adr << MVGBE_PHY_SMI_DEV_ADDR_OFFS)
179 | (reg_ofs << MVGBE_SMI_REG_ADDR_OFFS);
180 smi_reg &= ~MVGBE_PHY_SMI_OPCODE_READ;
182 /* write the smi register */
183 MVGBE_REG_WR(MVGBE_SMI_REG, smi_reg);
189 #if defined(CONFIG_PHYLIB)
190 int mvgbe_phy_read(struct mii_dev *bus, int phy_addr, int dev_addr,
195 ret = smi_reg_read(bus->name, phy_addr, reg_addr, &data);
201 int mvgbe_phy_write(struct mii_dev *bus, int phy_addr, int dev_addr,
202 int reg_addr, u16 data)
204 return smi_reg_write(bus->name, phy_addr, reg_addr, data);
208 /* Stop and checks all queues */
209 static void stop_queue(u32 * qreg)
213 reg_data = readl(qreg);
215 if (reg_data & 0xFF) {
216 /* Issue stop command for active channels only */
217 writel((reg_data << 8), qreg);
219 /* Wait for all queue activity to terminate. */
222 * Check port cause register that all queues
225 reg_data = readl(qreg);
227 while (reg_data & 0xFF);
232 * set_access_control - Config address decode parameters for Ethernet unit
234 * This function configures the address decode parameters for the Gigabit
235 * Ethernet Controller according the given parameters struct.
237 * @regs Register struct pointer.
238 * @param Address decode parameter struct.
240 static void set_access_control(struct mvgbe_registers *regs,
241 struct mvgbe_winparam *param)
245 /* Set access control register */
246 access_prot_reg = MVGBE_REG_RD(regs->epap);
247 /* clear window permission */
248 access_prot_reg &= (~(3 << (param->win * 2)));
249 access_prot_reg |= (param->access_ctrl << (param->win * 2));
250 MVGBE_REG_WR(regs->epap, access_prot_reg);
252 /* Set window Size reg (SR) */
253 MVGBE_REG_WR(regs->barsz[param->win].size,
254 (((param->size / 0x10000) - 1) << 16));
256 /* Set window Base address reg (BA) */
257 MVGBE_REG_WR(regs->barsz[param->win].bar,
258 (param->target | param->attrib | param->base_addr));
259 /* High address remap reg (HARR) */
261 MVGBE_REG_WR(regs->ha_remap[param->win], param->high_addr);
263 /* Base address enable reg (BARER) */
264 if (param->enable == 1)
265 MVGBE_REG_BITS_RESET(regs->bare, (1 << param->win));
267 MVGBE_REG_BITS_SET(regs->bare, (1 << param->win));
270 static void set_dram_access(struct mvgbe_registers *regs)
272 struct mvgbe_winparam win_param;
275 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
276 /* Set access parameters for DRAM bank i */
277 win_param.win = i; /* Use Ethernet window i */
278 /* Window target - DDR */
279 win_param.target = MVGBE_TARGET_DRAM;
280 /* Enable full access */
281 win_param.access_ctrl = EWIN_ACCESS_FULL;
282 win_param.high_addr = 0;
283 /* Get bank base and size */
284 win_param.base_addr = gd->bd->bi_dram[i].start;
285 win_param.size = gd->bd->bi_dram[i].size;
286 if (win_param.size == 0)
287 win_param.enable = 0;
289 win_param.enable = 1; /* Enable the access */
291 /* Enable DRAM bank */
294 win_param.attrib = EBAR_DRAM_CS0;
297 win_param.attrib = EBAR_DRAM_CS1;
300 win_param.attrib = EBAR_DRAM_CS2;
303 win_param.attrib = EBAR_DRAM_CS3;
306 /* invalid bank, disable access */
307 win_param.enable = 0;
308 win_param.attrib = 0;
311 /* Set the access control for address window(EPAPR) RD/WR */
312 set_access_control(regs, &win_param);
317 * port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables
319 * Go through all the DA filter tables (Unicast, Special Multicast & Other
320 * Multicast) and set each entry to 0.
322 static void port_init_mac_tables(struct mvgbe_registers *regs)
326 /* Clear DA filter unicast table (Ex_dFUT) */
327 for (table_index = 0; table_index < 4; ++table_index)
328 MVGBE_REG_WR(regs->dfut[table_index], 0);
330 for (table_index = 0; table_index < 64; ++table_index) {
331 /* Clear DA filter special multicast table (Ex_dFSMT) */
332 MVGBE_REG_WR(regs->dfsmt[table_index], 0);
333 /* Clear DA filter other multicast table (Ex_dFOMT) */
334 MVGBE_REG_WR(regs->dfomt[table_index], 0);
339 * port_uc_addr - This function Set the port unicast address table
341 * This function locates the proper entry in the Unicast table for the
342 * specified MAC nibble and sets its properties according to function
344 * This function add/removes MAC addresses from the port unicast address
347 * @uc_nibble Unicast MAC Address last nibble.
348 * @option 0 = Add, 1 = remove address.
350 * RETURN: 1 if output succeeded. 0 if option parameter is invalid.
352 static int port_uc_addr(struct mvgbe_registers *regs, u8 uc_nibble,
359 /* Locate the Unicast table entry */
360 uc_nibble = (0xf & uc_nibble);
361 /* Register offset from unicast table base */
362 tbl_offset = (uc_nibble / 4);
363 /* Entry offset within the above register */
364 reg_offset = uc_nibble % 4;
367 case REJECT_MAC_ADDR:
369 * Clear accepts frame bit at specified unicast
372 unicast_reg = MVGBE_REG_RD(regs->dfut[tbl_offset]);
373 unicast_reg &= (0xFF << (8 * reg_offset));
374 MVGBE_REG_WR(regs->dfut[tbl_offset], unicast_reg);
376 case ACCEPT_MAC_ADDR:
377 /* Set accepts frame bit at unicast DA filter table entry */
378 unicast_reg = MVGBE_REG_RD(regs->dfut[tbl_offset]);
379 unicast_reg &= (0xFF << (8 * reg_offset));
380 unicast_reg |= ((0x01 | (RXUQ << 1)) << (8 * reg_offset));
381 MVGBE_REG_WR(regs->dfut[tbl_offset], unicast_reg);
390 * port_uc_addr_set - This function Set the port Unicast address.
392 static void port_uc_addr_set(struct mvgbe_registers *regs, u8 * p_addr)
397 mac_l = (p_addr[4] << 8) | (p_addr[5]);
398 mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) |
401 MVGBE_REG_WR(regs->macal, mac_l);
402 MVGBE_REG_WR(regs->macah, mac_h);
404 /* Accept frames of this address */
405 port_uc_addr(regs, p_addr[5], ACCEPT_MAC_ADDR);
409 * mvgbe_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory.
411 static void mvgbe_init_rx_desc_ring(struct mvgbe_device *dmvgbe)
413 struct mvgbe_rxdesc *p_rx_desc;
416 /* initialize the Rx descriptors ring */
417 p_rx_desc = dmvgbe->p_rxdesc;
418 for (i = 0; i < RINGSZ; i++) {
420 MVGBE_BUFFER_OWNED_BY_DMA | MVGBE_RX_EN_INTERRUPT;
421 p_rx_desc->buf_size = PKTSIZE_ALIGN;
422 p_rx_desc->byte_cnt = 0;
423 p_rx_desc->buf_ptr = dmvgbe->p_rxbuf + i * PKTSIZE_ALIGN;
424 if (i == (RINGSZ - 1))
425 p_rx_desc->nxtdesc_p = dmvgbe->p_rxdesc;
427 p_rx_desc->nxtdesc_p = (struct mvgbe_rxdesc *)
428 ((u32) p_rx_desc + MV_RXQ_DESC_ALIGNED_SIZE);
429 p_rx_desc = p_rx_desc->nxtdesc_p;
432 dmvgbe->p_rxdesc_curr = dmvgbe->p_rxdesc;
435 static int mvgbe_init(struct eth_device *dev)
437 struct mvgbe_device *dmvgbe = to_mvgbe(dev);
438 struct mvgbe_registers *regs = dmvgbe->regs;
439 #if (defined (CONFIG_MII) || defined (CONFIG_CMD_MII)) \
440 && defined (CONFIG_SYS_FAULT_ECHO_LINK_DOWN)
444 mvgbe_init_rx_desc_ring(dmvgbe);
446 /* Clear the ethernet port interrupts */
447 MVGBE_REG_WR(regs->ic, 0);
448 MVGBE_REG_WR(regs->ice, 0);
449 /* Unmask RX buffer and TX end interrupt */
450 MVGBE_REG_WR(regs->pim, INT_CAUSE_UNMASK_ALL);
451 /* Unmask phy and link status changes interrupts */
452 MVGBE_REG_WR(regs->peim, INT_CAUSE_UNMASK_ALL_EXT);
454 set_dram_access(regs);
455 port_init_mac_tables(regs);
456 port_uc_addr_set(regs, dmvgbe->dev.enetaddr);
458 /* Assign port configuration and command. */
459 MVGBE_REG_WR(regs->pxc, PRT_CFG_VAL);
460 MVGBE_REG_WR(regs->pxcx, PORT_CFG_EXTEND_VALUE);
461 MVGBE_REG_WR(regs->psc0, PORT_SERIAL_CONTROL_VALUE);
463 /* Assign port SDMA configuration */
464 MVGBE_REG_WR(regs->sdc, PORT_SDMA_CFG_VALUE);
465 MVGBE_REG_WR(regs->tqx[0].qxttbc, QTKNBKT_DEF_VAL);
466 MVGBE_REG_WR(regs->tqx[0].tqxtbc,
467 (QMTBS_DEF_VAL << 16) | QTKNRT_DEF_VAL);
468 /* Turn off the port/RXUQ bandwidth limitation */
469 MVGBE_REG_WR(regs->pmtu, 0);
471 /* Set maximum receive buffer to 9700 bytes */
472 MVGBE_REG_WR(regs->psc0, MVGBE_MAX_RX_PACKET_9700BYTE
473 | (MVGBE_REG_RD(regs->psc0) & MRU_MASK));
475 /* Enable port initially */
476 MVGBE_REG_BITS_SET(regs->psc0, MVGBE_SERIAL_PORT_EN);
479 * Set ethernet MTU for leaky bucket mechanism to 0 - this will
480 * disable the leaky bucket mechanism .
482 MVGBE_REG_WR(regs->pmtu, 0);
484 /* Assignment of Rx CRDB of given RXUQ */
485 MVGBE_REG_WR(regs->rxcdp[RXUQ], (u32) dmvgbe->p_rxdesc_curr);
486 /* ensure previous write is done before enabling Rx DMA */
488 /* Enable port Rx. */
489 MVGBE_REG_WR(regs->rqc, (1 << RXUQ));
491 #if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) && \
492 !defined(CONFIG_PHYLIB) && \
493 defined(CONFIG_SYS_FAULT_ECHO_LINK_DOWN)
494 /* Wait up to 5s for the link status */
495 for (i = 0; i < 5; i++) {
498 miiphy_read(dev->name, MV_PHY_ADR_REQUEST,
499 MV_PHY_ADR_REQUEST, &phyadr);
500 /* Return if we get link up */
501 if (miiphy_link(dev->name, phyadr))
506 printf("No link on %s\n", dev->name);
512 static int mvgbe_halt(struct eth_device *dev)
514 struct mvgbe_device *dmvgbe = to_mvgbe(dev);
515 struct mvgbe_registers *regs = dmvgbe->regs;
517 /* Disable all gigE address decoder */
518 MVGBE_REG_WR(regs->bare, 0x3f);
520 stop_queue(®s->tqc);
521 stop_queue(®s->rqc);
524 MVGBE_REG_BITS_RESET(regs->psc0, MVGBE_SERIAL_PORT_EN);
525 /* Set port is not reset */
526 MVGBE_REG_BITS_RESET(regs->psc1, 1 << 4);
527 #ifdef CONFIG_SYS_MII_MODE
528 /* Set MMI interface up */
529 MVGBE_REG_BITS_RESET(regs->psc1, 1 << 3);
531 /* Disable & mask ethernet port interrupts */
532 MVGBE_REG_WR(regs->ic, 0);
533 MVGBE_REG_WR(regs->ice, 0);
534 MVGBE_REG_WR(regs->pim, 0);
535 MVGBE_REG_WR(regs->peim, 0);
540 static int mvgbe_write_hwaddr(struct eth_device *dev)
542 struct mvgbe_device *dmvgbe = to_mvgbe(dev);
543 struct mvgbe_registers *regs = dmvgbe->regs;
545 /* Programs net device MAC address after initialization */
546 port_uc_addr_set(regs, dmvgbe->dev.enetaddr);
550 static int mvgbe_send(struct eth_device *dev, void *dataptr, int datasize)
552 struct mvgbe_device *dmvgbe = to_mvgbe(dev);
553 struct mvgbe_registers *regs = dmvgbe->regs;
554 struct mvgbe_txdesc *p_txdesc = dmvgbe->p_txdesc;
555 void *p = (void *)dataptr;
559 /* Copy buffer if it's misaligned */
560 if ((u32) dataptr & 0x07) {
561 if (datasize > PKTSIZE_ALIGN) {
562 printf("Non-aligned data too large (%d)\n",
567 memcpy(dmvgbe->p_aligned_txbuf, p, datasize);
568 p = dmvgbe->p_aligned_txbuf;
571 p_txdesc->cmd_sts = MVGBE_ZERO_PADDING | MVGBE_GEN_CRC;
572 p_txdesc->cmd_sts |= MVGBE_TX_FIRST_DESC | MVGBE_TX_LAST_DESC;
573 p_txdesc->cmd_sts |= MVGBE_BUFFER_OWNED_BY_DMA;
574 p_txdesc->cmd_sts |= MVGBE_TX_EN_INTERRUPT;
575 p_txdesc->buf_ptr = (u8 *) p;
576 p_txdesc->byte_cnt = datasize;
578 /* Set this tc desc as zeroth TXUQ */
579 txuq0_reg_addr = (u32)®s->tcqdp[TXUQ];
580 writel((u32) p_txdesc, txuq0_reg_addr);
582 /* ensure tx desc writes above are performed before we start Tx DMA */
585 /* Apply send command using zeroth TXUQ */
586 MVGBE_REG_WR(regs->tqc, (1 << TXUQ));
589 * wait for packet xmit completion
591 cmd_sts = readl(&p_txdesc->cmd_sts);
592 while (cmd_sts & MVGBE_BUFFER_OWNED_BY_DMA) {
593 /* return fail if error is detected */
594 if ((cmd_sts & (MVGBE_ERROR_SUMMARY | MVGBE_TX_LAST_FRAME)) ==
595 (MVGBE_ERROR_SUMMARY | MVGBE_TX_LAST_FRAME) &&
596 cmd_sts & (MVGBE_UR_ERROR | MVGBE_RL_ERROR)) {
597 printf("Err..(%s) in xmit packet\n", __FUNCTION__);
600 cmd_sts = readl(&p_txdesc->cmd_sts);
605 static int mvgbe_recv(struct eth_device *dev)
607 struct mvgbe_device *dmvgbe = to_mvgbe(dev);
608 struct mvgbe_rxdesc *p_rxdesc_curr = dmvgbe->p_rxdesc_curr;
611 u32 rxdesc_curr_addr;
613 /* wait untill rx packet available or timeout */
615 if (timeout < MVGBE_PHY_SMI_TIMEOUT)
618 debug("%s time out...\n", __FUNCTION__);
621 } while (readl(&p_rxdesc_curr->cmd_sts) & MVGBE_BUFFER_OWNED_BY_DMA);
623 if (p_rxdesc_curr->byte_cnt != 0) {
624 debug("%s: Received %d byte Packet @ 0x%x (cmd_sts= %08x)\n",
625 __FUNCTION__, (u32) p_rxdesc_curr->byte_cnt,
626 (u32) p_rxdesc_curr->buf_ptr,
627 (u32) p_rxdesc_curr->cmd_sts);
631 * In case received a packet without first/last bits on
632 * OR the error summary bit is on,
633 * the packets needs to be dropeed.
635 cmd_sts = readl(&p_rxdesc_curr->cmd_sts);
638 (MVGBE_RX_FIRST_DESC | MVGBE_RX_LAST_DESC))
639 != (MVGBE_RX_FIRST_DESC | MVGBE_RX_LAST_DESC)) {
641 printf("Err..(%s) Dropping packet spread on"
642 " multiple descriptors\n", __FUNCTION__);
644 } else if (cmd_sts & MVGBE_ERROR_SUMMARY) {
646 printf("Err..(%s) Dropping packet with errors\n",
650 /* !!! call higher layer processing */
651 debug("%s: Sending Received packet to"
652 " upper layer (NetReceive)\n", __FUNCTION__);
654 /* let the upper layer handle the packet */
655 NetReceive((p_rxdesc_curr->buf_ptr + RX_BUF_OFFSET),
656 (int)(p_rxdesc_curr->byte_cnt - RX_BUF_OFFSET));
659 * free these descriptors and point next in the ring
661 p_rxdesc_curr->cmd_sts =
662 MVGBE_BUFFER_OWNED_BY_DMA | MVGBE_RX_EN_INTERRUPT;
663 p_rxdesc_curr->buf_size = PKTSIZE_ALIGN;
664 p_rxdesc_curr->byte_cnt = 0;
666 rxdesc_curr_addr = (u32)&dmvgbe->p_rxdesc_curr;
667 writel((unsigned)p_rxdesc_curr->nxtdesc_p, rxdesc_curr_addr);
672 #if defined(CONFIG_PHYLIB)
673 int mvgbe_phylib_init(struct eth_device *dev, int phyid)
676 struct phy_device *phydev;
681 printf("mdio_alloc failed\n");
684 bus->read = mvgbe_phy_read;
685 bus->write = mvgbe_phy_write;
686 sprintf(bus->name, dev->name);
688 ret = mdio_register(bus);
690 printf("mdio_register failed\n");
695 /* Set phy address of the port */
696 mvgbe_phy_write(bus, MV_PHY_ADR_REQUEST, 0, MV_PHY_ADR_REQUEST, phyid);
698 phydev = phy_connect(bus, phyid, dev, PHY_INTERFACE_MODE_RGMII);
700 printf("phy_connect failed\n");
711 int mvgbe_initialize(bd_t *bis)
713 struct mvgbe_device *dmvgbe;
714 struct eth_device *dev;
716 u8 used_ports[MAX_MVGBE_DEVS] = CONFIG_MVGBE_PORTS;
718 for (devnum = 0; devnum < MAX_MVGBE_DEVS; devnum++) {
719 /*skip if port is configured not to use */
720 if (used_ports[devnum] == 0)
723 dmvgbe = malloc(sizeof(struct mvgbe_device));
728 memset(dmvgbe, 0, sizeof(struct mvgbe_device));
731 (struct mvgbe_rxdesc *)memalign(PKTALIGN,
732 MV_RXQ_DESC_ALIGNED_SIZE*RINGSZ + 1);
734 if (!dmvgbe->p_rxdesc)
737 dmvgbe->p_rxbuf = (u8 *) memalign(PKTALIGN,
738 RINGSZ*PKTSIZE_ALIGN + 1);
740 if (!dmvgbe->p_rxbuf)
743 dmvgbe->p_aligned_txbuf = memalign(8, PKTSIZE_ALIGN);
745 if (!dmvgbe->p_aligned_txbuf)
748 dmvgbe->p_txdesc = (struct mvgbe_txdesc *) memalign(
749 PKTALIGN, sizeof(struct mvgbe_txdesc) + 1);
751 if (!dmvgbe->p_txdesc) {
752 free(dmvgbe->p_aligned_txbuf);
754 free(dmvgbe->p_rxbuf);
756 free(dmvgbe->p_rxdesc);
760 printf("Err.. %s Failed to allocate memory\n",
767 /* must be less than sizeof(dev->name) */
768 sprintf(dev->name, "egiga%d", devnum);
772 dmvgbe->regs = (void *)MVGBE0_BASE;
774 #if defined(MVGBE1_BASE)
776 dmvgbe->regs = (void *)MVGBE1_BASE;
779 default: /* this should never happen */
780 printf("Err..(%s) Invalid device number %d\n",
781 __FUNCTION__, devnum);
785 dev->init = (void *)mvgbe_init;
786 dev->halt = (void *)mvgbe_halt;
787 dev->send = (void *)mvgbe_send;
788 dev->recv = (void *)mvgbe_recv;
789 dev->write_hwaddr = (void *)mvgbe_write_hwaddr;
793 #if defined(CONFIG_PHYLIB)
794 mvgbe_phylib_init(dev, PHY_BASE_ADR + devnum);
795 #elif defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
796 miiphy_register(dev->name, smi_reg_read, smi_reg_write);
797 /* Set phy address of the port */
798 miiphy_write(dev->name, MV_PHY_ADR_REQUEST,
799 MV_PHY_ADR_REQUEST, PHY_BASE_ADR + devnum);