aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/qlcnic/qlcnic_main.c
diff options
context:
space:
mode:
authorAnirban Chakraborty <anirban.chakraborty@qlogic.com>2011-04-01 10:28:05 -0400
committerDavid S. Miller <davem@davemloft.net>2011-04-06 15:47:11 -0400
commitb1fc6d3cfaff6fefd838b84532cb356f8a80da7b (patch)
treecb453fc6ff25043aac738d84a56a9fd65a8715eb /drivers/net/qlcnic/qlcnic_main.c
parentf848d6dd10e8e27d5dd61a8ab7174a7dde3a3db5 (diff)
qlcnic: Cleanup patch
1. Changed adapter structure to move away from embedding hardware and receive context structs and use pointers to those objects 2. Packed all the structs that interface with FW 3. Removed unused code and structs Signed-off-by: Anirban Chakraborty <anirban.chakraborty@qlogic.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/qlcnic/qlcnic_main.c')
-rw-r--r--drivers/net/qlcnic/qlcnic_main.c158
1 files changed, 99 insertions, 59 deletions
diff --git a/drivers/net/qlcnic/qlcnic_main.c b/drivers/net/qlcnic/qlcnic_main.c
index de6f86681a3c..dde7e4403830 100644
--- a/drivers/net/qlcnic/qlcnic_main.c
+++ b/drivers/net/qlcnic/qlcnic_main.c
@@ -113,7 +113,7 @@ static DEFINE_PCI_DEVICE_TABLE(qlcnic_pci_tbl) = {
113MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl); 113MODULE_DEVICE_TABLE(pci, qlcnic_pci_tbl);
114 114
115 115
116void 116inline void
117qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter, 117qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter,
118 struct qlcnic_host_tx_ring *tx_ring) 118 struct qlcnic_host_tx_ring *tx_ring)
119{ 119{
@@ -169,7 +169,7 @@ qlcnic_napi_add(struct qlcnic_adapter *adapter, struct net_device *netdev)
169{ 169{
170 int ring; 170 int ring;
171 struct qlcnic_host_sds_ring *sds_ring; 171 struct qlcnic_host_sds_ring *sds_ring;
172 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; 172 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
173 173
174 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings)) 174 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
175 return -ENOMEM; 175 return -ENOMEM;
@@ -193,14 +193,14 @@ qlcnic_napi_del(struct qlcnic_adapter *adapter)
193{ 193{
194 int ring; 194 int ring;
195 struct qlcnic_host_sds_ring *sds_ring; 195 struct qlcnic_host_sds_ring *sds_ring;
196 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; 196 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
197 197
198 for (ring = 0; ring < adapter->max_sds_rings; ring++) { 198 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
199 sds_ring = &recv_ctx->sds_rings[ring]; 199 sds_ring = &recv_ctx->sds_rings[ring];
200 netif_napi_del(&sds_ring->napi); 200 netif_napi_del(&sds_ring->napi);
201 } 201 }
202 202
203 qlcnic_free_sds_rings(&adapter->recv_ctx); 203 qlcnic_free_sds_rings(adapter->recv_ctx);
204} 204}
205 205
206static void 206static void
@@ -208,7 +208,7 @@ qlcnic_napi_enable(struct qlcnic_adapter *adapter)
208{ 208{
209 int ring; 209 int ring;
210 struct qlcnic_host_sds_ring *sds_ring; 210 struct qlcnic_host_sds_ring *sds_ring;
211 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; 211 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
212 212
213 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 213 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
214 return; 214 return;
@@ -225,7 +225,7 @@ qlcnic_napi_disable(struct qlcnic_adapter *adapter)
225{ 225{
226 int ring; 226 int ring;
227 struct qlcnic_host_sds_ring *sds_ring; 227 struct qlcnic_host_sds_ring *sds_ring;
228 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; 228 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
229 229
230 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC) 230 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
231 return; 231 return;
@@ -359,7 +359,7 @@ qlcnic_setup_intr(struct qlcnic_adapter *adapter)
359 struct pci_dev *pdev = adapter->pdev; 359 struct pci_dev *pdev = adapter->pdev;
360 int err, num_msix; 360 int err, num_msix;
361 361
362 if (adapter->rss_supported) { 362 if (adapter->msix_supported) {
363 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ? 363 num_msix = (num_online_cpus() >= MSIX_ENTRIES_PER_ADAPTER) ?
364 MSIX_ENTRIES_PER_ADAPTER : 2; 364 MSIX_ENTRIES_PER_ADAPTER : 2;
365 } else 365 } else
@@ -369,7 +369,7 @@ qlcnic_setup_intr(struct qlcnic_adapter *adapter)
369 369
370 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED); 370 adapter->flags &= ~(QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED);
371 371
372 legacy_intrp = &legacy_intr[adapter->ahw.pci_func]; 372 legacy_intrp = &legacy_intr[adapter->ahw->pci_func];
373 373
374 adapter->int_vec_bit = legacy_intrp->int_vec_bit; 374 adapter->int_vec_bit = legacy_intrp->int_vec_bit;
375 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, 375 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
@@ -391,8 +391,7 @@ qlcnic_setup_intr(struct qlcnic_adapter *adapter)
391 adapter->flags |= QLCNIC_MSIX_ENABLED; 391 adapter->flags |= QLCNIC_MSIX_ENABLED;
392 qlcnic_set_msix_bit(pdev, 1); 392 qlcnic_set_msix_bit(pdev, 1);
393 393
394 if (adapter->rss_supported) 394 adapter->max_sds_rings = num_msix;
395 adapter->max_sds_rings = num_msix;
396 395
397 dev_info(&pdev->dev, "using msi-x interrupts\n"); 396 dev_info(&pdev->dev, "using msi-x interrupts\n");
398 return; 397 return;
@@ -407,7 +406,7 @@ qlcnic_setup_intr(struct qlcnic_adapter *adapter)
407 if (use_msi && !pci_enable_msi(pdev)) { 406 if (use_msi && !pci_enable_msi(pdev)) {
408 adapter->flags |= QLCNIC_MSI_ENABLED; 407 adapter->flags |= QLCNIC_MSI_ENABLED;
409 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter, 408 adapter->tgt_status_reg = qlcnic_get_ioaddr(adapter,
410 msi_tgt_status[adapter->ahw.pci_func]); 409 msi_tgt_status[adapter->ahw->pci_func]);
411 dev_info(&pdev->dev, "using msi interrupts\n"); 410 dev_info(&pdev->dev, "using msi interrupts\n");
412 adapter->msix_entries[0].vector = pdev->irq; 411 adapter->msix_entries[0].vector = pdev->irq;
413 return; 412 return;
@@ -429,8 +428,8 @@ qlcnic_teardown_intr(struct qlcnic_adapter *adapter)
429static void 428static void
430qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter) 429qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
431{ 430{
432 if (adapter->ahw.pci_base0 != NULL) 431 if (adapter->ahw->pci_base0 != NULL)
433 iounmap(adapter->ahw.pci_base0); 432 iounmap(adapter->ahw->pci_base0);
434} 433}
435 434
436static int 435static int
@@ -500,7 +499,7 @@ qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
500 u32 ref_count; 499 u32 ref_count;
501 int i, ret = 1; 500 int i, ret = 1;
502 u32 data = QLCNIC_MGMT_FUNC; 501 u32 data = QLCNIC_MGMT_FUNC;
503 void __iomem *priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; 502 void __iomem *priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE;
504 503
505 /* If other drivers are not in use set their privilege level */ 504 /* If other drivers are not in use set their privilege level */
506 ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE); 505 ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
@@ -512,16 +511,16 @@ qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
512 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 511 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
513 id = i; 512 id = i;
514 if (adapter->npars[i].type != QLCNIC_TYPE_NIC || 513 if (adapter->npars[i].type != QLCNIC_TYPE_NIC ||
515 id == adapter->ahw.pci_func) 514 id == adapter->ahw->pci_func)
516 continue; 515 continue;
517 data |= (qlcnic_config_npars & 516 data |= (qlcnic_config_npars &
518 QLC_DEV_SET_DRV(0xf, id)); 517 QLC_DEV_SET_DRV(0xf, id));
519 } 518 }
520 } else { 519 } else {
521 data = readl(priv_op); 520 data = readl(priv_op);
522 data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw.pci_func)) | 521 data = (data & ~QLC_DEV_SET_DRV(0xf, adapter->ahw->pci_func)) |
523 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC, 522 (QLC_DEV_SET_DRV(QLCNIC_MGMT_FUNC,
524 adapter->ahw.pci_func)); 523 adapter->ahw->pci_func));
525 } 524 }
526 writel(data, priv_op); 525 writel(data, priv_op);
527 qlcnic_api_unlock(adapter); 526 qlcnic_api_unlock(adapter);
@@ -539,22 +538,23 @@ qlcnic_check_vf(struct qlcnic_adapter *adapter)
539 u32 op_mode, priv_level; 538 u32 op_mode, priv_level;
540 539
541 /* Determine FW API version */ 540 /* Determine FW API version */
542 adapter->fw_hal_version = readl(adapter->ahw.pci_base0 + QLCNIC_FW_API); 541 adapter->fw_hal_version = readl(adapter->ahw->pci_base0 +
542 QLCNIC_FW_API);
543 543
544 /* Find PCI function number */ 544 /* Find PCI function number */
545 pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func); 545 pci_read_config_dword(adapter->pdev, QLCNIC_MSIX_TABLE_OFFSET, &func);
546 msix_base_addr = adapter->ahw.pci_base0 + QLCNIC_MSIX_BASE; 546 msix_base_addr = adapter->ahw->pci_base0 + QLCNIC_MSIX_BASE;
547 msix_base = readl(msix_base_addr); 547 msix_base = readl(msix_base_addr);
548 func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE; 548 func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE;
549 adapter->ahw.pci_func = func; 549 adapter->ahw->pci_func = func;
550 550
551 /* Determine function privilege level */ 551 /* Determine function privilege level */
552 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; 552 priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE;
553 op_mode = readl(priv_op); 553 op_mode = readl(priv_op);
554 if (op_mode == QLC_DEV_DRV_DEFAULT) 554 if (op_mode == QLC_DEV_DRV_DEFAULT)
555 priv_level = QLCNIC_MGMT_FUNC; 555 priv_level = QLCNIC_MGMT_FUNC;
556 else 556 else
557 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func); 557 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
558 558
559 if (priv_level == QLCNIC_NON_PRIV_FUNC) { 559 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
560 adapter->op_mode = QLCNIC_NON_PRIV_FUNC; 560 adapter->op_mode = QLCNIC_NON_PRIV_FUNC;
@@ -593,13 +593,14 @@ qlcnic_setup_pci_map(struct qlcnic_adapter *adapter)
593 593
594 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20)); 594 dev_info(&pdev->dev, "%dMB memory map\n", (int)(mem_len>>20));
595 595
596 adapter->ahw.pci_base0 = mem_ptr0; 596 adapter->ahw->pci_base0 = mem_ptr0;
597 adapter->ahw.pci_len0 = pci_len0; 597 adapter->ahw->pci_len0 = pci_len0;
598 598
599 qlcnic_check_vf(adapter); 599 qlcnic_check_vf(adapter);
600 600
601 adapter->ahw.ocm_win_crb = qlcnic_get_ioaddr(adapter, 601 adapter->ahw->ocm_win_crb = qlcnic_get_ioaddr(adapter,
602 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter->ahw.pci_func))); 602 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(
603 adapter->ahw->pci_func)));
603 604
604 return 0; 605 return 0;
605} 606}
@@ -641,7 +642,7 @@ qlcnic_check_options(struct qlcnic_adapter *adapter)
641 642
642 dev_info(&pdev->dev, "firmware v%d.%d.%d\n", 643 dev_info(&pdev->dev, "firmware v%d.%d.%d\n",
643 fw_major, fw_minor, fw_build); 644 fw_major, fw_minor, fw_build);
644 if (adapter->ahw.port_type == QLCNIC_XGBE) { 645 if (adapter->ahw->port_type == QLCNIC_XGBE) {
645 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 646 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
646 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF; 647 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_VF;
647 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF; 648 adapter->max_rxd = MAX_RCV_DESCRIPTORS_VF;
@@ -653,7 +654,7 @@ qlcnic_check_options(struct qlcnic_adapter *adapter)
653 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 654 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
654 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G; 655 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_10G;
655 656
656 } else if (adapter->ahw.port_type == QLCNIC_GBE) { 657 } else if (adapter->ahw->port_type == QLCNIC_GBE) {
657 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G; 658 adapter->num_rxd = DEFAULT_RCV_DESCRIPTORS_1G;
658 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 659 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
659 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 660 adapter->max_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
@@ -661,7 +662,6 @@ qlcnic_check_options(struct qlcnic_adapter *adapter)
661 } 662 }
662 663
663 adapter->msix_supported = !!use_msi_x; 664 adapter->msix_supported = !!use_msi_x;
664 adapter->rss_supported = !!use_msi_x;
665 665
666 adapter->num_txd = MAX_CMD_DESCRIPTORS; 666 adapter->num_txd = MAX_CMD_DESCRIPTORS;
667 667
@@ -674,7 +674,7 @@ qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
674 int err; 674 int err;
675 struct qlcnic_info nic_info; 675 struct qlcnic_info nic_info;
676 676
677 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw.pci_func); 677 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw->pci_func);
678 if (err) 678 if (err)
679 return err; 679 return err;
680 680
@@ -736,7 +736,7 @@ qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
736 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) 736 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
737 return 0; 737 return 0;
738 738
739 esw_cfg.pci_func = adapter->ahw.pci_func; 739 esw_cfg.pci_func = adapter->ahw->pci_func;
740 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg)) 740 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
741 return -EIO; 741 return -EIO;
742 qlcnic_set_vlan_config(adapter, &esw_cfg); 742 qlcnic_set_vlan_config(adapter, &esw_cfg);
@@ -793,14 +793,14 @@ qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
793 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED) 793 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
794 return 0; 794 return 0;
795 795
796 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; 796 priv_op = adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE;
797 op_mode = readl(priv_op); 797 op_mode = readl(priv_op);
798 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func); 798 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
799 799
800 if (op_mode == QLC_DEV_DRV_DEFAULT) 800 if (op_mode == QLC_DEV_DRV_DEFAULT)
801 priv_level = QLCNIC_MGMT_FUNC; 801 priv_level = QLCNIC_MGMT_FUNC;
802 else 802 else
803 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func); 803 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw->pci_func);
804 804
805 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) { 805 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
806 if (priv_level == QLCNIC_MGMT_FUNC) { 806 if (priv_level == QLCNIC_MGMT_FUNC) {
@@ -1040,7 +1040,7 @@ qlcnic_request_irq(struct qlcnic_adapter *adapter)
1040 1040
1041 unsigned long flags = 0; 1041 unsigned long flags = 0;
1042 struct net_device *netdev = adapter->netdev; 1042 struct net_device *netdev = adapter->netdev;
1043 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; 1043 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1044 1044
1045 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { 1045 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1046 handler = qlcnic_tmp_intr; 1046 handler = qlcnic_tmp_intr;
@@ -1077,7 +1077,7 @@ qlcnic_free_irq(struct qlcnic_adapter *adapter)
1077 int ring; 1077 int ring;
1078 struct qlcnic_host_sds_ring *sds_ring; 1078 struct qlcnic_host_sds_ring *sds_ring;
1079 1079
1080 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; 1080 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1081 1081
1082 for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1082 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1083 sds_ring = &recv_ctx->sds_rings[ring]; 1083 sds_ring = &recv_ctx->sds_rings[ring];
@@ -1117,14 +1117,14 @@ __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
1117 return -EIO; 1117 return -EIO;
1118 1118
1119 for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1119 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1120 rds_ring = &adapter->recv_ctx.rds_rings[ring]; 1120 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1121 qlcnic_post_rx_buffers(adapter, ring, rds_ring); 1121 qlcnic_post_rx_buffers(adapter, rds_ring);
1122 } 1122 }
1123 1123
1124 qlcnic_set_multi(netdev); 1124 qlcnic_set_multi(netdev);
1125 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu); 1125 qlcnic_fw_cmd_set_mtu(adapter, netdev->mtu);
1126 1126
1127 adapter->ahw.linkup = 0; 1127 adapter->ahw->linkup = 0;
1128 1128
1129 if (adapter->max_sds_rings > 1) 1129 if (adapter->max_sds_rings > 1)
1130 qlcnic_config_rss(adapter, 1); 1130 qlcnic_config_rss(adapter, 1);
@@ -1274,7 +1274,7 @@ void qlcnic_diag_free_res(struct net_device *netdev, int max_sds_rings)
1274 clear_bit(__QLCNIC_DEV_UP, &adapter->state); 1274 clear_bit(__QLCNIC_DEV_UP, &adapter->state);
1275 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { 1275 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1276 for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1276 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1277 sds_ring = &adapter->recv_ctx.sds_rings[ring]; 1277 sds_ring = &adapter->recv_ctx->sds_rings[ring];
1278 qlcnic_disable_int(sds_ring); 1278 qlcnic_disable_int(sds_ring);
1279 } 1279 }
1280 } 1280 }
@@ -1295,6 +1295,39 @@ out:
1295 netif_device_attach(netdev); 1295 netif_device_attach(netdev);
1296} 1296}
1297 1297
1298static int qlcnic_alloc_adapter_resources(struct qlcnic_adapter *adapter)
1299{
1300 int err = 0;
1301 adapter->ahw = kzalloc(sizeof(struct qlcnic_hardware_context),
1302 GFP_KERNEL);
1303 if (!adapter->ahw) {
1304 dev_err(&adapter->pdev->dev,
1305 "Failed to allocate recv ctx resources for adapter\n");
1306 err = -ENOMEM;
1307 goto err_out;
1308 }
1309 adapter->recv_ctx = kzalloc(sizeof(struct qlcnic_recv_context),
1310 GFP_KERNEL);
1311 if (!adapter->recv_ctx) {
1312 dev_err(&adapter->pdev->dev,
1313 "Failed to allocate recv ctx resources for adapter\n");
1314 kfree(adapter->ahw);
1315 adapter->ahw = NULL;
1316 err = -ENOMEM;
1317 }
1318err_out:
1319 return err;
1320}
1321
1322static void qlcnic_free_adapter_resources(struct qlcnic_adapter *adapter)
1323{
1324 kfree(adapter->recv_ctx);
1325 adapter->recv_ctx = NULL;
1326
1327 kfree(adapter->ahw);
1328 adapter->ahw = NULL;
1329}
1330
1298int qlcnic_diag_alloc_res(struct net_device *netdev, int test) 1331int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1299{ 1332{
1300 struct qlcnic_adapter *adapter = netdev_priv(netdev); 1333 struct qlcnic_adapter *adapter = netdev_priv(netdev);
@@ -1327,13 +1360,13 @@ int qlcnic_diag_alloc_res(struct net_device *netdev, int test)
1327 } 1360 }
1328 1361
1329 for (ring = 0; ring < adapter->max_rds_rings; ring++) { 1362 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1330 rds_ring = &adapter->recv_ctx.rds_rings[ring]; 1363 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1331 qlcnic_post_rx_buffers(adapter, ring, rds_ring); 1364 qlcnic_post_rx_buffers(adapter, rds_ring);
1332 } 1365 }
1333 1366
1334 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) { 1367 if (adapter->diag_test == QLCNIC_INTERRUPT_TEST) {
1335 for (ring = 0; ring < adapter->max_sds_rings; ring++) { 1368 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1336 sds_ring = &adapter->recv_ctx.sds_rings[ring]; 1369 sds_ring = &adapter->recv_ctx->sds_rings[ring];
1337 qlcnic_enable_int(sds_ring); 1370 qlcnic_enable_int(sds_ring);
1338 } 1371 }
1339 } 1372 }
@@ -1503,23 +1536,26 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1503 adapter = netdev_priv(netdev); 1536 adapter = netdev_priv(netdev);
1504 adapter->netdev = netdev; 1537 adapter->netdev = netdev;
1505 adapter->pdev = pdev; 1538 adapter->pdev = pdev;
1506 adapter->dev_rst_time = jiffies;
1507 1539
1540 if (qlcnic_alloc_adapter_resources(adapter))
1541 goto err_out_free_netdev;
1542
1543 adapter->dev_rst_time = jiffies;
1508 revision_id = pdev->revision; 1544 revision_id = pdev->revision;
1509 adapter->ahw.revision_id = revision_id; 1545 adapter->ahw->revision_id = revision_id;
1510 1546
1511 rwlock_init(&adapter->ahw.crb_lock); 1547 rwlock_init(&adapter->ahw->crb_lock);
1512 mutex_init(&adapter->ahw.mem_lock); 1548 mutex_init(&adapter->ahw->mem_lock);
1513 1549
1514 spin_lock_init(&adapter->tx_clean_lock); 1550 spin_lock_init(&adapter->tx_clean_lock);
1515 INIT_LIST_HEAD(&adapter->mac_list); 1551 INIT_LIST_HEAD(&adapter->mac_list);
1516 1552
1517 err = qlcnic_setup_pci_map(adapter); 1553 err = qlcnic_setup_pci_map(adapter);
1518 if (err) 1554 if (err)
1519 goto err_out_free_netdev; 1555 goto err_out_free_hw;
1520 1556
1521 /* This will be reset for mezz cards */ 1557 /* This will be reset for mezz cards */
1522 adapter->portnum = adapter->ahw.pci_func; 1558 adapter->portnum = adapter->ahw->pci_func;
1523 1559
1524 err = qlcnic_get_board_info(adapter); 1560 err = qlcnic_get_board_info(adapter);
1525 if (err) { 1561 if (err) {
@@ -1547,7 +1583,7 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1547 1583
1548 pr_info("%s: %s Board Chip rev 0x%x\n", 1584 pr_info("%s: %s Board Chip rev 0x%x\n",
1549 module_name(THIS_MODULE), 1585 module_name(THIS_MODULE),
1550 brd_name, adapter->ahw.revision_id); 1586 brd_name, adapter->ahw->revision_id);
1551 } 1587 }
1552 1588
1553 qlcnic_clear_stats(adapter); 1589 qlcnic_clear_stats(adapter);
@@ -1562,7 +1598,7 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1562 1598
1563 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 1599 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
1564 1600
1565 switch (adapter->ahw.port_type) { 1601 switch (adapter->ahw->port_type) {
1566 case QLCNIC_GBE: 1602 case QLCNIC_GBE:
1567 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n", 1603 dev_info(&adapter->pdev->dev, "%s: GbE port initialized\n",
1568 adapter->netdev->name); 1604 adapter->netdev->name);
@@ -1587,6 +1623,9 @@ err_out_decr_ref:
1587err_out_iounmap: 1623err_out_iounmap:
1588 qlcnic_cleanup_pci_map(adapter); 1624 qlcnic_cleanup_pci_map(adapter);
1589 1625
1626err_out_free_hw:
1627 qlcnic_free_adapter_resources(adapter);
1628
1590err_out_free_netdev: 1629err_out_free_netdev:
1591 free_netdev(netdev); 1630 free_netdev(netdev);
1592 1631
@@ -1640,6 +1679,7 @@ static void __devexit qlcnic_remove(struct pci_dev *pdev)
1640 pci_disable_device(pdev); 1679 pci_disable_device(pdev);
1641 pci_set_drvdata(pdev, NULL); 1680 pci_set_drvdata(pdev, NULL);
1642 1681
1682 qlcnic_free_adapter_resources(adapter);
1643 free_netdev(netdev); 1683 free_netdev(netdev);
1644} 1684}
1645static int __qlcnic_shutdown(struct pci_dev *pdev) 1685static int __qlcnic_shutdown(struct pci_dev *pdev)
@@ -2248,16 +2288,16 @@ void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
2248{ 2288{
2249 struct net_device *netdev = adapter->netdev; 2289 struct net_device *netdev = adapter->netdev;
2250 2290
2251 if (adapter->ahw.linkup && !linkup) { 2291 if (adapter->ahw->linkup && !linkup) {
2252 netdev_info(netdev, "NIC Link is down\n"); 2292 netdev_info(netdev, "NIC Link is down\n");
2253 adapter->ahw.linkup = 0; 2293 adapter->ahw->linkup = 0;
2254 if (netif_running(netdev)) { 2294 if (netif_running(netdev)) {
2255 netif_carrier_off(netdev); 2295 netif_carrier_off(netdev);
2256 netif_stop_queue(netdev); 2296 netif_stop_queue(netdev);
2257 } 2297 }
2258 } else if (!adapter->ahw.linkup && linkup) { 2298 } else if (!adapter->ahw->linkup && linkup) {
2259 netdev_info(netdev, "NIC Link is up\n"); 2299 netdev_info(netdev, "NIC Link is up\n");
2260 adapter->ahw.linkup = 1; 2300 adapter->ahw->linkup = 1;
2261 if (netif_running(netdev)) { 2301 if (netif_running(netdev)) {
2262 netif_carrier_on(netdev); 2302 netif_carrier_on(netdev);
2263 netif_wake_queue(netdev); 2303 netif_wake_queue(netdev);
@@ -2493,7 +2533,7 @@ static void qlcnic_poll_controller(struct net_device *netdev)
2493 int ring; 2533 int ring;
2494 struct qlcnic_host_sds_ring *sds_ring; 2534 struct qlcnic_host_sds_ring *sds_ring;
2495 struct qlcnic_adapter *adapter = netdev_priv(netdev); 2535 struct qlcnic_adapter *adapter = netdev_priv(netdev);
2496 struct qlcnic_recv_context *recv_ctx = &adapter->recv_ctx; 2536 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2497 2537
2498 disable_irq(adapter->irq); 2538 disable_irq(adapter->irq);
2499 for (ring = 0; ring < adapter->max_sds_rings; ring++) { 2539 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
@@ -3503,7 +3543,7 @@ validate_esw_config(struct qlcnic_adapter *adapter,
3503 u8 pci_func; 3543 u8 pci_func;
3504 int i; 3544 int i;
3505 3545
3506 op_mode = readl(adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE); 3546 op_mode = readl(adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE);
3507 3547
3508 for (i = 0; i < count; i++) { 3548 for (i = 0; i < count; i++) {
3509 pci_func = esw_cfg[i].pci_func; 3549 pci_func = esw_cfg[i].pci_func;
@@ -3569,13 +3609,13 @@ qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj,
3569 if (qlcnic_config_switch_port(adapter, &esw_cfg[i])) 3609 if (qlcnic_config_switch_port(adapter, &esw_cfg[i]))
3570 return QL_STATUS_INVALID_PARAM; 3610 return QL_STATUS_INVALID_PARAM;
3571 3611
3572 if (adapter->ahw.pci_func != esw_cfg[i].pci_func) 3612 if (adapter->ahw->pci_func != esw_cfg[i].pci_func)
3573 continue; 3613 continue;
3574 3614
3575 op_mode = esw_cfg[i].op_mode; 3615 op_mode = esw_cfg[i].op_mode;
3576 qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]); 3616 qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]);
3577 esw_cfg[i].op_mode = op_mode; 3617 esw_cfg[i].op_mode = op_mode;
3578 esw_cfg[i].pci_func = adapter->ahw.pci_func; 3618 esw_cfg[i].pci_func = adapter->ahw->pci_func;
3579 3619
3580 switch (esw_cfg[i].op_mode) { 3620 switch (esw_cfg[i].op_mode) {
3581 case QLCNIC_PORT_DEFAULTS: 3621 case QLCNIC_PORT_DEFAULTS: