aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDhananjay Phadke <dhananjay@netxen.com>2009-07-26 16:07:43 -0400
committerDavid S. Miller <davem@davemloft.net>2009-07-27 14:15:27 -0400
commitf17443f4b01659a5c44d5fc6f5c502c39c293959 (patch)
tree9ac3cdf3b3aaf16d211ba710a9418eda9435b45e /drivers
parent4f96b988e8d404b8b32aefed27503b4538949a3c (diff)
netxen: refactor net_device setup code
Move all net_device initialization into one function netxen_setup_netdev(). Signed-off-by: Dhananjay Phadke <dhananjay@netxen.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/netxen/netxen_nic_main.c138
1 files changed, 75 insertions, 63 deletions
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 5d52630ecd88..43a99f6a23df 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -66,7 +66,7 @@ static int netxen_nic_open(struct net_device *netdev);
66static int netxen_nic_close(struct net_device *netdev); 66static int netxen_nic_close(struct net_device *netdev);
67static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *); 67static int netxen_nic_xmit_frame(struct sk_buff *, struct net_device *);
68static void netxen_tx_timeout(struct net_device *netdev); 68static void netxen_tx_timeout(struct net_device *netdev);
69static void netxen_tx_timeout_task(struct work_struct *work); 69static void netxen_reset_task(struct work_struct *work);
70static void netxen_watchdog(unsigned long); 70static void netxen_watchdog(unsigned long);
71static int netxen_nic_poll(struct napi_struct *napi, int budget); 71static int netxen_nic_poll(struct napi_struct *napi, int budget);
72#ifdef CONFIG_NET_POLL_CONTROLLER 72#ifdef CONFIG_NET_POLL_CONTROLLER
@@ -182,7 +182,7 @@ netxen_napi_add(struct netxen_adapter *adapter, struct net_device *netdev)
182 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; 182 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
183 183
184 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) 184 if (netxen_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
185 return 1; 185 return -ENOMEM;
186 186
187 for (ring = 0; ring < adapter->max_sds_rings; ring++) { 187 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
188 sds_ring = &recv_ctx->sds_rings[ring]; 188 sds_ring = &recv_ctx->sds_rings[ring];
@@ -981,6 +981,68 @@ netxen_nic_detach(struct netxen_adapter *adapter)
981 adapter->is_up = 0; 981 adapter->is_up = 0;
982} 982}
983 983
984static int
985netxen_setup_netdev(struct netxen_adapter *adapter,
986 struct net_device *netdev)
987{
988 int err = 0;
989 struct pci_dev *pdev = adapter->pdev;
990
991 adapter->rx_csum = 1;
992 adapter->mc_enabled = 0;
993 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
994 adapter->max_mc_count = 38;
995 else
996 adapter->max_mc_count = 16;
997
998 netdev->netdev_ops = &netxen_netdev_ops;
999 netdev->watchdog_timeo = 2*HZ;
1000
1001 netxen_nic_change_mtu(netdev, netdev->mtu);
1002
1003 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1004
1005 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1006 netdev->features |= (NETIF_F_GRO);
1007 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1008
1009 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
1010 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1011 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1012 }
1013
1014 if (adapter->pci_using_dac) {
1015 netdev->features |= NETIF_F_HIGHDMA;
1016 netdev->vlan_features |= NETIF_F_HIGHDMA;
1017 }
1018
1019 netdev->irq = adapter->msix_entries[0].vector;
1020
1021 err = netxen_napi_add(adapter, netdev);
1022 if (err)
1023 return err;
1024
1025 init_timer(&adapter->watchdog_timer);
1026 adapter->watchdog_timer.function = &netxen_watchdog;
1027 adapter->watchdog_timer.data = (unsigned long)adapter;
1028 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
1029 INIT_WORK(&adapter->tx_timeout_task, netxen_reset_task);
1030
1031 if (netxen_read_mac_addr(adapter))
1032 dev_warn(&pdev->dev, "failed to read mac addr\n");
1033
1034 netif_carrier_off(netdev);
1035 netif_stop_queue(netdev);
1036
1037 err = register_netdev(netdev);
1038 if (err) {
1039 dev_err(&pdev->dev, "failed to register net device\n");
1040 return err;
1041 }
1042
1043 return 0;
1044}
1045
984static int __devinit 1046static int __devinit
985netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 1047netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
986{ 1048{
@@ -1018,9 +1080,8 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1018 1080
1019 netdev = alloc_etherdev(sizeof(struct netxen_adapter)); 1081 netdev = alloc_etherdev(sizeof(struct netxen_adapter));
1020 if(!netdev) { 1082 if(!netdev) {
1021 printk(KERN_ERR"%s: Failed to allocate memory for the " 1083 dev_err(&pdev->dev, "failed to allocate net_device\n");
1022 "device block.Check system memory resource" 1084 err = -ENOMEM;
1023 " usage.\n", netxen_nic_driver_name);
1024 goto err_out_free_res; 1085 goto err_out_free_res;
1025 } 1086 }
1026 1087
@@ -1048,38 +1109,10 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1048 1109
1049 /* This will be reset for mezz cards */ 1110 /* This will be reset for mezz cards */
1050 adapter->portnum = pci_func_id; 1111 adapter->portnum = pci_func_id;
1051 adapter->rx_csum = 1;
1052 adapter->mc_enabled = 0;
1053 if (NX_IS_REVISION_P3(revision_id))
1054 adapter->max_mc_count = 38;
1055 else
1056 adapter->max_mc_count = 16;
1057
1058 netdev->netdev_ops = &netxen_netdev_ops;
1059 netdev->watchdog_timeo = 2*HZ;
1060
1061 netxen_nic_change_mtu(netdev, netdev->mtu);
1062
1063 SET_ETHTOOL_OPS(netdev, &netxen_nic_ethtool_ops);
1064
1065 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1066 netdev->features |= (NETIF_F_GRO);
1067 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO);
1068
1069 if (NX_IS_REVISION_P3(revision_id)) {
1070 netdev->features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1071 netdev->vlan_features |= (NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
1072 }
1073
1074 if (adapter->pci_using_dac) {
1075 netdev->features |= NETIF_F_HIGHDMA;
1076 netdev->vlan_features |= NETIF_F_HIGHDMA;
1077 }
1078 1112
1079 if (netxen_nic_get_board_info(adapter) != 0) { 1113 err = netxen_nic_get_board_info(adapter);
1080 printk("%s: Error getting board config info.\n", 1114 if (err) {
1081 netxen_nic_driver_name); 1115 dev_err(&pdev->dev, "Error getting board config info.\n");
1082 err = -EIO;
1083 goto err_out_iounmap; 1116 goto err_out_iounmap;
1084 } 1117 }
1085 1118
@@ -1099,6 +1132,7 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1099 err = netxen_start_firmware(adapter, 1); 1132 err = netxen_start_firmware(adapter, 1);
1100 if (err) 1133 if (err)
1101 goto err_out_iounmap; 1134 goto err_out_iounmap;
1135
1102 /* 1136 /*
1103 * See if the firmware gave us a virtual-physical port mapping. 1137 * See if the firmware gave us a virtual-physical port mapping.
1104 */ 1138 */
@@ -1113,31 +1147,9 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1113 1147
1114 netxen_setup_intr(adapter); 1148 netxen_setup_intr(adapter);
1115 1149
1116 netdev->irq = adapter->msix_entries[0].vector; 1150 err = netxen_setup_netdev(adapter, netdev);
1117
1118 if (netxen_napi_add(adapter, netdev))
1119 goto err_out_disable_msi;
1120
1121 init_timer(&adapter->watchdog_timer);
1122 adapter->watchdog_timer.function = &netxen_watchdog;
1123 adapter->watchdog_timer.data = (unsigned long)adapter;
1124 INIT_WORK(&adapter->watchdog_task, netxen_watchdog_task);
1125 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
1126
1127 err = netxen_read_mac_addr(adapter);
1128 if (err) 1151 if (err)
1129 dev_warn(&pdev->dev, "failed to read mac addr\n");
1130
1131 netif_carrier_off(netdev);
1132 netif_stop_queue(netdev);
1133
1134 if ((err = register_netdev(netdev))) {
1135 printk(KERN_ERR "%s: register_netdev failed port #%d"
1136 " aborting\n", netxen_nic_driver_name,
1137 adapter->portnum);
1138 err = -EIO;
1139 goto err_out_disable_msi; 1152 goto err_out_disable_msi;
1140 }
1141 1153
1142 pci_set_drvdata(pdev, adapter); 1154 pci_set_drvdata(pdev, adapter);
1143 1155
@@ -1656,10 +1668,13 @@ static void netxen_tx_timeout(struct net_device *netdev)
1656{ 1668{
1657 struct netxen_adapter *adapter = (struct netxen_adapter *) 1669 struct netxen_adapter *adapter = (struct netxen_adapter *)
1658 netdev_priv(netdev); 1670 netdev_priv(netdev);
1671
1672 dev_err(&netdev->dev, "transmit timeout, resetting.\n");
1673
1659 SCHEDULE_WORK(&adapter->tx_timeout_task); 1674 SCHEDULE_WORK(&adapter->tx_timeout_task);
1660} 1675}
1661 1676
1662static void netxen_tx_timeout_task(struct work_struct *work) 1677static void netxen_reset_task(struct work_struct *work)
1663{ 1678{
1664 struct netxen_adapter *adapter = 1679 struct netxen_adapter *adapter =
1665 container_of(work, struct netxen_adapter, tx_timeout_task); 1680 container_of(work, struct netxen_adapter, tx_timeout_task);
@@ -1667,9 +1682,6 @@ static void netxen_tx_timeout_task(struct work_struct *work)
1667 if (!netif_running(adapter->netdev)) 1682 if (!netif_running(adapter->netdev))
1668 return; 1683 return;
1669 1684
1670 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
1671 netxen_nic_driver_name, adapter->netdev->name);
1672
1673 netxen_napi_disable(adapter); 1685 netxen_napi_disable(adapter);
1674 1686
1675 adapter->netdev->trans_start = jiffies; 1687 adapter->netdev->trans_start = jiffies;