int bcmf_netdev_register(FAR struct bcmf_dev_s *priv) { uint32_t out_len; /* Initialize network driver structure */ memset(&priv->bc_dev, 0, sizeof(priv->bc_dev)); priv->bc_dev.d_ifup = bcmf_ifup; /* I/F up (new IP address) callback */ priv->bc_dev.d_ifdown = bcmf_ifdown; /* I/F down callback */ priv->bc_dev.d_txavail = bcmf_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP priv->bc_dev.d_addmac = bcmf_addmac; /* Add multicast MAC address */ priv->bc_dev.d_rmmac = bcmf_rmmac; /* Remove multicast MAC address */ #endif #ifdef CONFIG_NETDEV_IOCTL priv->bc_dev.d_ioctl = bcmf_ioctl; /* Handle network IOCTL commands */ #endif priv->bc_dev.d_private = (FAR void *)priv; /* Used to recover private state from dev */ /* Create a watchdog for timing polling */ priv->bc_txpoll = wd_create(); /* Create periodic poll timer */ DEBUGASSERT(priv->bc_txpoll != NULL); /* Initialize network stack interface buffer */ priv->cur_tx_frame = NULL; priv->bc_dev.d_buf = NULL; /* Put the interface in the down state. This usually amounts to resetting * the device and/or calling bcmf_ifdown(). */ /* Enable chip */ if (bcmf_wl_enable(priv, true) != OK) { return -EIO; } /* Query MAC address */ out_len = ETHER_ADDR_LEN; if (bcmf_cdc_iovar_request(priv, CHIP_STA_INTERFACE, false, IOVAR_STR_CUR_ETHERADDR, priv->bc_dev.d_mac.ether.ether_addr_octet, &out_len) != OK) { return -EIO; } /* Register the device with the OS so that socket IOCTLs can be performed */ (void)netdev_register(&priv->bc_dev, NET_LL_IEEE80211); return OK; }
int uipdriver_init(void) { /* Internal initalization */ timer_set(&g_periodic_timer, 500); netdev_init(); /* Register the device with the OS so that socket IOCTLs can be performed */ (void)netdev_register(&g_sim_dev); return OK; }
int localhost_initialize(void) { FAR struct lo_driver_s *priv; /* Get the interface structure associated with this interface number. */ priv = &g_loopback; /* Initialize the driver structure */ memset(priv, 0, sizeof(struct lo_driver_s)); priv->lo_dev.d_ifup = lo_ifup; /* I/F up (new IP address) callback */ priv->lo_dev.d_ifdown = lo_ifdown; /* I/F down callback */ priv->lo_dev.d_txavail = lo_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP priv->lo_dev.d_addmac = lo_addmac; /* Add multicast MAC address */ priv->lo_dev.d_rmmac = lo_rmmac; /* Remove multicast MAC address */ #endif #ifdef CONFIG_NET_MULTIBUFFER priv->lo_dev.d_buf = g_iobuffer; /* Attach the IO buffer */ #endif priv->lo_dev.d_private = (FAR void *)priv; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmissions */ priv->lo_polldog = wd_create(); /* Create periodic poll timer */ /* Register the loopabck device with the OS so that socket IOCTLs can b * performed. */ (void)netdev_register(&priv->lo_dev, NET_LL_LOOPBACK); /* Set the local loopback IP address */ #ifdef CONFIG_NET_IPv4 net_ipv4addr_copy(priv->lo_dev.d_ipaddr, g_lo_ipv4addr); net_ipv4addr_copy(priv->lo_dev.d_draddr, g_lo_ipv4addr); net_ipv4addr_copy(priv->lo_dev.d_netmask, g_lo_ipv4mask); #endif #ifdef CONFIG_NET_IPv6 net_ipv6addr_copy(priv->lo_dev.d_ipv6addr, g_lo_ipv6addr); net_ipv6addr_copy(priv->lo_dev.d_ipv6draddr, g_lo_ipv6addr); net_ipv6addr_copy(priv->lo_dev.d_ipv6netmask, g_ipv6_alloneaddr); #endif /* Put the network in the UP state */ priv->lo_dev.d_flags = IFF_UP; return lo_ifup(&priv->lo_dev); }
int emac_initialize(int intf) { struct lpc17_driver_s *priv; /* Get the interface structure associated with this interface number. */ DEBUGASSERT(inf < CONFIG_HCS12_NINTERFACES); priv = &g_ethdrvr[intf]; /* Check if a Ethernet chip is recognized at its I/O base */ /* Attach the IRQ to the driver */ if (irq_attach(CONFIG_HCS12_IRQ, emac_interrupt)) { /* We could not attach the ISR to the interrupt */ return -EAGAIN; } /* Initialize the driver structure */ memset(priv, 0, sizeof(struct emac_driver_s)); priv->d_dev.d_ifup = emac_ifup; /* I/F down callback */ priv->d_dev.d_ifdown = emac_ifdown; /* I/F up (new IP address) callback */ priv->d_dev.d_txavail = emac_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP priv->d_dev.d_addmac = emac_addmac; /* Add multicast MAC address */ priv->d_dev.d_rmmac = emac_rmmac; /* Remove multicast MAC address */ #endif priv->d_dev.d_private = (void*)g_emac; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ priv->d_txpoll = wd_create(); /* Create periodic poll timer */ priv->d_txtimeout = wd_create(); /* Create TX timeout timer */ /* Put the interface in the down state. This usually amounts to resetting * the device and/or calling emac_ifdown(). */ /* Read the MAC address from the hardware into priv->d_dev.d_mac.ether_addr_octet */ /* Register the device with the OS so that socket IOCTLs can be performed */ (void)netdev_register(&priv->d_dev, NET_LL_ETHERNET); return OK; }
int netdriver_init(void) { /* Internal initalization */ timer_set(&g_periodic_timer, 500); netdev_init(); /* Set callbacks */ g_sim_dev.d_buf = g_pktbuf; /* Single packet buffer */ g_sim_dev.d_ifup = netdriver_ifup; g_sim_dev.d_ifdown = netdriver_ifdown; /* Register the device with the OS so that socket IOCTLs can be performed */ (void)netdev_register(&g_sim_dev, NET_LL_ETHERNET); return OK; }
int vnet_init(struct rgmp_vnet *vnet) { struct vnet_driver_s *priv; static int i = 0; if (i >= CONFIG_VNET_NINTERFACES) { return -1; } priv = &g_vnet[i++]; /* Initialize the driver structure */ memset(priv, 0, sizeof(struct vnet_driver_s)); priv->sk_dev.d_ifup = vnet_ifup; /* I/F down callback */ priv->sk_dev.d_ifdown = vnet_ifdown; /* I/F up (new IP address) callback */ priv->sk_dev.d_txavail = vnet_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP priv->sk_dev.d_addmac = vnet_addmac; /* Add multicast MAC address */ priv->sk_dev.d_rmmac = vnet_rmmac; /* Remove multicast MAC address */ #endif priv->sk_dev.d_private = (FAR void *)priv; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ priv->sk_txpoll = wd_create(); /* Create periodic poll timer */ priv->vnet = vnet; vnet->priv = priv; /* Register the device with the OS */ (void)netdev_register(&priv->sk_dev), NET_LL_ETHERNET; return 0; }
void vnet_initialize(void) { struct vnet_driver_s *priv; struct rgmp_vnet *vnet = vnet_list.next; int i; for (i=0; i<CONFIG_VNET_NINTERFACES; i++) { if (vnet == NULL) break; priv = &g_vnet[i]; /* Initialize the driver structure */ memset(priv, 0, sizeof(struct vnet_driver_s)); priv->sk_dev.d_ifup = vnet_ifup; /* I/F down callback */ priv->sk_dev.d_ifdown = vnet_ifdown; /* I/F up (new IP address) callback */ priv->sk_dev.d_txavail = vnet_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP priv->sk_dev.d_addmac = vnet_addmac; /* Add multicast MAC address */ priv->sk_dev.d_rmmac = vnet_rmmac; /* Remove multicast MAC address */ #endif priv->sk_dev.d_private = (void*)g_vnet; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ priv->sk_txpoll = wd_create(); /* Create periodic poll timer */ //priv->sk_txtimeout = wd_create(); /* Create TX timeout timer */ priv->vnet = vnet; /* Register the device with the OS */ (void)netdev_register(&priv->sk_dev); vnet = vnet->next; } }
static int e1000_probe(uint16_t addr, pci_id_t id) { uint32_t mmio_base, mmio_size; uint32_t size; int err; void *kmem, *omem; struct e1000_dev *dev; // alloc e1000_dev memory if ((dev = kzalloc(sizeof(struct e1000_dev))) == NULL) return -1; // save pci addr dev->pci_addr = addr; // enable device if ((err = pci_enable_device(addr, PCI_BUS_MASTER)) < 0) goto error; // get e1000 device type dev->pci_dev_id = id.join; // remap the controller's i/o-memory into kernel's address-space mmio_base = pci_resource_start(addr, 0); mmio_size = pci_resource_len(addr, 0); err = rgmp_memmap_nocache(mmio_base, mmio_size, mmio_base); if (err) goto error; dev->phy_mem_base = mmio_base; dev->io_mem_base = mmio_base; dev->mem_size = mmio_size; // MAC address memset(dev->dst_mac, 0xFF, 6); memcpy(dev->src_mac, (void *)(dev->io_mem_base+E1000_RA), 6); // IRQ setup dev->int_desc.handler = e1000_interrupt_handler; dev->int_desc.dev_id = dev; if ((err = pci_request_irq(addr, &dev->int_desc, 0)) < 0) goto err0; // Here we alloc a big block of memory once and make it // aligned to page boundary and multiple of page size. This // is because the memory can be modified by E1000 DMA and // should be mapped no-cache which will hugely reduce memory // access performance. The page size alloc will restrict // this bad effect only within the memory we alloc here. // // NEED FIX: the memalign may alloc memory continous in // virtual address but dis-continous in physical address // due to RGMP memory setup. size = CONFIG_E1000_N_TX_DESC * sizeof(struct tx_desc) + CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE + CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc) + CONFIG_E1000_N_RX_DESC * CONFIG_E1000_BUFF_SIZE; size = ROUNDUP(size, PGSIZE); omem = kmem = memalign(PGSIZE, size); if (kmem == NULL) { err = -ENOMEM; goto err1; } rgmp_memremap_nocache((uintptr_t)kmem, size); // alloc memory for tx ring dev->tx_ring.desc = (struct tx_desc*)kmem; kmem += CONFIG_E1000_N_TX_DESC * sizeof(struct tx_desc); dev->tx_ring.buf = kmem; kmem += CONFIG_E1000_N_TX_DESC * CONFIG_E1000_BUFF_SIZE; // alloc memory for rx rings dev->rx_ring.desc = (struct rx_desc*)kmem; kmem += CONFIG_E1000_N_RX_DESC * sizeof(struct rx_desc); dev->rx_ring.buf = kmem; /* Initialize the driver structure */ dev->uip_dev.d_ifup = e1000_ifup; /* I/F up (new IP address) callback */ dev->uip_dev.d_ifdown = e1000_ifdown; /* I/F down callback */ dev->uip_dev.d_txavail = e1000_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP dev->uip_dev.d_addmac = e1000_addmac; /* Add multicast MAC address */ dev->uip_dev.d_rmmac = e1000_rmmac; /* Remove multicast MAC address */ #endif dev->uip_dev.d_private = dev; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ dev->txpoll = wd_create(); /* Create periodic poll timer */ dev->txtimeout = wd_create(); /* Create TX timeout timer */ // Put the interface in the down state. // e1000 reset e1000_reset(dev); /* Read the MAC address from the hardware */ memcpy(dev->uip_dev.d_mac.ether_addr_octet, (void *)(dev->io_mem_base+E1000_RA), 6); /* Register the device with the OS so that socket IOCTLs can be performed */ err = netdev_register(&dev->uip_dev); if (err) goto err2; // insert into e1000_list dev->next = e1000_list.next; e1000_list.next = dev; cprintf("bring up e1000 device: %04x %08x\n", addr, id.join); return 0; err2: rgmp_memremap((uintptr_t)omem, size); free(omem); err1: pci_free_irq(addr); err0: rgmp_memunmap(mmio_base, mmio_size); error: kfree(dev); cprintf("e1000 device probe fail: %d\n", err); return err; }
int slip_initialize(int intf, FAR const char *devname) { FAR struct slip_driver_s *priv; char buffer[8]; FAR char *argv[2]; /* Get the interface structure associated with this interface number. */ DEBUGASSERT(intf < CONFIG_NET_SLIP_NINTERFACES); priv = &g_slip[intf]; /* Initialize the driver structure */ memset(priv, 0, sizeof(struct slip_driver_s)); priv->dev.d_ifup = slip_ifup; /* I/F up (new IP address) callback */ priv->dev.d_ifdown = slip_ifdown; /* I/F down callback */ priv->dev.d_txavail = slip_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP priv->dev.d_addmac = slip_addmac; /* Add multicast MAC address */ priv->dev.d_rmmac = slip_rmmac; /* Remove multicast MAC address */ #endif priv->dev.d_private = priv; /* Used to recover private state from dev */ /* Open the device */ priv->fd = open(devname, O_RDWR, 0666); if (priv->fd < 0) { nerr("ERROR: Failed to open %s: %d\n", devname, errno); return -errno; } /* Initialize the wait semaphore */ sem_init(&priv->waitsem, 0, 0); /* Put the interface in the down state. This usually amounts to resetting * the device and/or calling slip_ifdown(). */ slip_ifdown(&priv->dev); /* Start the SLIP receiver task */ snprintf(buffer, 8, "%d", intf); argv[0] = buffer; argv[1] = NULL; priv->rxpid = task_create("rxslip", CONFIG_NET_SLIP_DEFPRIO, CONFIG_NET_SLIP_STACKSIZE, (main_t)slip_rxtask, (FAR char * const *)argv); if (priv->rxpid < 0) { nerr("ERROR: Failed to start receiver task\n"); return -errno; } /* Wait and make sure that the receive task is started. */ slip_semtake(priv); /* Start the SLIP transmitter task */ priv->txpid = task_create("txslip", CONFIG_NET_SLIP_DEFPRIO, CONFIG_NET_SLIP_STACKSIZE, (main_t)slip_txtask, (FAR char * const *)argv); if (priv->txpid < 0) { nerr("ERROR: Failed to start receiver task\n"); return -errno; } /* Wait and make sure that the transmit task is started. */ slip_semtake(priv); /* Bump the semaphore count so that it can now be used as a mutex */ slip_semgive(priv); /* Register the device with the OS so that socket IOCTLs can be performed */ (void)netdev_register(&priv->dev, NET_LL_SLIP); /* When the RX and TX tasks were created, the TTY file descriptor was * dup'ed for each task. This task no longer needs the file descriptor * and we can safely close it. */ close(priv->fd); return OK; }
int misoc_net_initialize(int intf) { FAR struct misoc_net_driver_s *priv; /* Get the interface structure associated with this interface number. */ DEBUGASSERT(intf < CONFIG_MISOC_NET_NINTERFACES); priv = &g_misoc_net[intf]; /* Check if a Ethernet chip is recognized at its I/O base */ /* Attach the IRQ to the driver */ if (irq_attach(ETHMAC_INTERRUPT, misoc_net_interrupt, NULL)) { /* We could not attach the ISR to the interrupt */ return -EAGAIN; } /* clear pending int */ ethmac_sram_writer_ev_pending_write(1); ethmac_sram_reader_ev_pending_write(1); /* Initialize the driver structure */ memset(priv, 0, sizeof(struct misoc_net_driver_s)); priv->rx0_buf = (uint8_t *)ETHMAC_RX0_BASE; priv->rx1_buf = (uint8_t *)ETHMAC_RX1_BASE; priv->tx0_buf = (uint8_t *)ETHMAC_TX0_BASE; priv->tx1_buf = (uint8_t *)ETHMAC_TX1_BASE; priv->tx_buf = priv->tx0_buf; priv->tx_slot=0; priv->misoc_net_dev.d_buf = g_pktbuf; /* Single packet buffer */ priv->misoc_net_dev.d_ifup = misoc_net_ifup; /* I/F up (new IP address) callback */ priv->misoc_net_dev.d_ifdown = misoc_net_ifdown; /* I/F down callback */ priv->misoc_net_dev.d_txavail = misoc_net_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP priv->misoc_net_dev.d_addmac = misoc_net_addmac; /* Add multicast MAC address */ priv->misoc_net_dev.d_rmmac = misoc_net_rmmac; /* Remove multicast MAC address */ #endif priv->misoc_net_dev.d_private = (FAR void *)g_misoc_net; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmissions */ priv->misoc_net_txpoll = wd_create(); /* Create periodic poll timer */ priv->misoc_net_txtimeout = wd_create(); /* Create TX timeout timer */ /* Put the interface in the down state. This usually amounts to resetting * the device and/or calling misoc_net_ifdown(). */ /* Read the MAC address from the hardware into * priv->misoc_net_dev.d_mac.ether.ether_addr_octet */ /* Register the device with the OS so that socket IOCTLs can be performed */ (void)netdev_register(&priv->misoc_net_dev, NET_LL_ETHERNET); return OK; }