/** * Check for link state changes * * @v netdev Network device * @v stat Status flags */ static void nii_poll_link ( struct net_device *netdev, unsigned int stat ) { int no_media = ( stat & PXE_STATFLAGS_GET_STATUS_NO_MEDIA ); if ( no_media && netdev_link_ok ( netdev ) ) { netdev_link_down ( netdev ); } else if ( ( ! no_media ) && ( ! netdev_link_ok ( netdev ) ) ) { netdev_link_up ( netdev ); } }
/** Handle a device request for the af_packet driver */ static int af_packet_nic_probe ( struct linux_device *device, struct linux_device_request *request ) { struct linux_setting *if_setting; struct net_device *netdev; struct af_packet_nic *nic; int rc; netdev = alloc_etherdev(sizeof(*nic)); if (! netdev) return -ENOMEM; netdev_init(netdev, &af_packet_nic_operations); nic = netdev->priv; linux_set_drvdata(device, netdev); netdev->dev = &device->dev; memset(nic, 0, sizeof(*nic)); /* Look for the mandatory if setting */ if_setting = linux_find_setting("if", &request->settings); /* No if setting */ if (! if_setting) { printf("af_packet missing a mandatory if setting\n"); rc = -EINVAL; goto err_settings; } nic->ifname = if_setting->value; snprintf ( device->dev.name, sizeof ( device->dev.name ), "%s", nic->ifname ); device->dev.desc.bus_type = BUS_TYPE_TAP; af_packet_update_properties(netdev); if_setting->applied = 1; /* Apply rest of the settings */ linux_apply_settings(&request->settings, &netdev->settings.settings); /* Register network device */ if ((rc = register_netdev(netdev)) != 0) goto err_register; netdev_link_up(netdev); return 0; err_settings: unregister_netdev(netdev); err_register: netdev_nullify(netdev); netdev_put(netdev); return rc; }
/** * Probe PCI device * * @v pci PCI device * @ret rc Return status code */ static int myson_probe ( struct pci_device *pci ) { struct net_device *netdev; struct myson_nic *myson; union myson_physical_address mac; int rc; /* Allocate and initialise net device */ netdev = alloc_etherdev ( sizeof ( *myson ) ); if ( ! netdev ) { rc = -ENOMEM; goto err_alloc; } netdev_init ( netdev, &myson_operations ); myson = netdev->priv; pci_set_drvdata ( pci, netdev ); netdev->dev = &pci->dev; memset ( myson, 0, sizeof ( *myson ) ); myson_init_ring ( &myson->tx, MYSON_NUM_TX_DESC, MYSON_TXLBA ); myson_init_ring ( &myson->rx, MYSON_NUM_RX_DESC, MYSON_RXLBA ); /* Fix up PCI device */ adjust_pci_device ( pci ); /* Map registers */ myson->regs = ioremap ( pci->membase, MYSON_BAR_SIZE ); /* Reset the NIC */ if ( ( rc = myson_reset ( myson ) ) != 0 ) goto err_reset; /* Read MAC address */ mac.reg.low = cpu_to_le32 ( readl ( myson->regs + MYSON_PAR0 ) ); mac.reg.high = cpu_to_le32 ( readl ( myson->regs + MYSON_PAR4 ) ); memcpy ( netdev->hw_addr, mac.raw, ETH_ALEN ); /* Register network device */ if ( ( rc = register_netdev ( netdev ) ) != 0 ) goto err_register_netdev; /* Mark as link up; we don't yet handle link state */ netdev_link_up ( netdev ); return 0; unregister_netdev ( netdev ); err_register_netdev: myson_reset ( myson ); err_reset: iounmap ( myson->regs ); netdev_nullify ( netdev ); netdev_put ( netdev ); err_alloc: return rc; }
/** * Update link status based on network status register * * @v dm96xx DM96xx device * @v nsr Network status register */ static void dm96xx_link_nsr ( struct dm96xx_device *dm96xx, unsigned int nsr ) { struct net_device *netdev = dm96xx->netdev; if ( nsr & DM96XX_NSR_LINKST ) { if ( ! netdev_link_ok ( netdev ) ) netdev_link_up ( netdev ); } else { if ( netdev_link_ok ( netdev ) ) netdev_link_down ( netdev ); } }
/** * mii_check_link - check MII link status * @mii: MII interface * * If the link status changed (previous != current), call * netif_carrier_on() if current link status is Up or call * netif_carrier_off() if current link status is Down. */ void mii_check_link(struct mii_if_info *mii) { #warning "figure out what to do about etherboot netdev; does ours work?" #if 0 int cur_link = mii_link_ok(mii); int prev_link = netdev_link_ok(mii->dev); if (cur_link && !prev_link) netdev_link_up(mii->dev); else if (prev_link && !cur_link) netdev_link_down(mii->dev); #endif }
/** * Handle link status event * * @v netdev Network device * @v link Link status */ static void intelxlvf_admin_link ( struct net_device *netdev, struct intelxl_admin_vf_status_link *link ) { struct intelxl_nic *intelxl = netdev->priv; DBGC ( intelxl, "INTELXL %p link %#02x speed %#02x\n", intelxl, link->status, link->speed ); /* Update network device */ if ( link->status ) { netdev_link_up ( netdev ); } else { netdev_link_down ( netdev ); } }
/** * Check link state * * @v netdev Network device */ static void snpnet_check_link ( struct net_device *netdev ) { struct snp_nic *snp = netdev_priv ( netdev ); EFI_SIMPLE_NETWORK_MODE *mode = snp->snp->Mode; /* Do nothing unless media presence detection is supported */ if ( ! mode->MediaPresentSupported ) return; /* Report any link status change */ if ( mode->MediaPresent && ( ! netdev_link_ok ( netdev ) ) ) { netdev_link_up ( netdev ); } else if ( ( ! mode->MediaPresent ) && netdev_link_ok ( netdev ) ) { netdev_link_down ( netdev ); } }
/** * Check link state * * @v netdev Network device */ static void intelxvf_check_link ( struct net_device *netdev ) { struct intel_nic *intel = netdev->priv; uint32_t links; /* Read link status */ links = readl ( intel->regs + INTELXVF_LINKS ); DBGC ( intel, "INTEL %p link status is %08x\n", intel, links ); /* Update network device */ if ( links & INTELXVF_LINKS_UP ) { netdev_link_up ( netdev ); } else { netdev_link_down ( netdev ); } }
/** * Check link state * * @v netdev Network device */ static void rhine_check_link ( struct net_device *netdev ) { struct rhine_nic *rhn = netdev->priv; uint8_t mii_sr; /* Read MII status register */ mii_sr = readb ( rhn->regs + RHINE_MII_SR ); DBGC ( rhn, "RHINE %p link status %02x\n", rhn, mii_sr ); /* Report link state */ if ( ! ( mii_sr & RHINE_MII_SR_LINKPOLL ) ) { netdev_link_up ( netdev ); } else if ( mii_sr & RHINE_MII_SR_PHYERR ) { netdev_link_err ( netdev, -EIO ); } else { netdev_link_down ( netdev ); } }
/** * Attach driver to device * * @v efidev EFI device * @ret rc Return status code */ int snpnet_start ( struct efi_device *efidev ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE device = efidev->device; EFI_SIMPLE_NETWORK_MODE *mode; struct net_device *netdev; struct snp_nic *snp; void *interface; EFI_STATUS efirc; int rc; /* Open SNP protocol */ if ( ( efirc = bs->OpenProtocol ( device, &efi_simple_network_protocol_guid, &interface, efi_image_handle, device, ( EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0) { rc = -EEFI ( efirc ); DBGC ( device, "SNP %s cannot open SNP protocol: %s\n", efi_handle_name ( device ), strerror ( rc ) ); DBGC_EFI_OPENERS ( device, device, &efi_simple_network_protocol_guid ); goto err_open_protocol; } /* Allocate and initialise structure */ netdev = alloc_etherdev ( sizeof ( *snp ) ); if ( ! netdev ) { rc = -ENOMEM; goto err_alloc; } netdev_init ( netdev, &snpnet_operations ); snp = netdev->priv; snp->efidev = efidev; snp->snp = interface; mode = snp->snp->Mode; efidev_set_drvdata ( efidev, netdev ); /* Populate underlying device information */ efi_device_info ( device, "SNP", &snp->dev ); snp->dev.driver_name = "SNP"; snp->dev.parent = &efidev->dev; list_add ( &snp->dev.siblings, &efidev->dev.children ); INIT_LIST_HEAD ( &snp->dev.children ); netdev->dev = &snp->dev; /* Bring to the Started state */ if ( ( mode->State == EfiSimpleNetworkStopped ) && ( ( efirc = snp->snp->Start ( snp->snp ) ) != 0 ) ) { rc = -EEFI ( efirc ); DBGC ( device, "SNP %s could not start: %s\n", efi_handle_name ( device ), strerror ( rc ) ); goto err_start; } if ( ( mode->State == EfiSimpleNetworkInitialized ) && ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) ) { rc = -EEFI ( efirc ); DBGC ( device, "SNP %s could not shut down: %s\n", efi_handle_name ( device ), strerror ( rc ) ); goto err_shutdown; } /* Populate network device parameters */ if ( mode->HwAddressSize != netdev->ll_protocol->hw_addr_len ) { DBGC ( device, "SNP %s has invalid hardware address length " "%d\n", efi_handle_name ( device ), mode->HwAddressSize); rc = -ENOTSUP; goto err_hw_addr_len; } memcpy ( netdev->hw_addr, &mode->PermanentAddress, netdev->ll_protocol->hw_addr_len ); if ( mode->HwAddressSize != netdev->ll_protocol->ll_addr_len ) { DBGC ( device, "SNP %s has invalid link-layer address length " "%d\n", efi_handle_name ( device ), mode->HwAddressSize); rc = -ENOTSUP; goto err_ll_addr_len; } memcpy ( netdev->ll_addr, &mode->CurrentAddress, netdev->ll_protocol->ll_addr_len ); snp->mtu = ( snp->snp->Mode->MaxPacketSize + snp->snp->Mode->MediaHeaderSize ); /* Register network device */ if ( ( rc = register_netdev ( netdev ) ) != 0 ) goto err_register_netdev; DBGC ( device, "SNP %s registered as %s\n", efi_handle_name ( device ), netdev->name ); /* Set initial link state */ if ( snp->snp->Mode->MediaPresentSupported ) { snpnet_check_link ( netdev ); } else { netdev_link_up ( netdev ); } return 0; unregister_netdev ( netdev ); err_register_netdev: err_ll_addr_len: err_hw_addr_len: err_shutdown: err_start: list_del ( &snp->dev.siblings ); netdev_nullify ( netdev ); netdev_put ( netdev ); err_alloc: bs->CloseProtocol ( device, &efi_simple_network_protocol_guid, efi_image_handle, device ); err_open_protocol: return rc; }
/** * Attach driver to device * * @v efidev EFI device * @ret rc Return status code */ int nii_start ( struct efi_device *efidev ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE device = efidev->device; struct net_device *netdev; struct nii_nic *nii; void *interface; EFI_STATUS efirc; int rc; /* Allocate and initialise structure */ netdev = alloc_netdev ( sizeof ( *nii ) ); if ( ! netdev ) { rc = -ENOMEM; goto err_alloc; } netdev_init ( netdev, &nii_operations ); nii = netdev->priv; nii->efidev = efidev; netdev->ll_broadcast = nii->broadcast; efidev_set_drvdata ( efidev, netdev ); /* Populate underlying device information */ efi_device_info ( device, "NII", &nii->dev ); nii->dev.driver_name = "NII"; nii->dev.parent = &efidev->dev; list_add ( &nii->dev.siblings, &efidev->dev.children ); INIT_LIST_HEAD ( &nii->dev.children ); netdev->dev = &nii->dev; /* Open NII protocol */ if ( ( efirc = bs->OpenProtocol ( device, &efi_nii31_protocol_guid, &interface, efi_image_handle, device, ( EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE )))!=0){ rc = -EEFI ( efirc ); DBGC ( nii, "NII %s cannot open NII protocol: %s\n", nii->dev.name, strerror ( rc ) ); DBGC_EFI_OPENERS ( device, device, &efi_nii31_protocol_guid ); goto err_open_protocol; } nii->nii = interface; /* Locate UNDI and entry point */ nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id ); if ( ! nii->undi ) { DBGC ( nii, "NII %s has no UNDI\n", nii->dev.name ); rc = -ENODEV; goto err_no_undi; } if ( nii->undi->Implementation & PXE_ROMID_IMP_HW_UNDI ) { DBGC ( nii, "NII %s is a mythical hardware UNDI\n", nii->dev.name ); rc = -ENOTSUP; goto err_hw_undi; } if ( nii->undi->Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR ) { nii->issue = ( ( void * ) ( intptr_t ) nii->undi->EntryPoint ); } else { nii->issue = ( ( ( void * ) nii->undi ) + nii->undi->EntryPoint ); } DBGC ( nii, "NII %s using UNDI v%x.%x at %p entry %p\n", nii->dev.name, nii->nii->MajorVer, nii->nii->MinorVer, nii->undi, nii->issue ); /* Open PCI I/O protocols and locate BARs */ if ( ( rc = nii_pci_open ( nii ) ) != 0 ) goto err_pci_open; /* Start UNDI */ if ( ( rc = nii_start_undi ( nii ) ) != 0 ) goto err_start_undi; /* Get initialisation information */ if ( ( rc = nii_get_init_info ( nii, netdev ) ) != 0 ) goto err_get_init_info; /* Get MAC addresses */ if ( ( rc = nii_get_station_address ( nii, netdev ) ) != 0 ) goto err_get_station_address; /* Register network device */ if ( ( rc = register_netdev ( netdev ) ) != 0 ) goto err_register_netdev; DBGC ( nii, "NII %s registered as %s for %p %s\n", nii->dev.name, netdev->name, device, efi_handle_name ( device ) ); /* Set initial link state (if media detection is not supported) */ if ( ! nii->media ) netdev_link_up ( netdev ); return 0; unregister_netdev ( netdev ); err_register_netdev: err_get_station_address: err_get_init_info: nii_stop_undi ( nii ); err_start_undi: nii_pci_close ( nii ); err_pci_open: err_hw_undi: err_no_undi: bs->CloseProtocol ( device, &efi_nii31_protocol_guid, efi_image_handle, device ); err_open_protocol: list_del ( &nii->dev.siblings ); netdev_nullify ( netdev ); netdev_put ( netdev ); err_alloc: return rc; }
/** * Probe device * * @v pci PCI device * @v id Matching entry in ID table * @ret rc Return status code */ static int b44_probe(struct pci_device *pci, const struct pci_device_id *id) { struct net_device *netdev; struct b44_private *bp; int rc; /* * Bail out if more than 1GB of physical RAM is installed. * This limitation will be removed later when dma mapping * is merged into mainline. */ if (!phys_ram_within_limit(B44_30BIT_DMA_MASK)) { DBG("Sorry, this version of the driver does not\n" "support systems with more than 1GB of RAM.\n"); return -ENOMEM; } /* Set up netdev */ netdev = alloc_etherdev(sizeof(*bp)); if (!netdev) return -ENOMEM; netdev_init(netdev, &b44_operations); pci_set_drvdata(pci, netdev); netdev->dev = &pci->dev; /* Set up private data */ bp = netdev_priv(netdev); memset(bp, 0, sizeof(*bp)); bp->netdev = netdev; bp->pci = pci; /* Map device registers */ bp->regs = ioremap(pci->membase, B44_REGS_SIZE); if (!bp->regs) { netdev_put(netdev); return -ENOMEM; } /* Enable PCI bus mastering */ adjust_pci_device(pci); b44_load_mac_and_phy_addr(bp); /* Link management currently not implemented */ netdev_link_up(netdev); rc = register_netdev(netdev); if (rc != 0) { iounmap(bp->regs); netdev_put(netdev); return rc; } b44_chip_reset(bp, B44_CHIP_RESET_FULL); DBG("b44 %s (%04x:%04x) regs=%p MAC=%s\n", id->name, id->vendor, id->device, bp->regs, eth_ntoa(netdev->ll_addr)); return 0; }
/** * e1000_probe - Initial configuration of e1000 NIC * * @v pci PCI device * @v id PCI IDs * * @ret rc Return status code **/ int e1000e_probe ( struct pci_device *pdev, const struct pci_device_id *ent) { int i, err; struct net_device *netdev; struct e1000_adapter *adapter; unsigned long mmio_start, mmio_len; unsigned long flash_start, flash_len; struct e1000_hw *hw; const struct e1000_info *ei = e1000_info_tbl[ent->driver_data]; DBGP ( "e1000_probe\n" ); err = -ENOMEM; /* Allocate net device ( also allocates memory for netdev->priv and makes netdev-priv point to it ) */ netdev = alloc_etherdev ( sizeof ( struct e1000_adapter ) ); if ( ! netdev ) { DBG ( "err_alloc_etherdev\n" ); goto err_alloc_etherdev; } /* Associate e1000-specific network operations operations with * generic network device layer */ netdev_init ( netdev, &e1000e_operations ); /* Associate this network device with given PCI device */ pci_set_drvdata ( pdev, netdev ); netdev->dev = &pdev->dev; /* Initialize driver private storage */ adapter = netdev_priv ( netdev ); memset ( adapter, 0, ( sizeof ( *adapter ) ) ); adapter->pdev = pdev; adapter->ioaddr = pdev->ioaddr; adapter->hw.io_base = pdev->ioaddr; hw = &adapter->hw; hw->device_id = pdev->device; adapter->irqno = pdev->irq; adapter->netdev = netdev; adapter->hw.back = adapter; adapter->ei = ei; adapter->pba = ei->pba; adapter->flags = ei->flags; adapter->flags2 = ei->flags2; adapter->hw.adapter = adapter; adapter->hw.mac.type = ei->mac; adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN; adapter->tx_ring_size = sizeof ( *adapter->tx_base ) * NUM_TX_DESC; adapter->rx_ring_size = sizeof ( *adapter->rx_base ) * NUM_RX_DESC; /* Fix up PCI device */ adjust_pci_device ( pdev ); err = -EIO; mmio_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_0 ); mmio_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_0 ); DBG ( "mmio_start: %#08lx\n", mmio_start ); DBG ( "mmio_len: %#08lx\n", mmio_len ); adapter->hw.hw_addr = ioremap ( mmio_start, mmio_len ); DBG ( "adapter->hw.hw_addr: %p\n", adapter->hw.hw_addr ); if ( ! adapter->hw.hw_addr ) { DBG ( "err_ioremap\n" ); goto err_ioremap; } /* Flash BAR mapping depends on mac_type */ if ( ( adapter->flags & FLAG_HAS_FLASH) && ( pdev->ioaddr ) ) { flash_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_1 ); flash_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_1 ); adapter->hw.flash_address = ioremap ( flash_start, flash_len ); if ( ! adapter->hw.flash_address ) { DBG ( "err_flashmap\n" ); goto err_flashmap; } } /* setup adapter struct */ err = e1000e_sw_init ( adapter ); if (err) { DBG ( "err_sw_init\n" ); goto err_sw_init; } if (ei->get_variants) { err = ei->get_variants(adapter); if (err) { DBG ( "err_hw_initr\n" ); goto err_hw_init; } } /* Copper options */ if (adapter->hw.phy.media_type == e1000_media_type_copper) { adapter->hw.phy.mdix = AUTO_ALL_MODES; adapter->hw.phy.disable_polarity_correction = 0; adapter->hw.phy.ms_type = e1000_ms_hw_default; } DBG ( "adapter->hw.mac.type: %#08x\n", adapter->hw.mac.type ); /* Force auto-negotiation */ adapter->hw.mac.autoneg = 1; adapter->fc_autoneg = 1; adapter->hw.phy.autoneg_wait_to_complete = true; adapter->hw.mac.adaptive_ifs = true; adapter->hw.fc.requested_mode = e1000_fc_default; adapter->hw.fc.current_mode = e1000_fc_default; /* * before reading the NVM, reset the controller to * put the device in a known good starting state */ adapter->hw.mac.ops.reset_hw(&adapter->hw); /* * systems with ASPM and others may see the checksum fail on the first * attempt. Let's give it a few tries */ for (i = 0;; i++) { if (e1000e_validate_nvm_checksum(&adapter->hw) >= 0) break; if (i == 2) { DBG("The NVM Checksum Is Not Valid\n"); err = -EIO; goto err_eeprom; } } /* copy the MAC address out of the EEPROM */ if ( e1000e_read_mac_addr ( &adapter->hw ) ) DBG ( "EEPROM Read Error\n" ); memcpy ( netdev->hw_addr, adapter->hw.mac.perm_addr, ETH_ALEN ); /* reset the hardware with the new settings */ e1000e_reset ( adapter ); /* Mark as link up; we don't yet handle link state */ netdev_link_up ( netdev ); if ( ( err = register_netdev ( netdev ) ) != 0) { DBG ( "err_register\n" ); goto err_register; } for (i = 0; i < 6; i++) DBG ("%02x%s", netdev->ll_addr[i], i == 5 ? "\n" : ":"); DBG ( "e1000e_probe succeeded!\n" ); /* No errors, return success */ return 0; /* Error return paths */ err_register: err_hw_init: err_eeprom: err_flashmap: if (!e1000e_check_reset_block(&adapter->hw)) e1000e_phy_hw_reset(&adapter->hw); if (adapter->hw.flash_address) iounmap(adapter->hw.flash_address); err_sw_init: iounmap ( adapter->hw.hw_addr ); err_ioremap: netdev_put ( netdev ); err_alloc_etherdev: return err; }
/** * Open network device * * @v netdev Network device * @ret rc Return status code */ static int netfront_open ( struct net_device *netdev ) { struct netfront_nic *netfront = netdev->priv; struct xen_device *xendev = netfront->xendev; int rc; /* Ensure device is in a suitable initial state */ if ( ( rc = netfront_reset ( netfront ) ) != 0 ) goto err_reset; /* Create transmit descriptor ring */ if ( ( rc = netfront_create_ring ( netfront, &netfront->tx ) ) != 0 ) goto err_create_tx; SHARED_RING_INIT ( netfront->tx_sring ); FRONT_RING_INIT ( &netfront->tx_fring, netfront->tx_sring, PAGE_SIZE ); assert ( RING_SIZE ( &netfront->tx_fring ) >= netfront->tx.count ); /* Create receive descriptor ring */ if ( ( rc = netfront_create_ring ( netfront, &netfront->rx ) ) != 0 ) goto err_create_rx; SHARED_RING_INIT ( netfront->rx_sring ); FRONT_RING_INIT ( &netfront->rx_fring, netfront->rx_sring, PAGE_SIZE ); assert ( RING_SIZE ( &netfront->rx_fring ) >= netfront->rx.count ); /* Create event channel */ if ( ( rc = netfront_create_event ( netfront ) ) != 0 ) goto err_create_event; /* "Request" the rx-copy feature. Current versions of * xen_netback.ko will fail silently if this parameter is not * present. */ if ( ( rc = netfront_write_flag ( netfront, "request-rx-copy" ) ) != 0 ) goto err_request_rx_copy; /* Disable checksum offload, since we will always do the work anyway */ if ( ( rc = netfront_write_flag ( netfront, "feature-no-csum-offload" ) ) != 0 ) goto err_feature_no_csum_offload; /* Inform backend that we will send notifications for RX requests */ if ( ( rc = netfront_write_flag ( netfront, "feature-rx-notify" ) ) != 0 ) goto err_feature_rx_notify; /* Set state to Connected */ if ( ( rc = xenbus_set_state ( xendev, XenbusStateConnected ) ) != 0 ) { DBGC ( netfront, "NETFRONT %s could not set state=\"%d\": %s\n", xendev->key, XenbusStateConnected, strerror ( rc ) ); goto err_set_state; } /* Wait for backend to connect */ if ( ( rc = xenbus_backend_wait ( xendev, XenbusStateConnected ) ) !=0){ DBGC ( netfront, "NETFRONT %s could not connect to backend: " "%s\n", xendev->key, strerror ( rc ) ); goto err_backend_wait; } /* Refill receive descriptor ring */ netfront_refill_rx ( netdev ); /* Set link up */ netdev_link_up ( netdev ); return 0; err_backend_wait: netfront_reset ( netfront ); err_set_state: netfront_rm ( netfront, "feature-rx-notify" ); err_feature_rx_notify: netfront_rm ( netfront, "feature-no-csum-offload" ); err_feature_no_csum_offload: netfront_rm ( netfront, "request-rx-copy" ); err_request_rx_copy: netfront_destroy_event ( netfront ); err_create_event: netfront_destroy_ring ( netfront, &netfront->rx, NULL ); err_create_rx: netfront_destroy_ring ( netfront, &netfront->tx, NULL ); err_create_tx: err_reset: return rc; }
/** * e1000_probe - Initial configuration of e1000 NIC * * @v pci PCI device * @v id PCI IDs * * @ret rc Return status code **/ int e1000_probe ( struct pci_device *pdev ) { int i, err; struct net_device *netdev; struct e1000_adapter *adapter; unsigned long mmio_start, mmio_len; DBG ( "e1000_probe\n" ); err = -ENOMEM; /* Allocate net device ( also allocates memory for netdev->priv and makes netdev-priv point to it ) */ netdev = alloc_etherdev ( sizeof ( struct e1000_adapter ) ); if ( ! netdev ) goto err_alloc_etherdev; /* Associate e1000-specific network operations operations with * generic network device layer */ netdev_init ( netdev, &e1000_operations ); /* Associate this network device with given PCI device */ pci_set_drvdata ( pdev, netdev ); netdev->dev = &pdev->dev; /* Initialize driver private storage */ adapter = netdev_priv ( netdev ); memset ( adapter, 0, ( sizeof ( *adapter ) ) ); adapter->pdev = pdev; adapter->ioaddr = pdev->ioaddr; adapter->hw.io_base = pdev->ioaddr; adapter->irqno = pdev->irq; adapter->netdev = netdev; adapter->hw.back = adapter; adapter->tx_ring_size = sizeof ( *adapter->tx_base ) * NUM_TX_DESC; adapter->rx_ring_size = sizeof ( *adapter->rx_base ) * NUM_RX_DESC; mmio_start = pci_bar_start ( pdev, PCI_BASE_ADDRESS_0 ); mmio_len = pci_bar_size ( pdev, PCI_BASE_ADDRESS_0 ); DBG ( "mmio_start: %#08lx\n", mmio_start ); DBG ( "mmio_len: %#08lx\n", mmio_len ); /* Fix up PCI device */ adjust_pci_device ( pdev ); err = -EIO; adapter->hw.hw_addr = ioremap ( mmio_start, mmio_len ); DBG ( "adapter->hw.hw_addr: %p\n", adapter->hw.hw_addr ); if ( ! adapter->hw.hw_addr ) goto err_ioremap; /* Hardware features, flags and workarounds */ if (adapter->hw.mac.type >= e1000_82540) { adapter->flags |= E1000_FLAG_HAS_SMBUS; adapter->flags |= E1000_FLAG_HAS_INTR_MODERATION; } if (adapter->hw.mac.type == e1000_82543) adapter->flags |= E1000_FLAG_BAD_TX_CARRIER_STATS_FD; adapter->hw.phy.autoneg_wait_to_complete = true; adapter->hw.mac.adaptive_ifs = true; /* setup the private structure */ if ( ( err = e1000_sw_init ( adapter ) ) ) goto err_sw_init; if ((err = e1000_init_mac_params(&adapter->hw))) goto err_hw_init; if ((err = e1000_init_nvm_params(&adapter->hw))) goto err_hw_init; /* Force auto-negotiated speed and duplex */ adapter->hw.mac.autoneg = 1; if ((err = e1000_init_phy_params(&adapter->hw))) goto err_hw_init; DBG ( "adapter->hw.mac.type: %#08x\n", adapter->hw.mac.type ); /* before reading the EEPROM, reset the controller to * put the device in a known good starting state */ err = e1000_reset_hw ( &adapter->hw ); if ( err < 0 ) { DBG ( "Hardware Initialization Failed\n" ); goto err_reset; } /* make sure the NVM is good */ if ( e1000_validate_nvm_checksum(&adapter->hw) < 0 ) { DBG ( "The NVM Checksum Is Not Valid\n" ); err = -EIO; goto err_eeprom; } /* copy the MAC address out of the EEPROM */ if ( e1000_read_mac_addr ( &adapter->hw ) ) DBG ( "EEPROM Read Error\n" ); memcpy ( netdev->hw_addr, adapter->hw.mac.perm_addr, ETH_ALEN ); /* reset the hardware with the new settings */ e1000_reset ( adapter ); if ( ( err = register_netdev ( netdev ) ) != 0) goto err_register; /* Mark as link up; we don't yet handle link state */ netdev_link_up ( netdev ); for (i = 0; i < 6; i++) DBG ("%02x%s", netdev->ll_addr[i], i == 5 ? "\n" : ":"); DBG ( "e1000_probe succeeded!\n" ); /* No errors, return success */ return 0; /* Error return paths */ err_reset: err_register: err_hw_init: err_eeprom: if (!e1000_check_reset_block(&adapter->hw)) e1000_phy_hw_reset(&adapter->hw); if (adapter->hw.flash_address) iounmap(adapter->hw.flash_address); err_sw_init: iounmap ( adapter->hw.hw_addr ); err_ioremap: netdev_put ( netdev ); err_alloc_etherdev: return err; }