diff options
author | James Smart <James.Smart@Emulex.Com> | 2009-05-22 14:50:54 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2009-06-08 12:18:10 -0400 |
commit | 3772a99175f5378b5001e8da364341a8b8226a4a (patch) | |
tree | dd710f890c5bc097c874ad1783cd26ea56e88f57 /drivers/scsi/lpfc/lpfc_init.c | |
parent | a366695592ebc9151dd5a248681270f0925d8324 (diff) |
[SCSI] lpfc 8.3.2 : Reorganization for SLI4
Preps the organization of the driver so that the bottom half, which
interacts with the hardware, can share common code sequences for
attachment, detachment, initialization, teardown, etc with new hardware.
For very common code sections, which become specific to the interface
type, the driver uses an indirect function call. The function is set at
initialization. For less common sections, such as initialization, the
driver looks at the interface type and calls the routines relative to
the interface.
Signed-off-by: James Smart <james.smart@emulex.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_init.c')
-rw-r--r-- | drivers/scsi/lpfc/lpfc_init.c | 1907 |
1 files changed, 1436 insertions, 471 deletions
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index 86d1bdcbf2d8..3f06ce2becf5 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c | |||
@@ -571,16 +571,20 @@ lpfc_hba_down_prep(struct lpfc_hba *phba) | |||
571 | { | 571 | { |
572 | struct lpfc_vport **vports; | 572 | struct lpfc_vport **vports; |
573 | int i; | 573 | int i; |
574 | /* Disable interrupts */ | 574 | |
575 | writel(0, phba->HCregaddr); | 575 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
576 | readl(phba->HCregaddr); /* flush */ | 576 | /* Disable interrupts */ |
577 | writel(0, phba->HCregaddr); | ||
578 | readl(phba->HCregaddr); /* flush */ | ||
579 | } | ||
577 | 580 | ||
578 | if (phba->pport->load_flag & FC_UNLOADING) | 581 | if (phba->pport->load_flag & FC_UNLOADING) |
579 | lpfc_cleanup_discovery_resources(phba->pport); | 582 | lpfc_cleanup_discovery_resources(phba->pport); |
580 | else { | 583 | else { |
581 | vports = lpfc_create_vport_work_array(phba); | 584 | vports = lpfc_create_vport_work_array(phba); |
582 | if (vports != NULL) | 585 | if (vports != NULL) |
583 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) | 586 | for (i = 0; i <= phba->max_vports && |
587 | vports[i] != NULL; i++) | ||
584 | lpfc_cleanup_discovery_resources(vports[i]); | 588 | lpfc_cleanup_discovery_resources(vports[i]); |
585 | lpfc_destroy_vport_work_array(phba, vports); | 589 | lpfc_destroy_vport_work_array(phba, vports); |
586 | } | 590 | } |
@@ -588,7 +592,7 @@ lpfc_hba_down_prep(struct lpfc_hba *phba) | |||
588 | } | 592 | } |
589 | 593 | ||
590 | /** | 594 | /** |
591 | * lpfc_hba_down_post - Perform lpfc uninitialization after HBA reset | 595 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
592 | * @phba: pointer to lpfc HBA data structure. | 596 | * @phba: pointer to lpfc HBA data structure. |
593 | * | 597 | * |
594 | * This routine will do uninitialization after the HBA is reset when bring | 598 | * This routine will do uninitialization after the HBA is reset when bring |
@@ -598,8 +602,8 @@ lpfc_hba_down_prep(struct lpfc_hba *phba) | |||
598 | * 0 - sucess. | 602 | * 0 - sucess. |
599 | * Any other value - error. | 603 | * Any other value - error. |
600 | **/ | 604 | **/ |
601 | int | 605 | static int |
602 | lpfc_hba_down_post(struct lpfc_hba *phba) | 606 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
603 | { | 607 | { |
604 | struct lpfc_sli *psli = &phba->sli; | 608 | struct lpfc_sli *psli = &phba->sli; |
605 | struct lpfc_sli_ring *pring; | 609 | struct lpfc_sli_ring *pring; |
@@ -909,13 +913,30 @@ lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |||
909 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) | 913 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
910 | phba->work_hs = old_host_status & ~HS_FFER1; | 914 | phba->work_hs = old_host_status & ~HS_FFER1; |
911 | 915 | ||
916 | spin_lock_irq(&phba->hbalock); | ||
912 | phba->hba_flag &= ~DEFER_ERATT; | 917 | phba->hba_flag &= ~DEFER_ERATT; |
918 | spin_unlock_irq(&phba->hbalock); | ||
913 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); | 919 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
914 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | 920 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
915 | } | 921 | } |
916 | 922 | ||
923 | static void | ||
924 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) | ||
925 | { | ||
926 | struct lpfc_board_event_header board_event; | ||
927 | struct Scsi_Host *shost; | ||
928 | |||
929 | board_event.event_type = FC_REG_BOARD_EVENT; | ||
930 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | ||
931 | shost = lpfc_shost_from_vport(phba->pport); | ||
932 | fc_host_post_vendor_event(shost, fc_get_event_number(), | ||
933 | sizeof(board_event), | ||
934 | (char *) &board_event, | ||
935 | LPFC_NL_VENDOR_ID); | ||
936 | } | ||
937 | |||
917 | /** | 938 | /** |
918 | * lpfc_handle_eratt - The HBA hardware error handler | 939 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
919 | * @phba: pointer to lpfc hba data structure. | 940 | * @phba: pointer to lpfc hba data structure. |
920 | * | 941 | * |
921 | * This routine is invoked to handle the following HBA hardware error | 942 | * This routine is invoked to handle the following HBA hardware error |
@@ -924,8 +945,8 @@ lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |||
924 | * 2 - DMA ring index out of range | 945 | * 2 - DMA ring index out of range |
925 | * 3 - Mailbox command came back as unknown | 946 | * 3 - Mailbox command came back as unknown |
926 | **/ | 947 | **/ |
927 | void | 948 | static void |
928 | lpfc_handle_eratt(struct lpfc_hba *phba) | 949 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
929 | { | 950 | { |
930 | struct lpfc_vport *vport = phba->pport; | 951 | struct lpfc_vport *vport = phba->pport; |
931 | struct lpfc_sli *psli = &phba->sli; | 952 | struct lpfc_sli *psli = &phba->sli; |
@@ -934,24 +955,23 @@ lpfc_handle_eratt(struct lpfc_hba *phba) | |||
934 | unsigned long temperature; | 955 | unsigned long temperature; |
935 | struct temp_event temp_event_data; | 956 | struct temp_event temp_event_data; |
936 | struct Scsi_Host *shost; | 957 | struct Scsi_Host *shost; |
937 | struct lpfc_board_event_header board_event; | ||
938 | 958 | ||
939 | /* If the pci channel is offline, ignore possible errors, | 959 | /* If the pci channel is offline, ignore possible errors, |
940 | * since we cannot communicate with the pci card anyway. */ | 960 | * since we cannot communicate with the pci card anyway. |
941 | if (pci_channel_offline(phba->pcidev)) | 961 | */ |
962 | if (pci_channel_offline(phba->pcidev)) { | ||
963 | spin_lock_irq(&phba->hbalock); | ||
964 | phba->hba_flag &= ~DEFER_ERATT; | ||
965 | spin_unlock_irq(&phba->hbalock); | ||
942 | return; | 966 | return; |
967 | } | ||
968 | |||
943 | /* If resets are disabled then leave the HBA alone and return */ | 969 | /* If resets are disabled then leave the HBA alone and return */ |
944 | if (!phba->cfg_enable_hba_reset) | 970 | if (!phba->cfg_enable_hba_reset) |
945 | return; | 971 | return; |
946 | 972 | ||
947 | /* Send an internal error event to mgmt application */ | 973 | /* Send an internal error event to mgmt application */ |
948 | board_event.event_type = FC_REG_BOARD_EVENT; | 974 | lpfc_board_errevt_to_mgmt(phba); |
949 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | ||
950 | shost = lpfc_shost_from_vport(phba->pport); | ||
951 | fc_host_post_vendor_event(shost, fc_get_event_number(), | ||
952 | sizeof(board_event), | ||
953 | (char *) &board_event, | ||
954 | LPFC_NL_VENDOR_ID); | ||
955 | 975 | ||
956 | if (phba->hba_flag & DEFER_ERATT) | 976 | if (phba->hba_flag & DEFER_ERATT) |
957 | lpfc_handle_deferred_eratt(phba); | 977 | lpfc_handle_deferred_eratt(phba); |
@@ -1137,7 +1157,7 @@ lpfc_handle_latt_err_exit: | |||
1137 | * 0 - pointer to the VPD passed in is NULL | 1157 | * 0 - pointer to the VPD passed in is NULL |
1138 | * 1 - success | 1158 | * 1 - success |
1139 | **/ | 1159 | **/ |
1140 | static int | 1160 | int |
1141 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) | 1161 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
1142 | { | 1162 | { |
1143 | uint8_t lenlo, lenhi; | 1163 | uint8_t lenlo, lenhi; |
@@ -1533,7 +1553,8 @@ lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) | |||
1533 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | 1553 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
1534 | icmd->ulpLe = 1; | 1554 | icmd->ulpLe = 1; |
1535 | 1555 | ||
1536 | if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { | 1556 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
1557 | IOCB_ERROR) { | ||
1537 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); | 1558 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
1538 | kfree(mp1); | 1559 | kfree(mp1); |
1539 | cnt++; | 1560 | cnt++; |
@@ -1761,7 +1782,6 @@ lpfc_cleanup(struct lpfc_vport *vport) | |||
1761 | * Lets wait for this to happen, if needed. | 1782 | * Lets wait for this to happen, if needed. |
1762 | */ | 1783 | */ |
1763 | while (!list_empty(&vport->fc_nodes)) { | 1784 | while (!list_empty(&vport->fc_nodes)) { |
1764 | |||
1765 | if (i++ > 3000) { | 1785 | if (i++ > 3000) { |
1766 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, | 1786 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
1767 | "0233 Nodelist not empty\n"); | 1787 | "0233 Nodelist not empty\n"); |
@@ -1782,7 +1802,6 @@ lpfc_cleanup(struct lpfc_vport *vport) | |||
1782 | /* Wait for any activity on ndlps to settle */ | 1802 | /* Wait for any activity on ndlps to settle */ |
1783 | msleep(10); | 1803 | msleep(10); |
1784 | } | 1804 | } |
1785 | return; | ||
1786 | } | 1805 | } |
1787 | 1806 | ||
1788 | /** | 1807 | /** |
@@ -1803,22 +1822,36 @@ lpfc_stop_vport_timers(struct lpfc_vport *vport) | |||
1803 | } | 1822 | } |
1804 | 1823 | ||
1805 | /** | 1824 | /** |
1806 | * lpfc_stop_phba_timers - Stop all the timers associated with an HBA | 1825 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
1807 | * @phba: pointer to lpfc hba data structure. | 1826 | * @phba: pointer to lpfc hba data structure. |
1808 | * | 1827 | * |
1809 | * This routine stops all the timers associated with a HBA. This function is | 1828 | * This routine stops all the timers associated with a HBA. This function is |
1810 | * invoked before either putting a HBA offline or unloading the driver. | 1829 | * invoked before either putting a HBA offline or unloading the driver. |
1811 | **/ | 1830 | **/ |
1812 | static void | 1831 | void |
1813 | lpfc_stop_phba_timers(struct lpfc_hba *phba) | 1832 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
1814 | { | 1833 | { |
1815 | del_timer_sync(&phba->fcp_poll_timer); | ||
1816 | lpfc_stop_vport_timers(phba->pport); | 1834 | lpfc_stop_vport_timers(phba->pport); |
1817 | del_timer_sync(&phba->sli.mbox_tmo); | 1835 | del_timer_sync(&phba->sli.mbox_tmo); |
1818 | del_timer_sync(&phba->fabric_block_timer); | 1836 | del_timer_sync(&phba->fabric_block_timer); |
1819 | phba->hb_outstanding = 0; | ||
1820 | del_timer_sync(&phba->hb_tmofunc); | ||
1821 | del_timer_sync(&phba->eratt_poll); | 1837 | del_timer_sync(&phba->eratt_poll); |
1838 | del_timer_sync(&phba->hb_tmofunc); | ||
1839 | phba->hb_outstanding = 0; | ||
1840 | |||
1841 | switch (phba->pci_dev_grp) { | ||
1842 | case LPFC_PCI_DEV_LP: | ||
1843 | /* Stop any LightPulse device specific driver timers */ | ||
1844 | del_timer_sync(&phba->fcp_poll_timer); | ||
1845 | break; | ||
1846 | case LPFC_PCI_DEV_OC: | ||
1847 | /* Stop any OneConnect device sepcific driver timers */ | ||
1848 | break; | ||
1849 | default: | ||
1850 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
1851 | "0297 Invalid device group (x%x)\n", | ||
1852 | phba->pci_dev_grp); | ||
1853 | break; | ||
1854 | } | ||
1822 | return; | 1855 | return; |
1823 | } | 1856 | } |
1824 | 1857 | ||
@@ -2509,9 +2542,8 @@ lpfc_disable_msi(struct lpfc_hba *phba) | |||
2509 | * | 2542 | * |
2510 | * This routine it invoked to log the currently used active interrupt mode | 2543 | * This routine it invoked to log the currently used active interrupt mode |
2511 | * to the device. | 2544 | * to the device. |
2512 | */ | 2545 | **/ |
2513 | static void | 2546 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) |
2514 | lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | ||
2515 | { | 2547 | { |
2516 | switch (intr_mode) { | 2548 | switch (intr_mode) { |
2517 | case 0: | 2549 | case 0: |
@@ -2534,228 +2566,671 @@ lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | |||
2534 | return; | 2566 | return; |
2535 | } | 2567 | } |
2536 | 2568 | ||
2569 | /** | ||
2570 | * lpfc_enable_pci_dev - Enable a generic PCI device. | ||
2571 | * @phba: pointer to lpfc hba data structure. | ||
2572 | * | ||
2573 | * This routine is invoked to enable the PCI device that is common to all | ||
2574 | * PCI devices. | ||
2575 | * | ||
2576 | * Return codes | ||
2577 | * 0 - sucessful | ||
2578 | * other values - error | ||
2579 | **/ | ||
2580 | static int | ||
2581 | lpfc_enable_pci_dev(struct lpfc_hba *phba) | ||
2582 | { | ||
2583 | struct pci_dev *pdev; | ||
2584 | int bars; | ||
2585 | |||
2586 | /* Obtain PCI device reference */ | ||
2587 | if (!phba->pcidev) | ||
2588 | goto out_error; | ||
2589 | else | ||
2590 | pdev = phba->pcidev; | ||
2591 | /* Select PCI BARs */ | ||
2592 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | ||
2593 | /* Enable PCI device */ | ||
2594 | if (pci_enable_device_mem(pdev)) | ||
2595 | goto out_error; | ||
2596 | /* Request PCI resource for the device */ | ||
2597 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | ||
2598 | goto out_disable_device; | ||
2599 | /* Set up device as PCI master and save state for EEH */ | ||
2600 | pci_set_master(pdev); | ||
2601 | pci_try_set_mwi(pdev); | ||
2602 | pci_save_state(pdev); | ||
2603 | |||
2604 | return 0; | ||
2605 | |||
2606 | out_disable_device: | ||
2607 | pci_disable_device(pdev); | ||
2608 | out_error: | ||
2609 | return -ENODEV; | ||
2610 | } | ||
2611 | |||
2612 | /** | ||
2613 | * lpfc_disable_pci_dev - Disable a generic PCI device. | ||
2614 | * @phba: pointer to lpfc hba data structure. | ||
2615 | * | ||
2616 | * This routine is invoked to disable the PCI device that is common to all | ||
2617 | * PCI devices. | ||
2618 | **/ | ||
2537 | static void | 2619 | static void |
2538 | lpfc_stop_port(struct lpfc_hba *phba) | 2620 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
2539 | { | 2621 | { |
2540 | /* Clear all interrupt enable conditions */ | 2622 | struct pci_dev *pdev; |
2541 | writel(0, phba->HCregaddr); | 2623 | int bars; |
2542 | readl(phba->HCregaddr); /* flush */ | ||
2543 | /* Clear all pending interrupts */ | ||
2544 | writel(0xffffffff, phba->HAregaddr); | ||
2545 | readl(phba->HAregaddr); /* flush */ | ||
2546 | 2624 | ||
2547 | /* Reset some HBA SLI setup states */ | 2625 | /* Obtain PCI device reference */ |
2548 | lpfc_stop_phba_timers(phba); | 2626 | if (!phba->pcidev) |
2549 | phba->pport->work_port_events = 0; | 2627 | return; |
2628 | else | ||
2629 | pdev = phba->pcidev; | ||
2630 | /* Select PCI BARs */ | ||
2631 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | ||
2632 | /* Release PCI resource and disable PCI device */ | ||
2633 | pci_release_selected_regions(pdev, bars); | ||
2634 | pci_disable_device(pdev); | ||
2635 | /* Null out PCI private reference to driver */ | ||
2636 | pci_set_drvdata(pdev, NULL); | ||
2550 | 2637 | ||
2551 | return; | 2638 | return; |
2552 | } | 2639 | } |
2553 | 2640 | ||
2554 | /** | 2641 | /** |
2555 | * lpfc_enable_intr - Enable device interrupt | 2642 | * lpfc_reset_hba - Reset a hba |
2556 | * @phba: pointer to lpfc hba data structure. | 2643 | * @phba: pointer to lpfc hba data structure. |
2557 | * | 2644 | * |
2558 | * This routine is invoked to enable device interrupt and associate driver's | 2645 | * This routine is invoked to reset a hba device. It brings the HBA |
2559 | * interrupt handler(s) to interrupt vector(s). Depends on the interrupt | 2646 | * offline, performs a board restart, and then brings the board back |
2560 | * mode configured to the driver, the driver will try to fallback from the | 2647 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
2561 | * configured interrupt mode to an interrupt mode which is supported by the | 2648 | * on outstanding mailbox commands. |
2562 | * platform, kernel, and device in the order of: MSI-X -> MSI -> IRQ. | 2649 | **/ |
2650 | void | ||
2651 | lpfc_reset_hba(struct lpfc_hba *phba) | ||
2652 | { | ||
2653 | /* If resets are disabled then set error state and return. */ | ||
2654 | if (!phba->cfg_enable_hba_reset) { | ||
2655 | phba->link_state = LPFC_HBA_ERROR; | ||
2656 | return; | ||
2657 | } | ||
2658 | lpfc_offline_prep(phba); | ||
2659 | lpfc_offline(phba); | ||
2660 | lpfc_sli_brdrestart(phba); | ||
2661 | lpfc_online(phba); | ||
2662 | lpfc_unblock_mgmt_io(phba); | ||
2663 | } | ||
2664 | |||
2665 | /** | ||
2666 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. | ||
2667 | * @phba: pointer to lpfc hba data structure. | ||
2668 | * | ||
2669 | * This routine is invoked to set up the driver internal resources specific to | ||
2670 | * support the SLI-3 HBA device it attached to. | ||
2563 | * | 2671 | * |
2564 | * Return codes | 2672 | * Return codes |
2565 | * 0 - sucessful | 2673 | * 0 - sucessful |
2566 | * other values - error | 2674 | * other values - error |
2567 | **/ | 2675 | **/ |
2568 | static uint32_t | 2676 | static int |
2569 | lpfc_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | 2677 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
2570 | { | 2678 | { |
2571 | uint32_t intr_mode = LPFC_INTR_ERROR; | 2679 | struct lpfc_sli *psli; |
2572 | int retval; | ||
2573 | 2680 | ||
2574 | if (cfg_mode == 2) { | 2681 | /* |
2575 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | 2682 | * Initialize timers used by driver |
2576 | retval = lpfc_sli_config_port(phba, 3); | 2683 | */ |
2577 | if (!retval) { | 2684 | |
2578 | /* Now, try to enable MSI-X interrupt mode */ | 2685 | /* Heartbeat timer */ |
2579 | retval = lpfc_enable_msix(phba); | 2686 | init_timer(&phba->hb_tmofunc); |
2580 | if (!retval) { | 2687 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
2581 | /* Indicate initialization to MSI-X mode */ | 2688 | phba->hb_tmofunc.data = (unsigned long)phba; |
2582 | phba->intr_type = MSIX; | 2689 | |
2583 | intr_mode = 2; | 2690 | psli = &phba->sli; |
2584 | } | 2691 | /* MBOX heartbeat timer */ |
2585 | } | 2692 | init_timer(&psli->mbox_tmo); |
2693 | psli->mbox_tmo.function = lpfc_mbox_timeout; | ||
2694 | psli->mbox_tmo.data = (unsigned long) phba; | ||
2695 | /* FCP polling mode timer */ | ||
2696 | init_timer(&phba->fcp_poll_timer); | ||
2697 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | ||
2698 | phba->fcp_poll_timer.data = (unsigned long) phba; | ||
2699 | /* Fabric block timer */ | ||
2700 | init_timer(&phba->fabric_block_timer); | ||
2701 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | ||
2702 | phba->fabric_block_timer.data = (unsigned long) phba; | ||
2703 | /* EA polling mode timer */ | ||
2704 | init_timer(&phba->eratt_poll); | ||
2705 | phba->eratt_poll.function = lpfc_poll_eratt; | ||
2706 | phba->eratt_poll.data = (unsigned long) phba; | ||
2707 | |||
2708 | /* Host attention work mask setup */ | ||
2709 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | ||
2710 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | ||
2711 | |||
2712 | /* Get all the module params for configuring this host */ | ||
2713 | lpfc_get_cfgparam(phba); | ||
2714 | /* | ||
2715 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | ||
2716 | * used to create the sg_dma_buf_pool must be dynamically calculated. | ||
2717 | * 2 segments are added since the IOCB needs a command and response bde. | ||
2718 | */ | ||
2719 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | ||
2720 | sizeof(struct fcp_rsp) + | ||
2721 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); | ||
2722 | |||
2723 | if (phba->cfg_enable_bg) { | ||
2724 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; | ||
2725 | phba->cfg_sg_dma_buf_size += | ||
2726 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); | ||
2586 | } | 2727 | } |
2587 | 2728 | ||
2588 | /* Fallback to MSI if MSI-X initialization failed */ | 2729 | /* Also reinitialize the host templates with new values. */ |
2589 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | 2730 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
2590 | retval = lpfc_enable_msi(phba); | 2731 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
2591 | if (!retval) { | 2732 | |
2592 | /* Indicate initialization to MSI mode */ | 2733 | phba->max_vpi = LPFC_MAX_VPI; |
2593 | phba->intr_type = MSI; | 2734 | /* This will be set to correct value after config_port mbox */ |
2594 | intr_mode = 1; | 2735 | phba->max_vports = 0; |
2595 | } | 2736 | |
2737 | /* | ||
2738 | * Initialize the SLI Layer to run with lpfc HBAs. | ||
2739 | */ | ||
2740 | lpfc_sli_setup(phba); | ||
2741 | lpfc_sli_queue_setup(phba); | ||
2742 | |||
2743 | /* Allocate device driver memory */ | ||
2744 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) | ||
2745 | return -ENOMEM; | ||
2746 | |||
2747 | return 0; | ||
2748 | } | ||
2749 | |||
2750 | /** | ||
2751 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev | ||
2752 | * @phba: pointer to lpfc hba data structure. | ||
2753 | * | ||
2754 | * This routine is invoked to unset the driver internal resources set up | ||
2755 | * specific for supporting the SLI-3 HBA device it attached to. | ||
2756 | **/ | ||
2757 | static void | ||
2758 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) | ||
2759 | { | ||
2760 | /* Free device driver memory allocated */ | ||
2761 | lpfc_mem_free_all(phba); | ||
2762 | |||
2763 | return; | ||
2764 | } | ||
2765 | |||
2766 | /** | ||
2767 | * lpfc_init_api_table_setup - Set up init api fucntion jump table | ||
2768 | * @phba: The hba struct for which this call is being executed. | ||
2769 | * @dev_grp: The HBA PCI-Device group number. | ||
2770 | * | ||
2771 | * This routine sets up the device INIT interface API function jump table | ||
2772 | * in @phba struct. | ||
2773 | * | ||
2774 | * Returns: 0 - success, -ENODEV - failure. | ||
2775 | **/ | ||
2776 | int | ||
2777 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | ||
2778 | { | ||
2779 | switch (dev_grp) { | ||
2780 | case LPFC_PCI_DEV_LP: | ||
2781 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; | ||
2782 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; | ||
2783 | phba->lpfc_stop_port = lpfc_stop_port_s3; | ||
2784 | break; | ||
2785 | default: | ||
2786 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
2787 | "1431 Invalid HBA PCI-device group: 0x%x\n", | ||
2788 | dev_grp); | ||
2789 | return -ENODEV; | ||
2790 | break; | ||
2596 | } | 2791 | } |
2792 | return 0; | ||
2793 | } | ||
2597 | 2794 | ||
2598 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | 2795 | /** |
2599 | if (phba->intr_type == NONE) { | 2796 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
2600 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, | 2797 | * @phba: pointer to lpfc hba data structure. |
2601 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | 2798 | * |
2602 | if (!retval) { | 2799 | * This routine is invoked to set up the driver internal resources before the |
2603 | /* Indicate initialization to INTx mode */ | 2800 | * device specific resource setup to support the HBA device it attached to. |
2604 | phba->intr_type = INTx; | 2801 | * |
2605 | intr_mode = 0; | 2802 | * Return codes |
2606 | } | 2803 | * 0 - sucessful |
2804 | * other values - error | ||
2805 | **/ | ||
2806 | static int | ||
2807 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) | ||
2808 | { | ||
2809 | /* | ||
2810 | * Driver resources common to all SLI revisions | ||
2811 | */ | ||
2812 | atomic_set(&phba->fast_event_count, 0); | ||
2813 | spin_lock_init(&phba->hbalock); | ||
2814 | |||
2815 | /* Initialize ndlp management spinlock */ | ||
2816 | spin_lock_init(&phba->ndlp_lock); | ||
2817 | |||
2818 | INIT_LIST_HEAD(&phba->port_list); | ||
2819 | INIT_LIST_HEAD(&phba->work_list); | ||
2820 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | ||
2821 | |||
2822 | /* Initialize the wait queue head for the kernel thread */ | ||
2823 | init_waitqueue_head(&phba->work_waitq); | ||
2824 | |||
2825 | /* Initialize the scsi buffer list used by driver for scsi IO */ | ||
2826 | spin_lock_init(&phba->scsi_buf_list_lock); | ||
2827 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | ||
2828 | |||
2829 | /* Initialize the fabric iocb list */ | ||
2830 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | ||
2831 | |||
2832 | /* Initialize list to save ELS buffers */ | ||
2833 | INIT_LIST_HEAD(&phba->elsbuf); | ||
2834 | |||
2835 | /* Initialize FCF connection rec list */ | ||
2836 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); | ||
2837 | |||
2838 | return 0; | ||
2839 | } | ||
2840 | |||
2841 | /** | ||
2842 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. | ||
2843 | * @phba: pointer to lpfc hba data structure. | ||
2844 | * | ||
2845 | * This routine is invoked to set up the driver internal resources after the | ||
2846 | * device specific resource setup to support the HBA device it attached to. | ||
2847 | * | ||
2848 | * Return codes | ||
2849 | * 0 - sucessful | ||
2850 | * other values - error | ||
2851 | **/ | ||
2852 | static int | ||
2853 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) | ||
2854 | { | ||
2855 | int error; | ||
2856 | |||
2857 | /* Startup the kernel thread for this host adapter. */ | ||
2858 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | ||
2859 | "lpfc_worker_%d", phba->brd_no); | ||
2860 | if (IS_ERR(phba->worker_thread)) { | ||
2861 | error = PTR_ERR(phba->worker_thread); | ||
2862 | return error; | ||
2607 | } | 2863 | } |
2608 | return intr_mode; | 2864 | |
2865 | return 0; | ||
2609 | } | 2866 | } |
2610 | 2867 | ||
2611 | /** | 2868 | /** |
2612 | * lpfc_disable_intr - Disable device interrupt | 2869 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
2613 | * @phba: pointer to lpfc hba data structure. | 2870 | * @phba: pointer to lpfc hba data structure. |
2614 | * | 2871 | * |
2615 | * This routine is invoked to disable device interrupt and disassociate the | 2872 | * This routine is invoked to unset the driver internal resources set up after |
2616 | * driver's interrupt handler(s) from interrupt vector(s). Depending on the | 2873 | * the device specific resource setup for supporting the HBA device it |
2617 | * interrupt mode, the driver will release the interrupt vector(s) for the | 2874 | * attached to. |
2618 | * message signaled interrupt. | ||
2619 | **/ | 2875 | **/ |
2620 | static void | 2876 | static void |
2621 | lpfc_disable_intr(struct lpfc_hba *phba) | 2877 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
2622 | { | 2878 | { |
2623 | /* Disable the currently initialized interrupt mode */ | 2879 | /* Stop kernel worker thread */ |
2624 | if (phba->intr_type == MSIX) | 2880 | kthread_stop(phba->worker_thread); |
2625 | lpfc_disable_msix(phba); | 2881 | } |
2626 | else if (phba->intr_type == MSI) | ||
2627 | lpfc_disable_msi(phba); | ||
2628 | else if (phba->intr_type == INTx) | ||
2629 | free_irq(phba->pcidev->irq, phba); | ||
2630 | 2882 | ||
2631 | /* Reset interrupt management states */ | 2883 | /** |
2632 | phba->intr_type = NONE; | 2884 | * lpfc_free_iocb_list - Free iocb list. |
2633 | phba->sli.slistat.sli_intr = 0; | 2885 | * @phba: pointer to lpfc hba data structure. |
2886 | * | ||
2887 | * This routine is invoked to free the driver's IOCB list and memory. | ||
2888 | **/ | ||
2889 | static void | ||
2890 | lpfc_free_iocb_list(struct lpfc_hba *phba) | ||
2891 | { | ||
2892 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | ||
2893 | |||
2894 | spin_lock_irq(&phba->hbalock); | ||
2895 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | ||
2896 | &phba->lpfc_iocb_list, list) { | ||
2897 | list_del(&iocbq_entry->list); | ||
2898 | kfree(iocbq_entry); | ||
2899 | phba->total_iocbq_bufs--; | ||
2900 | } | ||
2901 | spin_unlock_irq(&phba->hbalock); | ||
2634 | 2902 | ||
2635 | return; | 2903 | return; |
2636 | } | 2904 | } |
2637 | 2905 | ||
2638 | /** | 2906 | /** |
2639 | * lpfc_pci_probe_one - lpfc PCI probe func to register device to PCI subsystem | 2907 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
2640 | * @pdev: pointer to PCI device | 2908 | * @phba: pointer to lpfc hba data structure. |
2641 | * @pid: pointer to PCI device identifier | ||
2642 | * | 2909 | * |
2643 | * This routine is to be registered to the kernel's PCI subsystem. When an | 2910 | * This routine is invoked to allocate and initizlize the driver's IOCB |
2644 | * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at | 2911 | * list and set up the IOCB tag array accordingly. |
2645 | * PCI device-specific information of the device and driver to see if the | ||
2646 | * driver state that it can support this kind of device. If the match is | ||
2647 | * successful, the driver core invokes this routine. If this routine | ||
2648 | * determines it can claim the HBA, it does all the initialization that it | ||
2649 | * needs to do to handle the HBA properly. | ||
2650 | * | 2912 | * |
2651 | * Return code | 2913 | * Return codes |
2652 | * 0 - driver can claim the device | 2914 | * 0 - sucessful |
2653 | * negative value - driver can not claim the device | 2915 | * other values - error |
2654 | **/ | 2916 | **/ |
2655 | static int __devinit | 2917 | static int |
2656 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | 2918 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
2657 | { | 2919 | { |
2658 | struct lpfc_vport *vport = NULL; | 2920 | struct lpfc_iocbq *iocbq_entry = NULL; |
2659 | struct lpfc_hba *phba; | ||
2660 | struct lpfc_sli *psli; | ||
2661 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | ||
2662 | struct Scsi_Host *shost = NULL; | ||
2663 | void *ptr; | ||
2664 | unsigned long bar0map_len, bar2map_len; | ||
2665 | int error = -ENODEV, retval; | ||
2666 | int i, hbq_count; | ||
2667 | uint16_t iotag; | 2921 | uint16_t iotag; |
2668 | uint32_t cfg_mode, intr_mode; | 2922 | int i; |
2669 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | ||
2670 | struct lpfc_adapter_event_header adapter_event; | ||
2671 | 2923 | ||
2672 | if (pci_enable_device_mem(pdev)) | 2924 | /* Initialize and populate the iocb list per host. */ |
2673 | goto out; | 2925 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
2674 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | 2926 | for (i = 0; i < iocb_count; i++) { |
2675 | goto out_disable_device; | 2927 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
2928 | if (iocbq_entry == NULL) { | ||
2929 | printk(KERN_ERR "%s: only allocated %d iocbs of " | ||
2930 | "expected %d count. Unloading driver.\n", | ||
2931 | __func__, i, LPFC_IOCB_LIST_CNT); | ||
2932 | goto out_free_iocbq; | ||
2933 | } | ||
2676 | 2934 | ||
2677 | phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL); | 2935 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
2678 | if (!phba) | 2936 | if (iotag == 0) { |
2679 | goto out_release_regions; | 2937 | kfree(iocbq_entry); |
2938 | printk(KERN_ERR "%s: failed to allocate IOTAG. " | ||
2939 | "Unloading driver.\n", __func__); | ||
2940 | goto out_free_iocbq; | ||
2941 | } | ||
2942 | iocbq_entry->sli4_xritag = NO_XRI; | ||
2680 | 2943 | ||
2681 | atomic_set(&phba->fast_event_count, 0); | 2944 | spin_lock_irq(&phba->hbalock); |
2682 | spin_lock_init(&phba->hbalock); | 2945 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
2946 | phba->total_iocbq_bufs++; | ||
2947 | spin_unlock_irq(&phba->hbalock); | ||
2948 | } | ||
2683 | 2949 | ||
2684 | /* Initialize ndlp management spinlock */ | 2950 | return 0; |
2685 | spin_lock_init(&phba->ndlp_lock); | 2951 | |
2952 | out_free_iocbq: | ||
2953 | lpfc_free_iocb_list(phba); | ||
2686 | 2954 | ||
2955 | return -ENOMEM; | ||
2956 | } | ||
2957 | |||
2958 | /** | ||
2959 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. | ||
2960 | * @pdev: pointer to pci device data structure. | ||
2961 | * | ||
2962 | * This routine is invoked to allocate the driver hba data structure for an | ||
2963 | * HBA device. If the allocation is successful, the phba reference to the | ||
2964 | * PCI device data structure is set. | ||
2965 | * | ||
2966 | * Return codes | ||
2967 | * pointer to @phba - sucessful | ||
2968 | * NULL - error | ||
2969 | **/ | ||
2970 | static struct lpfc_hba * | ||
2971 | lpfc_hba_alloc(struct pci_dev *pdev) | ||
2972 | { | ||
2973 | struct lpfc_hba *phba; | ||
2974 | |||
2975 | /* Allocate memory for HBA structure */ | ||
2976 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); | ||
2977 | if (!phba) { | ||
2978 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
2979 | "1417 Failed to allocate hba struct.\n"); | ||
2980 | return NULL; | ||
2981 | } | ||
2982 | |||
2983 | /* Set reference to PCI device in HBA structure */ | ||
2687 | phba->pcidev = pdev; | 2984 | phba->pcidev = pdev; |
2688 | 2985 | ||
2689 | /* Assign an unused board number */ | 2986 | /* Assign an unused board number */ |
2690 | if ((phba->brd_no = lpfc_get_instance()) < 0) | 2987 | phba->brd_no = lpfc_get_instance(); |
2691 | goto out_free_phba; | 2988 | if (phba->brd_no < 0) { |
2989 | kfree(phba); | ||
2990 | return NULL; | ||
2991 | } | ||
2992 | |||
2993 | return phba; | ||
2994 | } | ||
2995 | |||
2996 | /** | ||
2997 | * lpfc_hba_free - Free driver hba data structure with a device. | ||
2998 | * @phba: pointer to lpfc hba data structure. | ||
2999 | * | ||
3000 | * This routine is invoked to free the driver hba data structure with an | ||
3001 | * HBA device. | ||
3002 | **/ | ||
3003 | static void | ||
3004 | lpfc_hba_free(struct lpfc_hba *phba) | ||
3005 | { | ||
3006 | /* Release the driver assigned board number */ | ||
3007 | idr_remove(&lpfc_hba_index, phba->brd_no); | ||
3008 | |||
3009 | kfree(phba); | ||
3010 | return; | ||
3011 | } | ||
3012 | |||
3013 | /** | ||
3014 | * lpfc_create_shost - Create hba physical port with associated scsi host. | ||
3015 | * @phba: pointer to lpfc hba data structure. | ||
3016 | * | ||
3017 | * This routine is invoked to create HBA physical port and associate a SCSI | ||
3018 | * host with it. | ||
3019 | * | ||
3020 | * Return codes | ||
3021 | * 0 - sucessful | ||
3022 | * other values - error | ||
3023 | **/ | ||
3024 | static int | ||
3025 | lpfc_create_shost(struct lpfc_hba *phba) | ||
3026 | { | ||
3027 | struct lpfc_vport *vport; | ||
3028 | struct Scsi_Host *shost; | ||
3029 | |||
3030 | /* Initialize HBA FC structure */ | ||
3031 | phba->fc_edtov = FF_DEF_EDTOV; | ||
3032 | phba->fc_ratov = FF_DEF_RATOV; | ||
3033 | phba->fc_altov = FF_DEF_ALTOV; | ||
3034 | phba->fc_arbtov = FF_DEF_ARBTOV; | ||
3035 | |||
3036 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); | ||
3037 | if (!vport) | ||
3038 | return -ENODEV; | ||
3039 | |||
3040 | shost = lpfc_shost_from_vport(vport); | ||
3041 | phba->pport = vport; | ||
3042 | lpfc_debugfs_initialize(vport); | ||
3043 | /* Put reference to SCSI host to driver's device private data */ | ||
3044 | pci_set_drvdata(phba->pcidev, shost); | ||
3045 | |||
3046 | return 0; | ||
3047 | } | ||
3048 | |||
3049 | /** | ||
3050 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. | ||
3051 | * @phba: pointer to lpfc hba data structure. | ||
3052 | * | ||
3053 | * This routine is invoked to destroy HBA physical port and the associated | ||
3054 | * SCSI host. | ||
3055 | **/ | ||
3056 | static void | ||
3057 | lpfc_destroy_shost(struct lpfc_hba *phba) | ||
3058 | { | ||
3059 | struct lpfc_vport *vport = phba->pport; | ||
3060 | |||
3061 | /* Destroy physical port that associated with the SCSI host */ | ||
3062 | destroy_port(vport); | ||
3063 | |||
3064 | return; | ||
3065 | } | ||
3066 | |||
3067 | /** | ||
3068 | * lpfc_setup_bg - Setup Block guard structures and debug areas. | ||
3069 | * @phba: pointer to lpfc hba data structure. | ||
3070 | * @shost: the shost to be used to detect Block guard settings. | ||
3071 | * | ||
3072 | * This routine sets up the local Block guard protocol settings for @shost. | ||
3073 | * This routine also allocates memory for debugging bg buffers. | ||
3074 | **/ | ||
3075 | static void | ||
3076 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) | ||
3077 | { | ||
3078 | int pagecnt = 10; | ||
3079 | if (lpfc_prot_mask && lpfc_prot_guard) { | ||
3080 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
3081 | "1478 Registering BlockGuard with the " | ||
3082 | "SCSI layer\n"); | ||
3083 | scsi_host_set_prot(shost, lpfc_prot_mask); | ||
3084 | scsi_host_set_guard(shost, lpfc_prot_guard); | ||
3085 | } | ||
3086 | if (!_dump_buf_data) { | ||
3087 | while (pagecnt) { | ||
3088 | spin_lock_init(&_dump_buf_lock); | ||
3089 | _dump_buf_data = | ||
3090 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | ||
3091 | if (_dump_buf_data) { | ||
3092 | printk(KERN_ERR "BLKGRD allocated %d pages for " | ||
3093 | "_dump_buf_data at 0x%p\n", | ||
3094 | (1 << pagecnt), _dump_buf_data); | ||
3095 | _dump_buf_data_order = pagecnt; | ||
3096 | memset(_dump_buf_data, 0, | ||
3097 | ((1 << PAGE_SHIFT) << pagecnt)); | ||
3098 | break; | ||
3099 | } else | ||
3100 | --pagecnt; | ||
3101 | } | ||
3102 | if (!_dump_buf_data_order) | ||
3103 | printk(KERN_ERR "BLKGRD ERROR unable to allocate " | ||
3104 | "memory for hexdump\n"); | ||
3105 | } else | ||
3106 | printk(KERN_ERR "BLKGRD already allocated _dump_buf_data=0x%p" | ||
3107 | "\n", _dump_buf_data); | ||
3108 | if (!_dump_buf_dif) { | ||
3109 | while (pagecnt) { | ||
3110 | _dump_buf_dif = | ||
3111 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | ||
3112 | if (_dump_buf_dif) { | ||
3113 | printk(KERN_ERR "BLKGRD allocated %d pages for " | ||
3114 | "_dump_buf_dif at 0x%p\n", | ||
3115 | (1 << pagecnt), _dump_buf_dif); | ||
3116 | _dump_buf_dif_order = pagecnt; | ||
3117 | memset(_dump_buf_dif, 0, | ||
3118 | ((1 << PAGE_SHIFT) << pagecnt)); | ||
3119 | break; | ||
3120 | } else | ||
3121 | --pagecnt; | ||
3122 | } | ||
3123 | if (!_dump_buf_dif_order) | ||
3124 | printk(KERN_ERR "BLKGRD ERROR unable to allocate " | ||
3125 | "memory for hexdump\n"); | ||
3126 | } else | ||
3127 | printk(KERN_ERR "BLKGRD already allocated _dump_buf_dif=0x%p\n", | ||
3128 | _dump_buf_dif); | ||
3129 | } | ||
3130 | |||
3131 | /** | ||
3132 | * lpfc_post_init_setup - Perform necessary device post initialization setup. | ||
3133 | * @phba: pointer to lpfc hba data structure. | ||
3134 | * | ||
3135 | * This routine is invoked to perform all the necessary post initialization | ||
3136 | * setup for the device. | ||
3137 | **/ | ||
3138 | static void | ||
3139 | lpfc_post_init_setup(struct lpfc_hba *phba) | ||
3140 | { | ||
3141 | struct Scsi_Host *shost; | ||
3142 | struct lpfc_adapter_event_header adapter_event; | ||
3143 | |||
3144 | /* Get the default values for Model Name and Description */ | ||
3145 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | ||
2692 | 3146 | ||
2693 | INIT_LIST_HEAD(&phba->port_list); | ||
2694 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | ||
2695 | /* | 3147 | /* |
2696 | * Get all the module params for configuring this host and then | 3148 | * hba setup may have changed the hba_queue_depth so we need to |
2697 | * establish the host. | 3149 | * adjust the value of can_queue. |
2698 | */ | 3150 | */ |
2699 | lpfc_get_cfgparam(phba); | 3151 | shost = pci_get_drvdata(phba->pcidev); |
2700 | phba->max_vpi = LPFC_MAX_VPI; | 3152 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3153 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | ||
3154 | lpfc_setup_bg(phba, shost); | ||
2701 | 3155 | ||
2702 | /* Initialize timers used by driver */ | 3156 | lpfc_host_attrib_init(shost); |
2703 | init_timer(&phba->hb_tmofunc); | ||
2704 | phba->hb_tmofunc.function = lpfc_hb_timeout; | ||
2705 | phba->hb_tmofunc.data = (unsigned long)phba; | ||
2706 | 3157 | ||
2707 | psli = &phba->sli; | 3158 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
2708 | init_timer(&psli->mbox_tmo); | 3159 | spin_lock_irq(shost->host_lock); |
2709 | psli->mbox_tmo.function = lpfc_mbox_timeout; | 3160 | lpfc_poll_start_timer(phba); |
2710 | psli->mbox_tmo.data = (unsigned long) phba; | 3161 | spin_unlock_irq(shost->host_lock); |
2711 | init_timer(&phba->fcp_poll_timer); | 3162 | } |
2712 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | ||
2713 | phba->fcp_poll_timer.data = (unsigned long) phba; | ||
2714 | init_timer(&phba->fabric_block_timer); | ||
2715 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | ||
2716 | phba->fabric_block_timer.data = (unsigned long) phba; | ||
2717 | init_timer(&phba->eratt_poll); | ||
2718 | phba->eratt_poll.function = lpfc_poll_eratt; | ||
2719 | phba->eratt_poll.data = (unsigned long) phba; | ||
2720 | 3163 | ||
2721 | pci_set_master(pdev); | 3164 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2722 | pci_save_state(pdev); | 3165 | "0428 Perform SCSI scan\n"); |
2723 | pci_try_set_mwi(pdev); | 3166 | /* Send board arrival event to upper layer */ |
3167 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | ||
3168 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | ||
3169 | fc_host_post_vendor_event(shost, fc_get_event_number(), | ||
3170 | sizeof(adapter_event), | ||
3171 | (char *) &adapter_event, | ||
3172 | LPFC_NL_VENDOR_ID); | ||
3173 | return; | ||
3174 | } | ||
3175 | |||
3176 | /** | ||
3177 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. | ||
3178 | * @phba: pointer to lpfc hba data structure. | ||
3179 | * | ||
3180 | * This routine is invoked to set up the PCI device memory space for device | ||
3181 | * with SLI-3 interface spec. | ||
3182 | * | ||
3183 | * Return codes | ||
3184 | * 0 - sucessful | ||
3185 | * other values - error | ||
3186 | **/ | ||
3187 | static int | ||
3188 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) | ||
3189 | { | ||
3190 | struct pci_dev *pdev; | ||
3191 | unsigned long bar0map_len, bar2map_len; | ||
3192 | int i, hbq_count; | ||
3193 | void *ptr; | ||
3194 | int error = -ENODEV; | ||
2724 | 3195 | ||
2725 | if (pci_set_dma_mask(phba->pcidev, DMA_BIT_MASK(64)) != 0) | 3196 | /* Obtain PCI device reference */ |
2726 | if (pci_set_dma_mask(phba->pcidev, DMA_BIT_MASK(32)) != 0) | 3197 | if (!phba->pcidev) |
2727 | goto out_idr_remove; | 3198 | return error; |
3199 | else | ||
3200 | pdev = phba->pcidev; | ||
2728 | 3201 | ||
2729 | /* | 3202 | /* Set the device DMA mask size */ |
2730 | * Get the bus address of Bar0 and Bar2 and the number of bytes | 3203 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) |
3204 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) | ||
3205 | return error; | ||
3206 | |||
3207 | /* Get the bus address of Bar0 and Bar2 and the number of bytes | ||
2731 | * required by each mapping. | 3208 | * required by each mapping. |
2732 | */ | 3209 | */ |
2733 | phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0); | 3210 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
2734 | bar0map_len = pci_resource_len(phba->pcidev, 0); | 3211 | bar0map_len = pci_resource_len(pdev, 0); |
2735 | 3212 | ||
2736 | phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2); | 3213 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
2737 | bar2map_len = pci_resource_len(phba->pcidev, 2); | 3214 | bar2map_len = pci_resource_len(pdev, 2); |
2738 | 3215 | ||
2739 | /* Map HBA SLIM to a kernel virtual address. */ | 3216 | /* Map HBA SLIM to a kernel virtual address. */ |
2740 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | 3217 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
2741 | if (!phba->slim_memmap_p) { | 3218 | if (!phba->slim_memmap_p) { |
2742 | error = -ENODEV; | ||
2743 | dev_printk(KERN_ERR, &pdev->dev, | 3219 | dev_printk(KERN_ERR, &pdev->dev, |
2744 | "ioremap failed for SLIM memory.\n"); | 3220 | "ioremap failed for SLIM memory.\n"); |
2745 | goto out_idr_remove; | 3221 | goto out; |
2746 | } | 3222 | } |
2747 | 3223 | ||
2748 | /* Map HBA Control Registers to a kernel virtual address. */ | 3224 | /* Map HBA Control Registers to a kernel virtual address. */ |
2749 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | 3225 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
2750 | if (!phba->ctrl_regs_memmap_p) { | 3226 | if (!phba->ctrl_regs_memmap_p) { |
2751 | error = -ENODEV; | ||
2752 | dev_printk(KERN_ERR, &pdev->dev, | 3227 | dev_printk(KERN_ERR, &pdev->dev, |
2753 | "ioremap failed for HBA control registers.\n"); | 3228 | "ioremap failed for HBA control registers.\n"); |
2754 | goto out_iounmap_slim; | 3229 | goto out_iounmap_slim; |
2755 | } | 3230 | } |
2756 | 3231 | ||
2757 | /* Allocate memory for SLI-2 structures */ | 3232 | /* Allocate memory for SLI-2 structures */ |
2758 | phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev, | 3233 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, |
2759 | SLI2_SLIM_SIZE, | 3234 | SLI2_SLIM_SIZE, |
2760 | &phba->slim2p.phys, | 3235 | &phba->slim2p.phys, |
2761 | GFP_KERNEL); | 3236 | GFP_KERNEL); |
@@ -2768,7 +3243,7 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |||
2768 | phba->IOCBs = (phba->slim2p.virt + | 3243 | phba->IOCBs = (phba->slim2p.virt + |
2769 | offsetof(struct lpfc_sli2_slim, IOCBs)); | 3244 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
2770 | 3245 | ||
2771 | phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev, | 3246 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
2772 | lpfc_sli_hbq_size(), | 3247 | lpfc_sli_hbq_size(), |
2773 | &phba->hbqslimp.phys, | 3248 | &phba->hbqslimp.phys, |
2774 | GFP_KERNEL); | 3249 | GFP_KERNEL); |
@@ -2784,115 +3259,487 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |||
2784 | sizeof(struct lpfc_hbq_entry)); | 3259 | sizeof(struct lpfc_hbq_entry)); |
2785 | } | 3260 | } |
2786 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | 3261 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
2787 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | 3262 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
2788 | 3263 | ||
2789 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | 3264 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
2790 | 3265 | ||
2791 | INIT_LIST_HEAD(&phba->hbqbuf_in_list); | 3266 | INIT_LIST_HEAD(&phba->rb_pend_list); |
2792 | 3267 | ||
2793 | /* Initialize the SLI Layer to run with lpfc HBAs. */ | 3268 | phba->MBslimaddr = phba->slim_memmap_p; |
2794 | lpfc_sli_setup(phba); | 3269 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
2795 | lpfc_sli_queue_setup(phba); | 3270 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
3271 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | ||
3272 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | ||
3273 | |||
3274 | return 0; | ||
3275 | |||
3276 | out_free_slim: | ||
3277 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | ||
3278 | phba->slim2p.virt, phba->slim2p.phys); | ||
3279 | out_iounmap: | ||
3280 | iounmap(phba->ctrl_regs_memmap_p); | ||
3281 | out_iounmap_slim: | ||
3282 | iounmap(phba->slim_memmap_p); | ||
3283 | out: | ||
3284 | return error; | ||
3285 | } | ||
3286 | |||
3287 | /** | ||
3288 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. | ||
3289 | * @phba: pointer to lpfc hba data structure. | ||
3290 | * | ||
3291 | * This routine is invoked to unset the PCI device memory space for device | ||
3292 | * with SLI-3 interface spec. | ||
3293 | **/ | ||
3294 | static void | ||
3295 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) | ||
3296 | { | ||
3297 | struct pci_dev *pdev; | ||
3298 | |||
3299 | /* Obtain PCI device reference */ | ||
3300 | if (!phba->pcidev) | ||
3301 | return; | ||
3302 | else | ||
3303 | pdev = phba->pcidev; | ||
3304 | |||
3305 | /* Free coherent DMA memory allocated */ | ||
3306 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | ||
3307 | phba->hbqslimp.virt, phba->hbqslimp.phys); | ||
3308 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | ||
3309 | phba->slim2p.virt, phba->slim2p.phys); | ||
3310 | |||
3311 | /* I/O memory unmap */ | ||
3312 | iounmap(phba->ctrl_regs_memmap_p); | ||
3313 | iounmap(phba->slim_memmap_p); | ||
3314 | |||
3315 | return; | ||
3316 | } | ||
3317 | |||
3318 | /** | ||
3319 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device | ||
3320 | * @phba: pointer to lpfc hba data structure. | ||
3321 | * | ||
3322 | * This routine is invoked to enable the MSI-X interrupt vectors to device | ||
3323 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is | ||
3324 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once | ||
3325 | * invoked, enables either all or nothing, depending on the current | ||
3326 | * availability of PCI vector resources. The device driver is responsible | ||
3327 | * for calling the individual request_irq() to register each MSI-X vector | ||
3328 | * with a interrupt handler, which is done in this function. Note that | ||
3329 | * later when device is unloading, the driver should always call free_irq() | ||
3330 | * on all MSI-X vectors it has done request_irq() on before calling | ||
3331 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device | ||
3332 | * will be left with MSI-X enabled and leaks its vectors. | ||
3333 | * | ||
3334 | * Return codes | ||
3335 | * 0 - sucessful | ||
3336 | * other values - error | ||
3337 | **/ | ||
3338 | static int | ||
3339 | lpfc_sli_enable_msix(struct lpfc_hba *phba) | ||
3340 | { | ||
3341 | int rc, i; | ||
3342 | LPFC_MBOXQ_t *pmb; | ||
3343 | |||
3344 | /* Set up MSI-X multi-message vectors */ | ||
3345 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | ||
3346 | phba->msix_entries[i].entry = i; | ||
2796 | 3347 | ||
2797 | retval = lpfc_mem_alloc(phba); | 3348 | /* Configure MSI-X capability structure */ |
2798 | if (retval) { | 3349 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, |
2799 | error = retval; | 3350 | ARRAY_SIZE(phba->msix_entries)); |
2800 | goto out_free_hbqslimp; | 3351 | if (rc) { |
3352 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
3353 | "0420 PCI enable MSI-X failed (%d)\n", rc); | ||
3354 | goto msi_fail_out; | ||
2801 | } | 3355 | } |
3356 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | ||
3357 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
3358 | "0477 MSI-X entry[%d]: vector=x%x " | ||
3359 | "message=%d\n", i, | ||
3360 | phba->msix_entries[i].vector, | ||
3361 | phba->msix_entries[i].entry); | ||
3362 | /* | ||
3363 | * Assign MSI-X vectors to interrupt handlers | ||
3364 | */ | ||
2802 | 3365 | ||
2803 | /* Initialize and populate the iocb list per host. */ | 3366 | /* vector-0 is associated to slow-path handler */ |
2804 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | 3367 | rc = request_irq(phba->msix_entries[0].vector, |
2805 | for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) { | 3368 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, |
2806 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); | 3369 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
2807 | if (iocbq_entry == NULL) { | 3370 | if (rc) { |
2808 | printk(KERN_ERR "%s: only allocated %d iocbs of " | 3371 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
2809 | "expected %d count. Unloading driver.\n", | 3372 | "0421 MSI-X slow-path request_irq failed " |
2810 | __func__, i, LPFC_IOCB_LIST_CNT); | 3373 | "(%d)\n", rc); |
2811 | error = -ENOMEM; | 3374 | goto msi_fail_out; |
2812 | goto out_free_iocbq; | 3375 | } |
3376 | |||
3377 | /* vector-1 is associated to fast-path handler */ | ||
3378 | rc = request_irq(phba->msix_entries[1].vector, | ||
3379 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, | ||
3380 | LPFC_FP_DRIVER_HANDLER_NAME, phba); | ||
3381 | |||
3382 | if (rc) { | ||
3383 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
3384 | "0429 MSI-X fast-path request_irq failed " | ||
3385 | "(%d)\n", rc); | ||
3386 | goto irq_fail_out; | ||
3387 | } | ||
3388 | |||
3389 | /* | ||
3390 | * Configure HBA MSI-X attention conditions to messages | ||
3391 | */ | ||
3392 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
3393 | |||
3394 | if (!pmb) { | ||
3395 | rc = -ENOMEM; | ||
3396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3397 | "0474 Unable to allocate memory for issuing " | ||
3398 | "MBOX_CONFIG_MSI command\n"); | ||
3399 | goto mem_fail_out; | ||
3400 | } | ||
3401 | rc = lpfc_config_msi(phba, pmb); | ||
3402 | if (rc) | ||
3403 | goto mbx_fail_out; | ||
3404 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | ||
3405 | if (rc != MBX_SUCCESS) { | ||
3406 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | ||
3407 | "0351 Config MSI mailbox command failed, " | ||
3408 | "mbxCmd x%x, mbxStatus x%x\n", | ||
3409 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); | ||
3410 | goto mbx_fail_out; | ||
3411 | } | ||
3412 | |||
3413 | /* Free memory allocated for mailbox command */ | ||
3414 | mempool_free(pmb, phba->mbox_mem_pool); | ||
3415 | return rc; | ||
3416 | |||
3417 | mbx_fail_out: | ||
3418 | /* Free memory allocated for mailbox command */ | ||
3419 | mempool_free(pmb, phba->mbox_mem_pool); | ||
3420 | |||
3421 | mem_fail_out: | ||
3422 | /* free the irq already requested */ | ||
3423 | free_irq(phba->msix_entries[1].vector, phba); | ||
3424 | |||
3425 | irq_fail_out: | ||
3426 | /* free the irq already requested */ | ||
3427 | free_irq(phba->msix_entries[0].vector, phba); | ||
3428 | |||
3429 | msi_fail_out: | ||
3430 | /* Unconfigure MSI-X capability structure */ | ||
3431 | pci_disable_msix(phba->pcidev); | ||
3432 | return rc; | ||
3433 | } | ||
3434 | |||
3435 | /** | ||
3436 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. | ||
3437 | * @phba: pointer to lpfc hba data structure. | ||
3438 | * | ||
3439 | * This routine is invoked to release the MSI-X vectors and then disable the | ||
3440 | * MSI-X interrupt mode to device with SLI-3 interface spec. | ||
3441 | **/ | ||
3442 | static void | ||
3443 | lpfc_sli_disable_msix(struct lpfc_hba *phba) | ||
3444 | { | ||
3445 | int i; | ||
3446 | |||
3447 | /* Free up MSI-X multi-message vectors */ | ||
3448 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | ||
3449 | free_irq(phba->msix_entries[i].vector, phba); | ||
3450 | /* Disable MSI-X */ | ||
3451 | pci_disable_msix(phba->pcidev); | ||
3452 | |||
3453 | return; | ||
3454 | } | ||
3455 | |||
3456 | /** | ||
3457 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. | ||
3458 | * @phba: pointer to lpfc hba data structure. | ||
3459 | * | ||
3460 | * This routine is invoked to enable the MSI interrupt mode to device with | ||
3461 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to | ||
3462 | * enable the MSI vector. The device driver is responsible for calling the | ||
3463 | * request_irq() to register MSI vector with a interrupt the handler, which | ||
3464 | * is done in this function. | ||
3465 | * | ||
3466 | * Return codes | ||
3467 | * 0 - sucessful | ||
3468 | * other values - error | ||
3469 | */ | ||
3470 | static int | ||
3471 | lpfc_sli_enable_msi(struct lpfc_hba *phba) | ||
3472 | { | ||
3473 | int rc; | ||
3474 | |||
3475 | rc = pci_enable_msi(phba->pcidev); | ||
3476 | if (!rc) | ||
3477 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
3478 | "0462 PCI enable MSI mode success.\n"); | ||
3479 | else { | ||
3480 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
3481 | "0471 PCI enable MSI mode failed (%d)\n", rc); | ||
3482 | return rc; | ||
3483 | } | ||
3484 | |||
3485 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | ||
3486 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | ||
3487 | if (rc) { | ||
3488 | pci_disable_msi(phba->pcidev); | ||
3489 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
3490 | "0478 MSI request_irq failed (%d)\n", rc); | ||
3491 | } | ||
3492 | return rc; | ||
3493 | } | ||
3494 | |||
3495 | /** | ||
3496 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. | ||
3497 | * @phba: pointer to lpfc hba data structure. | ||
3498 | * | ||
3499 | * This routine is invoked to disable the MSI interrupt mode to device with | ||
3500 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has | ||
3501 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | ||
3502 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | ||
3503 | * its vector. | ||
3504 | */ | ||
3505 | static void | ||
3506 | lpfc_sli_disable_msi(struct lpfc_hba *phba) | ||
3507 | { | ||
3508 | free_irq(phba->pcidev->irq, phba); | ||
3509 | pci_disable_msi(phba->pcidev); | ||
3510 | return; | ||
3511 | } | ||
3512 | |||
3513 | /** | ||
3514 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. | ||
3515 | * @phba: pointer to lpfc hba data structure. | ||
3516 | * | ||
3517 | * This routine is invoked to enable device interrupt and associate driver's | ||
3518 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface | ||
3519 | * spec. Depends on the interrupt mode configured to the driver, the driver | ||
3520 | * will try to fallback from the configured interrupt mode to an interrupt | ||
3521 | * mode which is supported by the platform, kernel, and device in the order | ||
3522 | * of: | ||
3523 | * MSI-X -> MSI -> IRQ. | ||
3524 | * | ||
3525 | * Return codes | ||
3526 | * 0 - sucessful | ||
3527 | * other values - error | ||
3528 | **/ | ||
3529 | static uint32_t | ||
3530 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | ||
3531 | { | ||
3532 | uint32_t intr_mode = LPFC_INTR_ERROR; | ||
3533 | int retval; | ||
3534 | |||
3535 | if (cfg_mode == 2) { | ||
3536 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | ||
3537 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); | ||
3538 | if (!retval) { | ||
3539 | /* Now, try to enable MSI-X interrupt mode */ | ||
3540 | retval = lpfc_sli_enable_msix(phba); | ||
3541 | if (!retval) { | ||
3542 | /* Indicate initialization to MSI-X mode */ | ||
3543 | phba->intr_type = MSIX; | ||
3544 | intr_mode = 2; | ||
3545 | } | ||
2813 | } | 3546 | } |
3547 | } | ||
2814 | 3548 | ||
2815 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); | 3549 | /* Fallback to MSI if MSI-X initialization failed */ |
2816 | if (iotag == 0) { | 3550 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
2817 | kfree (iocbq_entry); | 3551 | retval = lpfc_sli_enable_msi(phba); |
2818 | printk(KERN_ERR "%s: failed to allocate IOTAG. " | 3552 | if (!retval) { |
2819 | "Unloading driver.\n", | 3553 | /* Indicate initialization to MSI mode */ |
2820 | __func__); | 3554 | phba->intr_type = MSI; |
2821 | error = -ENOMEM; | 3555 | intr_mode = 1; |
2822 | goto out_free_iocbq; | ||
2823 | } | 3556 | } |
3557 | } | ||
2824 | 3558 | ||
2825 | spin_lock_irq(&phba->hbalock); | 3559 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
2826 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); | 3560 | if (phba->intr_type == NONE) { |
2827 | phba->total_iocbq_bufs++; | 3561 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
2828 | spin_unlock_irq(&phba->hbalock); | 3562 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
3563 | if (!retval) { | ||
3564 | /* Indicate initialization to INTx mode */ | ||
3565 | phba->intr_type = INTx; | ||
3566 | intr_mode = 0; | ||
3567 | } | ||
2829 | } | 3568 | } |
3569 | return intr_mode; | ||
3570 | } | ||
2830 | 3571 | ||
2831 | /* Initialize HBA structure */ | 3572 | /** |
2832 | phba->fc_edtov = FF_DEF_EDTOV; | 3573 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
2833 | phba->fc_ratov = FF_DEF_RATOV; | 3574 | * @phba: pointer to lpfc hba data structure. |
2834 | phba->fc_altov = FF_DEF_ALTOV; | 3575 | * |
2835 | phba->fc_arbtov = FF_DEF_ARBTOV; | 3576 | * This routine is invoked to disable device interrupt and disassociate the |
3577 | * driver's interrupt handler(s) from interrupt vector(s) to device with | ||
3578 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will | ||
3579 | * release the interrupt vector(s) for the message signaled interrupt. | ||
3580 | **/ | ||
3581 | static void | ||
3582 | lpfc_sli_disable_intr(struct lpfc_hba *phba) | ||
3583 | { | ||
3584 | /* Disable the currently initialized interrupt mode */ | ||
3585 | if (phba->intr_type == MSIX) | ||
3586 | lpfc_sli_disable_msix(phba); | ||
3587 | else if (phba->intr_type == MSI) | ||
3588 | lpfc_sli_disable_msi(phba); | ||
3589 | else if (phba->intr_type == INTx) | ||
3590 | free_irq(phba->pcidev->irq, phba); | ||
2836 | 3591 | ||
2837 | INIT_LIST_HEAD(&phba->work_list); | 3592 | /* Reset interrupt management states */ |
2838 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | 3593 | phba->intr_type = NONE; |
2839 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | 3594 | phba->sli.slistat.sli_intr = 0; |
2840 | 3595 | ||
2841 | /* Initialize the wait queue head for the kernel thread */ | 3596 | return; |
2842 | init_waitqueue_head(&phba->work_waitq); | 3597 | } |
2843 | 3598 | ||
2844 | /* Startup the kernel thread for this host adapter. */ | 3599 | /** |
2845 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | 3600 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
2846 | "lpfc_worker_%d", phba->brd_no); | 3601 | * @phba: pointer to lpfc hba data structure. |
2847 | if (IS_ERR(phba->worker_thread)) { | 3602 | * |
2848 | error = PTR_ERR(phba->worker_thread); | 3603 | * This routine is invoked to unset the HBA device initialization steps to |
2849 | goto out_free_iocbq; | 3604 | * a device with SLI-3 interface spec. |
3605 | **/ | ||
3606 | static void | ||
3607 | lpfc_unset_hba(struct lpfc_hba *phba) | ||
3608 | { | ||
3609 | struct lpfc_vport *vport = phba->pport; | ||
3610 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | ||
3611 | |||
3612 | spin_lock_irq(shost->host_lock); | ||
3613 | vport->load_flag |= FC_UNLOADING; | ||
3614 | spin_unlock_irq(shost->host_lock); | ||
3615 | |||
3616 | lpfc_stop_hba_timers(phba); | ||
3617 | |||
3618 | phba->pport->work_port_events = 0; | ||
3619 | |||
3620 | lpfc_sli_hba_down(phba); | ||
3621 | |||
3622 | lpfc_sli_brdrestart(phba); | ||
3623 | |||
3624 | lpfc_sli_disable_intr(phba); | ||
3625 | |||
3626 | return; | ||
3627 | } | ||
3628 | |||
3629 | /** | ||
3630 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. | ||
3631 | * @pdev: pointer to PCI device | ||
3632 | * @pid: pointer to PCI device identifier | ||
3633 | * | ||
3634 | * This routine is to be called to attach a device with SLI-3 interface spec | ||
3635 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | ||
3636 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | ||
3637 | * information of the device and driver to see if the driver state that it can | ||
3638 | * support this kind of device. If the match is successful, the driver core | ||
3639 | * invokes this routine. If this routine determines it can claim the HBA, it | ||
3640 | * does all the initialization that it needs to do to handle the HBA properly. | ||
3641 | * | ||
3642 | * Return code | ||
3643 | * 0 - driver can claim the device | ||
3644 | * negative value - driver can not claim the device | ||
3645 | **/ | ||
3646 | static int __devinit | ||
3647 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) | ||
3648 | { | ||
3649 | struct lpfc_hba *phba; | ||
3650 | struct lpfc_vport *vport = NULL; | ||
3651 | int error; | ||
3652 | uint32_t cfg_mode, intr_mode; | ||
3653 | |||
3654 | /* Allocate memory for HBA structure */ | ||
3655 | phba = lpfc_hba_alloc(pdev); | ||
3656 | if (!phba) | ||
3657 | return -ENOMEM; | ||
3658 | |||
3659 | /* Perform generic PCI device enabling operation */ | ||
3660 | error = lpfc_enable_pci_dev(phba); | ||
3661 | if (error) { | ||
3662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3663 | "1401 Failed to enable pci device.\n"); | ||
3664 | goto out_free_phba; | ||
2850 | } | 3665 | } |
2851 | 3666 | ||
2852 | /* Initialize the list of scsi buffers used by driver for scsi IO. */ | 3667 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
2853 | spin_lock_init(&phba->scsi_buf_list_lock); | 3668 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
2854 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | 3669 | if (error) |
3670 | goto out_disable_pci_dev; | ||
2855 | 3671 | ||
2856 | /* Initialize list of fabric iocbs */ | 3672 | /* Set up SLI-3 specific device PCI memory space */ |
2857 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | 3673 | error = lpfc_sli_pci_mem_setup(phba); |
3674 | if (error) { | ||
3675 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3676 | "1402 Failed to set up pci memory space.\n"); | ||
3677 | goto out_disable_pci_dev; | ||
3678 | } | ||
2858 | 3679 | ||
2859 | /* Initialize list to save ELS buffers */ | 3680 | /* Set up phase-1 common device driver resources */ |
2860 | INIT_LIST_HEAD(&phba->elsbuf); | 3681 | error = lpfc_setup_driver_resource_phase1(phba); |
3682 | if (error) { | ||
3683 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3684 | "1403 Failed to set up driver resource.\n"); | ||
3685 | goto out_unset_pci_mem_s3; | ||
3686 | } | ||
2861 | 3687 | ||
2862 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); | 3688 | /* Set up SLI-3 specific device driver resources */ |
2863 | if (!vport) | 3689 | error = lpfc_sli_driver_resource_setup(phba); |
2864 | goto out_kthread_stop; | 3690 | if (error) { |
3691 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3692 | "1404 Failed to set up driver resource.\n"); | ||
3693 | goto out_unset_pci_mem_s3; | ||
3694 | } | ||
2865 | 3695 | ||
2866 | shost = lpfc_shost_from_vport(vport); | 3696 | /* Initialize and populate the iocb list per host */ |
2867 | phba->pport = vport; | 3697 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
2868 | lpfc_debugfs_initialize(vport); | 3698 | if (error) { |
3699 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3700 | "1405 Failed to initialize iocb list.\n"); | ||
3701 | goto out_unset_driver_resource_s3; | ||
3702 | } | ||
2869 | 3703 | ||
2870 | pci_set_drvdata(pdev, shost); | 3704 | /* Set up common device driver resources */ |
3705 | error = lpfc_setup_driver_resource_phase2(phba); | ||
3706 | if (error) { | ||
3707 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3708 | "1406 Failed to set up driver resource.\n"); | ||
3709 | goto out_free_iocb_list; | ||
3710 | } | ||
2871 | 3711 | ||
2872 | phba->MBslimaddr = phba->slim_memmap_p; | 3712 | /* Create SCSI host to the physical port */ |
2873 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | 3713 | error = lpfc_create_shost(phba); |
2874 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | 3714 | if (error) { |
2875 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | 3715 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2876 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | 3716 | "1407 Failed to create scsi host.\n"); |
3717 | goto out_unset_driver_resource; | ||
3718 | } | ||
2877 | 3719 | ||
2878 | /* Configure sysfs attributes */ | 3720 | /* Configure sysfs attributes */ |
2879 | if (lpfc_alloc_sysfs_attr(vport)) { | 3721 | vport = phba->pport; |
3722 | error = lpfc_alloc_sysfs_attr(vport); | ||
3723 | if (error) { | ||
2880 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 3724 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2881 | "1476 Failed to allocate sysfs attr\n"); | 3725 | "1476 Failed to allocate sysfs attr\n"); |
2882 | error = -ENOMEM; | 3726 | goto out_destroy_shost; |
2883 | goto out_destroy_port; | ||
2884 | } | 3727 | } |
2885 | 3728 | ||
3729 | /* Now, trying to enable interrupt and bring up the device */ | ||
2886 | cfg_mode = phba->cfg_use_msi; | 3730 | cfg_mode = phba->cfg_use_msi; |
2887 | while (true) { | 3731 | while (true) { |
3732 | /* Put device to a known state before enabling interrupt */ | ||
3733 | lpfc_stop_port(phba); | ||
2888 | /* Configure and enable interrupt */ | 3734 | /* Configure and enable interrupt */ |
2889 | intr_mode = lpfc_enable_intr(phba, cfg_mode); | 3735 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
2890 | if (intr_mode == LPFC_INTR_ERROR) { | 3736 | if (intr_mode == LPFC_INTR_ERROR) { |
2891 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 3737 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2892 | "0426 Failed to enable interrupt.\n"); | 3738 | "0431 Failed to enable interrupt.\n"); |
3739 | error = -ENODEV; | ||
2893 | goto out_free_sysfs_attr; | 3740 | goto out_free_sysfs_attr; |
2894 | } | 3741 | } |
2895 | /* HBA SLI setup */ | 3742 | /* SLI-3 HBA setup */ |
2896 | if (lpfc_sli_hba_setup(phba)) { | 3743 | if (lpfc_sli_hba_setup(phba)) { |
2897 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 3744 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2898 | "1477 Failed to set up hba\n"); | 3745 | "1477 Failed to set up hba\n"); |
@@ -2902,185 +3749,65 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |||
2902 | 3749 | ||
2903 | /* Wait 50ms for the interrupts of previous mailbox commands */ | 3750 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
2904 | msleep(50); | 3751 | msleep(50); |
2905 | /* Check active interrupts received */ | 3752 | /* Check active interrupts on message signaled interrupts */ |
2906 | if (phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | 3753 | if (intr_mode == 0 || |
3754 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | ||
2907 | /* Log the current active interrupt mode */ | 3755 | /* Log the current active interrupt mode */ |
2908 | phba->intr_mode = intr_mode; | 3756 | phba->intr_mode = intr_mode; |
2909 | lpfc_log_intr_mode(phba, intr_mode); | 3757 | lpfc_log_intr_mode(phba, intr_mode); |
2910 | break; | 3758 | break; |
2911 | } else { | 3759 | } else { |
2912 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 3760 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2913 | "0451 Configure interrupt mode (%d) " | 3761 | "0447 Configure interrupt mode (%d) " |
2914 | "failed active interrupt test.\n", | 3762 | "failed active interrupt test.\n", |
2915 | intr_mode); | 3763 | intr_mode); |
2916 | if (intr_mode == 0) { | ||
2917 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
2918 | "0479 Failed to enable " | ||
2919 | "interrupt.\n"); | ||
2920 | error = -ENODEV; | ||
2921 | goto out_remove_device; | ||
2922 | } | ||
2923 | /* Stop HBA SLI setups */ | ||
2924 | lpfc_stop_port(phba); | ||
2925 | /* Disable the current interrupt mode */ | 3764 | /* Disable the current interrupt mode */ |
2926 | lpfc_disable_intr(phba); | 3765 | lpfc_sli_disable_intr(phba); |
2927 | /* Try next level of interrupt mode */ | 3766 | /* Try next level of interrupt mode */ |
2928 | cfg_mode = --intr_mode; | 3767 | cfg_mode = --intr_mode; |
2929 | } | 3768 | } |
2930 | } | 3769 | } |
2931 | 3770 | ||
2932 | /* | 3771 | /* Perform post initialization setup */ |
2933 | * hba setup may have changed the hba_queue_depth so we need to adjust | 3772 | lpfc_post_init_setup(phba); |
2934 | * the value of can_queue. | ||
2935 | */ | ||
2936 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | ||
2937 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { | ||
2938 | |||
2939 | if (lpfc_prot_mask && lpfc_prot_guard) { | ||
2940 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
2941 | "1478 Registering BlockGuard with the " | ||
2942 | "SCSI layer\n"); | ||
2943 | 3773 | ||
2944 | scsi_host_set_prot(shost, lpfc_prot_mask); | 3774 | /* Check if there are static vports to be created. */ |
2945 | scsi_host_set_guard(shost, lpfc_prot_guard); | 3775 | lpfc_create_static_vport(phba); |
2946 | } | ||
2947 | } | ||
2948 | |||
2949 | if (!_dump_buf_data) { | ||
2950 | int pagecnt = 10; | ||
2951 | while (pagecnt) { | ||
2952 | spin_lock_init(&_dump_buf_lock); | ||
2953 | _dump_buf_data = | ||
2954 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | ||
2955 | if (_dump_buf_data) { | ||
2956 | printk(KERN_ERR "BLKGRD allocated %d pages for " | ||
2957 | "_dump_buf_data at 0x%p\n", | ||
2958 | (1 << pagecnt), _dump_buf_data); | ||
2959 | _dump_buf_data_order = pagecnt; | ||
2960 | memset(_dump_buf_data, 0, ((1 << PAGE_SHIFT) | ||
2961 | << pagecnt)); | ||
2962 | break; | ||
2963 | } else { | ||
2964 | --pagecnt; | ||
2965 | } | ||
2966 | |||
2967 | } | ||
2968 | |||
2969 | if (!_dump_buf_data_order) | ||
2970 | printk(KERN_ERR "BLKGRD ERROR unable to allocate " | ||
2971 | "memory for hexdump\n"); | ||
2972 | |||
2973 | } else { | ||
2974 | printk(KERN_ERR "BLKGRD already allocated _dump_buf_data=0x%p" | ||
2975 | "\n", _dump_buf_data); | ||
2976 | } | ||
2977 | |||
2978 | |||
2979 | if (!_dump_buf_dif) { | ||
2980 | int pagecnt = 10; | ||
2981 | while (pagecnt) { | ||
2982 | _dump_buf_dif = | ||
2983 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | ||
2984 | if (_dump_buf_dif) { | ||
2985 | printk(KERN_ERR "BLKGRD allocated %d pages for " | ||
2986 | "_dump_buf_dif at 0x%p\n", | ||
2987 | (1 << pagecnt), _dump_buf_dif); | ||
2988 | _dump_buf_dif_order = pagecnt; | ||
2989 | memset(_dump_buf_dif, 0, ((1 << PAGE_SHIFT) | ||
2990 | << pagecnt)); | ||
2991 | break; | ||
2992 | } else { | ||
2993 | --pagecnt; | ||
2994 | } | ||
2995 | |||
2996 | } | ||
2997 | |||
2998 | if (!_dump_buf_dif_order) | ||
2999 | printk(KERN_ERR "BLKGRD ERROR unable to allocate " | ||
3000 | "memory for hexdump\n"); | ||
3001 | |||
3002 | } else { | ||
3003 | printk(KERN_ERR "BLKGRD already allocated _dump_buf_dif=0x%p\n", | ||
3004 | _dump_buf_dif); | ||
3005 | } | ||
3006 | |||
3007 | lpfc_host_attrib_init(shost); | ||
3008 | |||
3009 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | ||
3010 | spin_lock_irq(shost->host_lock); | ||
3011 | lpfc_poll_start_timer(phba); | ||
3012 | spin_unlock_irq(shost->host_lock); | ||
3013 | } | ||
3014 | |||
3015 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
3016 | "0428 Perform SCSI scan\n"); | ||
3017 | /* Send board arrival event to upper layer */ | ||
3018 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | ||
3019 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | ||
3020 | fc_host_post_vendor_event(shost, fc_get_event_number(), | ||
3021 | sizeof(adapter_event), | ||
3022 | (char *) &adapter_event, | ||
3023 | LPFC_NL_VENDOR_ID); | ||
3024 | 3776 | ||
3025 | return 0; | 3777 | return 0; |
3026 | 3778 | ||
3027 | out_remove_device: | 3779 | out_remove_device: |
3028 | spin_lock_irq(shost->host_lock); | 3780 | lpfc_unset_hba(phba); |
3029 | vport->load_flag |= FC_UNLOADING; | ||
3030 | spin_unlock_irq(shost->host_lock); | ||
3031 | lpfc_stop_phba_timers(phba); | ||
3032 | phba->pport->work_port_events = 0; | ||
3033 | lpfc_disable_intr(phba); | ||
3034 | lpfc_sli_hba_down(phba); | ||
3035 | lpfc_sli_brdrestart(phba); | ||
3036 | out_free_sysfs_attr: | 3781 | out_free_sysfs_attr: |
3037 | lpfc_free_sysfs_attr(vport); | 3782 | lpfc_free_sysfs_attr(vport); |
3038 | out_destroy_port: | 3783 | out_destroy_shost: |
3039 | destroy_port(vport); | 3784 | lpfc_destroy_shost(phba); |
3040 | out_kthread_stop: | 3785 | out_unset_driver_resource: |
3041 | kthread_stop(phba->worker_thread); | 3786 | lpfc_unset_driver_resource_phase2(phba); |
3042 | out_free_iocbq: | 3787 | out_free_iocb_list: |
3043 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | 3788 | lpfc_free_iocb_list(phba); |
3044 | &phba->lpfc_iocb_list, list) { | 3789 | out_unset_driver_resource_s3: |
3045 | kfree(iocbq_entry); | 3790 | lpfc_sli_driver_resource_unset(phba); |
3046 | phba->total_iocbq_bufs--; | 3791 | out_unset_pci_mem_s3: |
3047 | } | 3792 | lpfc_sli_pci_mem_unset(phba); |
3048 | lpfc_mem_free(phba); | 3793 | out_disable_pci_dev: |
3049 | out_free_hbqslimp: | 3794 | lpfc_disable_pci_dev(phba); |
3050 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | ||
3051 | phba->hbqslimp.virt, phba->hbqslimp.phys); | ||
3052 | out_free_slim: | ||
3053 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | ||
3054 | phba->slim2p.virt, phba->slim2p.phys); | ||
3055 | out_iounmap: | ||
3056 | iounmap(phba->ctrl_regs_memmap_p); | ||
3057 | out_iounmap_slim: | ||
3058 | iounmap(phba->slim_memmap_p); | ||
3059 | out_idr_remove: | ||
3060 | idr_remove(&lpfc_hba_index, phba->brd_no); | ||
3061 | out_free_phba: | 3795 | out_free_phba: |
3062 | kfree(phba); | 3796 | lpfc_hba_free(phba); |
3063 | out_release_regions: | ||
3064 | pci_release_selected_regions(pdev, bars); | ||
3065 | out_disable_device: | ||
3066 | pci_disable_device(pdev); | ||
3067 | out: | ||
3068 | pci_set_drvdata(pdev, NULL); | ||
3069 | if (shost) | ||
3070 | scsi_host_put(shost); | ||
3071 | return error; | 3797 | return error; |
3072 | } | 3798 | } |
3073 | 3799 | ||
3074 | /** | 3800 | /** |
3075 | * lpfc_pci_remove_one - lpfc PCI func to unregister device from PCI subsystem | 3801 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. |
3076 | * @pdev: pointer to PCI device | 3802 | * @pdev: pointer to PCI device |
3077 | * | 3803 | * |
3078 | * This routine is to be registered to the kernel's PCI subsystem. When an | 3804 | * This routine is to be called to disattach a device with SLI-3 interface |
3079 | * Emulex HBA is removed from PCI bus, it performs all the necessary cleanup | 3805 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
3080 | * for the HBA device to be removed from the PCI subsystem properly. | 3806 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
3807 | * device to be removed from the PCI subsystem properly. | ||
3081 | **/ | 3808 | **/ |
3082 | static void __devexit | 3809 | static void __devexit |
3083 | lpfc_pci_remove_one(struct pci_dev *pdev) | 3810 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
3084 | { | 3811 | { |
3085 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 3812 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3086 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 3813 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
@@ -3098,7 +3825,7 @@ lpfc_pci_remove_one(struct pci_dev *pdev) | |||
3098 | /* Release all the vports against this physical port */ | 3825 | /* Release all the vports against this physical port */ |
3099 | vports = lpfc_create_vport_work_array(phba); | 3826 | vports = lpfc_create_vport_work_array(phba); |
3100 | if (vports != NULL) | 3827 | if (vports != NULL) |
3101 | for (i = 1; i <= phba->max_vpi && vports[i] != NULL; i++) | 3828 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) |
3102 | fc_vport_terminate(vports[i]->fc_vport); | 3829 | fc_vport_terminate(vports[i]->fc_vport); |
3103 | lpfc_destroy_vport_work_array(phba, vports); | 3830 | lpfc_destroy_vport_work_array(phba, vports); |
3104 | 3831 | ||
@@ -3120,7 +3847,7 @@ lpfc_pci_remove_one(struct pci_dev *pdev) | |||
3120 | /* Final cleanup of txcmplq and reset the HBA */ | 3847 | /* Final cleanup of txcmplq and reset the HBA */ |
3121 | lpfc_sli_brdrestart(phba); | 3848 | lpfc_sli_brdrestart(phba); |
3122 | 3849 | ||
3123 | lpfc_stop_phba_timers(phba); | 3850 | lpfc_stop_hba_timers(phba); |
3124 | spin_lock_irq(&phba->hbalock); | 3851 | spin_lock_irq(&phba->hbalock); |
3125 | list_del_init(&vport->listentry); | 3852 | list_del_init(&vport->listentry); |
3126 | spin_unlock_irq(&phba->hbalock); | 3853 | spin_unlock_irq(&phba->hbalock); |
@@ -3128,7 +3855,7 @@ lpfc_pci_remove_one(struct pci_dev *pdev) | |||
3128 | lpfc_debugfs_terminate(vport); | 3855 | lpfc_debugfs_terminate(vport); |
3129 | 3856 | ||
3130 | /* Disable interrupt */ | 3857 | /* Disable interrupt */ |
3131 | lpfc_disable_intr(phba); | 3858 | lpfc_sli_disable_intr(phba); |
3132 | 3859 | ||
3133 | pci_set_drvdata(pdev, NULL); | 3860 | pci_set_drvdata(pdev, NULL); |
3134 | scsi_host_put(shost); | 3861 | scsi_host_put(shost); |
@@ -3138,7 +3865,7 @@ lpfc_pci_remove_one(struct pci_dev *pdev) | |||
3138 | * corresponding pools here. | 3865 | * corresponding pools here. |
3139 | */ | 3866 | */ |
3140 | lpfc_scsi_free(phba); | 3867 | lpfc_scsi_free(phba); |
3141 | lpfc_mem_free(phba); | 3868 | lpfc_mem_free_all(phba); |
3142 | 3869 | ||
3143 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | 3870 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
3144 | phba->hbqslimp.virt, phba->hbqslimp.phys); | 3871 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
@@ -3151,36 +3878,35 @@ lpfc_pci_remove_one(struct pci_dev *pdev) | |||
3151 | iounmap(phba->ctrl_regs_memmap_p); | 3878 | iounmap(phba->ctrl_regs_memmap_p); |
3152 | iounmap(phba->slim_memmap_p); | 3879 | iounmap(phba->slim_memmap_p); |
3153 | 3880 | ||
3154 | idr_remove(&lpfc_hba_index, phba->brd_no); | 3881 | lpfc_hba_free(phba); |
3155 | |||
3156 | kfree(phba); | ||
3157 | 3882 | ||
3158 | pci_release_selected_regions(pdev, bars); | 3883 | pci_release_selected_regions(pdev, bars); |
3159 | pci_disable_device(pdev); | 3884 | pci_disable_device(pdev); |
3160 | } | 3885 | } |
3161 | 3886 | ||
3162 | /** | 3887 | /** |
3163 | * lpfc_pci_suspend_one - lpfc PCI func to suspend device for power management | 3888 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt |
3164 | * @pdev: pointer to PCI device | 3889 | * @pdev: pointer to PCI device |
3165 | * @msg: power management message | 3890 | * @msg: power management message |
3166 | * | 3891 | * |
3167 | * This routine is to be registered to the kernel's PCI subsystem to support | 3892 | * This routine is to be called from the kernel's PCI subsystem to support |
3168 | * system Power Management (PM). When PM invokes this method, it quiesces the | 3893 | * system Power Management (PM) to device with SLI-3 interface spec. When |
3169 | * device by stopping the driver's worker thread for the device, turning off | 3894 | * PM invokes this method, it quiesces the device by stopping the driver's |
3170 | * device's interrupt and DMA, and bring the device offline. Note that as the | 3895 | * worker thread for the device, turning off device's interrupt and DMA, |
3171 | * driver implements the minimum PM requirements to a power-aware driver's PM | 3896 | * and bring the device offline. Note that as the driver implements the |
3172 | * support for suspend/resume -- all the possible PM messages (SUSPEND, | 3897 | * minimum PM requirements to a power-aware driver's PM support for the |
3173 | * HIBERNATE, FREEZE) to the suspend() method call will be treated as SUSPEND | 3898 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
3174 | * and the driver will fully reinitialize its device during resume() method | 3899 | * to the suspend() method call will be treated as SUSPEND and the driver will |
3175 | * call, the driver will set device to PCI_D3hot state in PCI config space | 3900 | * fully reinitialize its device during resume() method call, the driver will |
3176 | * instead of setting it according to the @msg provided by the PM. | 3901 | * set device to PCI_D3hot state in PCI config space instead of setting it |
3902 | * according to the @msg provided by the PM. | ||
3177 | * | 3903 | * |
3178 | * Return code | 3904 | * Return code |
3179 | * 0 - driver suspended the device | 3905 | * 0 - driver suspended the device |
3180 | * Error otherwise | 3906 | * Error otherwise |
3181 | **/ | 3907 | **/ |
3182 | static int | 3908 | static int |
3183 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | 3909 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) |
3184 | { | 3910 | { |
3185 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 3911 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3186 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 3912 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
@@ -3194,7 +3920,7 @@ lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |||
3194 | kthread_stop(phba->worker_thread); | 3920 | kthread_stop(phba->worker_thread); |
3195 | 3921 | ||
3196 | /* Disable interrupt from device */ | 3922 | /* Disable interrupt from device */ |
3197 | lpfc_disable_intr(phba); | 3923 | lpfc_sli_disable_intr(phba); |
3198 | 3924 | ||
3199 | /* Save device state to PCI config space */ | 3925 | /* Save device state to PCI config space */ |
3200 | pci_save_state(pdev); | 3926 | pci_save_state(pdev); |
@@ -3204,25 +3930,26 @@ lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |||
3204 | } | 3930 | } |
3205 | 3931 | ||
3206 | /** | 3932 | /** |
3207 | * lpfc_pci_resume_one - lpfc PCI func to resume device for power management | 3933 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt |
3208 | * @pdev: pointer to PCI device | 3934 | * @pdev: pointer to PCI device |
3209 | * | 3935 | * |
3210 | * This routine is to be registered to the kernel's PCI subsystem to support | 3936 | * This routine is to be called from the kernel's PCI subsystem to support |
3211 | * system Power Management (PM). When PM invokes this method, it restores | 3937 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
3212 | * the device's PCI config space state and fully reinitializes the device | 3938 | * invokes this method, it restores the device's PCI config space state and |
3213 | * and brings it online. Note that as the driver implements the minimum PM | 3939 | * fully reinitializes the device and brings it online. Note that as the |
3214 | * requirements to a power-aware driver's PM for suspend/resume -- all | 3940 | * driver implements the minimum PM requirements to a power-aware driver's |
3215 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | 3941 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
3216 | * method call will be treated as SUSPEND and the driver will fully | 3942 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
3217 | * reinitialize its device during resume() method call, the device will be | 3943 | * driver will fully reinitialize its device during resume() method call, |
3218 | * set to PCI_D0 directly in PCI config space before restoring the state. | 3944 | * the device will be set to PCI_D0 directly in PCI config space before |
3945 | * restoring the state. | ||
3219 | * | 3946 | * |
3220 | * Return code | 3947 | * Return code |
3221 | * 0 - driver suspended the device | 3948 | * 0 - driver suspended the device |
3222 | * Error otherwise | 3949 | * Error otherwise |
3223 | **/ | 3950 | **/ |
3224 | static int | 3951 | static int |
3225 | lpfc_pci_resume_one(struct pci_dev *pdev) | 3952 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
3226 | { | 3953 | { |
3227 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 3954 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3228 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 3955 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
@@ -3250,7 +3977,7 @@ lpfc_pci_resume_one(struct pci_dev *pdev) | |||
3250 | } | 3977 | } |
3251 | 3978 | ||
3252 | /* Configure and enable interrupt */ | 3979 | /* Configure and enable interrupt */ |
3253 | intr_mode = lpfc_enable_intr(phba, phba->intr_mode); | 3980 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
3254 | if (intr_mode == LPFC_INTR_ERROR) { | 3981 | if (intr_mode == LPFC_INTR_ERROR) { |
3255 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 3982 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3256 | "0430 PM resume Failed to enable interrupt\n"); | 3983 | "0430 PM resume Failed to enable interrupt\n"); |
@@ -3269,23 +3996,24 @@ lpfc_pci_resume_one(struct pci_dev *pdev) | |||
3269 | } | 3996 | } |
3270 | 3997 | ||
3271 | /** | 3998 | /** |
3272 | * lpfc_io_error_detected - Driver method for handling PCI I/O error detected | 3999 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error |
3273 | * @pdev: pointer to PCI device. | 4000 | * @pdev: pointer to PCI device. |
3274 | * @state: the current PCI connection state. | 4001 | * @state: the current PCI connection state. |
3275 | * | 4002 | * |
3276 | * This routine is registered to the PCI subsystem for error handling. This | 4003 | * This routine is called from the PCI subsystem for I/O error handling to |
3277 | * function is called by the PCI subsystem after a PCI bus error affecting | 4004 | * device with SLI-3 interface spec. This function is called by the PCI |
3278 | * this device has been detected. When this function is invoked, it will | 4005 | * subsystem after a PCI bus error affecting this device has been detected. |
3279 | * need to stop all the I/Os and interrupt(s) to the device. Once that is | 4006 | * When this function is invoked, it will need to stop all the I/Os and |
3280 | * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to | 4007 | * interrupt(s) to the device. Once that is done, it will return |
3281 | * perform proper recovery as desired. | 4008 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
4009 | * as desired. | ||
3282 | * | 4010 | * |
3283 | * Return codes | 4011 | * Return codes |
3284 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | 4012 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
3285 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | 4013 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
3286 | **/ | 4014 | **/ |
3287 | static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, | 4015 | static pci_ers_result_t |
3288 | pci_channel_state_t state) | 4016 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) |
3289 | { | 4017 | { |
3290 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 4018 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3291 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 4019 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
@@ -3312,30 +4040,32 @@ static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, | |||
3312 | lpfc_sli_abort_iocb_ring(phba, pring); | 4040 | lpfc_sli_abort_iocb_ring(phba, pring); |
3313 | 4041 | ||
3314 | /* Disable interrupt */ | 4042 | /* Disable interrupt */ |
3315 | lpfc_disable_intr(phba); | 4043 | lpfc_sli_disable_intr(phba); |
3316 | 4044 | ||
3317 | /* Request a slot reset. */ | 4045 | /* Request a slot reset. */ |
3318 | return PCI_ERS_RESULT_NEED_RESET; | 4046 | return PCI_ERS_RESULT_NEED_RESET; |
3319 | } | 4047 | } |
3320 | 4048 | ||
3321 | /** | 4049 | /** |
3322 | * lpfc_io_slot_reset - Restart a PCI device from scratch | 4050 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. |
3323 | * @pdev: pointer to PCI device. | 4051 | * @pdev: pointer to PCI device. |
3324 | * | 4052 | * |
3325 | * This routine is registered to the PCI subsystem for error handling. This is | 4053 | * This routine is called from the PCI subsystem for error handling to |
3326 | * called after PCI bus has been reset to restart the PCI card from scratch, | 4054 | * device with SLI-3 interface spec. This is called after PCI bus has been |
3327 | * as if from a cold-boot. During the PCI subsystem error recovery, after the | 4055 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
3328 | * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform | 4056 | * During the PCI subsystem error recovery, after driver returns |
3329 | * proper error recovery and then call this routine before calling the .resume | 4057 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
3330 | * method to recover the device. This function will initialize the HBA device, | 4058 | * recovery and then call this routine before calling the .resume method |
3331 | * enable the interrupt, but it will just put the HBA to offline state without | 4059 | * to recover the device. This function will initialize the HBA device, |
3332 | * passing any I/O traffic. | 4060 | * enable the interrupt, but it will just put the HBA to offline state |
4061 | * without passing any I/O traffic. | ||
3333 | * | 4062 | * |
3334 | * Return codes | 4063 | * Return codes |
3335 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | 4064 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
3336 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | 4065 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
3337 | */ | 4066 | */ |
3338 | static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) | 4067 | static pci_ers_result_t |
4068 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) | ||
3339 | { | 4069 | { |
3340 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 4070 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3341 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 4071 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
@@ -3354,11 +4084,11 @@ static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) | |||
3354 | pci_set_master(pdev); | 4084 | pci_set_master(pdev); |
3355 | 4085 | ||
3356 | spin_lock_irq(&phba->hbalock); | 4086 | spin_lock_irq(&phba->hbalock); |
3357 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 4087 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
3358 | spin_unlock_irq(&phba->hbalock); | 4088 | spin_unlock_irq(&phba->hbalock); |
3359 | 4089 | ||
3360 | /* Configure and enable interrupt */ | 4090 | /* Configure and enable interrupt */ |
3361 | intr_mode = lpfc_enable_intr(phba, phba->intr_mode); | 4091 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
3362 | if (intr_mode == LPFC_INTR_ERROR) { | 4092 | if (intr_mode == LPFC_INTR_ERROR) { |
3363 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 4093 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3364 | "0427 Cannot re-enable interrupt after " | 4094 | "0427 Cannot re-enable interrupt after " |
@@ -3378,15 +4108,17 @@ static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) | |||
3378 | } | 4108 | } |
3379 | 4109 | ||
3380 | /** | 4110 | /** |
3381 | * lpfc_io_resume - Resume PCI I/O operation | 4111 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. |
3382 | * @pdev: pointer to PCI device | 4112 | * @pdev: pointer to PCI device |
3383 | * | 4113 | * |
3384 | * This routine is registered to the PCI subsystem for error handling. It is | 4114 | * This routine is called from the PCI subsystem for error handling to device |
3385 | * called when kernel error recovery tells the lpfc driver that it is ok to | 4115 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
3386 | * resume normal PCI operation after PCI bus error recovery. After this call, | 4116 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
3387 | * traffic can start to flow from this device again. | 4117 | * error recovery. After this call, traffic can start to flow from this device |
4118 | * again. | ||
3388 | */ | 4119 | */ |
3389 | static void lpfc_io_resume(struct pci_dev *pdev) | 4120 | static void |
4121 | lpfc_io_resume_s3(struct pci_dev *pdev) | ||
3390 | { | 4122 | { |
3391 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 4123 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3392 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 4124 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
@@ -3394,6 +4126,235 @@ static void lpfc_io_resume(struct pci_dev *pdev) | |||
3394 | lpfc_online(phba); | 4126 | lpfc_online(phba); |
3395 | } | 4127 | } |
3396 | 4128 | ||
4129 | /** | ||
4130 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem | ||
4131 | * @pdev: pointer to PCI device | ||
4132 | * @pid: pointer to PCI device identifier | ||
4133 | * | ||
4134 | * This routine is to be registered to the kernel's PCI subsystem. When an | ||
4135 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks | ||
4136 | * at PCI device-specific information of the device and driver to see if the | ||
4137 | * driver state that it can support this kind of device. If the match is | ||
4138 | * successful, the driver core invokes this routine. This routine dispatches | ||
4139 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will | ||
4140 | * do all the initialization that it needs to do to handle the HBA device | ||
4141 | * properly. | ||
4142 | * | ||
4143 | * Return code | ||
4144 | * 0 - driver can claim the device | ||
4145 | * negative value - driver can not claim the device | ||
4146 | **/ | ||
4147 | static int __devinit | ||
4148 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | ||
4149 | { | ||
4150 | int rc; | ||
4151 | uint16_t dev_id; | ||
4152 | |||
4153 | if (pci_read_config_word(pdev, PCI_DEVICE_ID, &dev_id)) | ||
4154 | return -ENODEV; | ||
4155 | |||
4156 | switch (dev_id) { | ||
4157 | default: | ||
4158 | rc = lpfc_pci_probe_one_s3(pdev, pid); | ||
4159 | break; | ||
4160 | } | ||
4161 | return rc; | ||
4162 | } | ||
4163 | |||
4164 | /** | ||
4165 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem | ||
4166 | * @pdev: pointer to PCI device | ||
4167 | * | ||
4168 | * This routine is to be registered to the kernel's PCI subsystem. When an | ||
4169 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. | ||
4170 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device | ||
4171 | * remove routine, which will perform all the necessary cleanup for the | ||
4172 | * device to be removed from the PCI subsystem properly. | ||
4173 | **/ | ||
4174 | static void __devexit | ||
4175 | lpfc_pci_remove_one(struct pci_dev *pdev) | ||
4176 | { | ||
4177 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
4178 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
4179 | |||
4180 | switch (phba->pci_dev_grp) { | ||
4181 | case LPFC_PCI_DEV_LP: | ||
4182 | lpfc_pci_remove_one_s3(pdev); | ||
4183 | break; | ||
4184 | default: | ||
4185 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4186 | "1424 Invalid PCI device group: 0x%x\n", | ||
4187 | phba->pci_dev_grp); | ||
4188 | break; | ||
4189 | } | ||
4190 | return; | ||
4191 | } | ||
4192 | |||
4193 | /** | ||
4194 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management | ||
4195 | * @pdev: pointer to PCI device | ||
4196 | * @msg: power management message | ||
4197 | * | ||
4198 | * This routine is to be registered to the kernel's PCI subsystem to support | ||
4199 | * system Power Management (PM). When PM invokes this method, it dispatches | ||
4200 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will | ||
4201 | * suspend the device. | ||
4202 | * | ||
4203 | * Return code | ||
4204 | * 0 - driver suspended the device | ||
4205 | * Error otherwise | ||
4206 | **/ | ||
4207 | static int | ||
4208 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | ||
4209 | { | ||
4210 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
4211 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
4212 | int rc = -ENODEV; | ||
4213 | |||
4214 | switch (phba->pci_dev_grp) { | ||
4215 | case LPFC_PCI_DEV_LP: | ||
4216 | rc = lpfc_pci_suspend_one_s3(pdev, msg); | ||
4217 | break; | ||
4218 | default: | ||
4219 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4220 | "1425 Invalid PCI device group: 0x%x\n", | ||
4221 | phba->pci_dev_grp); | ||
4222 | break; | ||
4223 | } | ||
4224 | return rc; | ||
4225 | } | ||
4226 | |||
4227 | /** | ||
4228 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management | ||
4229 | * @pdev: pointer to PCI device | ||
4230 | * | ||
4231 | * This routine is to be registered to the kernel's PCI subsystem to support | ||
4232 | * system Power Management (PM). When PM invokes this method, it dispatches | ||
4233 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will | ||
4234 | * resume the device. | ||
4235 | * | ||
4236 | * Return code | ||
4237 | * 0 - driver suspended the device | ||
4238 | * Error otherwise | ||
4239 | **/ | ||
4240 | static int | ||
4241 | lpfc_pci_resume_one(struct pci_dev *pdev) | ||
4242 | { | ||
4243 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
4244 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
4245 | int rc = -ENODEV; | ||
4246 | |||
4247 | switch (phba->pci_dev_grp) { | ||
4248 | case LPFC_PCI_DEV_LP: | ||
4249 | rc = lpfc_pci_resume_one_s3(pdev); | ||
4250 | break; | ||
4251 | default: | ||
4252 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4253 | "1426 Invalid PCI device group: 0x%x\n", | ||
4254 | phba->pci_dev_grp); | ||
4255 | break; | ||
4256 | } | ||
4257 | return rc; | ||
4258 | } | ||
4259 | |||
4260 | /** | ||
4261 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error | ||
4262 | * @pdev: pointer to PCI device. | ||
4263 | * @state: the current PCI connection state. | ||
4264 | * | ||
4265 | * This routine is registered to the PCI subsystem for error handling. This | ||
4266 | * function is called by the PCI subsystem after a PCI bus error affecting | ||
4267 | * this device has been detected. When this routine is invoked, it dispatches | ||
4268 | * the action to the proper SLI-3 or SLI-4 device error detected handling | ||
4269 | * routine, which will perform the proper error detected operation. | ||
4270 | * | ||
4271 | * Return codes | ||
4272 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | ||
4273 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | ||
4274 | **/ | ||
4275 | static pci_ers_result_t | ||
4276 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | ||
4277 | { | ||
4278 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
4279 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
4280 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | ||
4281 | |||
4282 | switch (phba->pci_dev_grp) { | ||
4283 | case LPFC_PCI_DEV_LP: | ||
4284 | rc = lpfc_io_error_detected_s3(pdev, state); | ||
4285 | break; | ||
4286 | default: | ||
4287 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4288 | "1427 Invalid PCI device group: 0x%x\n", | ||
4289 | phba->pci_dev_grp); | ||
4290 | break; | ||
4291 | } | ||
4292 | return rc; | ||
4293 | } | ||
4294 | |||
4295 | /** | ||
4296 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch | ||
4297 | * @pdev: pointer to PCI device. | ||
4298 | * | ||
4299 | * This routine is registered to the PCI subsystem for error handling. This | ||
4300 | * function is called after PCI bus has been reset to restart the PCI card | ||
4301 | * from scratch, as if from a cold-boot. When this routine is invoked, it | ||
4302 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling | ||
4303 | * routine, which will perform the proper device reset. | ||
4304 | * | ||
4305 | * Return codes | ||
4306 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | ||
4307 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | ||
4308 | **/ | ||
4309 | static pci_ers_result_t | ||
4310 | lpfc_io_slot_reset(struct pci_dev *pdev) | ||
4311 | { | ||
4312 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
4313 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
4314 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | ||
4315 | |||
4316 | switch (phba->pci_dev_grp) { | ||
4317 | case LPFC_PCI_DEV_LP: | ||
4318 | rc = lpfc_io_slot_reset_s3(pdev); | ||
4319 | break; | ||
4320 | default: | ||
4321 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4322 | "1428 Invalid PCI device group: 0x%x\n", | ||
4323 | phba->pci_dev_grp); | ||
4324 | break; | ||
4325 | } | ||
4326 | return rc; | ||
4327 | } | ||
4328 | |||
4329 | /** | ||
4330 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation | ||
4331 | * @pdev: pointer to PCI device | ||
4332 | * | ||
4333 | * This routine is registered to the PCI subsystem for error handling. It | ||
4334 | * is called when kernel error recovery tells the lpfc driver that it is | ||
4335 | * OK to resume normal PCI operation after PCI bus error recovery. When | ||
4336 | * this routine is invoked, it dispatches the action to the proper SLI-3 | ||
4337 | * or SLI-4 device io_resume routine, which will resume the device operation. | ||
4338 | **/ | ||
4339 | static void | ||
4340 | lpfc_io_resume(struct pci_dev *pdev) | ||
4341 | { | ||
4342 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
4343 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
4344 | |||
4345 | switch (phba->pci_dev_grp) { | ||
4346 | case LPFC_PCI_DEV_LP: | ||
4347 | lpfc_io_resume_s3(pdev); | ||
4348 | break; | ||
4349 | default: | ||
4350 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4351 | "1429 Invalid PCI device group: 0x%x\n", | ||
4352 | phba->pci_dev_grp); | ||
4353 | break; | ||
4354 | } | ||
4355 | return; | ||
4356 | } | ||
4357 | |||
3397 | static struct pci_device_id lpfc_id_table[] = { | 4358 | static struct pci_device_id lpfc_id_table[] = { |
3398 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | 4359 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
3399 | PCI_ANY_ID, PCI_ANY_ID, }, | 4360 | PCI_ANY_ID, PCI_ANY_ID, }, |
@@ -3469,6 +4430,10 @@ static struct pci_device_id lpfc_id_table[] = { | |||
3469 | PCI_ANY_ID, PCI_ANY_ID, }, | 4430 | PCI_ANY_ID, PCI_ANY_ID, }, |
3470 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, | 4431 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
3471 | PCI_ANY_ID, PCI_ANY_ID, }, | 4432 | PCI_ANY_ID, PCI_ANY_ID, }, |
4433 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, | ||
4434 | PCI_ANY_ID, PCI_ANY_ID, }, | ||
4435 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK_S, | ||
4436 | PCI_ANY_ID, PCI_ANY_ID, }, | ||
3472 | { 0 } | 4437 | { 0 } |
3473 | }; | 4438 | }; |
3474 | 4439 | ||
@@ -3486,7 +4451,7 @@ static struct pci_driver lpfc_driver = { | |||
3486 | .probe = lpfc_pci_probe_one, | 4451 | .probe = lpfc_pci_probe_one, |
3487 | .remove = __devexit_p(lpfc_pci_remove_one), | 4452 | .remove = __devexit_p(lpfc_pci_remove_one), |
3488 | .suspend = lpfc_pci_suspend_one, | 4453 | .suspend = lpfc_pci_suspend_one, |
3489 | .resume = lpfc_pci_resume_one, | 4454 | .resume = lpfc_pci_resume_one, |
3490 | .err_handler = &lpfc_err_handler, | 4455 | .err_handler = &lpfc_err_handler, |
3491 | }; | 4456 | }; |
3492 | 4457 | ||