📄 e100_main.c
字号:
if(ret >= 0) {#ifdef CONFIG_PM register_reboot_notifier(&e100_notifier_reboot);#endif } return ret;}static void __exite100_cleanup_module(void){#ifdef CONFIG_PM unregister_reboot_notifier(&e100_notifier_reboot);#endif pci_unregister_driver(&e100_driver);}module_init(e100_init_module);module_exit(e100_cleanup_module);/** * e100_check_options - check command line options * @board: board number * @bdp: atapter's private data struct * * This routine does range checking on command-line options */void __devinite100_check_options(int board, struct e100_private *bdp){ if (board >= E100_MAX_NIC) { printk(KERN_NOTICE "e100: No configuration available for board #%d\n", board); printk(KERN_NOTICE "e100: Using defaults for all values\n"); board = E100_MAX_NIC; } e100_set_int_option(&(bdp->params.TxDescriptors), TxDescriptors[board], E100_MIN_TCB, E100_MAX_TCB, E100_DEFAULT_TCB, "TxDescriptor count"); e100_set_int_option(&(bdp->params.RxDescriptors), RxDescriptors[board], E100_MIN_RFD, E100_MAX_RFD, E100_DEFAULT_RFD, "RxDescriptor count"); e100_set_int_option(&(bdp->params.e100_speed_duplex), e100_speed_duplex[board], 0, 4, E100_DEFAULT_SPEED_DUPLEX, "speed/duplex mode"); e100_set_int_option(&(bdp->params.ber), ber[board], 0, ZLOCK_MAX_ERRORS, E100_DEFAULT_BER, "Bit Error Rate count"); e100_set_bool_option(bdp, XsumRX[board], PRM_XSUMRX, E100_DEFAULT_XSUM, "XsumRX value"); /* Default ucode value depended on controller revision */ if (bdp->rev_id >= D101MA_REV_ID) { e100_set_bool_option(bdp, ucode[board], PRM_UCODE, E100_DEFAULT_UCODE, "ucode value"); } else { e100_set_bool_option(bdp, ucode[board], PRM_UCODE, false, "ucode value"); } e100_set_bool_option(bdp, flow_control[board], PRM_FC, E100_DEFAULT_FC, "flow control value"); e100_set_bool_option(bdp, IFS[board], PRM_IFS, E100_DEFAULT_IFS, "IFS value"); e100_set_bool_option(bdp, BundleSmallFr[board], PRM_BUNDLE_SMALL, E100_DEFAULT_BUNDLE_SMALL_FR, "CPU saver bundle small frames value"); e100_set_int_option(&(bdp->params.IntDelay), IntDelay[board], 0x0, 0xFFFF, E100_DEFAULT_CPUSAVER_INTERRUPT_DELAY, "CPU saver interrupt delay value"); e100_set_int_option(&(bdp->params.BundleMax), BundleMax[board], 0x1, 0xFFFF, E100_DEFAULT_CPUSAVER_BUNDLE_MAX, "CPU saver bundle max value");}/** * e100_set_int_option - check and set an integer option * @option: a pointer to the relevant option field * @val: the value specified * @min: the minimum valid value * @max: the maximum valid value * @default_val: the default value * @name: the name of the option * * This routine does range checking on a command-line option. * If the option's value is '-1' use the specified default. * Otherwise, if the value is invalid, change it to the default. */void __devinite100_set_int_option(int *option, int val, int min, int max, int default_val, char *name){ if (val == -1) { /* no value specified. use default */ *option = default_val; } else if ((val < min) || (val > max)) { printk(KERN_NOTICE "e100: Invalid %s specified (%i). " "Valid range is %i-%i\n", name, val, min, max); printk(KERN_NOTICE "e100: Using default %s of %i\n", name, default_val); *option = default_val; } else { printk(KERN_INFO "e100: Using specified %s of %i\n", name, val); *option = val; }}/** * e100_set_bool_option - check and set a boolean option * @bdp: atapter's private data struct * @val: the value specified * @mask: the mask for the relevant option * @default_val: the default value * @name: the name of the option * * This routine checks a boolean command-line option. * If the option's value is '-1' use the specified default. * Otherwise, if the value is invalid (not 0 or 1), * change it to the default. */void __devinite100_set_bool_option(struct e100_private *bdp, int val, u32 mask, int default_val, char *name){ if (val == -1) { if (default_val) bdp->params.b_params |= mask; } else if ((val != true) && (val != false)) { printk(KERN_NOTICE "e100: Invalid %s specified (%i). " "Valid values are %i/%i\n", name, val, false, true); printk(KERN_NOTICE "e100: Using default %s of %i\n", name, default_val); if (default_val) bdp->params.b_params |= mask; } else { printk(KERN_INFO "e100: Using specified %s of %i\n", name, val); if (val) bdp->params.b_params |= mask; }}inte100_open(struct net_device *dev){ struct e100_private *bdp; int rc = 0; bdp = dev->priv; /* setup the tcb pool */ if (!e100_alloc_tcb_pool(bdp)) { rc = -ENOMEM; goto err_exit; } bdp->last_tcb = NULL; bdp->tcb_pool.head = 0; bdp->tcb_pool.tail = 1; e100_setup_tcb_pool((tcb_t *) bdp->tcb_pool.data, bdp->params.TxDescriptors, bdp); if (!e100_alloc_rfd_pool(bdp)) { rc = -ENOMEM; goto err_exit; } if (!e100_wait_exec_cmplx(bdp, 0, SCB_CUC_LOAD_BASE, 0)) { rc = -EAGAIN; goto err_exit; } if (!e100_wait_exec_cmplx(bdp, 0, SCB_RUC_LOAD_BASE, 0)) { rc = -EAGAIN; goto err_exit; } mod_timer(&(bdp->watchdog_timer), jiffies + (2 * HZ)); if (dev->flags & IFF_UP) /* Otherwise process may sleep forever */ netif_wake_queue(dev); else netif_start_queue(dev); e100_start_ru(bdp); if ((rc = request_irq(dev->irq, &e100intr, SA_SHIRQ, dev->name, dev)) != 0) { del_timer_sync(&bdp->watchdog_timer); goto err_exit; } bdp->intr_mask = 0; e100_set_intr_mask(bdp); e100_force_config(bdp); goto exit;err_exit: e100_clear_pools(bdp);exit: return rc;}inte100_close(struct net_device *dev){ struct e100_private *bdp = dev->priv; e100_disable_clear_intr(bdp); free_irq(dev->irq, dev); bdp->intr_mask = SCB_INT_MASK; e100_isolate_driver(bdp); netif_carrier_off(bdp->device); bdp->cur_line_speed = 0; bdp->cur_dplx_mode = 0; e100_clear_pools(bdp); return 0;}static inte100_change_mtu(struct net_device *dev, int new_mtu){ if ((new_mtu < 68) || (new_mtu > (ETH_DATA_LEN + VLAN_SIZE))) return -EINVAL; dev->mtu = new_mtu; return 0;}static inte100_xmit_frame(struct sk_buff *skb, struct net_device *dev){ int rc = 0; int notify_stop = false; struct e100_private *bdp = dev->priv; if (!spin_trylock(&bdp->bd_non_tx_lock)) { notify_stop = true; rc = 1; goto exit2; } /* tcb list may be empty temporarily during releasing resources */ if (!TCBS_AVAIL(bdp->tcb_pool) || (bdp->tcb_phys == 0) || (bdp->non_tx_command_state != E100_NON_TX_IDLE)) { notify_stop = true; rc = 1; goto exit1; }#ifdef E100_IA64_DMA_FIX if ((u64) skb->head >= (PAGE_OFFSET + 0x100000000UL)) skb_linearize(skb, GFP_ATOMIC | GFP_DMA);#endif bdp->drv_stats.net_stats.tx_bytes += skb->len; e100_prepare_xmit_buff(bdp, skb); dev->trans_start = jiffies;exit1: spin_unlock(&bdp->bd_non_tx_lock);exit2: if (notify_stop) { netif_stop_queue(dev); } return rc;}/** * e100_get_stats - get driver statistics * @dev: adapter's net_device struct * * This routine is called when the OS wants the adapter's stats returned. * It returns the address of the net_device_stats stucture for the device. * If the statistics are currently being updated, then they might be incorrect * for a short while. However, since this cannot actually cause damage, no * locking is used. */struct net_device_stats *e100_get_stats(struct net_device *dev){ struct e100_private *bdp = dev->priv; bdp->drv_stats.net_stats.tx_errors = bdp->drv_stats.net_stats.tx_carrier_errors + bdp->drv_stats.net_stats.tx_aborted_errors; bdp->drv_stats.net_stats.rx_errors = bdp->drv_stats.net_stats.rx_crc_errors + bdp->drv_stats.net_stats.rx_frame_errors + bdp->drv_stats.net_stats.rx_length_errors + bdp->drv_stats.rcv_cdt_frames; return &(bdp->drv_stats.net_stats);}/** * e100_set_mac - set the MAC address * @dev: adapter's net_device struct * @addr: the new address * * This routine sets the ethernet address of the board * Returns: * 0 - if successful * -1 - otherwise */static inte100_set_mac(struct net_device *dev, void *addr){ struct e100_private *bdp; int rc = -1; struct sockaddr *p_sockaddr = (struct sockaddr *) addr; if (!is_valid_ether_addr(p_sockaddr->sa_data)) return -EADDRNOTAVAIL; bdp = dev->priv; if (e100_setup_iaaddr(bdp, (u8 *) (p_sockaddr->sa_data))) { memcpy(&(dev->dev_addr[0]), p_sockaddr->sa_data, ETH_ALEN); rc = 0; } return rc;}static voide100_set_multi_exec(struct net_device *dev){ struct e100_private *bdp = dev->priv; mltcst_cb_t *mcast_buff; cb_header_t *cb_hdr; struct dev_mc_list *mc_list; unsigned int i; nxmit_cb_entry_t *cmd = e100_alloc_non_tx_cmd(bdp); if (cmd != NULL) { mcast_buff = &((cmd->non_tx_cmd)->ntcb.multicast); cb_hdr = &((cmd->non_tx_cmd)->ntcb.multicast.mc_cbhdr); } else { return; } /* initialize the multi cast command */ cb_hdr->cb_cmd = __constant_cpu_to_le16(CB_MULTICAST); /* now fill in the rest of the multicast command */ *(u16 *) (&(mcast_buff->mc_count)) = cpu_to_le16(dev->mc_count * 6); for (i = 0, mc_list = dev->mc_list; (i < dev->mc_count) && (i < MAX_MULTICAST_ADDRS); i++, mc_list = mc_list->next) { /* copy into the command */ memcpy(&(mcast_buff->mc_addr[i * ETH_ALEN]), (u8 *) &(mc_list->dmi_addr), ETH_ALEN); } if (!e100_exec_non_cu_cmd(bdp, cmd)) { printk(KERN_WARNING "e100: %s: Multicast setup failed\n", dev->name); }}/** * e100_set_multi - set multicast status * @dev: adapter's net_device struct * * This routine is called to add or remove multicast addresses, and/or to * change the adapter's promiscuous state. */static voide100_set_multi(struct net_device *dev){ struct e100_private *bdp = dev->priv; unsigned char promisc_enbl; unsigned char mulcast_enbl; promisc_enbl = ((dev->flags & IFF_PROMISC) == IFF_PROMISC); mulcast_enbl = ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > MAX_MULTICAST_ADDRS)); e100_config_promisc(bdp, promisc_enbl); e100_config_mulcast_enbl(bdp, mulcast_enbl); /* reconfigure the chip if something has changed in its config space */ e100_config(bdp); if (promisc_enbl || mulcast_enbl) { return; /* no need for Multicast Cmd */ } /* get the multicast CB */ e100_set_multi_exec(dev);}static inte100_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd){ switch (cmd) {#ifdef SIOCETHTOOL case SIOCETHTOOL: return e100_do_ethtool_ioctl(dev, ifr); break;#endif /*SIOCETHTOOL */#ifdef SIOCGMIIPHY case SIOCGMIIPHY: /* Get address of MII PHY in use. */ case SIOCGMIIREG: /* Read MII PHY register. */ case SIOCSMIIREG: /* Write to MII PHY register. */ return e100_mii_ioctl(dev, ifr, cmd); break;#endif /* SIOCGMIIPHY */ default: return -EOPNOTSUPP; } return 0;}/** * e100init - initialize the adapter * @bdp: atapter's private data struct * * This routine is called when this driver is loaded. This is the initialization * routine which allocates memory, configures the adapter and determines the * system resources. * * Returns: * true: if successful * false: otherwise */static unsigned char __devinite100_init(struct e100_private *bdp){ u32 st_timeout = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -