int rtems_at91rm9200_emac_attach ( struct rtems_bsdnet_ifconfig *config, void *chip /* only one ethernet, so no chip number */ ) { struct ifnet *ifp; int mtu; int unitnumber; char *unitname; void *p; /* an array of receive buffer descriptors -- avoid type punned warning */ p = (void *)&at91rm9200_emac_rxbuf_hdrs; rxbuf_hdrs = (RXBUF_HDR *)p; /* one transmit buffer, 1536 bytes maximum */ txbuf = (unsigned char *)&at91rm9200_emac_txbuf; /* receive buffers starting address */ rxbuf = (unsigned char *)&at91rm9200_emac_rxbufs; /* * Parse driver name */ if ((unitnumber = rtems_bsdnet_parse_driver_name (config, &unitname)) < 0) return 0; /* * Is driver free? */ if (unitnumber != 0) { printk ("Bad AT91RM9200 EMAC unit number.\n"); return 0; } ifp = &softc.arpcom.ac_if; if (ifp->if_softc != NULL) { printk ("Driver already in use.\n"); return 0; } /* * zero out the control structure */ memset( &softc, 0, sizeof(softc) ); /* get the MAC address from the chip */ softc.arpcom.ac_enaddr[0] = (EMAC_REG(EMAC_SA1L) >> 0) & 0xff; softc.arpcom.ac_enaddr[1] = (EMAC_REG(EMAC_SA1L) >> 8) & 0xff; softc.arpcom.ac_enaddr[2] = (EMAC_REG(EMAC_SA1L) >> 16) & 0xff; softc.arpcom.ac_enaddr[3] = (EMAC_REG(EMAC_SA1L) >> 24) & 0xff; softc.arpcom.ac_enaddr[4] = (EMAC_REG(EMAC_SA1H) >> 0) & 0xff; softc.arpcom.ac_enaddr[5] = (EMAC_REG(EMAC_SA1H) >> 8) & 0xff; #if 0 printk( "MAC=%02x:%02x:%02x:%02x:%02x:%02x\n", softc.arpcom.ac_enaddr[0], softc.arpcom.ac_enaddr[1], softc.arpcom.ac_enaddr[2], softc.arpcom.ac_enaddr[3], softc.arpcom.ac_enaddr[4], softc.arpcom.ac_enaddr[5] ); #endif if (config->mtu) { mtu = config->mtu; } else { mtu = ETHERMTU; } softc.acceptBroadcast = !config->ignore_broadcast; /* * Set up network interface values */ ifp->if_softc = &softc; ifp->if_unit = unitnumber; ifp->if_name = unitname; ifp->if_mtu = mtu; ifp->if_init = at91rm9200_emac_init; ifp->if_ioctl = at91rm9200_emac_ioctl; ifp->if_start = at91rm9200_emac_start; ifp->if_output = ether_output; ifp->if_flags = IFF_BROADCAST; if (ifp->if_snd.ifq_maxlen == 0) { ifp->if_snd.ifq_maxlen = ifqmaxlen; } softc.rx_buf_idx = 0; /* * Attach the interface */ if_attach (ifp); ether_ifattach (ifp); return 1; }
int rtems_mc9328mxl_enet_attach ( struct rtems_bsdnet_ifconfig *config, void *chip /* only one ethernet, so no chip number */ ) { struct ifnet *ifp; int mtu; int unitnumber; char *unitname; int tmp; /* * Parse driver name */ unitnumber = rtems_bsdnet_parse_driver_name(config, &unitname); if (unitnumber < 0) { return 0; } /* * Is driver free? */ if (unitnumber != 0) { printf ("Bad MC9328MXL unit number.\n"); return 0; } ifp = &softc.arpcom.ac_if; if (ifp->if_softc != NULL) { printf ("Driver already in use.\n"); return 0; } /* zero out the control structure */ memset( &softc, 0, sizeof(softc) ); /* set the MAC address */ tmp = lan91c11x_read_reg(LAN91C11X_IA0); softc.arpcom.ac_enaddr[0] = tmp & 0xff; softc.arpcom.ac_enaddr[1] = (tmp >> 8) & 0xff; tmp = lan91c11x_read_reg(LAN91C11X_IA2); softc.arpcom.ac_enaddr[2] = tmp & 0xff; softc.arpcom.ac_enaddr[3] = (tmp >> 8) & 0xff; tmp = lan91c11x_read_reg(LAN91C11X_IA4); softc.arpcom.ac_enaddr[4] = tmp & 0xff; softc.arpcom.ac_enaddr[5] = (tmp >> 8) & 0xff; if (config->mtu) { mtu = config->mtu; } else { mtu = ETHERMTU; } softc.accept_bcast = !config->ignore_broadcast; /* * Set up network interface values */ ifp->if_softc = &softc; ifp->if_unit = unitnumber; ifp->if_name = unitname; ifp->if_mtu = mtu; ifp->if_init = mc9328mxl_enet_init; ifp->if_ioctl = mc9328mxl_enet_ioctl; ifp->if_start = mc9328mxl_enet_start; ifp->if_output = ether_output; ifp->if_flags = IFF_BROADCAST; if (ifp->if_snd.ifq_maxlen == 0) { ifp->if_snd.ifq_maxlen = ifqmaxlen; } /* Attach the interface */ if_attach (ifp); ether_ifattach (ifp); return 1; }
int32_t xilTemac_driver_attach(struct rtems_bsdnet_ifconfig* aBsdConfig, int aDummy) { struct ifnet* ifp; int32_t mtu; int32_t unit; char* unitName; struct XilTemac* xilTemac; unit = rtems_bsdnet_parse_driver_name(aBsdConfig, &unitName); if(unit < 0 ) { printk("%s: Interface Unit number < 0\n", DRIVER_PREFIX ); return 0; } if( aBsdConfig->bpar == 0 ) { printk("%s: Did not specify base address for device '%s'", DRIVER_PREFIX, unitName ); return 0; } if( aBsdConfig->hardware_address == NULL ) { printk("%s: No MAC address given for interface '%s'\n", DRIVER_PREFIX, unitName ); return 0; } xilTemac = &gXilTemac[ unit ]; memset(xilTemac, 0, sizeof(struct XilTemac)); xilTemac->iIsPresent = 1; snprintf( xilTemac->iUnitName, MAX_UNIT_BYTES, "%s%" PRId32, unitName, unit ); xilTemac->iIfp = &(xilTemac->iArpcom.ac_if); ifp = &(xilTemac->iArpcom.ac_if); xilTemac->iAddr = aBsdConfig->bpar; xilTemac->iIoEvent = gUnitSignals[ unit ]; xilTemac->iIsrVector = aBsdConfig->irno; memcpy( xilTemac->iArpcom.ac_enaddr, aBsdConfig->hardware_address, ETHER_ADDR_LEN); if( aBsdConfig->mtu ) { mtu = aBsdConfig->mtu; } else { mtu = ETHERMTU; } ifp->if_softc = xilTemac; ifp->if_unit = unit; ifp->if_name = unitName; ifp->if_mtu = mtu; ifp->if_init = xilTemacInit; ifp->if_ioctl = xilTemacIoctl; ifp->if_start = xilTemacSend; ifp->if_output = ether_output; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; if(ifp->if_snd.ifq_maxlen == 0) { ifp->if_snd.ifq_maxlen = ifqmaxlen; } if_attach(ifp); ether_ifattach(ifp); /* create shared rx & tx threads */ if( (gXilRxThread == 0) && (gXilTxThread == 0) ) { printk("%s: Creating shared RX/TX threads\n", DRIVER_PREFIX ); gXilRxThread = rtems_bsdnet_newproc("xerx", 4096, xilTemacRxThread, NULL ); gXilTxThread = rtems_bsdnet_newproc("xetx", 4096, xilTemacTxThread, NULL ); } printk("%s: Initializing driver for '%s'\n", DRIVER_PREFIX, xilTemac->iUnitName ); printk("%s: base address 0x%08X, intnum 0x%02X, \n", DRIVER_PREFIX, aBsdConfig->bpar, aBsdConfig->irno ); return 1; }
int BSP_tsec_attach( struct rtems_bsdnet_ifconfig *config, int attaching ) { char *unit_name = NULL; int unit_number = rtems_bsdnet_parse_driver_name(config, &unit_name); tsec_config tsec_cfg; bool has_groups = false; memset(&tsec_cfg, 0, sizeof(tsec_cfg)); config->drv_ctrl = &tsec_cfg; if (unit_number <= 0 || unit_number > TSEC_COUNT) { return 0; } switch (ppc_fsl_system_version_sid(ppc_fsl_system_version())) { /* P1010 and P1020 */ case 0x0ec: case 0x0e4: case 0x0ed: case 0x0e5: has_groups = true; break; } if (config->hardware_address == NULL) { #ifdef HAS_UBOOT switch (unit_number) { case 1: config->hardware_address = bsp_uboot_board_info.bi_enetaddr; break; case 2: config->hardware_address = bsp_uboot_board_info.bi_enet1addr; break; case 3: config->hardware_address = bsp_uboot_board_info.bi_enet2addr; break; default: assert(0); break; } #else assert(0); #endif } switch (unit_number) { case 1: if (has_groups) { tsec_cfg.reg_ptr = &qoriq.tsec_1_group_0; } else { tsec_cfg.reg_ptr = &qoriq.tsec_1; } tsec_cfg.mdio_ptr = &qoriq.tsec_1; tsec_cfg.irq_num_tx = QORIQ_IRQ_ETSEC_TX_1; tsec_cfg.irq_num_rx = QORIQ_IRQ_ETSEC_RX_1; tsec_cfg.irq_num_err = QORIQ_IRQ_ETSEC_ER_1; tsec_cfg.phy_default = QORIQ_ETSEC_1_PHY_ADDR; break; case 2: if (has_groups) { tsec_cfg.reg_ptr = &qoriq.tsec_2_group_0; } else { tsec_cfg.reg_ptr = &qoriq.tsec_2; } tsec_cfg.mdio_ptr = &qoriq.tsec_1; tsec_cfg.irq_num_tx = QORIQ_IRQ_ETSEC_TX_2; tsec_cfg.irq_num_rx = QORIQ_IRQ_ETSEC_RX_2; tsec_cfg.irq_num_err = QORIQ_IRQ_ETSEC_ER_2; tsec_cfg.phy_default = QORIQ_ETSEC_2_PHY_ADDR; break; case 3: if (has_groups) { tsec_cfg.reg_ptr = &qoriq.tsec_3_group_0; } else { tsec_cfg.reg_ptr = &qoriq.tsec_3; } tsec_cfg.mdio_ptr = &qoriq.tsec_1; tsec_cfg.irq_num_tx = QORIQ_IRQ_ETSEC_TX_3; tsec_cfg.irq_num_rx = QORIQ_IRQ_ETSEC_RX_3; tsec_cfg.irq_num_err = QORIQ_IRQ_ETSEC_ER_3; tsec_cfg.phy_default = QORIQ_ETSEC_3_PHY_ADDR; break; default: assert(0); break; } tsec_cfg.unit_number = unit_number; tsec_cfg.unit_name = unit_name; return tsec_driver_attach_detach(config, attaching); }
int rtems_au1x00_emac_attach ( struct rtems_bsdnet_ifconfig *config, int attaching ) { struct ifnet *ifp; int mtu; int unitnumber; char *unitname; static au1x00_emac_softc_t *sc; /* * Parse driver name */ if ((unitnumber = rtems_bsdnet_parse_driver_name (config, &unitname)) < 0) return 0; /* * Is driver free? */ if (unitnumber > NUM_IFACES) { printf ("Bad AU1X00 EMAC unit number.\n"); return 0; } sc = &softc[unitnumber]; ifp = &sc->arpcom.ac_if; if (ifp->if_softc != NULL) { printf ("Driver already in use.\n"); return 0; } /* * zero out the control structure */ memset((void *)sc, 0, sizeof(*sc)); sc->unitnumber = unitnumber; sc->int_ctrlr = AU1X00_IC0_ADDR; if (unitnumber == 0) { sc->ctrl_regs = AU1100_MAC0_ADDR; sc->en_reg = (void *)(AU1100_MACEN_ADDR + 0); sc->tx_dma = (void *)(AU1X00_MACDMA0_ADDR + 0x000); sc->rx_dma = (void *)(AU1X00_MACDMA0_ADDR + 0x100); sc->int_mask = AU1X00_IC_IRQ_MAC0; } else { printk("Unknown network device: %d\n", unitnumber); return 0; } /* If the ethernet controller is already set up, read the MAC address */ if ((*sc->en_reg & 0x33) == 0x33) { sc->arpcom.ac_enaddr[5] = ((AU1X00_MAC_ADDRHIGH(sc->ctrl_regs) >> 8) & 0xff); sc->arpcom.ac_enaddr[4] = ((AU1X00_MAC_ADDRHIGH(sc->ctrl_regs) >> 0) & 0xff); sc->arpcom.ac_enaddr[3] = ((AU1X00_MAC_ADDRLOW(sc->ctrl_regs) >> 24) & 0xff); sc->arpcom.ac_enaddr[2] = ((AU1X00_MAC_ADDRLOW(sc->ctrl_regs) >> 16) & 0xff); sc->arpcom.ac_enaddr[1] = ((AU1X00_MAC_ADDRLOW(sc->ctrl_regs) >> 8) & 0xff); sc->arpcom.ac_enaddr[0] = ((AU1X00_MAC_ADDRLOW(sc->ctrl_regs) >> 0) & 0xff); } else {
/* attach a BFIN ETHERNET driver to the system */ int bfin_ethernet_driver_attach(struct rtems_bsdnet_ifconfig *config, int attaching, bfin_ethernet_configuration_t *chip) { struct bfin_ethernetSoftc *sc; struct ifnet *ifp; int mtu; int unitNumber; char *unitName; if ((unitNumber = rtems_bsdnet_parse_driver_name(config, &unitName)) < 0) return 0; if ((unitNumber <= 0) || (unitNumber > N_BFIN_ETHERNET)) { printf("Bad bfin ethernet unit number %d.\n", unitNumber); return 0; } sc = ðernetSoftc[unitNumber - 1]; ifp = &sc->arpcom.ac_if; if (ifp->if_softc != NULL) { printf("Driver already in use.\n"); return 0; } memset(sc, 0, sizeof(*sc)); /* process options */ if (config->hardware_address) memcpy(sc->arpcom.ac_enaddr, config->hardware_address, ETHER_ADDR_LEN); else memset(sc->arpcom.ac_enaddr, 0x08, ETHER_ADDR_LEN); if (config->mtu) mtu = config->mtu; else mtu = ETHERMTU; if (config->rbuf_count) sc->rxDescCount = config->rbuf_count; else sc->rxDescCount = chip->rxDescCount; if (config->xbuf_count) sc->txDescCount = config->xbuf_count; else sc->txDescCount = chip->txDescCount; /* minimum two of each type descriptor */ if (sc->rxDescCount <= 1) sc->rxDescCount = 2; if (sc->txDescCount <= 1) sc->txDescCount = 2; sc->acceptBroadcast = !config->ignore_broadcast; sc->sclk = chip->sclk; sc->ethBase = chip->ethBaseAddress; sc->rxdmaBase = chip->rxdmaBaseAddress; sc->txdmaBase = chip->txdmaBaseAddress; /* make sure we should not have any interrupts asserted */ resetHardware(sc); sc->rmii = (chip->phyType == rmii); sc->phyAddr = chip->phyAddr; /* set up network interface values */ ifp->if_softc = sc; ifp->if_unit = unitNumber; ifp->if_name = unitName; ifp->if_mtu = mtu; ifp->if_init = ethernetInit; ifp->if_ioctl = ethernetIoctl; ifp->if_start = ethernetStart; ifp->if_output = ether_output; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; if (ifp->if_snd.ifq_maxlen == 0) ifp->if_snd.ifq_maxlen = ifqmaxlen; if_attach(ifp); ether_ifattach(ifp); return 1; }