if (sp->device_type & XFRAME_II_DEVICE) { dev->features |= NETIF_F_UFO; dev->features |= NETIF_F_HW_CSUM; } 
s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre){	nic_t *sp;	struct net_device *dev;	int i, j, ret;	int dma_flag = FALSE;	u32 mac_up, mac_down;	u64 val64 = 0, tmp64 = 0;	XENA_dev_config_t __iomem *bar0 = NULL;	u16 subid;	mac_info_t *mac_control;	struct config_param *config;	int mode;	u8 dev_intr_type = intr_type;#ifdef CONFIG_S2IO_NAPI	if (dev_intr_type != INTA) {		DBG_PRINT(ERR_DBG, "NAPI cannot be enabled when MSI/MSI-X \is enabled. Defaulting to INTA\n");		dev_intr_type = INTA;	}	else		DBG_PRINT(ERR_DBG, "NAPI support has been enabled\n");#endif	if ((ret = pci_enable_device(pdev))) {		DBG_PRINT(ERR_DBG,			  "s2io_init_nic: pci_enable_device failed\n");		return ret;	}	if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {		DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n");		dma_flag = TRUE;		if (pci_set_consistent_dma_mask		    (pdev, DMA_64BIT_MASK)) {			DBG_PRINT(ERR_DBG,				  "Unable to obtain 64bit DMA for \					consistent allocations\n");			pci_disable_device(pdev);			return -ENOMEM;		}	} else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {		DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n");	} else {		pci_disable_device(pdev);		return -ENOMEM;	}	if ((dev_intr_type == MSI_X) && 			((pdev->device != PCI_DEVICE_ID_HERC_WIN) &&			(pdev->device != PCI_DEVICE_ID_HERC_UNI))) {		DBG_PRINT(ERR_DBG, "Xframe I does not support MSI_X. \Defaulting to INTA\n");		dev_intr_type = INTA;	}	if (dev_intr_type != MSI_X) {		if (pci_request_regions(pdev, s2io_driver_name)) {			DBG_PRINT(ERR_DBG, "Request Regions failed\n"),			    pci_disable_device(pdev);			return -ENODEV;		}	}	else {		if (!(request_mem_region(pci_resource_start(pdev, 0),               	         pci_resource_len(pdev, 0), s2io_driver_name))) {			DBG_PRINT(ERR_DBG, "bar0 Request Regions failed\n");			pci_disable_device(pdev);			return -ENODEV;		}        	if (!(request_mem_region(pci_resource_start(pdev, 2),               	         pci_resource_len(pdev, 2), s2io_driver_name))) {			DBG_PRINT(ERR_DBG, "bar1 Request Regions failed\n");                	release_mem_region(pci_resource_start(pdev, 0),                                   pci_resource_len(pdev, 0));			pci_disable_device(pdev);			return -ENODEV;		}	}	dev = alloc_etherdev(sizeof(nic_t));	if (dev == NULL) {		DBG_PRINT(ERR_DBG, "Device allocation failed\n");		pci_disable_device(pdev);		pci_release_regions(pdev);		return -ENODEV;	}	pci_set_master(pdev);	pci_set_drvdata(pdev, dev);	SET_MODULE_OWNER(dev);	SET_NETDEV_DEV(dev, &pdev->dev);	/*  Private member variable initialized to s2io NIC structure */	sp = dev->priv;	memset(sp, 0, sizeof(nic_t));	sp->dev = dev;	sp->pdev = pdev;	sp->high_dma_flag = dma_flag;	sp->device_enabled_once = FALSE;	if (rx_ring_mode == 1)		sp->rxd_mode = RXD_MODE_1;	if (rx_ring_mode == 2)		sp->rxd_mode = RXD_MODE_3B;	if (rx_ring_mode == 3)		sp->rxd_mode = RXD_MODE_3A;	sp->intr_type = dev_intr_type;	if ((pdev->device == PCI_DEVICE_ID_HERC_WIN) ||		(pdev->device == PCI_DEVICE_ID_HERC_UNI))		sp->device_type = XFRAME_II_DEVICE;	else		sp->device_type = XFRAME_I_DEVICE;			/* Initialize some PCI/PCI-X fields of the NIC. */	s2io_init_pci(sp);	/*	 * Setting the device configuration parameters.	 * Most of these parameters can be specified by the user during	 * module insertion as they are module loadable parameters. If	 * these parameters are not not specified during load time, they	 * are initialized with default values.	 */	mac_control = &sp->mac_control;	config = &sp->config;	/* Tx side parameters. */	if (tx_fifo_len[0] == 0)		tx_fifo_len[0] = DEFAULT_FIFO_LEN; /* Default value. */	config->tx_fifo_num = tx_fifo_num;	for (i = 0; i < MAX_TX_FIFOS; i++) {		config->tx_cfg[i].fifo_len = tx_fifo_len[i];		config->tx_cfg[i].fifo_priority = i;	}	/* mapping the QoS priority to the configured fifos */	for (i = 0; i < MAX_TX_FIFOS; i++)		config->fifo_mapping[i] = fifo_map[config->tx_fifo_num][i];	config->tx_intr_type = TXD_INT_TYPE_UTILZ;	for (i = 0; i < config->tx_fifo_num; i++) {		config->tx_cfg[i].f_no_snoop =		    (NO_SNOOP_TXD | NO_SNOOP_TXD_BUFFER);		if (config->tx_cfg[i].fifo_len < 65) {			config->tx_intr_type = TXD_INT_TYPE_PER_LIST;			break;		}	}	config->max_txds = MAX_SKB_FRAGS + 1;	/* Rx side parameters. */	if (rx_ring_sz[0] == 0)		rx_ring_sz[0] = SMALL_BLK_CNT; /* Default value. */	config->rx_ring_num = rx_ring_num;	for (i = 0; i < MAX_RX_RINGS; i++) {		config->rx_cfg[i].num_rxd = rx_ring_sz[i] *		    (rxd_count[sp->rxd_mode] + 1);		config->rx_cfg[i].ring_priority = i;	}	for (i = 0; i < rx_ring_num; i++) {		config->rx_cfg[i].ring_org = RING_ORG_BUFF1;		config->rx_cfg[i].f_no_snoop =		    (NO_SNOOP_RXD | NO_SNOOP_RXD_BUFFER);	}	/*  Setting Mac Control parameters */	mac_control->rmac_pause_time = rmac_pause_time;	mac_control->mc_pause_threshold_q0q3 = mc_pause_threshold_q0q3;	mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7;	/* Initialize Ring buffer parameters. */	for (i = 0; i < config->rx_ring_num; i++)		atomic_set(&sp->rx_bufs_left[i], 0);	/* Initialize the number of ISRs currently running */	atomic_set(&sp->isr_cnt, 0);	/*  initialize the shared memory used by the NIC and the host */	if (init_shared_mem(sp)) {		DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n",			  __FUNCTION__);		ret = -ENOMEM;		goto mem_alloc_failed;	}	sp->bar0 = ioremap(pci_resource_start(pdev, 0),				     pci_resource_len(pdev, 0));	if (!sp->bar0) {		DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem1\n",			  dev->name);		ret = -ENOMEM;		goto bar0_remap_failed;	}	sp->bar1 = ioremap(pci_resource_start(pdev, 2),				     pci_resource_len(pdev, 2));	if (!sp->bar1) {		DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem2\n",			  dev->name);		ret = -ENOMEM;		goto bar1_remap_failed;	}	dev->irq = pdev->irq;	dev->base_addr = (unsigned long) sp->bar0;	/* Initializing the BAR1 address as the start of the FIFO pointer. */	for (j = 0; j < MAX_TX_FIFOS; j++) {		mac_control->tx_FIFO_start[j] = (TxFIFO_element_t __iomem *)		    (sp->bar1 + (j * 0x00020000));	}	/*  Driver entry points */	dev->open = &s2io_open;	dev->stop = &s2io_close;	dev->hard_start_xmit = &s2io_xmit;	dev->get_stats = &s2io_get_stats;	dev->set_multicast_list = &s2io_set_multicast;	dev->do_ioctl = &s2io_ioctl;	dev->change_mtu = &s2io_change_mtu;	SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);	dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;	dev->vlan_rx_register = s2io_vlan_rx_register;	dev->vlan_rx_kill_vid = (void *)s2io_vlan_rx_kill_vid;	/*	 * will use eth_mac_addr() for  dev->set_mac_address	 * mac address will be set every time dev->open() is called	 */#if defined(CONFIG_S2IO_NAPI)	dev->poll = s2io_poll;	dev->weight = 32;#endif	dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;	if (sp->high_dma_flag == TRUE)		dev->features |= NETIF_F_HIGHDMA;#ifdef NETIF_F_TSO	dev->features |= NETIF_F_TSO;#endif	dev->tx_timeout = &s2io_tx_watchdog;	dev->watchdog_timeo = WATCH_DOG_TIMEOUT;	INIT_WORK(&sp->rst_timer_task,		  (void (*)(void *)) s2io_restart_nic, dev);	INIT_WORK(&sp->set_link_task,		  (void (*)(void *)) s2io_set_link, sp);	pci_save_state(sp->pdev);	/* Setting swapper control on the NIC, for proper reset operation */	if (s2io_set_swapper(sp)) {		DBG_PRINT(ERR_DBG, "%s:swapper settings are wrong\n",			  dev->name);		ret = -EAGAIN;		goto set_swap_failed;	}	/* Verify if the Herc works on the slot its placed into */	if (sp->device_type & XFRAME_II_DEVICE) {		mode = s2io_verify_pci_mode(sp);		if (mode < 0) {			DBG_PRINT(ERR_DBG, "%s: ", __FUNCTION__);			DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");			ret = -EBADSLT;			goto set_swap_failed;		}	}	/* Not needed for Herc */	if (sp->device_type & XFRAME_I_DEVICE) {		/*		 * Fix for all "FFs" MAC address problems observed on		 * Alpha platforms		 */		fix_mac_address(sp);		s2io_reset(sp);	}	/*	 * MAC address initialization.	 * For now only one mac address will be read and used.	 */	bar0 = sp->bar0;	val64 = RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |	    RMAC_ADDR_CMD_MEM_OFFSET(0 + MAC_MAC_ADDR_START_OFFSET);	writeq(val64, &bar0->rmac_addr_cmd_mem);	wait_for_cmd_complete(sp);	tmp64 = readq(&bar0->rmac_addr_data0_mem);	mac_down = (u32) tmp64;	mac_up = (u32) (tmp64 >> 32);	memset(sp->def_mac_addr[0].mac_addr, 0, sizeof(ETH_ALEN));	sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up);	sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8);	sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16);	sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_up >> 24);	sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_down >> 16);	sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_down >> 24);	/*  Set the factory defined MAC address initially   */	dev->addr_len = ETH_ALEN;	memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN);	/*	 * Initialize the tasklet status and link state flags	 * and the card state parameter	 */	atomic_set(&(sp->card_state), 0);	sp->tasklet_status = 0;	sp->link_state = 0;	/* Initialize spinlocks */	spin_lock_init(&sp->tx_lock);#ifndef CONFIG_S2IO_NAPI	spin_lock_init(&sp->put_lock);#endif	spin_lock_init(&sp->rx_lock);	/*	 * SXE-002: Configure link and activity LED to init state	 * on driver load.	 */	subid = sp->pdev->subsystem_device;	if ((subid & 0xFF) >= 0x07) {		val64 = readq(&bar0->gpio_control);		val64 |= 0x0000800000000000ULL;		writeq(val64, &bar0->gpio_control);		val64 = 0x0411040400000000ULL;		writeq(val64, (void __iomem *) bar0 + 0x2700);		val64 = readq(&bar0->gpio_control);	}	sp->rx_csum = 1;	/* Rx chksum verify enabled by default */	if (register_netdev(dev)) {		DBG_PRINT(ERR_DBG, "Device registration failed\n");		ret = -ENODEV;		goto register_failed;	}	if (sp->device_type & XFRAME_II_DEVICE) {		DBG_PRINT(ERR_DBG, "%s: Neterion Xframe II 10GbE adapter ",			  dev->name);		DBG_PRINT(ERR_DBG, "(rev %d), Version %s",				get_xena_rev_id(sp->pdev),				s2io_driver_version);		switch(sp->intr_type) {			case INTA:				DBG_PRINT(ERR_DBG, ", Intr type INTA");				break;			case MSI:				DBG_PRINT(ERR_DBG, ", Intr type MSI");				break;			case MSI_X:				DBG_PRINT(ERR_DBG, ", Intr type MSI-X");				break;		}		DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n");		DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",			  sp->def_mac_addr[0].mac_addr[0],			  sp->def_mac_addr[0].mac_addr[1],			  sp->def_mac_addr[0].mac_addr[2],			  sp->def_mac_addr[0].mac_addr[3],			  sp->def_mac_addr[0].mac_addr[4],			  sp->def_mac_addr[0].mac_addr[5]);		mode = s2io_print_pci_mode(sp);		if (mode < 0) {			DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode ");			ret = -EBADSLT;			goto set_swap_failed;		}	} else {		DBG_PRINT(ERR_DBG, "%s: Neterion Xframe I 10GbE adapter ",			  dev->name);		DBG_PRINT(ERR_DBG, "(rev %d), Version %s",					get_xena_rev_id(sp->pdev),					s2io_driver_version);		switch(sp->intr_type) {			case INTA:				DBG_PRINT(ERR_DBG, ", Intr type INTA");				break;			case MSI:				DBG_PRINT(ERR_DBG, ", Intr type MSI");				break;			case MSI_X:				DBG_PRINT(ERR_DBG, ", Intr type MSI-X");				break;		}		DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n");		DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",			  sp->def_mac_addr[0].mac_addr[0],			  sp->def_mac_addr[0].mac_addr[1],			  sp->def_mac_addr[0].mac_addr[2],			  sp->def_mac_addr[0].mac_addr[3],			  sp->def_mac_addr[0].mac_addr[4],			  sp->def_mac_addr[0].mac_addr[5]);	}	if (sp->rxd_mode == RXD_MODE_3B)		DBG_PRINT(ERR_DBG, "%s: 2-Buffer mode support has been "			  "enabled\n",dev->name);	if (sp->rxd_mode == RXD_MODE_3A)		DBG_PRINT(ERR_DBG, "%s: 3-Buffer mode support has been "			  "enabled\n",dev->name);	/* Initialize device name */	strcpy(sp->name, dev->name);	if (sp->device_type & XFRAME_II_DEVICE)		strcat(sp->name, ": Neterion Xframe II 10GbE adapter");	else		strcat(sp->name, ": Neterion Xframe I 10GbE adapter");	/* Initialize bimodal Interrupts */	sp->config.bimodal = bimodal;	if (!(sp->device_type & XFRAME_II_DEVICE) && bimodal) {		sp->config.bimodal = 0;		DBG_PRINT(ERR_DBG,"%s:Bimodal intr not supported by Xframe I\n",			dev->name);	}	/*	 * Make Link state as off at this point, when the Link change	 * interrupt comes the state will be automatically changed to	 * the right state.	 */	netif_carrier_off(dev);	return 0;      register_failed:      set_swap_failed:	iounmap(sp->bar1);      bar1_remap_failed:	iounmap(sp->bar0);      bar0_remap_failed:      mem_alloc_failed:	free_shared_mem(sp);	pci_disable_device(pdev);	if (dev_intr_type != MSI_X)		pci_release_regions(pdev);	else {		release_mem_region(pci_resource_start(pdev, 0),			pci_resource_len(pdev, 0));		release_mem_region(pci_resource_start(pdev, 2),			pci_resource_len(pdev, 2));	}	pci_set_drvdata(pdev, NULL);	free_netdev(dev);	return ret;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/fed5eccdcf542742786701b2514b5cb7ab282b93/s2io.c/clean/drivers/net/s2io.c