void
hxge_hw_init_niu_common(p_hxge_t hxgep)
{
	p_hxge_hw_list_t hw_p;

	HXGE_DEBUG_MSG((hxgep, DDI_CTL, "==> hxge_hw_init_niu_common"));

	if ((hw_p = hxgep->hxge_hw_p) == NULL) {
		return;
	}

	MUTEX_ENTER(&hw_p->hxge_cfg_lock);
	if (hw_p->flags & COMMON_INIT_DONE) {
		HXGE_DEBUG_MSG((hxgep, MOD_CTL, "hxge_hw_init_niu_common"
		    " already done for dip $%p exiting", hw_p->parent_devp));
		MUTEX_EXIT(&hw_p->hxge_cfg_lock);
		return;
	}

	hw_p->flags = COMMON_INIT_START;
	HXGE_DEBUG_MSG((hxgep, MOD_CTL,
	    "hxge_hw_init_niu_common Started for device id %x",
	    hw_p->parent_devp));

	(void) hxge_pfc_hw_reset(hxgep);
	hw_p->flags = COMMON_INIT_DONE;
	MUTEX_EXIT(&hw_p->hxge_cfg_lock);

	HXGE_DEBUG_MSG((hxgep, MOD_CTL,
	    "hxge_hw_init_niu_common Done for device id %x",
	    hw_p->parent_devp));
	HXGE_DEBUG_MSG((hxgep, DDI_CTL, "<== hxge_hw_init_niu_common"));
}
Exemple #2
0
static int
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 13)
__devinit
#endif
hxge_probe(struct pci_dev *pdev,
            const struct pci_device_id *ent)
{
	struct net_device *netdev;
	struct hxge_adapter *adapter;
	static int cards_found = 0;
	int err, pci_using_dac;

	if ((err = pci_enable_device(pdev)))
	{
		HXGE_ERR_PRINT("hxge_probe: Failed to (PCI) enable device");
		return err;
	}

	/* Hydra can address up to 44-bits of physical memory. Let the
           kernel know */
	if (!(err = pci_set_dma_mask(pdev, HXGE_MAX_ADDRESS_BITS_MASK)) &&
	    !(err = pci_set_consistent_dma_mask(pdev, HXGE_MAX_ADDRESS_BITS_MASK))) {
		pci_using_dac = 1;
	} else {
		if ((err = pci_set_dma_mask(pdev, DMA_MASK)) &&
		    (err = pci_set_consistent_dma_mask(pdev, DMA_MASK))) {
			HXGE_ERR_PRINT("No usable DMA configuration, aborting");
			goto err_dma;
		}
		pci_using_dac = 0;
	}

	if ((err = pci_request_regions(pdev, HXGE_DRIVER_NAME)))
		goto err_pci_reg;

	pci_set_master(pdev);

	err = -ENOMEM;
	netdev = alloc_etherdev(sizeof(struct hxge_adapter));
	if (!netdev)
		goto err_alloc_etherdev;

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
	SET_MODULE_OWNER(netdev);
#endif

	SET_NETDEV_DEV(netdev, &pdev->dev);

	pci_set_drvdata(pdev, netdev);
	adapter = netdev_priv(netdev);
	adapter->netdev = netdev;
	adapter->pdev = pdev;
	adapter->msg_enable = debug;

	if (hxge_map_registers(netdev) < 0)
		goto err_mapfailed;

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
	netdev->open = &hxge_open;
	netdev->stop = &hxge_close;
	netdev->hard_start_xmit = &hxge_start_xmit;
	netdev->get_stats = &hxge_get_stats;
	netdev->set_multicast_list = &hxge_set_multi;
	netdev->set_mac_address = &hxge_set_mac_address;
	netdev->change_mtu = &hxge_change_mtu;
	netdev->do_ioctl = &hxge_ioctl;
	netdev->tx_timeout = &hxge_tx_timeout;
	netdev->vlan_rx_register = hxge_vlan_rx_register;
	netdev->vlan_rx_add_vid = hxge_vlan_rx_add_vid;
	netdev->vlan_rx_kill_vid = hxge_vlan_rx_kill_vid;
#ifdef CONFIG_NET_POLL_CONTROLLER
	netdev->poll_controller = hxge_netpoll;
#endif
#else
	netdev->netdev_ops = &hxge_netdev_ops;
#endif

	hxge_set_ethtool_ops(netdev);
#ifdef CONFIG_HXGE_NAPI
	netdev->poll = &hxge_poll;
	netdev->weight = 64;
#endif
	netdev->watchdog_timeo = HXGE_TX_TIMEOUT;
	strncpy(netdev->name, pci_name(pdev), strlen(pci_name(pdev)));

	adapter->bd_number = cards_found;

	HXGE_DBG(adapter, "Allocated adapter");

	/* Initialize locks */
	hxge_init_locks(adapter);
	HXGE_DBG(adapter, "Got Locks");

	/* Get the driver parameters */
	if (hxge_init_param(adapter))
		goto err_register;
	HXGE_DBG(adapter, "Initialized parameter list");

	/* setup the private structure */
	if ((err = hxge_sw_init(adapter)))
		goto err_sw_init;
	HXGE_DBG(adapter, "Initialized hxgep with parameters");

        if (hxge_pfc_hw_reset(adapter))
        {
                HXGE_ERR(adapter, "hxge_probe: Failed hxge_pfc_hw_reset");
                goto err_register;
        }
	HXGE_DBG(adapter, "Reset the HW");

	/* Initialize link management */
	hxge_init_link(adapter);
	HXGE_DBG(adapter, "Initialized the link");

	/* Initialize and set up statistics for the device */
	hxge_init_stats(adapter);
	HXGE_DBG(adapter, "Initialized stats");

	err = -EIO;

	if (pci_using_dac)
		netdev->features |= NETIF_F_HIGHDMA;

	/* We have to provide our own locking for transmit */
	netdev->features |= NETIF_F_LLTX;
	netdev->features |= NETIF_F_SG;


	if (adapter->flags & HXGE_TX_CHKSUM_ENABLED)
		netdev->features |= (NETIF_F_IP_CSUM
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
				| NETIF_F_IPV6_CSUM
#endif
				);


	if (adapter->flags & HXGE_VLAN_ENABLED)
		netdev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;


	/* copy the MAC address from the PFC block; all 16 of them */
	if (hxge_pfc_init_mac_addrs(adapter)) {
		HXGE_ERR(adapter, "EEPROM Read Error");
		goto err_sw_init;
	}
	HXGE_DBG(adapter, "Initialized MAC addresses");

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
	INIT_WORK(&adapter->work_to_do,
		(void (*)(void *))hxge_work_to_do, adapter);
#else
	INIT_WORK(&adapter->work_to_do, hxge_work_to_do);
#endif

	/* we're going to reset the device because we have no clue what
           state we find it in */
	netif_carrier_off(netdev);
	netif_stop_queue(netdev);

	strcpy(netdev->name, "eth%d");
	if ((err = register_netdev(netdev)))
		goto err_register;

	HXGE_DBG(adapter, "hxge_probe: SMI(R) 10 Gb Ethernet Network Connection");

#ifdef CONFIG_ERRINJECT
	hxge_create_sysfs(netdev);
#endif
	cards_found++;
	set_bit (HXGE_DEVICE_INITIALIZED, &adapter->state);
	return 0;

err_register:
err_sw_init:
	iounmap(adapter->hw.hw_addr);
err_mapfailed:
	free_netdev(netdev);
err_alloc_etherdev:
	pci_release_regions(pdev);
err_pci_reg:
err_dma:
	pci_disable_device(pdev);
	return err;
}