Commit f17443f4 authored by Dhananjay Phadke's avatar Dhananjay Phadke Committed by David S. Miller

netxen: refactor net_device setup code

Move all net_device initialization into one function
netxen_setup_netdev().
Signed-off-by: default avatarDhananjay Phadke <dhananjay@netxen.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4f96b988
...@@ -66,7 +66,7 @@ static int netxen_nic_open(struct net_device *netdev); ...@@ -66,7 +66,7 @@ static int netxen_nic_open(struct net_device *netdev);
static int netxen_nic_close(struct net_device *netdev); static int netxen_nic_close(struct net_device *netdev);
static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *); static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *);
static void netxen_tx_timeout(struct net_device *netdev); static void netxen_tx_timeout(struct net_device *netdev);
static void netxen_tx_timeout_task(struct work_struct *work); static void netxen_reset_task(struct work_struct *work);
static void netxen_watchdog(unsigned long); static void netxen_watchdog(unsigned long);
static int netxen_nic_poll(struct napi_struct *napi, int budget); static int netxen_nic_poll(struct napi_struct *napi, int budget);
#ifdef CONFIG_NET_POLL_CONTROLLER #ifdef CONFIG_NET_POLL_CONTROLLER
...@@ -182,7 +182,7 @@ netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev) ...@@ -182,7 +182,7 @@ netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
return 1; return -ENOMEM;
for (ring = 0; ring < adapter->max_sds_rings; ring++) { for (ring = 0; ring < adapter->max_sds_rings; ring++) {
sds_ring = &recv_ctx->sds_rings[ring]; sds_ring = &recv_ctx->sds_rings[ring];
...@@ -981,6 +981,68 @@ netxen_nic_detach(struct netxen_adapter *adapter) ...@@ -981,6 +981,68 @@ netxen_nic_detach(struct netxen_adapter *adapter)
adapter->is_up = 0; adapter->is_up = 0;
} }
static int
netxen_setup_netdev(struct netxen_adapter *adapter,
struct net_device *netdev)
{
int err = 0;
struct pci_dev *pdev = adapter->pdev;
adapter->rx_csum = 1;
adapter->mc_enabled = 0;
if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
adapter->max_mc_count = 38;
else
adapter->max_mc_count = 16;
netdev->netdev_ops = &netxen_netdev_ops;
netdev->watchdog_timeo = 2*HZ;
netxen_nic_change_mtu(netdev, netdev->mtu);
SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
netdev->features |= (NETIF_F_GRO);
netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
}
if (adapter->pci_using_dac) {
netdev->features |= NETIF_F_HIGHDMA;
netdev->vlan_features |= NETIF_F_HIGHDMA;
}
netdev->irq = adapter->msix_entries[0].vector;
err = netxen_napi_add(adapter, netdev);
if (err)
return err;
init_timer(&adapter->watchdog_timer);
adapter->watchdog_timer.function = &netxen_watchdog;
adapter->watchdog_timer.data = (unsigned long)adapter;
INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task);
if (netxen_read_mac_addr(adapter))
dev_warn(&pdev->dev, "failed to read mac addr\n");
netif_carrier_off(netdev);
netif_stop_queue(netdev);
err = register_netdev(netdev);
if (err) {
dev_err(&pdev->dev, "failed to register net device\n");
return err;
}
return 0;
}
static int __devinit static int __devinit
netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
{ {
...@@ -1018,9 +1080,8 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1018,9 +1080,8 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
netdev = alloc_etherdev(sizeof(struct netxen_adapter)); netdev = alloc_etherdev(sizeof(struct netxen_adapter));
if(!netdev) { if(!netdev) {
printk(KERN_ERR"%s: Failed to allocate memory for the " dev_err(&pdev->dev, "failed to allocate net_device\n");
"device block.Check system memory resource" err = -ENOMEM;
" usage.\n", netxen_nic_driver_name);
goto err_out_free_res; goto err_out_free_res;
} }
...@@ -1048,38 +1109,10 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1048,38 +1109,10 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
/* This will be reset for mezz cards */ /* This will be reset for mezz cards */
adapter->portnum = pci_func_id; adapter->portnum = pci_func_id;
adapter->rx_csum = 1;
adapter->mc_enabled = 0;
if (NX_IS_REVISION_P3(revision_id))
adapter->max_mc_count = 38;
else
adapter->max_mc_count = 16;
netdev->netdev_ops = &netxen_netdev_ops;
netdev->watchdog_timeo = 2*HZ;
netxen_nic_change_mtu(netdev, netdev->mtu);
SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
netdev->features |= (NETIF_F_GRO);
netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
if (NX_IS_REVISION_P3(revision_id)) {
netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
}
if (adapter->pci_using_dac) {
netdev->features |= NETIF_F_HIGHDMA;
netdev->vlan_features |= NETIF_F_HIGHDMA;
}
if (netxen_nic_get_board_info(adapter) != 0) { err = netxen_nic_get_board_info(adapter);
printk("%s: Error getting board config info.\n", if (err) {
netxen_nic_driver_name); dev_err(&pdev->dev, "Error getting board config info.\n");
err = -EIO;
goto err_out_iounmap; goto err_out_iounmap;
} }
...@@ -1099,6 +1132,7 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1099,6 +1132,7 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
err = netxen_start_firmware(adapter, 1); err = netxen_start_firmware(adapter, 1);
if (err) if (err)
goto err_out_iounmap; goto err_out_iounmap;
/* /*
* See if the firmware gave us a virtual-physical port mapping. * See if the firmware gave us a virtual-physical port mapping.
*/ */
...@@ -1113,31 +1147,9 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1113,31 +1147,9 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
netxen_setup_intr(adapter); netxen_setup_intr(adapter);
netdev->irq = adapter->msix_entries[0].vector; err = netxen_setup_netdev(adapter, netdev);
if (netxen_napi_add(adapter, netdev))
goto err_out_disable_msi;
init_timer(&adapter->watchdog_timer);
adapter->watchdog_timer.function = &netxen_watchdog;
adapter->watchdog_timer.data = (unsigned long)adapter;
INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
err = netxen_read_mac_addr(adapter);
if (err) if (err)
dev_warn(&pdev->dev, "failed to read mac addr\n");
netif_carrier_off(netdev);
netif_stop_queue(netdev);
if ((err = register_netdev(netdev))) {
printk(KERN_ERR "%s: register_netdev failed port #%d"
" aborting\n", netxen_nic_driver_name,
adapter->portnum);
err = -EIO;
goto err_out_disable_msi; goto err_out_disable_msi;
}
pci_set_drvdata(pdev, adapter); pci_set_drvdata(pdev, adapter);
...@@ -1656,10 +1668,13 @@ static void netxen_tx_timeout(struct net_device *netdev) ...@@ -1656,10 +1668,13 @@ static void netxen_tx_timeout(struct net_device *netdev)
{ {
struct netxen_adapter *adapter = (struct netxen_adapter *) struct netxen_adapter *adapter = (struct netxen_adapter *)
netdev_priv(netdev); netdev_priv(netdev);
dev_err(&netdev->dev, "transmit timeout, resetting.\n");
SCHEDULE_WORK(&adapter->tx_timeout_task); SCHEDULE_WORK(&adapter->tx_timeout_task);
} }
static void netxen_tx_timeout_task(struct work_struct *work) static void netxen_reset_task(struct work_struct *work)
{ {
struct netxen_adapter *adapter = struct netxen_adapter *adapter =
container_of(work, struct netxen_adapter, tx_timeout_task); container_of(work, struct netxen_adapter, tx_timeout_task);
...@@ -1667,9 +1682,6 @@ static void netxen_tx_timeout_task(struct work_struct *work) ...@@ -1667,9 +1682,6 @@ static void netxen_tx_timeout_task(struct work_struct *work)
if (!netif_running(adapter->netdev)) if (!netif_running(adapter->netdev))
return; return;
printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
netxen_nic_driver_name, adapter->netdev->name);
netxen_napi_disable(adapter); netxen_napi_disable(adapter);
adapter->netdev->trans_start = jiffies; adapter->netdev->trans_start = jiffies;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment