1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2009-2012 Freescale Semiconductor, Inc.
4 * Dave Liu <daveliu@freescale.com>
15 #include <fsl_dtsec.h>
17 #include <fsl_memac.h>
21 static struct eth_device *devlist[NUM_FM_PORTS];
22 static int num_controllers;
24 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) && !defined(BITBANGMII)
26 #define TBIANA_SETTINGS (TBIANA_ASYMMETRIC_PAUSE | TBIANA_SYMMETRIC_PAUSE | \
29 #define TBIANA_SGMII_ACK 0x4001
31 #define TBICR_SETTINGS (TBICR_ANEG_ENABLE | TBICR_RESTART_ANEG | \
32 TBICR_FULL_DUPLEX | TBICR_SPEED1_SET)
34 /* Configure the TBI for SGMII operation */
35 static void dtsec_configure_serdes(struct fm_eth *priv)
37 #ifdef CONFIG_SYS_FMAN_V3
40 bus.priv = priv->mac->phyregs;
41 bool sgmii_2500 = (priv->enet_if ==
42 PHY_INTERFACE_MODE_SGMII_2500) ? true : false;
46 /* SGMII IF mode + AN enable only for 1G SGMII, not for 2.5G */
48 value = PHY_SGMII_CR_PHY_RESET |
49 PHY_SGMII_IF_SPEED_GIGABIT |
50 PHY_SGMII_IF_MODE_SGMII;
52 value = PHY_SGMII_IF_MODE_SGMII | PHY_SGMII_IF_MODE_AN;
54 memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0x14, value);
56 /* Dev ability according to SGMII specification */
57 value = PHY_SGMII_DEV_ABILITY_SGMII;
58 memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0x4, value);
61 /* Adjust link timer for 2.5G SGMII,
62 * 1.6 ms in units of 3.2 ns:
63 * 1.6ms / 3.2ns = 5 * 10^5 = 0x7a120.
65 memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0x13, 0x0007);
66 memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0x12, 0xa120);
68 /* Adjust link timer for SGMII,
69 * 1.6 ms in units of 8 ns:
70 * 1.6ms / 8ns = 2 * 10^5 = 0x30d40.
72 memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0x13, 0x0003);
73 memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0x12, 0x0d40);
77 value = PHY_SGMII_CR_DEF_VAL | PHY_SGMII_CR_RESET_AN;
78 memac_mdio_write(&bus, i, MDIO_DEVAD_NONE, 0, value);
80 if ((priv->enet_if == PHY_INTERFACE_MODE_QSGMII) && (i < 3)) {
85 struct dtsec *regs = priv->mac->base;
86 struct tsec_mii_mng *phyregs = priv->mac->phyregs;
89 * Access TBI PHY registers at given TSEC register offset as
90 * opposed to the register offset used for external PHY accesses
92 tsec_local_mdio_write(phyregs, in_be32(®s->tbipa), 0, TBI_TBICON,
94 tsec_local_mdio_write(phyregs, in_be32(®s->tbipa), 0, TBI_ANA,
96 tsec_local_mdio_write(phyregs, in_be32(®s->tbipa), 0,
97 TBI_CR, TBICR_SETTINGS);
101 static void dtsec_init_phy(struct eth_device *dev)
103 struct fm_eth *fm_eth = dev->priv;
104 #ifndef CONFIG_SYS_FMAN_V3
105 struct dtsec *regs = (struct dtsec *)CONFIG_SYS_FSL_FM1_DTSEC1_ADDR;
107 /* Assign a Physical address to the TBI */
108 out_be32(®s->tbipa, CONFIG_SYS_TBIPA_VALUE);
111 if (fm_eth->enet_if == PHY_INTERFACE_MODE_SGMII ||
112 fm_eth->enet_if == PHY_INTERFACE_MODE_QSGMII ||
113 fm_eth->enet_if == PHY_INTERFACE_MODE_SGMII_2500)
114 dtsec_configure_serdes(fm_eth);
118 static int tgec_is_fibre(struct eth_device *dev)
120 struct fm_eth *fm = dev->priv;
123 sprintf(phyopt, "fsl_fm%d_xaui_phy", fm->fm_index + 1);
125 return hwconfig_arg_cmp(phyopt, "xfi");
130 static u16 muram_readw(u16 *addr)
132 ulong base = (ulong)addr & ~0x3UL;
133 u32 val32 = in_be32((void *)base);
137 byte_pos = (ulong)addr & 0x3UL;
139 ret = (u16)(val32 & 0x0000ffff);
141 ret = (u16)((val32 & 0xffff0000) >> 16);
146 static void muram_writew(u16 *addr, u16 val)
148 ulong base = (ulong)addr & ~0x3UL;
149 u32 org32 = in_be32((void *)base);
153 byte_pos = (ulong)addr & 0x3UL;
155 val32 = (org32 & 0xffff0000) | val;
157 val32 = (org32 & 0x0000ffff) | ((u32)val << 16);
159 out_be32((void *)base, val32);
162 static void bmi_rx_port_disable(struct fm_bmi_rx_port *rx_port)
164 int timeout = 1000000;
166 clrbits_be32(&rx_port->fmbm_rcfg, FMBM_RCFG_EN);
168 /* wait until the rx port is not busy */
169 while ((in_be32(&rx_port->fmbm_rst) & FMBM_RST_BSY) && timeout--)
173 static void bmi_rx_port_init(struct fm_bmi_rx_port *rx_port)
175 /* set BMI to independent mode, Rx port disable */
176 out_be32(&rx_port->fmbm_rcfg, FMBM_RCFG_IM);
177 /* clear FOF in IM case */
178 out_be32(&rx_port->fmbm_rim, 0);
179 /* Rx frame next engine -RISC */
180 out_be32(&rx_port->fmbm_rfne, NIA_ENG_RISC | NIA_RISC_AC_IM_RX);
181 /* Rx command attribute - no order, MR[3] = 1 */
182 clrbits_be32(&rx_port->fmbm_rfca, FMBM_RFCA_ORDER | FMBM_RFCA_MR_MASK);
183 setbits_be32(&rx_port->fmbm_rfca, FMBM_RFCA_MR(4));
184 /* enable Rx statistic counters */
185 out_be32(&rx_port->fmbm_rstc, FMBM_RSTC_EN);
186 /* disable Rx performance counters */
187 out_be32(&rx_port->fmbm_rpc, 0);
190 static void bmi_tx_port_disable(struct fm_bmi_tx_port *tx_port)
192 int timeout = 1000000;
194 clrbits_be32(&tx_port->fmbm_tcfg, FMBM_TCFG_EN);
196 /* wait until the tx port is not busy */
197 while ((in_be32(&tx_port->fmbm_tst) & FMBM_TST_BSY) && timeout--)
201 static void bmi_tx_port_init(struct fm_bmi_tx_port *tx_port)
203 /* set BMI to independent mode, Tx port disable */
204 out_be32(&tx_port->fmbm_tcfg, FMBM_TCFG_IM);
205 /* Tx frame next engine -RISC */
206 out_be32(&tx_port->fmbm_tfne, NIA_ENG_RISC | NIA_RISC_AC_IM_TX);
207 out_be32(&tx_port->fmbm_tfene, NIA_ENG_RISC | NIA_RISC_AC_IM_TX);
208 /* Tx command attribute - no order, MR[3] = 1 */
209 clrbits_be32(&tx_port->fmbm_tfca, FMBM_TFCA_ORDER | FMBM_TFCA_MR_MASK);
210 setbits_be32(&tx_port->fmbm_tfca, FMBM_TFCA_MR(4));
211 /* enable Tx statistic counters */
212 out_be32(&tx_port->fmbm_tstc, FMBM_TSTC_EN);
213 /* disable Tx performance counters */
214 out_be32(&tx_port->fmbm_tpc, 0);
217 static int fm_eth_rx_port_parameter_init(struct fm_eth *fm_eth)
219 struct fm_port_global_pram *pram;
220 u32 pram_page_offset;
221 void *rx_bd_ring_base;
223 u32 bd_ring_base_lo, bd_ring_base_hi;
225 struct fm_port_bd *rxbd;
226 struct fm_port_qd *rxqd;
227 struct fm_bmi_rx_port *bmi_rx_port = fm_eth->rx_port;
230 /* alloc global parameter ram at MURAM */
231 pram = (struct fm_port_global_pram *)fm_muram_alloc(fm_eth->fm_index,
232 FM_PRAM_SIZE, FM_PRAM_ALIGN);
234 printf("%s: No muram for Rx global parameter\n", __func__);
238 fm_eth->rx_pram = pram;
240 /* parameter page offset to MURAM */
241 pram_page_offset = (void *)pram - fm_muram_base(fm_eth->fm_index);
243 /* enable global mode- snooping data buffers and BDs */
244 out_be32(&pram->mode, PRAM_MODE_GLOBAL);
246 /* init the Rx queue descriptor pionter */
247 out_be32(&pram->rxqd_ptr, pram_page_offset + 0x20);
249 /* set the max receive buffer length, power of 2 */
250 muram_writew(&pram->mrblr, MAX_RXBUF_LOG2);
252 /* alloc Rx buffer descriptors from main memory */
253 rx_bd_ring_base = malloc(sizeof(struct fm_port_bd)
255 if (!rx_bd_ring_base)
258 memset(rx_bd_ring_base, 0, sizeof(struct fm_port_bd)
261 /* alloc Rx buffer from main memory */
262 rx_buf_pool = malloc(MAX_RXBUF_LEN * RX_BD_RING_SIZE);
266 memset(rx_buf_pool, 0, MAX_RXBUF_LEN * RX_BD_RING_SIZE);
267 debug("%s: rx_buf_pool = %p\n", __func__, rx_buf_pool);
269 /* save them to fm_eth */
270 fm_eth->rx_bd_ring = rx_bd_ring_base;
271 fm_eth->cur_rxbd = rx_bd_ring_base;
272 fm_eth->rx_buf = rx_buf_pool;
274 /* init Rx BDs ring */
275 rxbd = (struct fm_port_bd *)rx_bd_ring_base;
276 for (i = 0; i < RX_BD_RING_SIZE; i++) {
277 muram_writew(&rxbd->status, RxBD_EMPTY);
278 muram_writew(&rxbd->len, 0);
279 buf_hi = upper_32_bits(virt_to_phys(rx_buf_pool +
281 buf_lo = lower_32_bits(virt_to_phys(rx_buf_pool +
283 muram_writew(&rxbd->buf_ptr_hi, (u16)buf_hi);
284 out_be32(&rxbd->buf_ptr_lo, buf_lo);
288 /* set the Rx queue descriptor */
290 muram_writew(&rxqd->gen, 0);
291 bd_ring_base_hi = upper_32_bits(virt_to_phys(rx_bd_ring_base));
292 bd_ring_base_lo = lower_32_bits(virt_to_phys(rx_bd_ring_base));
293 muram_writew(&rxqd->bd_ring_base_hi, (u16)bd_ring_base_hi);
294 out_be32(&rxqd->bd_ring_base_lo, bd_ring_base_lo);
295 muram_writew(&rxqd->bd_ring_size, sizeof(struct fm_port_bd)
297 muram_writew(&rxqd->offset_in, 0);
298 muram_writew(&rxqd->offset_out, 0);
300 /* set IM parameter ram pointer to Rx Frame Queue ID */
301 out_be32(&bmi_rx_port->fmbm_rfqid, pram_page_offset);
306 static int fm_eth_tx_port_parameter_init(struct fm_eth *fm_eth)
308 struct fm_port_global_pram *pram;
309 u32 pram_page_offset;
310 void *tx_bd_ring_base;
311 u32 bd_ring_base_lo, bd_ring_base_hi;
312 struct fm_port_bd *txbd;
313 struct fm_port_qd *txqd;
314 struct fm_bmi_tx_port *bmi_tx_port = fm_eth->tx_port;
317 /* alloc global parameter ram at MURAM */
318 pram = (struct fm_port_global_pram *)fm_muram_alloc(fm_eth->fm_index,
319 FM_PRAM_SIZE, FM_PRAM_ALIGN);
321 printf("%s: No muram for Tx global parameter\n", __func__);
324 fm_eth->tx_pram = pram;
326 /* parameter page offset to MURAM */
327 pram_page_offset = (void *)pram - fm_muram_base(fm_eth->fm_index);
329 /* enable global mode- snooping data buffers and BDs */
330 out_be32(&pram->mode, PRAM_MODE_GLOBAL);
332 /* init the Tx queue descriptor pionter */
333 out_be32(&pram->txqd_ptr, pram_page_offset + 0x40);
335 /* alloc Tx buffer descriptors from main memory */
336 tx_bd_ring_base = malloc(sizeof(struct fm_port_bd)
338 if (!tx_bd_ring_base)
341 memset(tx_bd_ring_base, 0, sizeof(struct fm_port_bd)
343 /* save it to fm_eth */
344 fm_eth->tx_bd_ring = tx_bd_ring_base;
345 fm_eth->cur_txbd = tx_bd_ring_base;
347 /* init Tx BDs ring */
348 txbd = (struct fm_port_bd *)tx_bd_ring_base;
349 for (i = 0; i < TX_BD_RING_SIZE; i++) {
350 muram_writew(&txbd->status, TxBD_LAST);
351 muram_writew(&txbd->len, 0);
352 muram_writew(&txbd->buf_ptr_hi, 0);
353 out_be32(&txbd->buf_ptr_lo, 0);
357 /* set the Tx queue decriptor */
359 bd_ring_base_hi = upper_32_bits(virt_to_phys(tx_bd_ring_base));
360 bd_ring_base_lo = lower_32_bits(virt_to_phys(tx_bd_ring_base));
361 muram_writew(&txqd->bd_ring_base_hi, (u16)bd_ring_base_hi);
362 out_be32(&txqd->bd_ring_base_lo, bd_ring_base_lo);
363 muram_writew(&txqd->bd_ring_size, sizeof(struct fm_port_bd)
365 muram_writew(&txqd->offset_in, 0);
366 muram_writew(&txqd->offset_out, 0);
368 /* set IM parameter ram pointer to Tx Confirmation Frame Queue ID */
369 out_be32(&bmi_tx_port->fmbm_tcfqid, pram_page_offset);
374 static int fm_eth_init(struct fm_eth *fm_eth)
378 ret = fm_eth_rx_port_parameter_init(fm_eth);
382 ret = fm_eth_tx_port_parameter_init(fm_eth);
389 static int fm_eth_startup(struct fm_eth *fm_eth)
391 struct fsl_enet_mac *mac;
396 /* Rx/TxBDs, Rx/TxQDs, Rx buff and parameter ram init */
397 ret = fm_eth_init(fm_eth);
400 /* setup the MAC controller */
403 /* For some reason we need to set SPEED_100 */
404 if (((fm_eth->enet_if == PHY_INTERFACE_MODE_SGMII) ||
405 (fm_eth->enet_if == PHY_INTERFACE_MODE_SGMII_2500) ||
406 (fm_eth->enet_if == PHY_INTERFACE_MODE_QSGMII)) &&
408 mac->set_if_mode(mac, fm_eth->enet_if, SPEED_100);
410 /* init bmi rx port, IM mode and disable */
411 bmi_rx_port_init(fm_eth->rx_port);
412 /* init bmi tx port, IM mode and disable */
413 bmi_tx_port_init(fm_eth->tx_port);
418 static void fmc_tx_port_graceful_stop_enable(struct fm_eth *fm_eth)
420 struct fm_port_global_pram *pram;
422 pram = fm_eth->tx_pram;
423 /* graceful stop transmission of frames */
424 setbits_be32(&pram->mode, PRAM_MODE_GRACEFUL_STOP);
428 static void fmc_tx_port_graceful_stop_disable(struct fm_eth *fm_eth)
430 struct fm_port_global_pram *pram;
432 pram = fm_eth->tx_pram;
433 /* re-enable transmission of frames */
434 clrbits_be32(&pram->mode, PRAM_MODE_GRACEFUL_STOP);
438 static int fm_eth_open(struct eth_device *dev, bd_t *bd)
440 struct fm_eth *fm_eth;
441 struct fsl_enet_mac *mac;
446 fm_eth = (struct fm_eth *)dev->priv;
449 /* setup the MAC address */
450 if (dev->enetaddr[0] & 0x01) {
451 printf("%s: MacAddress is multcast address\n", __func__);
454 mac->set_mac_addr(mac, dev->enetaddr);
456 /* enable bmi Rx port */
457 setbits_be32(&fm_eth->rx_port->fmbm_rcfg, FMBM_RCFG_EN);
458 /* enable MAC rx/tx port */
459 mac->enable_mac(mac);
460 /* enable bmi Tx port */
461 setbits_be32(&fm_eth->tx_port->fmbm_tcfg, FMBM_TCFG_EN);
462 /* re-enable transmission of frame */
463 fmc_tx_port_graceful_stop_disable(fm_eth);
466 if (fm_eth->phydev) {
467 ret = phy_startup(fm_eth->phydev);
469 printf("%s: Could not initialize\n",
470 fm_eth->phydev->dev->name);
477 fm_eth->phydev->speed = SPEED_1000;
478 fm_eth->phydev->link = 1;
479 fm_eth->phydev->duplex = DUPLEX_FULL;
482 /* set the MAC-PHY mode */
483 mac->set_if_mode(mac, fm_eth->enet_if, fm_eth->phydev->speed);
485 if (!fm_eth->phydev->link)
486 printf("%s: No link.\n", fm_eth->phydev->dev->name);
488 return fm_eth->phydev->link ? 0 : -1;
491 static void fm_eth_halt(struct eth_device *dev)
493 struct fm_eth *fm_eth;
494 struct fsl_enet_mac *mac;
496 fm_eth = (struct fm_eth *)dev->priv;
499 /* graceful stop the transmission of frames */
500 fmc_tx_port_graceful_stop_enable(fm_eth);
501 /* disable bmi Tx port */
502 bmi_tx_port_disable(fm_eth->tx_port);
503 /* disable MAC rx/tx port */
504 mac->disable_mac(mac);
505 /* disable bmi Rx port */
506 bmi_rx_port_disable(fm_eth->rx_port);
510 phy_shutdown(fm_eth->phydev);
514 static int fm_eth_send(struct eth_device *dev, void *buf, int len)
516 struct fm_eth *fm_eth;
517 struct fm_port_global_pram *pram;
518 struct fm_port_bd *txbd, *txbd_base;
522 fm_eth = (struct fm_eth *)dev->priv;
523 pram = fm_eth->tx_pram;
524 txbd = fm_eth->cur_txbd;
526 /* find one empty TxBD */
527 for (i = 0; muram_readw(&txbd->status) & TxBD_READY; i++) {
530 printf("%s: Tx buffer not ready, txbd->status = 0x%x\n",
531 dev->name, muram_readw(&txbd->status));
536 muram_writew(&txbd->buf_ptr_hi, (u16)upper_32_bits(virt_to_phys(buf)));
537 out_be32(&txbd->buf_ptr_lo, lower_32_bits(virt_to_phys(buf)));
538 muram_writew(&txbd->len, len);
540 muram_writew(&txbd->status, TxBD_READY | TxBD_LAST);
543 /* update TxQD, let RISC to send the packet */
544 offset_in = muram_readw(&pram->txqd.offset_in);
545 offset_in += sizeof(struct fm_port_bd);
546 if (offset_in >= muram_readw(&pram->txqd.bd_ring_size))
548 muram_writew(&pram->txqd.offset_in, offset_in);
551 /* wait for buffer to be transmitted */
552 for (i = 0; muram_readw(&txbd->status) & TxBD_READY; i++) {
555 printf("%s: Tx error, txbd->status = 0x%x\n",
556 dev->name, muram_readw(&txbd->status));
561 /* advance the TxBD */
563 txbd_base = (struct fm_port_bd *)fm_eth->tx_bd_ring;
564 if (txbd >= (txbd_base + TX_BD_RING_SIZE))
566 /* update current txbd */
567 fm_eth->cur_txbd = (void *)txbd;
572 static int fm_eth_recv(struct eth_device *dev)
574 struct fm_eth *fm_eth;
575 struct fm_port_global_pram *pram;
576 struct fm_port_bd *rxbd, *rxbd_base;
583 fm_eth = (struct fm_eth *)dev->priv;
584 pram = fm_eth->rx_pram;
585 rxbd = fm_eth->cur_rxbd;
586 status = muram_readw(&rxbd->status);
588 while (!(status & RxBD_EMPTY)) {
589 if (!(status & RxBD_ERROR)) {
590 buf_hi = muram_readw(&rxbd->buf_ptr_hi);
591 buf_lo = in_be32(&rxbd->buf_ptr_lo);
592 data = (u8 *)((ulong)(buf_hi << 16) << 16 | buf_lo);
593 len = muram_readw(&rxbd->len);
594 net_process_received_packet(data, len);
596 printf("%s: Rx error\n", dev->name);
600 /* clear the RxBDs */
601 muram_writew(&rxbd->status, RxBD_EMPTY);
602 muram_writew(&rxbd->len, 0);
607 rxbd_base = (struct fm_port_bd *)fm_eth->rx_bd_ring;
608 if (rxbd >= (rxbd_base + RX_BD_RING_SIZE))
610 /* read next status */
611 status = muram_readw(&rxbd->status);
614 offset_out = muram_readw(&pram->rxqd.offset_out);
615 offset_out += sizeof(struct fm_port_bd);
616 if (offset_out >= muram_readw(&pram->rxqd.bd_ring_size))
618 muram_writew(&pram->rxqd.offset_out, offset_out);
621 fm_eth->cur_rxbd = (void *)rxbd;
626 static int fm_eth_init_mac(struct fm_eth *fm_eth, struct ccsr_fman *reg)
628 struct fsl_enet_mac *mac;
630 void *base, *phyregs = NULL;
634 #ifdef CONFIG_SYS_FMAN_V3
635 #ifndef CONFIG_FSL_FM_10GEC_REGULAR_NOTATION
636 if (fm_eth->type == FM_ETH_10G_E) {
637 /* 10GEC1/10GEC2 use mEMAC9/mEMAC10 on T2080/T4240.
638 * 10GEC3/10GEC4 use mEMAC1/mEMAC2 on T2080.
639 * 10GEC1 uses mEMAC1 on T1024.
640 * so it needs to change the num.
642 if (fm_eth->num >= 2)
648 base = ®->memac[num].fm_memac;
649 phyregs = ®->memac[num].fm_memac_mdio;
651 /* Get the mac registers base address */
652 if (fm_eth->type == FM_ETH_1G_E) {
653 base = ®->mac_1g[num].fm_dtesc;
654 phyregs = ®->mac_1g[num].fm_mdio.miimcfg;
656 base = ®->mac_10g[num].fm_10gec;
657 phyregs = ®->mac_10g[num].fm_10gec_mdio;
661 /* alloc mac controller */
662 mac = malloc(sizeof(struct fsl_enet_mac));
665 memset(mac, 0, sizeof(struct fsl_enet_mac));
667 /* save the mac to fm_eth struct */
670 #ifdef CONFIG_SYS_FMAN_V3
671 init_memac(mac, base, phyregs, MAX_RXBUF_LEN);
673 if (fm_eth->type == FM_ETH_1G_E)
674 init_dtsec(mac, base, phyregs, MAX_RXBUF_LEN);
676 init_tgec(mac, base, phyregs, MAX_RXBUF_LEN);
682 static int init_phy(struct eth_device *dev)
684 struct fm_eth *fm_eth = dev->priv;
686 struct phy_device *phydev = NULL;
690 if (fm_eth->type == FM_ETH_1G_E)
695 phydev = phy_connect(fm_eth->bus, fm_eth->phyaddr, dev,
698 printf("Failed to connect\n");
705 if (fm_eth->type == FM_ETH_1G_E) {
706 supported = (SUPPORTED_10baseT_Half |
707 SUPPORTED_10baseT_Full |
708 SUPPORTED_100baseT_Half |
709 SUPPORTED_100baseT_Full |
710 SUPPORTED_1000baseT_Full);
712 supported = SUPPORTED_10000baseT_Full;
714 if (tgec_is_fibre(dev))
715 phydev->port = PORT_FIBRE;
718 phydev->supported &= supported;
719 phydev->advertising = phydev->supported;
721 fm_eth->phydev = phydev;
729 int fm_eth_initialize(struct ccsr_fman *reg, struct fm_eth_info *info)
731 struct eth_device *dev;
732 struct fm_eth *fm_eth;
733 int i, num = info->num;
736 /* alloc eth device */
737 dev = (struct eth_device *)malloc(sizeof(struct eth_device));
740 memset(dev, 0, sizeof(struct eth_device));
742 /* alloc the FMan ethernet private struct */
743 fm_eth = (struct fm_eth *)malloc(sizeof(struct fm_eth));
746 memset(fm_eth, 0, sizeof(struct fm_eth));
748 /* save off some things we need from the info struct */
749 fm_eth->fm_index = info->index - 1; /* keep as 0 based for muram */
751 fm_eth->type = info->type;
753 fm_eth->rx_port = (void *)®->port[info->rx_port_id - 1].fm_bmi;
754 fm_eth->tx_port = (void *)®->port[info->tx_port_id - 1].fm_bmi;
756 /* set the ethernet max receive length */
757 fm_eth->max_rx_len = MAX_RXBUF_LEN;
759 /* init global mac structure */
760 ret = fm_eth_init_mac(fm_eth, reg);
764 /* keep same as the manual, we call FMAN1, FMAN2, DTSEC1, DTSEC2, etc */
765 if (fm_eth->type == FM_ETH_1G_E)
766 sprintf(dev->name, "FM%d@DTSEC%d", info->index, num + 1);
768 sprintf(dev->name, "FM%d@TGEC%d", info->index, num + 1);
770 devlist[num_controllers++] = dev;
772 dev->priv = (void *)fm_eth;
773 dev->init = fm_eth_open;
774 dev->halt = fm_eth_halt;
775 dev->send = fm_eth_send;
776 dev->recv = fm_eth_recv;
778 fm_eth->bus = info->bus;
779 fm_eth->phyaddr = info->phy_addr;
780 fm_eth->enet_if = info->enet_if;
782 /* startup the FM im */
783 ret = fm_eth_startup(fm_eth);
789 /* clear the ethernet address */
790 for (i = 0; i < 6; i++)
791 dev->enetaddr[i] = 0;