diff options
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_init.c')
-rw-r--r-- | drivers/scsi/lpfc/lpfc_init.c | 5626 |
1 files changed, 5050 insertions, 576 deletions
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index 86d1bdcbf2d8..2f5907f92eea 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /******************************************************************* | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | 2 | * This file is part of the Emulex Linux Device Driver for * |
3 | * Fibre Channel Host Bus Adapters. * | 3 | * Fibre Channel Host Bus Adapters. * |
4 | * Copyright (C) 2004-2008 Emulex. All rights reserved. * | 4 | * Copyright (C) 2004-2009 Emulex. All rights reserved. * |
5 | * EMULEX and SLI are trademarks of Emulex. * | 5 | * EMULEX and SLI are trademarks of Emulex. * |
6 | * www.emulex.com * | 6 | * www.emulex.com * |
7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
@@ -34,8 +34,10 @@ | |||
34 | #include <scsi/scsi_host.h> | 34 | #include <scsi/scsi_host.h> |
35 | #include <scsi/scsi_transport_fc.h> | 35 | #include <scsi/scsi_transport_fc.h> |
36 | 36 | ||
37 | #include "lpfc_hw4.h" | ||
37 | #include "lpfc_hw.h" | 38 | #include "lpfc_hw.h" |
38 | #include "lpfc_sli.h" | 39 | #include "lpfc_sli.h" |
40 | #include "lpfc_sli4.h" | ||
39 | #include "lpfc_nl.h" | 41 | #include "lpfc_nl.h" |
40 | #include "lpfc_disc.h" | 42 | #include "lpfc_disc.h" |
41 | #include "lpfc_scsi.h" | 43 | #include "lpfc_scsi.h" |
@@ -51,9 +53,23 @@ char *_dump_buf_dif; | |||
51 | unsigned long _dump_buf_dif_order; | 53 | unsigned long _dump_buf_dif_order; |
52 | spinlock_t _dump_buf_lock; | 54 | spinlock_t _dump_buf_lock; |
53 | 55 | ||
54 | static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int); | ||
55 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); | 56 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
56 | static int lpfc_post_rcv_buf(struct lpfc_hba *); | 57 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
58 | static int lpfc_sli4_queue_create(struct lpfc_hba *); | ||
59 | static void lpfc_sli4_queue_destroy(struct lpfc_hba *); | ||
60 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); | ||
61 | static int lpfc_setup_endian_order(struct lpfc_hba *); | ||
62 | static int lpfc_sli4_read_config(struct lpfc_hba *); | ||
63 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); | ||
64 | static void lpfc_free_sgl_list(struct lpfc_hba *); | ||
65 | static int lpfc_init_sgl_list(struct lpfc_hba *); | ||
66 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); | ||
67 | static void lpfc_free_active_sgl(struct lpfc_hba *); | ||
68 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); | ||
69 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); | ||
70 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); | ||
71 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); | ||
72 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); | ||
57 | 73 | ||
58 | static struct scsi_transport_template *lpfc_transport_template = NULL; | 74 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
59 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; | 75 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
@@ -92,7 +108,7 @@ lpfc_config_port_prep(struct lpfc_hba *phba) | |||
92 | return -ENOMEM; | 108 | return -ENOMEM; |
93 | } | 109 | } |
94 | 110 | ||
95 | mb = &pmb->mb; | 111 | mb = &pmb->u.mb; |
96 | phba->link_state = LPFC_INIT_MBX_CMDS; | 112 | phba->link_state = LPFC_INIT_MBX_CMDS; |
97 | 113 | ||
98 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | 114 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
@@ -205,6 +221,11 @@ lpfc_config_port_prep(struct lpfc_hba *phba) | |||
205 | mb->mbxCommand, mb->mbxStatus); | 221 | mb->mbxCommand, mb->mbxStatus); |
206 | mb->un.varDmp.word_cnt = 0; | 222 | mb->un.varDmp.word_cnt = 0; |
207 | } | 223 | } |
224 | /* dump mem may return a zero when finished or we got a | ||
225 | * mailbox error, either way we are done. | ||
226 | */ | ||
227 | if (mb->un.varDmp.word_cnt == 0) | ||
228 | break; | ||
208 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) | 229 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
209 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; | 230 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
210 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, | 231 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
@@ -233,7 +254,7 @@ out_free_mbox: | |||
233 | static void | 254 | static void |
234 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | 255 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
235 | { | 256 | { |
236 | if (pmboxq->mb.mbxStatus == MBX_SUCCESS) | 257 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
237 | phba->temp_sensor_support = 1; | 258 | phba->temp_sensor_support = 1; |
238 | else | 259 | else |
239 | phba->temp_sensor_support = 0; | 260 | phba->temp_sensor_support = 0; |
@@ -260,7 +281,7 @@ lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |||
260 | /* character array used for decoding dist type. */ | 281 | /* character array used for decoding dist type. */ |
261 | char dist_char[] = "nabx"; | 282 | char dist_char[] = "nabx"; |
262 | 283 | ||
263 | if (pmboxq->mb.mbxStatus != MBX_SUCCESS) { | 284 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
264 | mempool_free(pmboxq, phba->mbox_mem_pool); | 285 | mempool_free(pmboxq, phba->mbox_mem_pool); |
265 | return; | 286 | return; |
266 | } | 287 | } |
@@ -268,7 +289,7 @@ lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |||
268 | prg = (struct prog_id *) &prog_id_word; | 289 | prg = (struct prog_id *) &prog_id_word; |
269 | 290 | ||
270 | /* word 7 contain option rom version */ | 291 | /* word 7 contain option rom version */ |
271 | prog_id_word = pmboxq->mb.un.varWords[7]; | 292 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
272 | 293 | ||
273 | /* Decode the Option rom version word to a readable string */ | 294 | /* Decode the Option rom version word to a readable string */ |
274 | if (prg->dist < 4) | 295 | if (prg->dist < 4) |
@@ -325,7 +346,7 @@ lpfc_config_port_post(struct lpfc_hba *phba) | |||
325 | phba->link_state = LPFC_HBA_ERROR; | 346 | phba->link_state = LPFC_HBA_ERROR; |
326 | return -ENOMEM; | 347 | return -ENOMEM; |
327 | } | 348 | } |
328 | mb = &pmb->mb; | 349 | mb = &pmb->u.mb; |
329 | 350 | ||
330 | /* Get login parameters for NID. */ | 351 | /* Get login parameters for NID. */ |
331 | lpfc_read_sparam(phba, pmb, 0); | 352 | lpfc_read_sparam(phba, pmb, 0); |
@@ -364,6 +385,7 @@ lpfc_config_port_post(struct lpfc_hba *phba) | |||
364 | /* Update the fc_host data structures with new wwn. */ | 385 | /* Update the fc_host data structures with new wwn. */ |
365 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | 386 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
366 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | 387 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
388 | fc_host_max_npiv_vports(shost) = phba->max_vpi; | ||
367 | 389 | ||
368 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ | 390 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
369 | /* This should be consolidated into parse_vpd ? - mr */ | 391 | /* This should be consolidated into parse_vpd ? - mr */ |
@@ -460,17 +482,18 @@ lpfc_config_port_post(struct lpfc_hba *phba) | |||
460 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | 482 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
461 | "0352 Config MSI mailbox command " | 483 | "0352 Config MSI mailbox command " |
462 | "failed, mbxCmd x%x, mbxStatus x%x\n", | 484 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
463 | pmb->mb.mbxCommand, pmb->mb.mbxStatus); | 485 | pmb->u.mb.mbxCommand, |
486 | pmb->u.mb.mbxStatus); | ||
464 | mempool_free(pmb, phba->mbox_mem_pool); | 487 | mempool_free(pmb, phba->mbox_mem_pool); |
465 | return -EIO; | 488 | return -EIO; |
466 | } | 489 | } |
467 | } | 490 | } |
468 | 491 | ||
492 | spin_lock_irq(&phba->hbalock); | ||
469 | /* Initialize ERATT handling flag */ | 493 | /* Initialize ERATT handling flag */ |
470 | phba->hba_flag &= ~HBA_ERATT_HANDLED; | 494 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
471 | 495 | ||
472 | /* Enable appropriate host interrupts */ | 496 | /* Enable appropriate host interrupts */ |
473 | spin_lock_irq(&phba->hbalock); | ||
474 | status = readl(phba->HCregaddr); | 497 | status = readl(phba->HCregaddr); |
475 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; | 498 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
476 | if (psli->num_rings > 0) | 499 | if (psli->num_rings > 0) |
@@ -571,16 +594,20 @@ lpfc_hba_down_prep(struct lpfc_hba *phba) | |||
571 | { | 594 | { |
572 | struct lpfc_vport **vports; | 595 | struct lpfc_vport **vports; |
573 | int i; | 596 | int i; |
574 | /* Disable interrupts */ | 597 | |
575 | writel(0, phba->HCregaddr); | 598 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
576 | readl(phba->HCregaddr); /* flush */ | 599 | /* Disable interrupts */ |
600 | writel(0, phba->HCregaddr); | ||
601 | readl(phba->HCregaddr); /* flush */ | ||
602 | } | ||
577 | 603 | ||
578 | if (phba->pport->load_flag & FC_UNLOADING) | 604 | if (phba->pport->load_flag & FC_UNLOADING) |
579 | lpfc_cleanup_discovery_resources(phba->pport); | 605 | lpfc_cleanup_discovery_resources(phba->pport); |
580 | else { | 606 | else { |
581 | vports = lpfc_create_vport_work_array(phba); | 607 | vports = lpfc_create_vport_work_array(phba); |
582 | if (vports != NULL) | 608 | if (vports != NULL) |
583 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) | 609 | for (i = 0; i <= phba->max_vports && |
610 | vports[i] != NULL; i++) | ||
584 | lpfc_cleanup_discovery_resources(vports[i]); | 611 | lpfc_cleanup_discovery_resources(vports[i]); |
585 | lpfc_destroy_vport_work_array(phba, vports); | 612 | lpfc_destroy_vport_work_array(phba, vports); |
586 | } | 613 | } |
@@ -588,7 +615,7 @@ lpfc_hba_down_prep(struct lpfc_hba *phba) | |||
588 | } | 615 | } |
589 | 616 | ||
590 | /** | 617 | /** |
591 | * lpfc_hba_down_post - Perform lpfc uninitialization after HBA reset | 618 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
592 | * @phba: pointer to lpfc HBA data structure. | 619 | * @phba: pointer to lpfc HBA data structure. |
593 | * | 620 | * |
594 | * This routine will do uninitialization after the HBA is reset when bring | 621 | * This routine will do uninitialization after the HBA is reset when bring |
@@ -598,8 +625,8 @@ lpfc_hba_down_prep(struct lpfc_hba *phba) | |||
598 | * 0 - sucess. | 625 | * 0 - sucess. |
599 | * Any other value - error. | 626 | * Any other value - error. |
600 | **/ | 627 | **/ |
601 | int | 628 | static int |
602 | lpfc_hba_down_post(struct lpfc_hba *phba) | 629 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
603 | { | 630 | { |
604 | struct lpfc_sli *psli = &phba->sli; | 631 | struct lpfc_sli *psli = &phba->sli; |
605 | struct lpfc_sli_ring *pring; | 632 | struct lpfc_sli_ring *pring; |
@@ -642,6 +669,77 @@ lpfc_hba_down_post(struct lpfc_hba *phba) | |||
642 | 669 | ||
643 | return 0; | 670 | return 0; |
644 | } | 671 | } |
672 | /** | ||
673 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset | ||
674 | * @phba: pointer to lpfc HBA data structure. | ||
675 | * | ||
676 | * This routine will do uninitialization after the HBA is reset when bring | ||
677 | * down the SLI Layer. | ||
678 | * | ||
679 | * Return codes | ||
680 | * 0 - sucess. | ||
681 | * Any other value - error. | ||
682 | **/ | ||
683 | static int | ||
684 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) | ||
685 | { | ||
686 | struct lpfc_scsi_buf *psb, *psb_next; | ||
687 | LIST_HEAD(aborts); | ||
688 | int ret; | ||
689 | unsigned long iflag = 0; | ||
690 | ret = lpfc_hba_down_post_s3(phba); | ||
691 | if (ret) | ||
692 | return ret; | ||
693 | /* At this point in time the HBA is either reset or DOA. Either | ||
694 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be | ||
695 | * on the lpfc_sgl_list so that it can either be freed if the | ||
696 | * driver is unloading or reposted if the driver is restarting | ||
697 | * the port. | ||
698 | */ | ||
699 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ | ||
700 | /* scsl_buf_list */ | ||
701 | /* abts_sgl_list_lock required because worker thread uses this | ||
702 | * list. | ||
703 | */ | ||
704 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | ||
705 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, | ||
706 | &phba->sli4_hba.lpfc_sgl_list); | ||
707 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | ||
708 | /* abts_scsi_buf_list_lock required because worker thread uses this | ||
709 | * list. | ||
710 | */ | ||
711 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | ||
712 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, | ||
713 | &aborts); | ||
714 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | ||
715 | spin_unlock_irq(&phba->hbalock); | ||
716 | |||
717 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { | ||
718 | psb->pCmd = NULL; | ||
719 | psb->status = IOSTAT_SUCCESS; | ||
720 | } | ||
721 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); | ||
722 | list_splice(&aborts, &phba->lpfc_scsi_buf_list); | ||
723 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); | ||
724 | return 0; | ||
725 | } | ||
726 | |||
727 | /** | ||
728 | * lpfc_hba_down_post - Wrapper func for hba down post routine | ||
729 | * @phba: pointer to lpfc HBA data structure. | ||
730 | * | ||
731 | * This routine wraps the actual SLI3 or SLI4 routine for performing | ||
732 | * uninitialization after the HBA is reset when bring down the SLI Layer. | ||
733 | * | ||
734 | * Return codes | ||
735 | * 0 - sucess. | ||
736 | * Any other value - error. | ||
737 | **/ | ||
738 | int | ||
739 | lpfc_hba_down_post(struct lpfc_hba *phba) | ||
740 | { | ||
741 | return (*phba->lpfc_hba_down_post)(phba); | ||
742 | } | ||
645 | 743 | ||
646 | /** | 744 | /** |
647 | * lpfc_hb_timeout - The HBA-timer timeout handler | 745 | * lpfc_hb_timeout - The HBA-timer timeout handler |
@@ -809,7 +907,7 @@ lpfc_hb_timeout_handler(struct lpfc_hba *phba) | |||
809 | "taking this port offline.\n"); | 907 | "taking this port offline.\n"); |
810 | 908 | ||
811 | spin_lock_irq(&phba->hbalock); | 909 | spin_lock_irq(&phba->hbalock); |
812 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 910 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
813 | spin_unlock_irq(&phba->hbalock); | 911 | spin_unlock_irq(&phba->hbalock); |
814 | 912 | ||
815 | lpfc_offline_prep(phba); | 913 | lpfc_offline_prep(phba); |
@@ -834,13 +932,15 @@ lpfc_offline_eratt(struct lpfc_hba *phba) | |||
834 | struct lpfc_sli *psli = &phba->sli; | 932 | struct lpfc_sli *psli = &phba->sli; |
835 | 933 | ||
836 | spin_lock_irq(&phba->hbalock); | 934 | spin_lock_irq(&phba->hbalock); |
837 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 935 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
838 | spin_unlock_irq(&phba->hbalock); | 936 | spin_unlock_irq(&phba->hbalock); |
839 | lpfc_offline_prep(phba); | 937 | lpfc_offline_prep(phba); |
840 | 938 | ||
841 | lpfc_offline(phba); | 939 | lpfc_offline(phba); |
842 | lpfc_reset_barrier(phba); | 940 | lpfc_reset_barrier(phba); |
941 | spin_lock_irq(&phba->hbalock); | ||
843 | lpfc_sli_brdreset(phba); | 942 | lpfc_sli_brdreset(phba); |
943 | spin_unlock_irq(&phba->hbalock); | ||
844 | lpfc_hba_down_post(phba); | 944 | lpfc_hba_down_post(phba); |
845 | lpfc_sli_brdready(phba, HS_MBRDY); | 945 | lpfc_sli_brdready(phba, HS_MBRDY); |
846 | lpfc_unblock_mgmt_io(phba); | 946 | lpfc_unblock_mgmt_io(phba); |
@@ -849,6 +949,25 @@ lpfc_offline_eratt(struct lpfc_hba *phba) | |||
849 | } | 949 | } |
850 | 950 | ||
851 | /** | 951 | /** |
952 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention | ||
953 | * @phba: pointer to lpfc hba data structure. | ||
954 | * | ||
955 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error | ||
956 | * other than Port Error 6 has been detected. | ||
957 | **/ | ||
958 | static void | ||
959 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) | ||
960 | { | ||
961 | lpfc_offline_prep(phba); | ||
962 | lpfc_offline(phba); | ||
963 | lpfc_sli4_brdreset(phba); | ||
964 | lpfc_hba_down_post(phba); | ||
965 | lpfc_sli4_post_status_check(phba); | ||
966 | lpfc_unblock_mgmt_io(phba); | ||
967 | phba->link_state = LPFC_HBA_ERROR; | ||
968 | } | ||
969 | |||
970 | /** | ||
852 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler | 971 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
853 | * @phba: pointer to lpfc hba data structure. | 972 | * @phba: pointer to lpfc hba data structure. |
854 | * | 973 | * |
@@ -864,6 +983,16 @@ lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |||
864 | struct lpfc_sli_ring *pring; | 983 | struct lpfc_sli_ring *pring; |
865 | struct lpfc_sli *psli = &phba->sli; | 984 | struct lpfc_sli *psli = &phba->sli; |
866 | 985 | ||
986 | /* If the pci channel is offline, ignore possible errors, | ||
987 | * since we cannot communicate with the pci card anyway. | ||
988 | */ | ||
989 | if (pci_channel_offline(phba->pcidev)) { | ||
990 | spin_lock_irq(&phba->hbalock); | ||
991 | phba->hba_flag &= ~DEFER_ERATT; | ||
992 | spin_unlock_irq(&phba->hbalock); | ||
993 | return; | ||
994 | } | ||
995 | |||
867 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 996 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
868 | "0479 Deferred Adapter Hardware Error " | 997 | "0479 Deferred Adapter Hardware Error " |
869 | "Data: x%x x%x x%x\n", | 998 | "Data: x%x x%x x%x\n", |
@@ -871,7 +1000,7 @@ lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |||
871 | phba->work_status[0], phba->work_status[1]); | 1000 | phba->work_status[0], phba->work_status[1]); |
872 | 1001 | ||
873 | spin_lock_irq(&phba->hbalock); | 1002 | spin_lock_irq(&phba->hbalock); |
874 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 1003 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
875 | spin_unlock_irq(&phba->hbalock); | 1004 | spin_unlock_irq(&phba->hbalock); |
876 | 1005 | ||
877 | 1006 | ||
@@ -909,13 +1038,30 @@ lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |||
909 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) | 1038 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
910 | phba->work_hs = old_host_status & ~HS_FFER1; | 1039 | phba->work_hs = old_host_status & ~HS_FFER1; |
911 | 1040 | ||
1041 | spin_lock_irq(&phba->hbalock); | ||
912 | phba->hba_flag &= ~DEFER_ERATT; | 1042 | phba->hba_flag &= ~DEFER_ERATT; |
1043 | spin_unlock_irq(&phba->hbalock); | ||
913 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); | 1044 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
914 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | 1045 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
915 | } | 1046 | } |
916 | 1047 | ||
1048 | static void | ||
1049 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) | ||
1050 | { | ||
1051 | struct lpfc_board_event_header board_event; | ||
1052 | struct Scsi_Host *shost; | ||
1053 | |||
1054 | board_event.event_type = FC_REG_BOARD_EVENT; | ||
1055 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | ||
1056 | shost = lpfc_shost_from_vport(phba->pport); | ||
1057 | fc_host_post_vendor_event(shost, fc_get_event_number(), | ||
1058 | sizeof(board_event), | ||
1059 | (char *) &board_event, | ||
1060 | LPFC_NL_VENDOR_ID); | ||
1061 | } | ||
1062 | |||
917 | /** | 1063 | /** |
918 | * lpfc_handle_eratt - The HBA hardware error handler | 1064 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
919 | * @phba: pointer to lpfc hba data structure. | 1065 | * @phba: pointer to lpfc hba data structure. |
920 | * | 1066 | * |
921 | * This routine is invoked to handle the following HBA hardware error | 1067 | * This routine is invoked to handle the following HBA hardware error |
@@ -924,8 +1070,8 @@ lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |||
924 | * 2 - DMA ring index out of range | 1070 | * 2 - DMA ring index out of range |
925 | * 3 - Mailbox command came back as unknown | 1071 | * 3 - Mailbox command came back as unknown |
926 | **/ | 1072 | **/ |
927 | void | 1073 | static void |
928 | lpfc_handle_eratt(struct lpfc_hba *phba) | 1074 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
929 | { | 1075 | { |
930 | struct lpfc_vport *vport = phba->pport; | 1076 | struct lpfc_vport *vport = phba->pport; |
931 | struct lpfc_sli *psli = &phba->sli; | 1077 | struct lpfc_sli *psli = &phba->sli; |
@@ -934,24 +1080,23 @@ lpfc_handle_eratt(struct lpfc_hba *phba) | |||
934 | unsigned long temperature; | 1080 | unsigned long temperature; |
935 | struct temp_event temp_event_data; | 1081 | struct temp_event temp_event_data; |
936 | struct Scsi_Host *shost; | 1082 | struct Scsi_Host *shost; |
937 | struct lpfc_board_event_header board_event; | ||
938 | 1083 | ||
939 | /* If the pci channel is offline, ignore possible errors, | 1084 | /* If the pci channel is offline, ignore possible errors, |
940 | * since we cannot communicate with the pci card anyway. */ | 1085 | * since we cannot communicate with the pci card anyway. |
941 | if (pci_channel_offline(phba->pcidev)) | 1086 | */ |
1087 | if (pci_channel_offline(phba->pcidev)) { | ||
1088 | spin_lock_irq(&phba->hbalock); | ||
1089 | phba->hba_flag &= ~DEFER_ERATT; | ||
1090 | spin_unlock_irq(&phba->hbalock); | ||
942 | return; | 1091 | return; |
1092 | } | ||
1093 | |||
943 | /* If resets are disabled then leave the HBA alone and return */ | 1094 | /* If resets are disabled then leave the HBA alone and return */ |
944 | if (!phba->cfg_enable_hba_reset) | 1095 | if (!phba->cfg_enable_hba_reset) |
945 | return; | 1096 | return; |
946 | 1097 | ||
947 | /* Send an internal error event to mgmt application */ | 1098 | /* Send an internal error event to mgmt application */ |
948 | board_event.event_type = FC_REG_BOARD_EVENT; | 1099 | 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 | 1100 | ||
956 | if (phba->hba_flag & DEFER_ERATT) | 1101 | if (phba->hba_flag & DEFER_ERATT) |
957 | lpfc_handle_deferred_eratt(phba); | 1102 | lpfc_handle_deferred_eratt(phba); |
@@ -965,7 +1110,7 @@ lpfc_handle_eratt(struct lpfc_hba *phba) | |||
965 | phba->work_status[0], phba->work_status[1]); | 1110 | phba->work_status[0], phba->work_status[1]); |
966 | 1111 | ||
967 | spin_lock_irq(&phba->hbalock); | 1112 | spin_lock_irq(&phba->hbalock); |
968 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 1113 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
969 | spin_unlock_irq(&phba->hbalock); | 1114 | spin_unlock_irq(&phba->hbalock); |
970 | 1115 | ||
971 | /* | 1116 | /* |
@@ -1037,6 +1182,65 @@ lpfc_handle_eratt(struct lpfc_hba *phba) | |||
1037 | } | 1182 | } |
1038 | 1183 | ||
1039 | /** | 1184 | /** |
1185 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler | ||
1186 | * @phba: pointer to lpfc hba data structure. | ||
1187 | * | ||
1188 | * This routine is invoked to handle the SLI4 HBA hardware error attention | ||
1189 | * conditions. | ||
1190 | **/ | ||
1191 | static void | ||
1192 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) | ||
1193 | { | ||
1194 | struct lpfc_vport *vport = phba->pport; | ||
1195 | uint32_t event_data; | ||
1196 | struct Scsi_Host *shost; | ||
1197 | |||
1198 | /* If the pci channel is offline, ignore possible errors, since | ||
1199 | * we cannot communicate with the pci card anyway. | ||
1200 | */ | ||
1201 | if (pci_channel_offline(phba->pcidev)) | ||
1202 | return; | ||
1203 | /* If resets are disabled then leave the HBA alone and return */ | ||
1204 | if (!phba->cfg_enable_hba_reset) | ||
1205 | return; | ||
1206 | |||
1207 | /* Send an internal error event to mgmt application */ | ||
1208 | lpfc_board_errevt_to_mgmt(phba); | ||
1209 | |||
1210 | /* For now, the actual action for SLI4 device handling is not | ||
1211 | * specified yet, just treated it as adaptor hardware failure | ||
1212 | */ | ||
1213 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
1214 | "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n", | ||
1215 | phba->work_status[0], phba->work_status[1]); | ||
1216 | |||
1217 | event_data = FC_REG_DUMP_EVENT; | ||
1218 | shost = lpfc_shost_from_vport(vport); | ||
1219 | fc_host_post_vendor_event(shost, fc_get_event_number(), | ||
1220 | sizeof(event_data), (char *) &event_data, | ||
1221 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | ||
1222 | |||
1223 | lpfc_sli4_offline_eratt(phba); | ||
1224 | } | ||
1225 | |||
1226 | /** | ||
1227 | * lpfc_handle_eratt - Wrapper func for handling hba error attention | ||
1228 | * @phba: pointer to lpfc HBA data structure. | ||
1229 | * | ||
1230 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling | ||
1231 | * routine from the API jump table function pointer from the lpfc_hba struct. | ||
1232 | * | ||
1233 | * Return codes | ||
1234 | * 0 - sucess. | ||
1235 | * Any other value - error. | ||
1236 | **/ | ||
1237 | void | ||
1238 | lpfc_handle_eratt(struct lpfc_hba *phba) | ||
1239 | { | ||
1240 | (*phba->lpfc_handle_eratt)(phba); | ||
1241 | } | ||
1242 | |||
1243 | /** | ||
1040 | * lpfc_handle_latt - The HBA link event handler | 1244 | * lpfc_handle_latt - The HBA link event handler |
1041 | * @phba: pointer to lpfc hba data structure. | 1245 | * @phba: pointer to lpfc hba data structure. |
1042 | * | 1246 | * |
@@ -1137,7 +1341,7 @@ lpfc_handle_latt_err_exit: | |||
1137 | * 0 - pointer to the VPD passed in is NULL | 1341 | * 0 - pointer to the VPD passed in is NULL |
1138 | * 1 - success | 1342 | * 1 - success |
1139 | **/ | 1343 | **/ |
1140 | static int | 1344 | int |
1141 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) | 1345 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
1142 | { | 1346 | { |
1143 | uint8_t lenlo, lenhi; | 1347 | uint8_t lenlo, lenhi; |
@@ -1292,6 +1496,7 @@ lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) | |||
1292 | uint16_t dev_id = phba->pcidev->device; | 1496 | uint16_t dev_id = phba->pcidev->device; |
1293 | int max_speed; | 1497 | int max_speed; |
1294 | int GE = 0; | 1498 | int GE = 0; |
1499 | int oneConnect = 0; /* default is not a oneConnect */ | ||
1295 | struct { | 1500 | struct { |
1296 | char * name; | 1501 | char * name; |
1297 | int max_speed; | 1502 | int max_speed; |
@@ -1437,6 +1642,14 @@ lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) | |||
1437 | case PCI_DEVICE_ID_PROTEUS_S: | 1642 | case PCI_DEVICE_ID_PROTEUS_S: |
1438 | m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"}; | 1643 | m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"}; |
1439 | break; | 1644 | break; |
1645 | case PCI_DEVICE_ID_TIGERSHARK: | ||
1646 | oneConnect = 1; | ||
1647 | m = (typeof(m)) {"OCe10100-F", max_speed, "PCIe"}; | ||
1648 | break; | ||
1649 | case PCI_DEVICE_ID_TIGERSHARK_S: | ||
1650 | oneConnect = 1; | ||
1651 | m = (typeof(m)) {"OCe10100-F-S", max_speed, "PCIe"}; | ||
1652 | break; | ||
1440 | default: | 1653 | default: |
1441 | m = (typeof(m)){ NULL }; | 1654 | m = (typeof(m)){ NULL }; |
1442 | break; | 1655 | break; |
@@ -1444,13 +1657,24 @@ lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) | |||
1444 | 1657 | ||
1445 | if (mdp && mdp[0] == '\0') | 1658 | if (mdp && mdp[0] == '\0') |
1446 | snprintf(mdp, 79,"%s", m.name); | 1659 | snprintf(mdp, 79,"%s", m.name); |
1447 | if (descp && descp[0] == '\0') | 1660 | /* oneConnect hba requires special processing, they are all initiators |
1448 | snprintf(descp, 255, | 1661 | * and we put the port number on the end |
1449 | "Emulex %s %d%s %s %s", | 1662 | */ |
1450 | m.name, m.max_speed, | 1663 | if (descp && descp[0] == '\0') { |
1451 | (GE) ? "GE" : "Gb", | 1664 | if (oneConnect) |
1452 | m.bus, | 1665 | snprintf(descp, 255, |
1453 | (GE) ? "FCoE Adapter" : "Fibre Channel Adapter"); | 1666 | "Emulex OneConnect %s, FCoE Initiator, Port %s", |
1667 | m.name, | ||
1668 | phba->Port); | ||
1669 | else | ||
1670 | snprintf(descp, 255, | ||
1671 | "Emulex %s %d%s %s %s", | ||
1672 | m.name, m.max_speed, | ||
1673 | (GE) ? "GE" : "Gb", | ||
1674 | m.bus, | ||
1675 | (GE) ? "FCoE Adapter" : | ||
1676 | "Fibre Channel Adapter"); | ||
1677 | } | ||
1454 | } | 1678 | } |
1455 | 1679 | ||
1456 | /** | 1680 | /** |
@@ -1533,7 +1757,8 @@ lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) | |||
1533 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | 1757 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
1534 | icmd->ulpLe = 1; | 1758 | icmd->ulpLe = 1; |
1535 | 1759 | ||
1536 | if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { | 1760 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
1761 | IOCB_ERROR) { | ||
1537 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); | 1762 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
1538 | kfree(mp1); | 1763 | kfree(mp1); |
1539 | cnt++; | 1764 | cnt++; |
@@ -1761,7 +1986,6 @@ lpfc_cleanup(struct lpfc_vport *vport) | |||
1761 | * Lets wait for this to happen, if needed. | 1986 | * Lets wait for this to happen, if needed. |
1762 | */ | 1987 | */ |
1763 | while (!list_empty(&vport->fc_nodes)) { | 1988 | while (!list_empty(&vport->fc_nodes)) { |
1764 | |||
1765 | if (i++ > 3000) { | 1989 | if (i++ > 3000) { |
1766 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, | 1990 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
1767 | "0233 Nodelist not empty\n"); | 1991 | "0233 Nodelist not empty\n"); |
@@ -1782,7 +2006,6 @@ lpfc_cleanup(struct lpfc_vport *vport) | |||
1782 | /* Wait for any activity on ndlps to settle */ | 2006 | /* Wait for any activity on ndlps to settle */ |
1783 | msleep(10); | 2007 | msleep(10); |
1784 | } | 2008 | } |
1785 | return; | ||
1786 | } | 2009 | } |
1787 | 2010 | ||
1788 | /** | 2011 | /** |
@@ -1803,22 +2026,36 @@ lpfc_stop_vport_timers(struct lpfc_vport *vport) | |||
1803 | } | 2026 | } |
1804 | 2027 | ||
1805 | /** | 2028 | /** |
1806 | * lpfc_stop_phba_timers - Stop all the timers associated with an HBA | 2029 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
1807 | * @phba: pointer to lpfc hba data structure. | 2030 | * @phba: pointer to lpfc hba data structure. |
1808 | * | 2031 | * |
1809 | * This routine stops all the timers associated with a HBA. This function is | 2032 | * 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. | 2033 | * invoked before either putting a HBA offline or unloading the driver. |
1811 | **/ | 2034 | **/ |
1812 | static void | 2035 | void |
1813 | lpfc_stop_phba_timers(struct lpfc_hba *phba) | 2036 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
1814 | { | 2037 | { |
1815 | del_timer_sync(&phba->fcp_poll_timer); | ||
1816 | lpfc_stop_vport_timers(phba->pport); | 2038 | lpfc_stop_vport_timers(phba->pport); |
1817 | del_timer_sync(&phba->sli.mbox_tmo); | 2039 | del_timer_sync(&phba->sli.mbox_tmo); |
1818 | del_timer_sync(&phba->fabric_block_timer); | 2040 | 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); | 2041 | del_timer_sync(&phba->eratt_poll); |
2042 | del_timer_sync(&phba->hb_tmofunc); | ||
2043 | phba->hb_outstanding = 0; | ||
2044 | |||
2045 | switch (phba->pci_dev_grp) { | ||
2046 | case LPFC_PCI_DEV_LP: | ||
2047 | /* Stop any LightPulse device specific driver timers */ | ||
2048 | del_timer_sync(&phba->fcp_poll_timer); | ||
2049 | break; | ||
2050 | case LPFC_PCI_DEV_OC: | ||
2051 | /* Stop any OneConnect device sepcific driver timers */ | ||
2052 | break; | ||
2053 | default: | ||
2054 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
2055 | "0297 Invalid device group (x%x)\n", | ||
2056 | phba->pci_dev_grp); | ||
2057 | break; | ||
2058 | } | ||
1822 | return; | 2059 | return; |
1823 | } | 2060 | } |
1824 | 2061 | ||
@@ -1878,14 +2115,21 @@ lpfc_online(struct lpfc_hba *phba) | |||
1878 | return 1; | 2115 | return 1; |
1879 | } | 2116 | } |
1880 | 2117 | ||
1881 | if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */ | 2118 | if (phba->sli_rev == LPFC_SLI_REV4) { |
1882 | lpfc_unblock_mgmt_io(phba); | 2119 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
1883 | return 1; | 2120 | lpfc_unblock_mgmt_io(phba); |
2121 | return 1; | ||
2122 | } | ||
2123 | } else { | ||
2124 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ | ||
2125 | lpfc_unblock_mgmt_io(phba); | ||
2126 | return 1; | ||
2127 | } | ||
1884 | } | 2128 | } |
1885 | 2129 | ||
1886 | vports = lpfc_create_vport_work_array(phba); | 2130 | vports = lpfc_create_vport_work_array(phba); |
1887 | if (vports != NULL) | 2131 | if (vports != NULL) |
1888 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | 2132 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
1889 | struct Scsi_Host *shost; | 2133 | struct Scsi_Host *shost; |
1890 | shost = lpfc_shost_from_vport(vports[i]); | 2134 | shost = lpfc_shost_from_vport(vports[i]); |
1891 | spin_lock_irq(shost->host_lock); | 2135 | spin_lock_irq(shost->host_lock); |
@@ -1947,11 +2191,12 @@ lpfc_offline_prep(struct lpfc_hba * phba) | |||
1947 | /* Issue an unreg_login to all nodes on all vports */ | 2191 | /* Issue an unreg_login to all nodes on all vports */ |
1948 | vports = lpfc_create_vport_work_array(phba); | 2192 | vports = lpfc_create_vport_work_array(phba); |
1949 | if (vports != NULL) { | 2193 | if (vports != NULL) { |
1950 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | 2194 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
1951 | struct Scsi_Host *shost; | 2195 | struct Scsi_Host *shost; |
1952 | 2196 | ||
1953 | if (vports[i]->load_flag & FC_UNLOADING) | 2197 | if (vports[i]->load_flag & FC_UNLOADING) |
1954 | continue; | 2198 | continue; |
2199 | vports[i]->vfi_state &= ~LPFC_VFI_REGISTERED; | ||
1955 | shost = lpfc_shost_from_vport(vports[i]); | 2200 | shost = lpfc_shost_from_vport(vports[i]); |
1956 | list_for_each_entry_safe(ndlp, next_ndlp, | 2201 | list_for_each_entry_safe(ndlp, next_ndlp, |
1957 | &vports[i]->fc_nodes, | 2202 | &vports[i]->fc_nodes, |
@@ -1975,7 +2220,7 @@ lpfc_offline_prep(struct lpfc_hba * phba) | |||
1975 | } | 2220 | } |
1976 | lpfc_destroy_vport_work_array(phba, vports); | 2221 | lpfc_destroy_vport_work_array(phba, vports); |
1977 | 2222 | ||
1978 | lpfc_sli_flush_mbox_queue(phba); | 2223 | lpfc_sli_mbox_sys_shutdown(phba); |
1979 | } | 2224 | } |
1980 | 2225 | ||
1981 | /** | 2226 | /** |
@@ -1996,11 +2241,11 @@ lpfc_offline(struct lpfc_hba *phba) | |||
1996 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) | 2241 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
1997 | return; | 2242 | return; |
1998 | 2243 | ||
1999 | /* stop all timers associated with this hba */ | 2244 | /* stop port and all timers associated with this hba */ |
2000 | lpfc_stop_phba_timers(phba); | 2245 | lpfc_stop_port(phba); |
2001 | vports = lpfc_create_vport_work_array(phba); | 2246 | vports = lpfc_create_vport_work_array(phba); |
2002 | if (vports != NULL) | 2247 | if (vports != NULL) |
2003 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) | 2248 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
2004 | lpfc_stop_vport_timers(vports[i]); | 2249 | lpfc_stop_vport_timers(vports[i]); |
2005 | lpfc_destroy_vport_work_array(phba, vports); | 2250 | lpfc_destroy_vport_work_array(phba, vports); |
2006 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | 2251 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
@@ -2013,7 +2258,7 @@ lpfc_offline(struct lpfc_hba *phba) | |||
2013 | spin_unlock_irq(&phba->hbalock); | 2258 | spin_unlock_irq(&phba->hbalock); |
2014 | vports = lpfc_create_vport_work_array(phba); | 2259 | vports = lpfc_create_vport_work_array(phba); |
2015 | if (vports != NULL) | 2260 | if (vports != NULL) |
2016 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { | 2261 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
2017 | shost = lpfc_shost_from_vport(vports[i]); | 2262 | shost = lpfc_shost_from_vport(vports[i]); |
2018 | spin_lock_irq(shost->host_lock); | 2263 | spin_lock_irq(shost->host_lock); |
2019 | vports[i]->work_port_events = 0; | 2264 | vports[i]->work_port_events = 0; |
@@ -2106,6 +2351,10 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) | |||
2106 | shost->max_lun = vport->cfg_max_luns; | 2351 | shost->max_lun = vport->cfg_max_luns; |
2107 | shost->this_id = -1; | 2352 | shost->this_id = -1; |
2108 | shost->max_cmd_len = 16; | 2353 | shost->max_cmd_len = 16; |
2354 | if (phba->sli_rev == LPFC_SLI_REV4) { | ||
2355 | shost->dma_boundary = LPFC_SLI4_MAX_SEGMENT_SIZE; | ||
2356 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; | ||
2357 | } | ||
2109 | 2358 | ||
2110 | /* | 2359 | /* |
2111 | * Set initial can_queue value since 0 is no longer supported and | 2360 | * Set initial can_queue value since 0 is no longer supported and |
@@ -2123,6 +2372,7 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) | |||
2123 | 2372 | ||
2124 | /* Initialize all internally managed lists. */ | 2373 | /* Initialize all internally managed lists. */ |
2125 | INIT_LIST_HEAD(&vport->fc_nodes); | 2374 | INIT_LIST_HEAD(&vport->fc_nodes); |
2375 | INIT_LIST_HEAD(&vport->rcv_buffer_list); | ||
2126 | spin_lock_init(&vport->work_port_lock); | 2376 | spin_lock_init(&vport->work_port_lock); |
2127 | 2377 | ||
2128 | init_timer(&vport->fc_disctmo); | 2378 | init_timer(&vport->fc_disctmo); |
@@ -2314,15 +2564,3461 @@ void lpfc_host_attrib_init(struct Scsi_Host *shost) | |||
2314 | } | 2564 | } |
2315 | 2565 | ||
2316 | /** | 2566 | /** |
2317 | * lpfc_enable_msix - Enable MSI-X interrupt mode | 2567 | * lpfc_stop_port_s3 - Stop SLI3 device port |
2568 | * @phba: pointer to lpfc hba data structure. | ||
2569 | * | ||
2570 | * This routine is invoked to stop an SLI3 device port, it stops the device | ||
2571 | * from generating interrupts and stops the device driver's timers for the | ||
2572 | * device. | ||
2573 | **/ | ||
2574 | static void | ||
2575 | lpfc_stop_port_s3(struct lpfc_hba *phba) | ||
2576 | { | ||
2577 | /* Clear all interrupt enable conditions */ | ||
2578 | writel(0, phba->HCregaddr); | ||
2579 | readl(phba->HCregaddr); /* flush */ | ||
2580 | /* Clear all pending interrupts */ | ||
2581 | writel(0xffffffff, phba->HAregaddr); | ||
2582 | readl(phba->HAregaddr); /* flush */ | ||
2583 | |||
2584 | /* Reset some HBA SLI setup states */ | ||
2585 | lpfc_stop_hba_timers(phba); | ||
2586 | phba->pport->work_port_events = 0; | ||
2587 | } | ||
2588 | |||
2589 | /** | ||
2590 | * lpfc_stop_port_s4 - Stop SLI4 device port | ||
2591 | * @phba: pointer to lpfc hba data structure. | ||
2592 | * | ||
2593 | * This routine is invoked to stop an SLI4 device port, it stops the device | ||
2594 | * from generating interrupts and stops the device driver's timers for the | ||
2595 | * device. | ||
2596 | **/ | ||
2597 | static void | ||
2598 | lpfc_stop_port_s4(struct lpfc_hba *phba) | ||
2599 | { | ||
2600 | /* Reset some HBA SLI4 setup states */ | ||
2601 | lpfc_stop_hba_timers(phba); | ||
2602 | phba->pport->work_port_events = 0; | ||
2603 | phba->sli4_hba.intr_enable = 0; | ||
2604 | /* Hard clear it for now, shall have more graceful way to wait later */ | ||
2605 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | ||
2606 | } | ||
2607 | |||
2608 | /** | ||
2609 | * lpfc_stop_port - Wrapper function for stopping hba port | ||
2610 | * @phba: Pointer to HBA context object. | ||
2611 | * | ||
2612 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from | ||
2613 | * the API jump table function pointer from the lpfc_hba struct. | ||
2614 | **/ | ||
2615 | void | ||
2616 | lpfc_stop_port(struct lpfc_hba *phba) | ||
2617 | { | ||
2618 | phba->lpfc_stop_port(phba); | ||
2619 | } | ||
2620 | |||
2621 | /** | ||
2622 | * lpfc_sli4_remove_dflt_fcf - Remove the driver default fcf record from the port. | ||
2623 | * @phba: pointer to lpfc hba data structure. | ||
2624 | * | ||
2625 | * This routine is invoked to remove the driver default fcf record from | ||
2626 | * the port. This routine currently acts on FCF Index 0. | ||
2627 | * | ||
2628 | **/ | ||
2629 | void | ||
2630 | lpfc_sli_remove_dflt_fcf(struct lpfc_hba *phba) | ||
2631 | { | ||
2632 | int rc = 0; | ||
2633 | LPFC_MBOXQ_t *mboxq; | ||
2634 | struct lpfc_mbx_del_fcf_tbl_entry *del_fcf_record; | ||
2635 | uint32_t mbox_tmo, req_len; | ||
2636 | uint32_t shdr_status, shdr_add_status; | ||
2637 | |||
2638 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
2639 | if (!mboxq) { | ||
2640 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
2641 | "2020 Failed to allocate mbox for ADD_FCF cmd\n"); | ||
2642 | return; | ||
2643 | } | ||
2644 | |||
2645 | req_len = sizeof(struct lpfc_mbx_del_fcf_tbl_entry) - | ||
2646 | sizeof(struct lpfc_sli4_cfg_mhdr); | ||
2647 | rc = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | ||
2648 | LPFC_MBOX_OPCODE_FCOE_DELETE_FCF, | ||
2649 | req_len, LPFC_SLI4_MBX_EMBED); | ||
2650 | /* | ||
2651 | * In phase 1, there is a single FCF index, 0. In phase2, the driver | ||
2652 | * supports multiple FCF indices. | ||
2653 | */ | ||
2654 | del_fcf_record = &mboxq->u.mqe.un.del_fcf_entry; | ||
2655 | bf_set(lpfc_mbx_del_fcf_tbl_count, del_fcf_record, 1); | ||
2656 | bf_set(lpfc_mbx_del_fcf_tbl_index, del_fcf_record, | ||
2657 | phba->fcf.fcf_indx); | ||
2658 | |||
2659 | if (!phba->sli4_hba.intr_enable) | ||
2660 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | ||
2661 | else { | ||
2662 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | ||
2663 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | ||
2664 | } | ||
2665 | /* The IOCTL status is embedded in the mailbox subheader. */ | ||
2666 | shdr_status = bf_get(lpfc_mbox_hdr_status, | ||
2667 | &del_fcf_record->header.cfg_shdr.response); | ||
2668 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | ||
2669 | &del_fcf_record->header.cfg_shdr.response); | ||
2670 | if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) { | ||
2671 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
2672 | "2516 DEL FCF of default FCF Index failed " | ||
2673 | "mbx status x%x, status x%x add_status x%x\n", | ||
2674 | rc, shdr_status, shdr_add_status); | ||
2675 | } | ||
2676 | if (rc != MBX_TIMEOUT) | ||
2677 | mempool_free(mboxq, phba->mbox_mem_pool); | ||
2678 | } | ||
2679 | |||
2680 | /** | ||
2681 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code | ||
2682 | * @phba: pointer to lpfc hba data structure. | ||
2683 | * @acqe_link: pointer to the async link completion queue entry. | ||
2684 | * | ||
2685 | * This routine is to parse the SLI4 link-attention link fault code and | ||
2686 | * translate it into the base driver's read link attention mailbox command | ||
2687 | * status. | ||
2688 | * | ||
2689 | * Return: Link-attention status in terms of base driver's coding. | ||
2690 | **/ | ||
2691 | static uint16_t | ||
2692 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, | ||
2693 | struct lpfc_acqe_link *acqe_link) | ||
2694 | { | ||
2695 | uint16_t latt_fault; | ||
2696 | |||
2697 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { | ||
2698 | case LPFC_ASYNC_LINK_FAULT_NONE: | ||
2699 | case LPFC_ASYNC_LINK_FAULT_LOCAL: | ||
2700 | case LPFC_ASYNC_LINK_FAULT_REMOTE: | ||
2701 | latt_fault = 0; | ||
2702 | break; | ||
2703 | default: | ||
2704 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
2705 | "0398 Invalid link fault code: x%x\n", | ||
2706 | bf_get(lpfc_acqe_link_fault, acqe_link)); | ||
2707 | latt_fault = MBXERR_ERROR; | ||
2708 | break; | ||
2709 | } | ||
2710 | return latt_fault; | ||
2711 | } | ||
2712 | |||
2713 | /** | ||
2714 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type | ||
2715 | * @phba: pointer to lpfc hba data structure. | ||
2716 | * @acqe_link: pointer to the async link completion queue entry. | ||
2717 | * | ||
2718 | * This routine is to parse the SLI4 link attention type and translate it | ||
2719 | * into the base driver's link attention type coding. | ||
2720 | * | ||
2721 | * Return: Link attention type in terms of base driver's coding. | ||
2722 | **/ | ||
2723 | static uint8_t | ||
2724 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, | ||
2725 | struct lpfc_acqe_link *acqe_link) | ||
2726 | { | ||
2727 | uint8_t att_type; | ||
2728 | |||
2729 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { | ||
2730 | case LPFC_ASYNC_LINK_STATUS_DOWN: | ||
2731 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: | ||
2732 | att_type = AT_LINK_DOWN; | ||
2733 | break; | ||
2734 | case LPFC_ASYNC_LINK_STATUS_UP: | ||
2735 | /* Ignore physical link up events - wait for logical link up */ | ||
2736 | att_type = AT_RESERVED; | ||
2737 | break; | ||
2738 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: | ||
2739 | att_type = AT_LINK_UP; | ||
2740 | break; | ||
2741 | default: | ||
2742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
2743 | "0399 Invalid link attention type: x%x\n", | ||
2744 | bf_get(lpfc_acqe_link_status, acqe_link)); | ||
2745 | att_type = AT_RESERVED; | ||
2746 | break; | ||
2747 | } | ||
2748 | return att_type; | ||
2749 | } | ||
2750 | |||
2751 | /** | ||
2752 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed | ||
2753 | * @phba: pointer to lpfc hba data structure. | ||
2754 | * @acqe_link: pointer to the async link completion queue entry. | ||
2755 | * | ||
2756 | * This routine is to parse the SLI4 link-attention link speed and translate | ||
2757 | * it into the base driver's link-attention link speed coding. | ||
2758 | * | ||
2759 | * Return: Link-attention link speed in terms of base driver's coding. | ||
2760 | **/ | ||
2761 | static uint8_t | ||
2762 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, | ||
2763 | struct lpfc_acqe_link *acqe_link) | ||
2764 | { | ||
2765 | uint8_t link_speed; | ||
2766 | |||
2767 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { | ||
2768 | case LPFC_ASYNC_LINK_SPEED_ZERO: | ||
2769 | link_speed = LA_UNKNW_LINK; | ||
2770 | break; | ||
2771 | case LPFC_ASYNC_LINK_SPEED_10MBPS: | ||
2772 | link_speed = LA_UNKNW_LINK; | ||
2773 | break; | ||
2774 | case LPFC_ASYNC_LINK_SPEED_100MBPS: | ||
2775 | link_speed = LA_UNKNW_LINK; | ||
2776 | break; | ||
2777 | case LPFC_ASYNC_LINK_SPEED_1GBPS: | ||
2778 | link_speed = LA_1GHZ_LINK; | ||
2779 | break; | ||
2780 | case LPFC_ASYNC_LINK_SPEED_10GBPS: | ||
2781 | link_speed = LA_10GHZ_LINK; | ||
2782 | break; | ||
2783 | default: | ||
2784 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
2785 | "0483 Invalid link-attention link speed: x%x\n", | ||
2786 | bf_get(lpfc_acqe_link_speed, acqe_link)); | ||
2787 | link_speed = LA_UNKNW_LINK; | ||
2788 | break; | ||
2789 | } | ||
2790 | return link_speed; | ||
2791 | } | ||
2792 | |||
2793 | /** | ||
2794 | * lpfc_sli4_async_link_evt - Process the asynchronous link event | ||
2795 | * @phba: pointer to lpfc hba data structure. | ||
2796 | * @acqe_link: pointer to the async link completion queue entry. | ||
2797 | * | ||
2798 | * This routine is to handle the SLI4 asynchronous link event. | ||
2799 | **/ | ||
2800 | static void | ||
2801 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, | ||
2802 | struct lpfc_acqe_link *acqe_link) | ||
2803 | { | ||
2804 | struct lpfc_dmabuf *mp; | ||
2805 | LPFC_MBOXQ_t *pmb; | ||
2806 | MAILBOX_t *mb; | ||
2807 | READ_LA_VAR *la; | ||
2808 | uint8_t att_type; | ||
2809 | |||
2810 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); | ||
2811 | if (att_type != AT_LINK_DOWN && att_type != AT_LINK_UP) | ||
2812 | return; | ||
2813 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
2814 | if (!pmb) { | ||
2815 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
2816 | "0395 The mboxq allocation failed\n"); | ||
2817 | return; | ||
2818 | } | ||
2819 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | ||
2820 | if (!mp) { | ||
2821 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
2822 | "0396 The lpfc_dmabuf allocation failed\n"); | ||
2823 | goto out_free_pmb; | ||
2824 | } | ||
2825 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | ||
2826 | if (!mp->virt) { | ||
2827 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
2828 | "0397 The mbuf allocation failed\n"); | ||
2829 | goto out_free_dmabuf; | ||
2830 | } | ||
2831 | |||
2832 | /* Cleanup any outstanding ELS commands */ | ||
2833 | lpfc_els_flush_all_cmd(phba); | ||
2834 | |||
2835 | /* Block ELS IOCBs until we have done process link event */ | ||
2836 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | ||
2837 | |||
2838 | /* Update link event statistics */ | ||
2839 | phba->sli.slistat.link_event++; | ||
2840 | |||
2841 | /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */ | ||
2842 | lpfc_read_la(phba, pmb, mp); | ||
2843 | pmb->vport = phba->pport; | ||
2844 | |||
2845 | /* Parse and translate status field */ | ||
2846 | mb = &pmb->u.mb; | ||
2847 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); | ||
2848 | |||
2849 | /* Parse and translate link attention fields */ | ||
2850 | la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA; | ||
2851 | la->eventTag = acqe_link->event_tag; | ||
2852 | la->attType = att_type; | ||
2853 | la->UlnkSpeed = lpfc_sli4_parse_latt_link_speed(phba, acqe_link); | ||
2854 | |||
2855 | /* Fake the the following irrelvant fields */ | ||
2856 | la->topology = TOPOLOGY_PT_PT; | ||
2857 | la->granted_AL_PA = 0; | ||
2858 | la->il = 0; | ||
2859 | la->pb = 0; | ||
2860 | la->fa = 0; | ||
2861 | la->mm = 0; | ||
2862 | |||
2863 | /* Keep the link status for extra SLI4 state machine reference */ | ||
2864 | phba->sli4_hba.link_state.speed = | ||
2865 | bf_get(lpfc_acqe_link_speed, acqe_link); | ||
2866 | phba->sli4_hba.link_state.duplex = | ||
2867 | bf_get(lpfc_acqe_link_duplex, acqe_link); | ||
2868 | phba->sli4_hba.link_state.status = | ||
2869 | bf_get(lpfc_acqe_link_status, acqe_link); | ||
2870 | phba->sli4_hba.link_state.physical = | ||
2871 | bf_get(lpfc_acqe_link_physical, acqe_link); | ||
2872 | phba->sli4_hba.link_state.fault = | ||
2873 | bf_get(lpfc_acqe_link_fault, acqe_link); | ||
2874 | |||
2875 | /* Invoke the lpfc_handle_latt mailbox command callback function */ | ||
2876 | lpfc_mbx_cmpl_read_la(phba, pmb); | ||
2877 | |||
2878 | return; | ||
2879 | |||
2880 | out_free_dmabuf: | ||
2881 | kfree(mp); | ||
2882 | out_free_pmb: | ||
2883 | mempool_free(pmb, phba->mbox_mem_pool); | ||
2884 | } | ||
2885 | |||
2886 | /** | ||
2887 | * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event | ||
2888 | * @phba: pointer to lpfc hba data structure. | ||
2889 | * @acqe_link: pointer to the async fcoe completion queue entry. | ||
2890 | * | ||
2891 | * This routine is to handle the SLI4 asynchronous fcoe event. | ||
2892 | **/ | ||
2893 | static void | ||
2894 | lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba, | ||
2895 | struct lpfc_acqe_fcoe *acqe_fcoe) | ||
2896 | { | ||
2897 | uint8_t event_type = bf_get(lpfc_acqe_fcoe_event_type, acqe_fcoe); | ||
2898 | int rc; | ||
2899 | |||
2900 | switch (event_type) { | ||
2901 | case LPFC_FCOE_EVENT_TYPE_NEW_FCF: | ||
2902 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | ||
2903 | "2546 New FCF found index 0x%x tag 0x%x \n", | ||
2904 | acqe_fcoe->fcf_index, | ||
2905 | acqe_fcoe->event_tag); | ||
2906 | /* | ||
2907 | * If the current FCF is in discovered state, | ||
2908 | * do nothing. | ||
2909 | */ | ||
2910 | spin_lock_irq(&phba->hbalock); | ||
2911 | if (phba->fcf.fcf_flag & FCF_DISCOVERED) { | ||
2912 | spin_unlock_irq(&phba->hbalock); | ||
2913 | break; | ||
2914 | } | ||
2915 | spin_unlock_irq(&phba->hbalock); | ||
2916 | |||
2917 | /* Read the FCF table and re-discover SAN. */ | ||
2918 | rc = lpfc_sli4_read_fcf_record(phba, | ||
2919 | LPFC_FCOE_FCF_GET_FIRST); | ||
2920 | if (rc) | ||
2921 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | ||
2922 | "2547 Read FCF record failed 0x%x\n", | ||
2923 | rc); | ||
2924 | break; | ||
2925 | |||
2926 | case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL: | ||
2927 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
2928 | "2548 FCF Table full count 0x%x tag 0x%x \n", | ||
2929 | bf_get(lpfc_acqe_fcoe_fcf_count, acqe_fcoe), | ||
2930 | acqe_fcoe->event_tag); | ||
2931 | break; | ||
2932 | |||
2933 | case LPFC_FCOE_EVENT_TYPE_FCF_DEAD: | ||
2934 | lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, | ||
2935 | "2549 FCF disconnected fron network index 0x%x" | ||
2936 | " tag 0x%x \n", acqe_fcoe->fcf_index, | ||
2937 | acqe_fcoe->event_tag); | ||
2938 | /* If the event is not for currently used fcf do nothing */ | ||
2939 | if (phba->fcf.fcf_indx != acqe_fcoe->fcf_index) | ||
2940 | break; | ||
2941 | /* | ||
2942 | * Currently, driver support only one FCF - so treat this as | ||
2943 | * a link down. | ||
2944 | */ | ||
2945 | lpfc_linkdown(phba); | ||
2946 | /* Unregister FCF if no devices connected to it */ | ||
2947 | lpfc_unregister_unused_fcf(phba); | ||
2948 | break; | ||
2949 | |||
2950 | default: | ||
2951 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
2952 | "0288 Unknown FCoE event type 0x%x event tag " | ||
2953 | "0x%x\n", event_type, acqe_fcoe->event_tag); | ||
2954 | break; | ||
2955 | } | ||
2956 | } | ||
2957 | |||
2958 | /** | ||
2959 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event | ||
2960 | * @phba: pointer to lpfc hba data structure. | ||
2961 | * @acqe_link: pointer to the async dcbx completion queue entry. | ||
2962 | * | ||
2963 | * This routine is to handle the SLI4 asynchronous dcbx event. | ||
2964 | **/ | ||
2965 | static void | ||
2966 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, | ||
2967 | struct lpfc_acqe_dcbx *acqe_dcbx) | ||
2968 | { | ||
2969 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
2970 | "0290 The SLI4 DCBX asynchronous event is not " | ||
2971 | "handled yet\n"); | ||
2972 | } | ||
2973 | |||
2974 | /** | ||
2975 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event | ||
2976 | * @phba: pointer to lpfc hba data structure. | ||
2977 | * | ||
2978 | * This routine is invoked by the worker thread to process all the pending | ||
2979 | * SLI4 asynchronous events. | ||
2980 | **/ | ||
2981 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) | ||
2982 | { | ||
2983 | struct lpfc_cq_event *cq_event; | ||
2984 | |||
2985 | /* First, declare the async event has been handled */ | ||
2986 | spin_lock_irq(&phba->hbalock); | ||
2987 | phba->hba_flag &= ~ASYNC_EVENT; | ||
2988 | spin_unlock_irq(&phba->hbalock); | ||
2989 | /* Now, handle all the async events */ | ||
2990 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { | ||
2991 | /* Get the first event from the head of the event queue */ | ||
2992 | spin_lock_irq(&phba->hbalock); | ||
2993 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, | ||
2994 | cq_event, struct lpfc_cq_event, list); | ||
2995 | spin_unlock_irq(&phba->hbalock); | ||
2996 | /* Process the asynchronous event */ | ||
2997 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { | ||
2998 | case LPFC_TRAILER_CODE_LINK: | ||
2999 | lpfc_sli4_async_link_evt(phba, | ||
3000 | &cq_event->cqe.acqe_link); | ||
3001 | break; | ||
3002 | case LPFC_TRAILER_CODE_FCOE: | ||
3003 | lpfc_sli4_async_fcoe_evt(phba, | ||
3004 | &cq_event->cqe.acqe_fcoe); | ||
3005 | break; | ||
3006 | case LPFC_TRAILER_CODE_DCBX: | ||
3007 | lpfc_sli4_async_dcbx_evt(phba, | ||
3008 | &cq_event->cqe.acqe_dcbx); | ||
3009 | break; | ||
3010 | default: | ||
3011 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
3012 | "1804 Invalid asynchrous event code: " | ||
3013 | "x%x\n", bf_get(lpfc_trailer_code, | ||
3014 | &cq_event->cqe.mcqe_cmpl)); | ||
3015 | break; | ||
3016 | } | ||
3017 | /* Free the completion event processed to the free pool */ | ||
3018 | lpfc_sli4_cq_event_release(phba, cq_event); | ||
3019 | } | ||
3020 | } | ||
3021 | |||
3022 | /** | ||
3023 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table | ||
3024 | * @phba: pointer to lpfc hba data structure. | ||
3025 | * @dev_grp: The HBA PCI-Device group number. | ||
3026 | * | ||
3027 | * This routine is invoked to set up the per HBA PCI-Device group function | ||
3028 | * API jump table entries. | ||
3029 | * | ||
3030 | * Return: 0 if success, otherwise -ENODEV | ||
3031 | **/ | ||
3032 | int | ||
3033 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | ||
3034 | { | ||
3035 | int rc; | ||
3036 | |||
3037 | /* Set up lpfc PCI-device group */ | ||
3038 | phba->pci_dev_grp = dev_grp; | ||
3039 | |||
3040 | /* The LPFC_PCI_DEV_OC uses SLI4 */ | ||
3041 | if (dev_grp == LPFC_PCI_DEV_OC) | ||
3042 | phba->sli_rev = LPFC_SLI_REV4; | ||
3043 | |||
3044 | /* Set up device INIT API function jump table */ | ||
3045 | rc = lpfc_init_api_table_setup(phba, dev_grp); | ||
3046 | if (rc) | ||
3047 | return -ENODEV; | ||
3048 | /* Set up SCSI API function jump table */ | ||
3049 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); | ||
3050 | if (rc) | ||
3051 | return -ENODEV; | ||
3052 | /* Set up SLI API function jump table */ | ||
3053 | rc = lpfc_sli_api_table_setup(phba, dev_grp); | ||
3054 | if (rc) | ||
3055 | return -ENODEV; | ||
3056 | /* Set up MBOX API function jump table */ | ||
3057 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); | ||
3058 | if (rc) | ||
3059 | return -ENODEV; | ||
3060 | |||
3061 | return 0; | ||
3062 | } | ||
3063 | |||
3064 | /** | ||
3065 | * lpfc_log_intr_mode - Log the active interrupt mode | ||
3066 | * @phba: pointer to lpfc hba data structure. | ||
3067 | * @intr_mode: active interrupt mode adopted. | ||
3068 | * | ||
3069 | * This routine it invoked to log the currently used active interrupt mode | ||
3070 | * to the device. | ||
3071 | **/ | ||
3072 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | ||
3073 | { | ||
3074 | switch (intr_mode) { | ||
3075 | case 0: | ||
3076 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
3077 | "0470 Enable INTx interrupt mode.\n"); | ||
3078 | break; | ||
3079 | case 1: | ||
3080 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
3081 | "0481 Enabled MSI interrupt mode.\n"); | ||
3082 | break; | ||
3083 | case 2: | ||
3084 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
3085 | "0480 Enabled MSI-X interrupt mode.\n"); | ||
3086 | break; | ||
3087 | default: | ||
3088 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3089 | "0482 Illegal interrupt mode.\n"); | ||
3090 | break; | ||
3091 | } | ||
3092 | return; | ||
3093 | } | ||
3094 | |||
3095 | /** | ||
3096 | * lpfc_enable_pci_dev - Enable a generic PCI device. | ||
3097 | * @phba: pointer to lpfc hba data structure. | ||
3098 | * | ||
3099 | * This routine is invoked to enable the PCI device that is common to all | ||
3100 | * PCI devices. | ||
3101 | * | ||
3102 | * Return codes | ||
3103 | * 0 - sucessful | ||
3104 | * other values - error | ||
3105 | **/ | ||
3106 | static int | ||
3107 | lpfc_enable_pci_dev(struct lpfc_hba *phba) | ||
3108 | { | ||
3109 | struct pci_dev *pdev; | ||
3110 | int bars; | ||
3111 | |||
3112 | /* Obtain PCI device reference */ | ||
3113 | if (!phba->pcidev) | ||
3114 | goto out_error; | ||
3115 | else | ||
3116 | pdev = phba->pcidev; | ||
3117 | /* Select PCI BARs */ | ||
3118 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | ||
3119 | /* Enable PCI device */ | ||
3120 | if (pci_enable_device_mem(pdev)) | ||
3121 | goto out_error; | ||
3122 | /* Request PCI resource for the device */ | ||
3123 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | ||
3124 | goto out_disable_device; | ||
3125 | /* Set up device as PCI master and save state for EEH */ | ||
3126 | pci_set_master(pdev); | ||
3127 | pci_try_set_mwi(pdev); | ||
3128 | pci_save_state(pdev); | ||
3129 | |||
3130 | return 0; | ||
3131 | |||
3132 | out_disable_device: | ||
3133 | pci_disable_device(pdev); | ||
3134 | out_error: | ||
3135 | return -ENODEV; | ||
3136 | } | ||
3137 | |||
3138 | /** | ||
3139 | * lpfc_disable_pci_dev - Disable a generic PCI device. | ||
3140 | * @phba: pointer to lpfc hba data structure. | ||
3141 | * | ||
3142 | * This routine is invoked to disable the PCI device that is common to all | ||
3143 | * PCI devices. | ||
3144 | **/ | ||
3145 | static void | ||
3146 | lpfc_disable_pci_dev(struct lpfc_hba *phba) | ||
3147 | { | ||
3148 | struct pci_dev *pdev; | ||
3149 | int bars; | ||
3150 | |||
3151 | /* Obtain PCI device reference */ | ||
3152 | if (!phba->pcidev) | ||
3153 | return; | ||
3154 | else | ||
3155 | pdev = phba->pcidev; | ||
3156 | /* Select PCI BARs */ | ||
3157 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | ||
3158 | /* Release PCI resource and disable PCI device */ | ||
3159 | pci_release_selected_regions(pdev, bars); | ||
3160 | pci_disable_device(pdev); | ||
3161 | /* Null out PCI private reference to driver */ | ||
3162 | pci_set_drvdata(pdev, NULL); | ||
3163 | |||
3164 | return; | ||
3165 | } | ||
3166 | |||
3167 | /** | ||
3168 | * lpfc_reset_hba - Reset a hba | ||
3169 | * @phba: pointer to lpfc hba data structure. | ||
3170 | * | ||
3171 | * This routine is invoked to reset a hba device. It brings the HBA | ||
3172 | * offline, performs a board restart, and then brings the board back | ||
3173 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up | ||
3174 | * on outstanding mailbox commands. | ||
3175 | **/ | ||
3176 | void | ||
3177 | lpfc_reset_hba(struct lpfc_hba *phba) | ||
3178 | { | ||
3179 | /* If resets are disabled then set error state and return. */ | ||
3180 | if (!phba->cfg_enable_hba_reset) { | ||
3181 | phba->link_state = LPFC_HBA_ERROR; | ||
3182 | return; | ||
3183 | } | ||
3184 | lpfc_offline_prep(phba); | ||
3185 | lpfc_offline(phba); | ||
3186 | lpfc_sli_brdrestart(phba); | ||
3187 | lpfc_online(phba); | ||
3188 | lpfc_unblock_mgmt_io(phba); | ||
3189 | } | ||
3190 | |||
3191 | /** | ||
3192 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. | ||
3193 | * @phba: pointer to lpfc hba data structure. | ||
3194 | * | ||
3195 | * This routine is invoked to set up the driver internal resources specific to | ||
3196 | * support the SLI-3 HBA device it attached to. | ||
3197 | * | ||
3198 | * Return codes | ||
3199 | * 0 - sucessful | ||
3200 | * other values - error | ||
3201 | **/ | ||
3202 | static int | ||
3203 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) | ||
3204 | { | ||
3205 | struct lpfc_sli *psli; | ||
3206 | |||
3207 | /* | ||
3208 | * Initialize timers used by driver | ||
3209 | */ | ||
3210 | |||
3211 | /* Heartbeat timer */ | ||
3212 | init_timer(&phba->hb_tmofunc); | ||
3213 | phba->hb_tmofunc.function = lpfc_hb_timeout; | ||
3214 | phba->hb_tmofunc.data = (unsigned long)phba; | ||
3215 | |||
3216 | psli = &phba->sli; | ||
3217 | /* MBOX heartbeat timer */ | ||
3218 | init_timer(&psli->mbox_tmo); | ||
3219 | psli->mbox_tmo.function = lpfc_mbox_timeout; | ||
3220 | psli->mbox_tmo.data = (unsigned long) phba; | ||
3221 | /* FCP polling mode timer */ | ||
3222 | init_timer(&phba->fcp_poll_timer); | ||
3223 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | ||
3224 | phba->fcp_poll_timer.data = (unsigned long) phba; | ||
3225 | /* Fabric block timer */ | ||
3226 | init_timer(&phba->fabric_block_timer); | ||
3227 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | ||
3228 | phba->fabric_block_timer.data = (unsigned long) phba; | ||
3229 | /* EA polling mode timer */ | ||
3230 | init_timer(&phba->eratt_poll); | ||
3231 | phba->eratt_poll.function = lpfc_poll_eratt; | ||
3232 | phba->eratt_poll.data = (unsigned long) phba; | ||
3233 | |||
3234 | /* Host attention work mask setup */ | ||
3235 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | ||
3236 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | ||
3237 | |||
3238 | /* Get all the module params for configuring this host */ | ||
3239 | lpfc_get_cfgparam(phba); | ||
3240 | /* | ||
3241 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | ||
3242 | * used to create the sg_dma_buf_pool must be dynamically calculated. | ||
3243 | * 2 segments are added since the IOCB needs a command and response bde. | ||
3244 | */ | ||
3245 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | ||
3246 | sizeof(struct fcp_rsp) + | ||
3247 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); | ||
3248 | |||
3249 | if (phba->cfg_enable_bg) { | ||
3250 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; | ||
3251 | phba->cfg_sg_dma_buf_size += | ||
3252 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); | ||
3253 | } | ||
3254 | |||
3255 | /* Also reinitialize the host templates with new values. */ | ||
3256 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | ||
3257 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | ||
3258 | |||
3259 | phba->max_vpi = LPFC_MAX_VPI; | ||
3260 | /* This will be set to correct value after config_port mbox */ | ||
3261 | phba->max_vports = 0; | ||
3262 | |||
3263 | /* | ||
3264 | * Initialize the SLI Layer to run with lpfc HBAs. | ||
3265 | */ | ||
3266 | lpfc_sli_setup(phba); | ||
3267 | lpfc_sli_queue_setup(phba); | ||
3268 | |||
3269 | /* Allocate device driver memory */ | ||
3270 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) | ||
3271 | return -ENOMEM; | ||
3272 | |||
3273 | return 0; | ||
3274 | } | ||
3275 | |||
3276 | /** | ||
3277 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev | ||
3278 | * @phba: pointer to lpfc hba data structure. | ||
3279 | * | ||
3280 | * This routine is invoked to unset the driver internal resources set up | ||
3281 | * specific for supporting the SLI-3 HBA device it attached to. | ||
3282 | **/ | ||
3283 | static void | ||
3284 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) | ||
3285 | { | ||
3286 | /* Free device driver memory allocated */ | ||
3287 | lpfc_mem_free_all(phba); | ||
3288 | |||
3289 | return; | ||
3290 | } | ||
3291 | |||
3292 | /** | ||
3293 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev | ||
3294 | * @phba: pointer to lpfc hba data structure. | ||
3295 | * | ||
3296 | * This routine is invoked to set up the driver internal resources specific to | ||
3297 | * support the SLI-4 HBA device it attached to. | ||
3298 | * | ||
3299 | * Return codes | ||
3300 | * 0 - sucessful | ||
3301 | * other values - error | ||
3302 | **/ | ||
3303 | static int | ||
3304 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) | ||
3305 | { | ||
3306 | struct lpfc_sli *psli; | ||
3307 | int rc; | ||
3308 | int i, hbq_count; | ||
3309 | |||
3310 | /* Before proceed, wait for POST done and device ready */ | ||
3311 | rc = lpfc_sli4_post_status_check(phba); | ||
3312 | if (rc) | ||
3313 | return -ENODEV; | ||
3314 | |||
3315 | /* | ||
3316 | * Initialize timers used by driver | ||
3317 | */ | ||
3318 | |||
3319 | /* Heartbeat timer */ | ||
3320 | init_timer(&phba->hb_tmofunc); | ||
3321 | phba->hb_tmofunc.function = lpfc_hb_timeout; | ||
3322 | phba->hb_tmofunc.data = (unsigned long)phba; | ||
3323 | |||
3324 | psli = &phba->sli; | ||
3325 | /* MBOX heartbeat timer */ | ||
3326 | init_timer(&psli->mbox_tmo); | ||
3327 | psli->mbox_tmo.function = lpfc_mbox_timeout; | ||
3328 | psli->mbox_tmo.data = (unsigned long) phba; | ||
3329 | /* Fabric block timer */ | ||
3330 | init_timer(&phba->fabric_block_timer); | ||
3331 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | ||
3332 | phba->fabric_block_timer.data = (unsigned long) phba; | ||
3333 | /* EA polling mode timer */ | ||
3334 | init_timer(&phba->eratt_poll); | ||
3335 | phba->eratt_poll.function = lpfc_poll_eratt; | ||
3336 | phba->eratt_poll.data = (unsigned long) phba; | ||
3337 | /* | ||
3338 | * We need to do a READ_CONFIG mailbox command here before | ||
3339 | * calling lpfc_get_cfgparam. For VFs this will report the | ||
3340 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. | ||
3341 | * All of the resources allocated | ||
3342 | * for this Port are tied to these values. | ||
3343 | */ | ||
3344 | /* Get all the module params for configuring this host */ | ||
3345 | lpfc_get_cfgparam(phba); | ||
3346 | phba->max_vpi = LPFC_MAX_VPI; | ||
3347 | /* This will be set to correct value after the read_config mbox */ | ||
3348 | phba->max_vports = 0; | ||
3349 | |||
3350 | /* Program the default value of vlan_id and fc_map */ | ||
3351 | phba->valid_vlan = 0; | ||
3352 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | ||
3353 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | ||
3354 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | ||
3355 | |||
3356 | /* | ||
3357 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | ||
3358 | * used to create the sg_dma_buf_pool must be dynamically calculated. | ||
3359 | * 2 segments are added since the IOCB needs a command and response bde. | ||
3360 | * To insure that the scsi sgl does not cross a 4k page boundary only | ||
3361 | * sgl sizes of 1k, 2k, 4k, and 8k are supported. | ||
3362 | * Table of sgl sizes and seg_cnt: | ||
3363 | * sgl size, sg_seg_cnt total seg | ||
3364 | * 1k 50 52 | ||
3365 | * 2k 114 116 | ||
3366 | * 4k 242 244 | ||
3367 | * 8k 498 500 | ||
3368 | * cmd(32) + rsp(160) + (52 * sizeof(sli4_sge)) = 1024 | ||
3369 | * cmd(32) + rsp(160) + (116 * sizeof(sli4_sge)) = 2048 | ||
3370 | * cmd(32) + rsp(160) + (244 * sizeof(sli4_sge)) = 4096 | ||
3371 | * cmd(32) + rsp(160) + (500 * sizeof(sli4_sge)) = 8192 | ||
3372 | */ | ||
3373 | if (phba->cfg_sg_seg_cnt <= LPFC_DEFAULT_SG_SEG_CNT) | ||
3374 | phba->cfg_sg_seg_cnt = 50; | ||
3375 | else if (phba->cfg_sg_seg_cnt <= 114) | ||
3376 | phba->cfg_sg_seg_cnt = 114; | ||
3377 | else if (phba->cfg_sg_seg_cnt <= 242) | ||
3378 | phba->cfg_sg_seg_cnt = 242; | ||
3379 | else | ||
3380 | phba->cfg_sg_seg_cnt = 498; | ||
3381 | |||
3382 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) | ||
3383 | + sizeof(struct fcp_rsp); | ||
3384 | phba->cfg_sg_dma_buf_size += | ||
3385 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)); | ||
3386 | |||
3387 | /* Initialize buffer queue management fields */ | ||
3388 | hbq_count = lpfc_sli_hbq_count(); | ||
3389 | for (i = 0; i < hbq_count; ++i) | ||
3390 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | ||
3391 | INIT_LIST_HEAD(&phba->rb_pend_list); | ||
3392 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; | ||
3393 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; | ||
3394 | |||
3395 | /* | ||
3396 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. | ||
3397 | */ | ||
3398 | /* Initialize the Abort scsi buffer list used by driver */ | ||
3399 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); | ||
3400 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | ||
3401 | /* This abort list used by worker thread */ | ||
3402 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); | ||
3403 | |||
3404 | /* | ||
3405 | * Initialize dirver internal slow-path work queues | ||
3406 | */ | ||
3407 | |||
3408 | /* Driver internel slow-path CQ Event pool */ | ||
3409 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); | ||
3410 | /* Response IOCB work queue list */ | ||
3411 | INIT_LIST_HEAD(&phba->sli4_hba.sp_rspiocb_work_queue); | ||
3412 | /* Asynchronous event CQ Event work queue list */ | ||
3413 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); | ||
3414 | /* Fast-path XRI aborted CQ Event work queue list */ | ||
3415 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | ||
3416 | /* Slow-path XRI aborted CQ Event work queue list */ | ||
3417 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); | ||
3418 | /* Receive queue CQ Event work queue list */ | ||
3419 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); | ||
3420 | |||
3421 | /* Initialize the driver internal SLI layer lists. */ | ||
3422 | lpfc_sli_setup(phba); | ||
3423 | lpfc_sli_queue_setup(phba); | ||
3424 | |||
3425 | /* Allocate device driver memory */ | ||
3426 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); | ||
3427 | if (rc) | ||
3428 | return -ENOMEM; | ||
3429 | |||
3430 | /* Create the bootstrap mailbox command */ | ||
3431 | rc = lpfc_create_bootstrap_mbox(phba); | ||
3432 | if (unlikely(rc)) | ||
3433 | goto out_free_mem; | ||
3434 | |||
3435 | /* Set up the host's endian order with the device. */ | ||
3436 | rc = lpfc_setup_endian_order(phba); | ||
3437 | if (unlikely(rc)) | ||
3438 | goto out_free_bsmbx; | ||
3439 | |||
3440 | /* Set up the hba's configuration parameters. */ | ||
3441 | rc = lpfc_sli4_read_config(phba); | ||
3442 | if (unlikely(rc)) | ||
3443 | goto out_free_bsmbx; | ||
3444 | |||
3445 | /* Perform a function reset */ | ||
3446 | rc = lpfc_pci_function_reset(phba); | ||
3447 | if (unlikely(rc)) | ||
3448 | goto out_free_bsmbx; | ||
3449 | |||
3450 | /* Create all the SLI4 queues */ | ||
3451 | rc = lpfc_sli4_queue_create(phba); | ||
3452 | if (rc) | ||
3453 | goto out_free_bsmbx; | ||
3454 | |||
3455 | /* Create driver internal CQE event pool */ | ||
3456 | rc = lpfc_sli4_cq_event_pool_create(phba); | ||
3457 | if (rc) | ||
3458 | goto out_destroy_queue; | ||
3459 | |||
3460 | /* Initialize and populate the iocb list per host */ | ||
3461 | rc = lpfc_init_sgl_list(phba); | ||
3462 | if (rc) { | ||
3463 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3464 | "1400 Failed to initialize sgl list.\n"); | ||
3465 | goto out_destroy_cq_event_pool; | ||
3466 | } | ||
3467 | rc = lpfc_init_active_sgl_array(phba); | ||
3468 | if (rc) { | ||
3469 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3470 | "1430 Failed to initialize sgl list.\n"); | ||
3471 | goto out_free_sgl_list; | ||
3472 | } | ||
3473 | |||
3474 | rc = lpfc_sli4_init_rpi_hdrs(phba); | ||
3475 | if (rc) { | ||
3476 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3477 | "1432 Failed to initialize rpi headers.\n"); | ||
3478 | goto out_free_active_sgl; | ||
3479 | } | ||
3480 | |||
3481 | phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * | ||
3482 | phba->cfg_fcp_eq_count), GFP_KERNEL); | ||
3483 | if (!phba->sli4_hba.fcp_eq_hdl) { | ||
3484 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3485 | "2572 Failed allocate memory for fast-path " | ||
3486 | "per-EQ handle array\n"); | ||
3487 | goto out_remove_rpi_hdrs; | ||
3488 | } | ||
3489 | |||
3490 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * | ||
3491 | phba->sli4_hba.cfg_eqn), GFP_KERNEL); | ||
3492 | if (!phba->sli4_hba.msix_entries) { | ||
3493 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3494 | "2573 Failed allocate memory for msi-x " | ||
3495 | "interrupt vector entries\n"); | ||
3496 | goto out_free_fcp_eq_hdl; | ||
3497 | } | ||
3498 | |||
3499 | return rc; | ||
3500 | |||
3501 | out_free_fcp_eq_hdl: | ||
3502 | kfree(phba->sli4_hba.fcp_eq_hdl); | ||
3503 | out_remove_rpi_hdrs: | ||
3504 | lpfc_sli4_remove_rpi_hdrs(phba); | ||
3505 | out_free_active_sgl: | ||
3506 | lpfc_free_active_sgl(phba); | ||
3507 | out_free_sgl_list: | ||
3508 | lpfc_free_sgl_list(phba); | ||
3509 | out_destroy_cq_event_pool: | ||
3510 | lpfc_sli4_cq_event_pool_destroy(phba); | ||
3511 | out_destroy_queue: | ||
3512 | lpfc_sli4_queue_destroy(phba); | ||
3513 | out_free_bsmbx: | ||
3514 | lpfc_destroy_bootstrap_mbox(phba); | ||
3515 | out_free_mem: | ||
3516 | lpfc_mem_free(phba); | ||
3517 | return rc; | ||
3518 | } | ||
3519 | |||
3520 | /** | ||
3521 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev | ||
3522 | * @phba: pointer to lpfc hba data structure. | ||
3523 | * | ||
3524 | * This routine is invoked to unset the driver internal resources set up | ||
3525 | * specific for supporting the SLI-4 HBA device it attached to. | ||
3526 | **/ | ||
3527 | static void | ||
3528 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) | ||
3529 | { | ||
3530 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; | ||
3531 | |||
3532 | /* unregister default FCFI from the HBA */ | ||
3533 | lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi); | ||
3534 | |||
3535 | /* Free the default FCR table */ | ||
3536 | lpfc_sli_remove_dflt_fcf(phba); | ||
3537 | |||
3538 | /* Free memory allocated for msi-x interrupt vector entries */ | ||
3539 | kfree(phba->sli4_hba.msix_entries); | ||
3540 | |||
3541 | /* Free memory allocated for fast-path work queue handles */ | ||
3542 | kfree(phba->sli4_hba.fcp_eq_hdl); | ||
3543 | |||
3544 | /* Free the allocated rpi headers. */ | ||
3545 | lpfc_sli4_remove_rpi_hdrs(phba); | ||
3546 | |||
3547 | /* Free the ELS sgl list */ | ||
3548 | lpfc_free_active_sgl(phba); | ||
3549 | lpfc_free_sgl_list(phba); | ||
3550 | |||
3551 | /* Free the SCSI sgl management array */ | ||
3552 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | ||
3553 | |||
3554 | /* Free the SLI4 queues */ | ||
3555 | lpfc_sli4_queue_destroy(phba); | ||
3556 | |||
3557 | /* Free the completion queue EQ event pool */ | ||
3558 | lpfc_sli4_cq_event_release_all(phba); | ||
3559 | lpfc_sli4_cq_event_pool_destroy(phba); | ||
3560 | |||
3561 | /* Reset SLI4 HBA FCoE function */ | ||
3562 | lpfc_pci_function_reset(phba); | ||
3563 | |||
3564 | /* Free the bsmbx region. */ | ||
3565 | lpfc_destroy_bootstrap_mbox(phba); | ||
3566 | |||
3567 | /* Free the SLI Layer memory with SLI4 HBAs */ | ||
3568 | lpfc_mem_free_all(phba); | ||
3569 | |||
3570 | /* Free the current connect table */ | ||
3571 | list_for_each_entry_safe(conn_entry, next_conn_entry, | ||
3572 | &phba->fcf_conn_rec_list, list) | ||
3573 | kfree(conn_entry); | ||
3574 | |||
3575 | return; | ||
3576 | } | ||
3577 | |||
3578 | /** | ||
3579 | * lpfc_init_api_table_setup - Set up init api fucntion jump table | ||
3580 | * @phba: The hba struct for which this call is being executed. | ||
3581 | * @dev_grp: The HBA PCI-Device group number. | ||
3582 | * | ||
3583 | * This routine sets up the device INIT interface API function jump table | ||
3584 | * in @phba struct. | ||
3585 | * | ||
3586 | * Returns: 0 - success, -ENODEV - failure. | ||
3587 | **/ | ||
3588 | int | ||
3589 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | ||
3590 | { | ||
3591 | switch (dev_grp) { | ||
3592 | case LPFC_PCI_DEV_LP: | ||
3593 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; | ||
3594 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; | ||
3595 | phba->lpfc_stop_port = lpfc_stop_port_s3; | ||
3596 | break; | ||
3597 | case LPFC_PCI_DEV_OC: | ||
3598 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; | ||
3599 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; | ||
3600 | phba->lpfc_stop_port = lpfc_stop_port_s4; | ||
3601 | break; | ||
3602 | default: | ||
3603 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
3604 | "1431 Invalid HBA PCI-device group: 0x%x\n", | ||
3605 | dev_grp); | ||
3606 | return -ENODEV; | ||
3607 | break; | ||
3608 | } | ||
3609 | return 0; | ||
3610 | } | ||
3611 | |||
3612 | /** | ||
3613 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. | ||
3614 | * @phba: pointer to lpfc hba data structure. | ||
3615 | * | ||
3616 | * This routine is invoked to set up the driver internal resources before the | ||
3617 | * device specific resource setup to support the HBA device it attached to. | ||
3618 | * | ||
3619 | * Return codes | ||
3620 | * 0 - sucessful | ||
3621 | * other values - error | ||
3622 | **/ | ||
3623 | static int | ||
3624 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) | ||
3625 | { | ||
3626 | /* | ||
3627 | * Driver resources common to all SLI revisions | ||
3628 | */ | ||
3629 | atomic_set(&phba->fast_event_count, 0); | ||
3630 | spin_lock_init(&phba->hbalock); | ||
3631 | |||
3632 | /* Initialize ndlp management spinlock */ | ||
3633 | spin_lock_init(&phba->ndlp_lock); | ||
3634 | |||
3635 | INIT_LIST_HEAD(&phba->port_list); | ||
3636 | INIT_LIST_HEAD(&phba->work_list); | ||
3637 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | ||
3638 | |||
3639 | /* Initialize the wait queue head for the kernel thread */ | ||
3640 | init_waitqueue_head(&phba->work_waitq); | ||
3641 | |||
3642 | /* Initialize the scsi buffer list used by driver for scsi IO */ | ||
3643 | spin_lock_init(&phba->scsi_buf_list_lock); | ||
3644 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | ||
3645 | |||
3646 | /* Initialize the fabric iocb list */ | ||
3647 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | ||
3648 | |||
3649 | /* Initialize list to save ELS buffers */ | ||
3650 | INIT_LIST_HEAD(&phba->elsbuf); | ||
3651 | |||
3652 | /* Initialize FCF connection rec list */ | ||
3653 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); | ||
3654 | |||
3655 | return 0; | ||
3656 | } | ||
3657 | |||
3658 | /** | ||
3659 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. | ||
3660 | * @phba: pointer to lpfc hba data structure. | ||
3661 | * | ||
3662 | * This routine is invoked to set up the driver internal resources after the | ||
3663 | * device specific resource setup to support the HBA device it attached to. | ||
3664 | * | ||
3665 | * Return codes | ||
3666 | * 0 - sucessful | ||
3667 | * other values - error | ||
3668 | **/ | ||
3669 | static int | ||
3670 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) | ||
3671 | { | ||
3672 | int error; | ||
3673 | |||
3674 | /* Startup the kernel thread for this host adapter. */ | ||
3675 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | ||
3676 | "lpfc_worker_%d", phba->brd_no); | ||
3677 | if (IS_ERR(phba->worker_thread)) { | ||
3678 | error = PTR_ERR(phba->worker_thread); | ||
3679 | return error; | ||
3680 | } | ||
3681 | |||
3682 | return 0; | ||
3683 | } | ||
3684 | |||
3685 | /** | ||
3686 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. | ||
3687 | * @phba: pointer to lpfc hba data structure. | ||
3688 | * | ||
3689 | * This routine is invoked to unset the driver internal resources set up after | ||
3690 | * the device specific resource setup for supporting the HBA device it | ||
3691 | * attached to. | ||
3692 | **/ | ||
3693 | static void | ||
3694 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) | ||
3695 | { | ||
3696 | /* Stop kernel worker thread */ | ||
3697 | kthread_stop(phba->worker_thread); | ||
3698 | } | ||
3699 | |||
3700 | /** | ||
3701 | * lpfc_free_iocb_list - Free iocb list. | ||
3702 | * @phba: pointer to lpfc hba data structure. | ||
3703 | * | ||
3704 | * This routine is invoked to free the driver's IOCB list and memory. | ||
3705 | **/ | ||
3706 | static void | ||
3707 | lpfc_free_iocb_list(struct lpfc_hba *phba) | ||
3708 | { | ||
3709 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | ||
3710 | |||
3711 | spin_lock_irq(&phba->hbalock); | ||
3712 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | ||
3713 | &phba->lpfc_iocb_list, list) { | ||
3714 | list_del(&iocbq_entry->list); | ||
3715 | kfree(iocbq_entry); | ||
3716 | phba->total_iocbq_bufs--; | ||
3717 | } | ||
3718 | spin_unlock_irq(&phba->hbalock); | ||
3719 | |||
3720 | return; | ||
3721 | } | ||
3722 | |||
3723 | /** | ||
3724 | * lpfc_init_iocb_list - Allocate and initialize iocb list. | ||
3725 | * @phba: pointer to lpfc hba data structure. | ||
3726 | * | ||
3727 | * This routine is invoked to allocate and initizlize the driver's IOCB | ||
3728 | * list and set up the IOCB tag array accordingly. | ||
3729 | * | ||
3730 | * Return codes | ||
3731 | * 0 - sucessful | ||
3732 | * other values - error | ||
3733 | **/ | ||
3734 | static int | ||
3735 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) | ||
3736 | { | ||
3737 | struct lpfc_iocbq *iocbq_entry = NULL; | ||
3738 | uint16_t iotag; | ||
3739 | int i; | ||
3740 | |||
3741 | /* Initialize and populate the iocb list per host. */ | ||
3742 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | ||
3743 | for (i = 0; i < iocb_count; i++) { | ||
3744 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); | ||
3745 | if (iocbq_entry == NULL) { | ||
3746 | printk(KERN_ERR "%s: only allocated %d iocbs of " | ||
3747 | "expected %d count. Unloading driver.\n", | ||
3748 | __func__, i, LPFC_IOCB_LIST_CNT); | ||
3749 | goto out_free_iocbq; | ||
3750 | } | ||
3751 | |||
3752 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); | ||
3753 | if (iotag == 0) { | ||
3754 | kfree(iocbq_entry); | ||
3755 | printk(KERN_ERR "%s: failed to allocate IOTAG. " | ||
3756 | "Unloading driver.\n", __func__); | ||
3757 | goto out_free_iocbq; | ||
3758 | } | ||
3759 | iocbq_entry->sli4_xritag = NO_XRI; | ||
3760 | |||
3761 | spin_lock_irq(&phba->hbalock); | ||
3762 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); | ||
3763 | phba->total_iocbq_bufs++; | ||
3764 | spin_unlock_irq(&phba->hbalock); | ||
3765 | } | ||
3766 | |||
3767 | return 0; | ||
3768 | |||
3769 | out_free_iocbq: | ||
3770 | lpfc_free_iocb_list(phba); | ||
3771 | |||
3772 | return -ENOMEM; | ||
3773 | } | ||
3774 | |||
3775 | /** | ||
3776 | * lpfc_free_sgl_list - Free sgl list. | ||
3777 | * @phba: pointer to lpfc hba data structure. | ||
3778 | * | ||
3779 | * This routine is invoked to free the driver's sgl list and memory. | ||
3780 | **/ | ||
3781 | static void | ||
3782 | lpfc_free_sgl_list(struct lpfc_hba *phba) | ||
3783 | { | ||
3784 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; | ||
3785 | LIST_HEAD(sglq_list); | ||
3786 | int rc = 0; | ||
3787 | |||
3788 | spin_lock_irq(&phba->hbalock); | ||
3789 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); | ||
3790 | spin_unlock_irq(&phba->hbalock); | ||
3791 | |||
3792 | list_for_each_entry_safe(sglq_entry, sglq_next, | ||
3793 | &sglq_list, list) { | ||
3794 | list_del(&sglq_entry->list); | ||
3795 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); | ||
3796 | kfree(sglq_entry); | ||
3797 | phba->sli4_hba.total_sglq_bufs--; | ||
3798 | } | ||
3799 | rc = lpfc_sli4_remove_all_sgl_pages(phba); | ||
3800 | if (rc) { | ||
3801 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
3802 | "2005 Unable to deregister pages from HBA: %x", rc); | ||
3803 | } | ||
3804 | kfree(phba->sli4_hba.lpfc_els_sgl_array); | ||
3805 | } | ||
3806 | |||
3807 | /** | ||
3808 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. | ||
3809 | * @phba: pointer to lpfc hba data structure. | ||
3810 | * | ||
3811 | * This routine is invoked to allocate the driver's active sgl memory. | ||
3812 | * This array will hold the sglq_entry's for active IOs. | ||
3813 | **/ | ||
3814 | static int | ||
3815 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) | ||
3816 | { | ||
3817 | int size; | ||
3818 | size = sizeof(struct lpfc_sglq *); | ||
3819 | size *= phba->sli4_hba.max_cfg_param.max_xri; | ||
3820 | |||
3821 | phba->sli4_hba.lpfc_sglq_active_list = | ||
3822 | kzalloc(size, GFP_KERNEL); | ||
3823 | if (!phba->sli4_hba.lpfc_sglq_active_list) | ||
3824 | return -ENOMEM; | ||
3825 | return 0; | ||
3826 | } | ||
3827 | |||
3828 | /** | ||
3829 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. | ||
3830 | * @phba: pointer to lpfc hba data structure. | ||
3831 | * | ||
3832 | * This routine is invoked to walk through the array of active sglq entries | ||
3833 | * and free all of the resources. | ||
3834 | * This is just a place holder for now. | ||
3835 | **/ | ||
3836 | static void | ||
3837 | lpfc_free_active_sgl(struct lpfc_hba *phba) | ||
3838 | { | ||
3839 | kfree(phba->sli4_hba.lpfc_sglq_active_list); | ||
3840 | } | ||
3841 | |||
3842 | /** | ||
3843 | * lpfc_init_sgl_list - Allocate and initialize sgl list. | ||
3844 | * @phba: pointer to lpfc hba data structure. | ||
3845 | * | ||
3846 | * This routine is invoked to allocate and initizlize the driver's sgl | ||
3847 | * list and set up the sgl xritag tag array accordingly. | ||
3848 | * | ||
3849 | * Return codes | ||
3850 | * 0 - sucessful | ||
3851 | * other values - error | ||
3852 | **/ | ||
3853 | static int | ||
3854 | lpfc_init_sgl_list(struct lpfc_hba *phba) | ||
3855 | { | ||
3856 | struct lpfc_sglq *sglq_entry = NULL; | ||
3857 | int i; | ||
3858 | int els_xri_cnt; | ||
3859 | |||
3860 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | ||
3861 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | ||
3862 | "2400 lpfc_init_sgl_list els %d.\n", | ||
3863 | els_xri_cnt); | ||
3864 | /* Initialize and populate the sglq list per host/VF. */ | ||
3865 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); | ||
3866 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); | ||
3867 | |||
3868 | /* Sanity check on XRI management */ | ||
3869 | if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) { | ||
3870 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
3871 | "2562 No room left for SCSI XRI allocation: " | ||
3872 | "max_xri=%d, els_xri=%d\n", | ||
3873 | phba->sli4_hba.max_cfg_param.max_xri, | ||
3874 | els_xri_cnt); | ||
3875 | return -ENOMEM; | ||
3876 | } | ||
3877 | |||
3878 | /* Allocate memory for the ELS XRI management array */ | ||
3879 | phba->sli4_hba.lpfc_els_sgl_array = | ||
3880 | kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt), | ||
3881 | GFP_KERNEL); | ||
3882 | |||
3883 | if (!phba->sli4_hba.lpfc_els_sgl_array) { | ||
3884 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
3885 | "2401 Failed to allocate memory for ELS " | ||
3886 | "XRI management array of size %d.\n", | ||
3887 | els_xri_cnt); | ||
3888 | return -ENOMEM; | ||
3889 | } | ||
3890 | |||
3891 | /* Keep the SCSI XRI into the XRI management array */ | ||
3892 | phba->sli4_hba.scsi_xri_max = | ||
3893 | phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; | ||
3894 | phba->sli4_hba.scsi_xri_cnt = 0; | ||
3895 | |||
3896 | phba->sli4_hba.lpfc_scsi_psb_array = | ||
3897 | kzalloc((sizeof(struct lpfc_scsi_buf *) * | ||
3898 | phba->sli4_hba.scsi_xri_max), GFP_KERNEL); | ||
3899 | |||
3900 | if (!phba->sli4_hba.lpfc_scsi_psb_array) { | ||
3901 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
3902 | "2563 Failed to allocate memory for SCSI " | ||
3903 | "XRI management array of size %d.\n", | ||
3904 | phba->sli4_hba.scsi_xri_max); | ||
3905 | kfree(phba->sli4_hba.lpfc_els_sgl_array); | ||
3906 | return -ENOMEM; | ||
3907 | } | ||
3908 | |||
3909 | for (i = 0; i < els_xri_cnt; i++) { | ||
3910 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL); | ||
3911 | if (sglq_entry == NULL) { | ||
3912 | printk(KERN_ERR "%s: only allocated %d sgls of " | ||
3913 | "expected %d count. Unloading driver.\n", | ||
3914 | __func__, i, els_xri_cnt); | ||
3915 | goto out_free_mem; | ||
3916 | } | ||
3917 | |||
3918 | sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba); | ||
3919 | if (sglq_entry->sli4_xritag == NO_XRI) { | ||
3920 | kfree(sglq_entry); | ||
3921 | printk(KERN_ERR "%s: failed to allocate XRI.\n" | ||
3922 | "Unloading driver.\n", __func__); | ||
3923 | goto out_free_mem; | ||
3924 | } | ||
3925 | sglq_entry->buff_type = GEN_BUFF_TYPE; | ||
3926 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys); | ||
3927 | if (sglq_entry->virt == NULL) { | ||
3928 | kfree(sglq_entry); | ||
3929 | printk(KERN_ERR "%s: failed to allocate mbuf.\n" | ||
3930 | "Unloading driver.\n", __func__); | ||
3931 | goto out_free_mem; | ||
3932 | } | ||
3933 | sglq_entry->sgl = sglq_entry->virt; | ||
3934 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); | ||
3935 | |||
3936 | /* The list order is used by later block SGL registraton */ | ||
3937 | spin_lock_irq(&phba->hbalock); | ||
3938 | list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list); | ||
3939 | phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry; | ||
3940 | phba->sli4_hba.total_sglq_bufs++; | ||
3941 | spin_unlock_irq(&phba->hbalock); | ||
3942 | } | ||
3943 | return 0; | ||
3944 | |||
3945 | out_free_mem: | ||
3946 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | ||
3947 | lpfc_free_sgl_list(phba); | ||
3948 | return -ENOMEM; | ||
3949 | } | ||
3950 | |||
3951 | /** | ||
3952 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port | ||
3953 | * @phba: pointer to lpfc hba data structure. | ||
3954 | * | ||
3955 | * This routine is invoked to post rpi header templates to the | ||
3956 | * HBA consistent with the SLI-4 interface spec. This routine | ||
3957 | * posts a PAGE_SIZE memory region to the port to hold up to | ||
3958 | * PAGE_SIZE modulo 64 rpi context headers. | ||
3959 | * No locks are held here because this is an initialization routine | ||
3960 | * called only from probe or lpfc_online when interrupts are not | ||
3961 | * enabled and the driver is reinitializing the device. | ||
3962 | * | ||
3963 | * Return codes | ||
3964 | * 0 - sucessful | ||
3965 | * ENOMEM - No availble memory | ||
3966 | * EIO - The mailbox failed to complete successfully. | ||
3967 | **/ | ||
3968 | int | ||
3969 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) | ||
3970 | { | ||
3971 | int rc = 0; | ||
3972 | int longs; | ||
3973 | uint16_t rpi_count; | ||
3974 | struct lpfc_rpi_hdr *rpi_hdr; | ||
3975 | |||
3976 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); | ||
3977 | |||
3978 | /* | ||
3979 | * Provision an rpi bitmask range for discovery. The total count | ||
3980 | * is the difference between max and base + 1. | ||
3981 | */ | ||
3982 | rpi_count = phba->sli4_hba.max_cfg_param.rpi_base + | ||
3983 | phba->sli4_hba.max_cfg_param.max_rpi - 1; | ||
3984 | |||
3985 | longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG; | ||
3986 | phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long), | ||
3987 | GFP_KERNEL); | ||
3988 | if (!phba->sli4_hba.rpi_bmask) | ||
3989 | return -ENOMEM; | ||
3990 | |||
3991 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | ||
3992 | if (!rpi_hdr) { | ||
3993 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | ||
3994 | "0391 Error during rpi post operation\n"); | ||
3995 | lpfc_sli4_remove_rpis(phba); | ||
3996 | rc = -ENODEV; | ||
3997 | } | ||
3998 | |||
3999 | return rc; | ||
4000 | } | ||
4001 | |||
4002 | /** | ||
4003 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region | ||
4004 | * @phba: pointer to lpfc hba data structure. | ||
4005 | * | ||
4006 | * This routine is invoked to allocate a single 4KB memory region to | ||
4007 | * support rpis and stores them in the phba. This single region | ||
4008 | * provides support for up to 64 rpis. The region is used globally | ||
4009 | * by the device. | ||
4010 | * | ||
4011 | * Returns: | ||
4012 | * A valid rpi hdr on success. | ||
4013 | * A NULL pointer on any failure. | ||
4014 | **/ | ||
4015 | struct lpfc_rpi_hdr * | ||
4016 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) | ||
4017 | { | ||
4018 | uint16_t rpi_limit, curr_rpi_range; | ||
4019 | struct lpfc_dmabuf *dmabuf; | ||
4020 | struct lpfc_rpi_hdr *rpi_hdr; | ||
4021 | |||
4022 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + | ||
4023 | phba->sli4_hba.max_cfg_param.max_rpi - 1; | ||
4024 | |||
4025 | spin_lock_irq(&phba->hbalock); | ||
4026 | curr_rpi_range = phba->sli4_hba.next_rpi; | ||
4027 | spin_unlock_irq(&phba->hbalock); | ||
4028 | |||
4029 | /* | ||
4030 | * The port has a limited number of rpis. The increment here | ||
4031 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value | ||
4032 | * and to allow the full max_rpi range per port. | ||
4033 | */ | ||
4034 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) | ||
4035 | return NULL; | ||
4036 | |||
4037 | /* | ||
4038 | * First allocate the protocol header region for the port. The | ||
4039 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. | ||
4040 | */ | ||
4041 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | ||
4042 | if (!dmabuf) | ||
4043 | return NULL; | ||
4044 | |||
4045 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | ||
4046 | LPFC_HDR_TEMPLATE_SIZE, | ||
4047 | &dmabuf->phys, | ||
4048 | GFP_KERNEL); | ||
4049 | if (!dmabuf->virt) { | ||
4050 | rpi_hdr = NULL; | ||
4051 | goto err_free_dmabuf; | ||
4052 | } | ||
4053 | |||
4054 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); | ||
4055 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { | ||
4056 | rpi_hdr = NULL; | ||
4057 | goto err_free_coherent; | ||
4058 | } | ||
4059 | |||
4060 | /* Save the rpi header data for cleanup later. */ | ||
4061 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); | ||
4062 | if (!rpi_hdr) | ||
4063 | goto err_free_coherent; | ||
4064 | |||
4065 | rpi_hdr->dmabuf = dmabuf; | ||
4066 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; | ||
4067 | rpi_hdr->page_count = 1; | ||
4068 | spin_lock_irq(&phba->hbalock); | ||
4069 | rpi_hdr->start_rpi = phba->sli4_hba.next_rpi; | ||
4070 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); | ||
4071 | |||
4072 | /* | ||
4073 | * The next_rpi stores the next module-64 rpi value to post | ||
4074 | * in any subsequent rpi memory region postings. | ||
4075 | */ | ||
4076 | phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT; | ||
4077 | spin_unlock_irq(&phba->hbalock); | ||
4078 | return rpi_hdr; | ||
4079 | |||
4080 | err_free_coherent: | ||
4081 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, | ||
4082 | dmabuf->virt, dmabuf->phys); | ||
4083 | err_free_dmabuf: | ||
4084 | kfree(dmabuf); | ||
4085 | return NULL; | ||
4086 | } | ||
4087 | |||
4088 | /** | ||
4089 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions | ||
2318 | * @phba: pointer to lpfc hba data structure. | 4090 | * @phba: pointer to lpfc hba data structure. |
2319 | * | 4091 | * |
2320 | * This routine is invoked to enable the MSI-X interrupt vectors. The kernel | 4092 | * This routine is invoked to remove all memory resources allocated |
2321 | * function pci_enable_msix() is called to enable the MSI-X vectors. Note that | 4093 | * to support rpis. This routine presumes the caller has released all |
2322 | * pci_enable_msix(), once invoked, enables either all or nothing, depending | 4094 | * rpis consumed by fabric or port logins and is prepared to have |
2323 | * on the current availability of PCI vector resources. The device driver is | 4095 | * the header pages removed. |
2324 | * responsible for calling the individual request_irq() to register each MSI-X | 4096 | **/ |
2325 | * vector with a interrupt handler, which is done in this function. Note that | 4097 | void |
4098 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) | ||
4099 | { | ||
4100 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; | ||
4101 | |||
4102 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, | ||
4103 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | ||
4104 | list_del(&rpi_hdr->list); | ||
4105 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, | ||
4106 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); | ||
4107 | kfree(rpi_hdr->dmabuf); | ||
4108 | kfree(rpi_hdr); | ||
4109 | } | ||
4110 | |||
4111 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base; | ||
4112 | memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask)); | ||
4113 | } | ||
4114 | |||
4115 | /** | ||
4116 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. | ||
4117 | * @pdev: pointer to pci device data structure. | ||
4118 | * | ||
4119 | * This routine is invoked to allocate the driver hba data structure for an | ||
4120 | * HBA device. If the allocation is successful, the phba reference to the | ||
4121 | * PCI device data structure is set. | ||
4122 | * | ||
4123 | * Return codes | ||
4124 | * pointer to @phba - sucessful | ||
4125 | * NULL - error | ||
4126 | **/ | ||
4127 | static struct lpfc_hba * | ||
4128 | lpfc_hba_alloc(struct pci_dev *pdev) | ||
4129 | { | ||
4130 | struct lpfc_hba *phba; | ||
4131 | |||
4132 | /* Allocate memory for HBA structure */ | ||
4133 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); | ||
4134 | if (!phba) { | ||
4135 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4136 | "1417 Failed to allocate hba struct.\n"); | ||
4137 | return NULL; | ||
4138 | } | ||
4139 | |||
4140 | /* Set reference to PCI device in HBA structure */ | ||
4141 | phba->pcidev = pdev; | ||
4142 | |||
4143 | /* Assign an unused board number */ | ||
4144 | phba->brd_no = lpfc_get_instance(); | ||
4145 | if (phba->brd_no < 0) { | ||
4146 | kfree(phba); | ||
4147 | return NULL; | ||
4148 | } | ||
4149 | |||
4150 | return phba; | ||
4151 | } | ||
4152 | |||
4153 | /** | ||
4154 | * lpfc_hba_free - Free driver hba data structure with a device. | ||
4155 | * @phba: pointer to lpfc hba data structure. | ||
4156 | * | ||
4157 | * This routine is invoked to free the driver hba data structure with an | ||
4158 | * HBA device. | ||
4159 | **/ | ||
4160 | static void | ||
4161 | lpfc_hba_free(struct lpfc_hba *phba) | ||
4162 | { | ||
4163 | /* Release the driver assigned board number */ | ||
4164 | idr_remove(&lpfc_hba_index, phba->brd_no); | ||
4165 | |||
4166 | kfree(phba); | ||
4167 | return; | ||
4168 | } | ||
4169 | |||
4170 | /** | ||
4171 | * lpfc_create_shost - Create hba physical port with associated scsi host. | ||
4172 | * @phba: pointer to lpfc hba data structure. | ||
4173 | * | ||
4174 | * This routine is invoked to create HBA physical port and associate a SCSI | ||
4175 | * host with it. | ||
4176 | * | ||
4177 | * Return codes | ||
4178 | * 0 - sucessful | ||
4179 | * other values - error | ||
4180 | **/ | ||
4181 | static int | ||
4182 | lpfc_create_shost(struct lpfc_hba *phba) | ||
4183 | { | ||
4184 | struct lpfc_vport *vport; | ||
4185 | struct Scsi_Host *shost; | ||
4186 | |||
4187 | /* Initialize HBA FC structure */ | ||
4188 | phba->fc_edtov = FF_DEF_EDTOV; | ||
4189 | phba->fc_ratov = FF_DEF_RATOV; | ||
4190 | phba->fc_altov = FF_DEF_ALTOV; | ||
4191 | phba->fc_arbtov = FF_DEF_ARBTOV; | ||
4192 | |||
4193 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); | ||
4194 | if (!vport) | ||
4195 | return -ENODEV; | ||
4196 | |||
4197 | shost = lpfc_shost_from_vport(vport); | ||
4198 | phba->pport = vport; | ||
4199 | lpfc_debugfs_initialize(vport); | ||
4200 | /* Put reference to SCSI host to driver's device private data */ | ||
4201 | pci_set_drvdata(phba->pcidev, shost); | ||
4202 | |||
4203 | return 0; | ||
4204 | } | ||
4205 | |||
4206 | /** | ||
4207 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. | ||
4208 | * @phba: pointer to lpfc hba data structure. | ||
4209 | * | ||
4210 | * This routine is invoked to destroy HBA physical port and the associated | ||
4211 | * SCSI host. | ||
4212 | **/ | ||
4213 | static void | ||
4214 | lpfc_destroy_shost(struct lpfc_hba *phba) | ||
4215 | { | ||
4216 | struct lpfc_vport *vport = phba->pport; | ||
4217 | |||
4218 | /* Destroy physical port that associated with the SCSI host */ | ||
4219 | destroy_port(vport); | ||
4220 | |||
4221 | return; | ||
4222 | } | ||
4223 | |||
4224 | /** | ||
4225 | * lpfc_setup_bg - Setup Block guard structures and debug areas. | ||
4226 | * @phba: pointer to lpfc hba data structure. | ||
4227 | * @shost: the shost to be used to detect Block guard settings. | ||
4228 | * | ||
4229 | * This routine sets up the local Block guard protocol settings for @shost. | ||
4230 | * This routine also allocates memory for debugging bg buffers. | ||
4231 | **/ | ||
4232 | static void | ||
4233 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) | ||
4234 | { | ||
4235 | int pagecnt = 10; | ||
4236 | if (lpfc_prot_mask && lpfc_prot_guard) { | ||
4237 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
4238 | "1478 Registering BlockGuard with the " | ||
4239 | "SCSI layer\n"); | ||
4240 | scsi_host_set_prot(shost, lpfc_prot_mask); | ||
4241 | scsi_host_set_guard(shost, lpfc_prot_guard); | ||
4242 | } | ||
4243 | if (!_dump_buf_data) { | ||
4244 | while (pagecnt) { | ||
4245 | spin_lock_init(&_dump_buf_lock); | ||
4246 | _dump_buf_data = | ||
4247 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | ||
4248 | if (_dump_buf_data) { | ||
4249 | printk(KERN_ERR "BLKGRD allocated %d pages for " | ||
4250 | "_dump_buf_data at 0x%p\n", | ||
4251 | (1 << pagecnt), _dump_buf_data); | ||
4252 | _dump_buf_data_order = pagecnt; | ||
4253 | memset(_dump_buf_data, 0, | ||
4254 | ((1 << PAGE_SHIFT) << pagecnt)); | ||
4255 | break; | ||
4256 | } else | ||
4257 | --pagecnt; | ||
4258 | } | ||
4259 | if (!_dump_buf_data_order) | ||
4260 | printk(KERN_ERR "BLKGRD ERROR unable to allocate " | ||
4261 | "memory for hexdump\n"); | ||
4262 | } else | ||
4263 | printk(KERN_ERR "BLKGRD already allocated _dump_buf_data=0x%p" | ||
4264 | "\n", _dump_buf_data); | ||
4265 | if (!_dump_buf_dif) { | ||
4266 | while (pagecnt) { | ||
4267 | _dump_buf_dif = | ||
4268 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | ||
4269 | if (_dump_buf_dif) { | ||
4270 | printk(KERN_ERR "BLKGRD allocated %d pages for " | ||
4271 | "_dump_buf_dif at 0x%p\n", | ||
4272 | (1 << pagecnt), _dump_buf_dif); | ||
4273 | _dump_buf_dif_order = pagecnt; | ||
4274 | memset(_dump_buf_dif, 0, | ||
4275 | ((1 << PAGE_SHIFT) << pagecnt)); | ||
4276 | break; | ||
4277 | } else | ||
4278 | --pagecnt; | ||
4279 | } | ||
4280 | if (!_dump_buf_dif_order) | ||
4281 | printk(KERN_ERR "BLKGRD ERROR unable to allocate " | ||
4282 | "memory for hexdump\n"); | ||
4283 | } else | ||
4284 | printk(KERN_ERR "BLKGRD already allocated _dump_buf_dif=0x%p\n", | ||
4285 | _dump_buf_dif); | ||
4286 | } | ||
4287 | |||
4288 | /** | ||
4289 | * lpfc_post_init_setup - Perform necessary device post initialization setup. | ||
4290 | * @phba: pointer to lpfc hba data structure. | ||
4291 | * | ||
4292 | * This routine is invoked to perform all the necessary post initialization | ||
4293 | * setup for the device. | ||
4294 | **/ | ||
4295 | static void | ||
4296 | lpfc_post_init_setup(struct lpfc_hba *phba) | ||
4297 | { | ||
4298 | struct Scsi_Host *shost; | ||
4299 | struct lpfc_adapter_event_header adapter_event; | ||
4300 | |||
4301 | /* Get the default values for Model Name and Description */ | ||
4302 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | ||
4303 | |||
4304 | /* | ||
4305 | * hba setup may have changed the hba_queue_depth so we need to | ||
4306 | * adjust the value of can_queue. | ||
4307 | */ | ||
4308 | shost = pci_get_drvdata(phba->pcidev); | ||
4309 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | ||
4310 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | ||
4311 | lpfc_setup_bg(phba, shost); | ||
4312 | |||
4313 | lpfc_host_attrib_init(shost); | ||
4314 | |||
4315 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | ||
4316 | spin_lock_irq(shost->host_lock); | ||
4317 | lpfc_poll_start_timer(phba); | ||
4318 | spin_unlock_irq(shost->host_lock); | ||
4319 | } | ||
4320 | |||
4321 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
4322 | "0428 Perform SCSI scan\n"); | ||
4323 | /* Send board arrival event to upper layer */ | ||
4324 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | ||
4325 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | ||
4326 | fc_host_post_vendor_event(shost, fc_get_event_number(), | ||
4327 | sizeof(adapter_event), | ||
4328 | (char *) &adapter_event, | ||
4329 | LPFC_NL_VENDOR_ID); | ||
4330 | return; | ||
4331 | } | ||
4332 | |||
4333 | /** | ||
4334 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. | ||
4335 | * @phba: pointer to lpfc hba data structure. | ||
4336 | * | ||
4337 | * This routine is invoked to set up the PCI device memory space for device | ||
4338 | * with SLI-3 interface spec. | ||
4339 | * | ||
4340 | * Return codes | ||
4341 | * 0 - sucessful | ||
4342 | * other values - error | ||
4343 | **/ | ||
4344 | static int | ||
4345 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) | ||
4346 | { | ||
4347 | struct pci_dev *pdev; | ||
4348 | unsigned long bar0map_len, bar2map_len; | ||
4349 | int i, hbq_count; | ||
4350 | void *ptr; | ||
4351 | int error = -ENODEV; | ||
4352 | |||
4353 | /* Obtain PCI device reference */ | ||
4354 | if (!phba->pcidev) | ||
4355 | return error; | ||
4356 | else | ||
4357 | pdev = phba->pcidev; | ||
4358 | |||
4359 | /* Set the device DMA mask size */ | ||
4360 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) | ||
4361 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) | ||
4362 | return error; | ||
4363 | |||
4364 | /* Get the bus address of Bar0 and Bar2 and the number of bytes | ||
4365 | * required by each mapping. | ||
4366 | */ | ||
4367 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | ||
4368 | bar0map_len = pci_resource_len(pdev, 0); | ||
4369 | |||
4370 | phba->pci_bar2_map = pci_resource_start(pdev, 2); | ||
4371 | bar2map_len = pci_resource_len(pdev, 2); | ||
4372 | |||
4373 | /* Map HBA SLIM to a kernel virtual address. */ | ||
4374 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | ||
4375 | if (!phba->slim_memmap_p) { | ||
4376 | dev_printk(KERN_ERR, &pdev->dev, | ||
4377 | "ioremap failed for SLIM memory.\n"); | ||
4378 | goto out; | ||
4379 | } | ||
4380 | |||
4381 | /* Map HBA Control Registers to a kernel virtual address. */ | ||
4382 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | ||
4383 | if (!phba->ctrl_regs_memmap_p) { | ||
4384 | dev_printk(KERN_ERR, &pdev->dev, | ||
4385 | "ioremap failed for HBA control registers.\n"); | ||
4386 | goto out_iounmap_slim; | ||
4387 | } | ||
4388 | |||
4389 | /* Allocate memory for SLI-2 structures */ | ||
4390 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, | ||
4391 | SLI2_SLIM_SIZE, | ||
4392 | &phba->slim2p.phys, | ||
4393 | GFP_KERNEL); | ||
4394 | if (!phba->slim2p.virt) | ||
4395 | goto out_iounmap; | ||
4396 | |||
4397 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); | ||
4398 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); | ||
4399 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); | ||
4400 | phba->IOCBs = (phba->slim2p.virt + | ||
4401 | offsetof(struct lpfc_sli2_slim, IOCBs)); | ||
4402 | |||
4403 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, | ||
4404 | lpfc_sli_hbq_size(), | ||
4405 | &phba->hbqslimp.phys, | ||
4406 | GFP_KERNEL); | ||
4407 | if (!phba->hbqslimp.virt) | ||
4408 | goto out_free_slim; | ||
4409 | |||
4410 | hbq_count = lpfc_sli_hbq_count(); | ||
4411 | ptr = phba->hbqslimp.virt; | ||
4412 | for (i = 0; i < hbq_count; ++i) { | ||
4413 | phba->hbqs[i].hbq_virt = ptr; | ||
4414 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | ||
4415 | ptr += (lpfc_hbq_defs[i]->entry_count * | ||
4416 | sizeof(struct lpfc_hbq_entry)); | ||
4417 | } | ||
4418 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | ||
4419 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | ||
4420 | |||
4421 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | ||
4422 | |||
4423 | INIT_LIST_HEAD(&phba->rb_pend_list); | ||
4424 | |||
4425 | phba->MBslimaddr = phba->slim_memmap_p; | ||
4426 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | ||
4427 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | ||
4428 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | ||
4429 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | ||
4430 | |||
4431 | return 0; | ||
4432 | |||
4433 | out_free_slim: | ||
4434 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | ||
4435 | phba->slim2p.virt, phba->slim2p.phys); | ||
4436 | out_iounmap: | ||
4437 | iounmap(phba->ctrl_regs_memmap_p); | ||
4438 | out_iounmap_slim: | ||
4439 | iounmap(phba->slim_memmap_p); | ||
4440 | out: | ||
4441 | return error; | ||
4442 | } | ||
4443 | |||
4444 | /** | ||
4445 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. | ||
4446 | * @phba: pointer to lpfc hba data structure. | ||
4447 | * | ||
4448 | * This routine is invoked to unset the PCI device memory space for device | ||
4449 | * with SLI-3 interface spec. | ||
4450 | **/ | ||
4451 | static void | ||
4452 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) | ||
4453 | { | ||
4454 | struct pci_dev *pdev; | ||
4455 | |||
4456 | /* Obtain PCI device reference */ | ||
4457 | if (!phba->pcidev) | ||
4458 | return; | ||
4459 | else | ||
4460 | pdev = phba->pcidev; | ||
4461 | |||
4462 | /* Free coherent DMA memory allocated */ | ||
4463 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | ||
4464 | phba->hbqslimp.virt, phba->hbqslimp.phys); | ||
4465 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | ||
4466 | phba->slim2p.virt, phba->slim2p.phys); | ||
4467 | |||
4468 | /* I/O memory unmap */ | ||
4469 | iounmap(phba->ctrl_regs_memmap_p); | ||
4470 | iounmap(phba->slim_memmap_p); | ||
4471 | |||
4472 | return; | ||
4473 | } | ||
4474 | |||
4475 | /** | ||
4476 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status | ||
4477 | * @phba: pointer to lpfc hba data structure. | ||
4478 | * | ||
4479 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) | ||
4480 | * done and check status. | ||
4481 | * | ||
4482 | * Return 0 if successful, otherwise -ENODEV. | ||
4483 | **/ | ||
4484 | int | ||
4485 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) | ||
4486 | { | ||
4487 | struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg, scratchpad; | ||
4488 | uint32_t onlnreg0, onlnreg1; | ||
4489 | int i, port_error = -ENODEV; | ||
4490 | |||
4491 | if (!phba->sli4_hba.STAregaddr) | ||
4492 | return -ENODEV; | ||
4493 | |||
4494 | /* With uncoverable error, log the error message and return error */ | ||
4495 | onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr); | ||
4496 | onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr); | ||
4497 | if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) { | ||
4498 | uerrlo_reg.word0 = readl(phba->sli4_hba.UERRLOregaddr); | ||
4499 | uerrhi_reg.word0 = readl(phba->sli4_hba.UERRHIregaddr); | ||
4500 | if (uerrlo_reg.word0 || uerrhi_reg.word0) { | ||
4501 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4502 | "1422 HBA Unrecoverable error: " | ||
4503 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | ||
4504 | "online0_reg=0x%x, online1_reg=0x%x\n", | ||
4505 | uerrlo_reg.word0, uerrhi_reg.word0, | ||
4506 | onlnreg0, onlnreg1); | ||
4507 | } | ||
4508 | return -ENODEV; | ||
4509 | } | ||
4510 | |||
4511 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ | ||
4512 | for (i = 0; i < 3000; i++) { | ||
4513 | sta_reg.word0 = readl(phba->sli4_hba.STAregaddr); | ||
4514 | /* Encounter fatal POST error, break out */ | ||
4515 | if (bf_get(lpfc_hst_state_perr, &sta_reg)) { | ||
4516 | port_error = -ENODEV; | ||
4517 | break; | ||
4518 | } | ||
4519 | if (LPFC_POST_STAGE_ARMFW_READY == | ||
4520 | bf_get(lpfc_hst_state_port_status, &sta_reg)) { | ||
4521 | port_error = 0; | ||
4522 | break; | ||
4523 | } | ||
4524 | msleep(10); | ||
4525 | } | ||
4526 | |||
4527 | if (port_error) | ||
4528 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4529 | "1408 Failure HBA POST Status: sta_reg=0x%x, " | ||
4530 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, " | ||
4531 | "dl=x%x, pstatus=x%x\n", sta_reg.word0, | ||
4532 | bf_get(lpfc_hst_state_perr, &sta_reg), | ||
4533 | bf_get(lpfc_hst_state_sfi, &sta_reg), | ||
4534 | bf_get(lpfc_hst_state_nip, &sta_reg), | ||
4535 | bf_get(lpfc_hst_state_ipc, &sta_reg), | ||
4536 | bf_get(lpfc_hst_state_xrom, &sta_reg), | ||
4537 | bf_get(lpfc_hst_state_dl, &sta_reg), | ||
4538 | bf_get(lpfc_hst_state_port_status, &sta_reg)); | ||
4539 | |||
4540 | /* Log device information */ | ||
4541 | scratchpad.word0 = readl(phba->sli4_hba.SCRATCHPADregaddr); | ||
4542 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
4543 | "2534 Device Info: ChipType=0x%x, SliRev=0x%x, " | ||
4544 | "FeatureL1=0x%x, FeatureL2=0x%x\n", | ||
4545 | bf_get(lpfc_scratchpad_chiptype, &scratchpad), | ||
4546 | bf_get(lpfc_scratchpad_slirev, &scratchpad), | ||
4547 | bf_get(lpfc_scratchpad_featurelevel1, &scratchpad), | ||
4548 | bf_get(lpfc_scratchpad_featurelevel2, &scratchpad)); | ||
4549 | |||
4550 | return port_error; | ||
4551 | } | ||
4552 | |||
4553 | /** | ||
4554 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. | ||
4555 | * @phba: pointer to lpfc hba data structure. | ||
4556 | * | ||
4557 | * This routine is invoked to set up SLI4 BAR0 PCI config space register | ||
4558 | * memory map. | ||
4559 | **/ | ||
4560 | static void | ||
4561 | lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba) | ||
4562 | { | ||
4563 | phba->sli4_hba.UERRLOregaddr = phba->sli4_hba.conf_regs_memmap_p + | ||
4564 | LPFC_UERR_STATUS_LO; | ||
4565 | phba->sli4_hba.UERRHIregaddr = phba->sli4_hba.conf_regs_memmap_p + | ||
4566 | LPFC_UERR_STATUS_HI; | ||
4567 | phba->sli4_hba.ONLINE0regaddr = phba->sli4_hba.conf_regs_memmap_p + | ||
4568 | LPFC_ONLINE0; | ||
4569 | phba->sli4_hba.ONLINE1regaddr = phba->sli4_hba.conf_regs_memmap_p + | ||
4570 | LPFC_ONLINE1; | ||
4571 | phba->sli4_hba.SCRATCHPADregaddr = phba->sli4_hba.conf_regs_memmap_p + | ||
4572 | LPFC_SCRATCHPAD; | ||
4573 | } | ||
4574 | |||
4575 | /** | ||
4576 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. | ||
4577 | * @phba: pointer to lpfc hba data structure. | ||
4578 | * | ||
4579 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) | ||
4580 | * memory map. | ||
4581 | **/ | ||
4582 | static void | ||
4583 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) | ||
4584 | { | ||
4585 | |||
4586 | phba->sli4_hba.STAregaddr = phba->sli4_hba.ctrl_regs_memmap_p + | ||
4587 | LPFC_HST_STATE; | ||
4588 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + | ||
4589 | LPFC_HST_ISR0; | ||
4590 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + | ||
4591 | LPFC_HST_IMR0; | ||
4592 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + | ||
4593 | LPFC_HST_ISCR0; | ||
4594 | return; | ||
4595 | } | ||
4596 | |||
4597 | /** | ||
4598 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. | ||
4599 | * @phba: pointer to lpfc hba data structure. | ||
4600 | * @vf: virtual function number | ||
4601 | * | ||
4602 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map | ||
4603 | * based on the given viftual function number, @vf. | ||
4604 | * | ||
4605 | * Return 0 if successful, otherwise -ENODEV. | ||
4606 | **/ | ||
4607 | static int | ||
4608 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) | ||
4609 | { | ||
4610 | if (vf > LPFC_VIR_FUNC_MAX) | ||
4611 | return -ENODEV; | ||
4612 | |||
4613 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | ||
4614 | vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL); | ||
4615 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | ||
4616 | vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL); | ||
4617 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | ||
4618 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); | ||
4619 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | ||
4620 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); | ||
4621 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | ||
4622 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); | ||
4623 | return 0; | ||
4624 | } | ||
4625 | |||
4626 | /** | ||
4627 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox | ||
4628 | * @phba: pointer to lpfc hba data structure. | ||
4629 | * | ||
4630 | * This routine is invoked to create the bootstrap mailbox | ||
4631 | * region consistent with the SLI-4 interface spec. This | ||
4632 | * routine allocates all memory necessary to communicate | ||
4633 | * mailbox commands to the port and sets up all alignment | ||
4634 | * needs. No locks are expected to be held when calling | ||
4635 | * this routine. | ||
4636 | * | ||
4637 | * Return codes | ||
4638 | * 0 - sucessful | ||
4639 | * ENOMEM - could not allocated memory. | ||
4640 | **/ | ||
4641 | static int | ||
4642 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) | ||
4643 | { | ||
4644 | uint32_t bmbx_size; | ||
4645 | struct lpfc_dmabuf *dmabuf; | ||
4646 | struct dma_address *dma_address; | ||
4647 | uint32_t pa_addr; | ||
4648 | uint64_t phys_addr; | ||
4649 | |||
4650 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | ||
4651 | if (!dmabuf) | ||
4652 | return -ENOMEM; | ||
4653 | |||
4654 | /* | ||
4655 | * The bootstrap mailbox region is comprised of 2 parts | ||
4656 | * plus an alignment restriction of 16 bytes. | ||
4657 | */ | ||
4658 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); | ||
4659 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | ||
4660 | bmbx_size, | ||
4661 | &dmabuf->phys, | ||
4662 | GFP_KERNEL); | ||
4663 | if (!dmabuf->virt) { | ||
4664 | kfree(dmabuf); | ||
4665 | return -ENOMEM; | ||
4666 | } | ||
4667 | memset(dmabuf->virt, 0, bmbx_size); | ||
4668 | |||
4669 | /* | ||
4670 | * Initialize the bootstrap mailbox pointers now so that the register | ||
4671 | * operations are simple later. The mailbox dma address is required | ||
4672 | * to be 16-byte aligned. Also align the virtual memory as each | ||
4673 | * maibox is copied into the bmbx mailbox region before issuing the | ||
4674 | * command to the port. | ||
4675 | */ | ||
4676 | phba->sli4_hba.bmbx.dmabuf = dmabuf; | ||
4677 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; | ||
4678 | |||
4679 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, | ||
4680 | LPFC_ALIGN_16_BYTE); | ||
4681 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, | ||
4682 | LPFC_ALIGN_16_BYTE); | ||
4683 | |||
4684 | /* | ||
4685 | * Set the high and low physical addresses now. The SLI4 alignment | ||
4686 | * requirement is 16 bytes and the mailbox is posted to the port | ||
4687 | * as two 30-bit addresses. The other data is a bit marking whether | ||
4688 | * the 30-bit address is the high or low address. | ||
4689 | * Upcast bmbx aphys to 64bits so shift instruction compiles | ||
4690 | * clean on 32 bit machines. | ||
4691 | */ | ||
4692 | dma_address = &phba->sli4_hba.bmbx.dma_address; | ||
4693 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; | ||
4694 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); | ||
4695 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | | ||
4696 | LPFC_BMBX_BIT1_ADDR_HI); | ||
4697 | |||
4698 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); | ||
4699 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | | ||
4700 | LPFC_BMBX_BIT1_ADDR_LO); | ||
4701 | return 0; | ||
4702 | } | ||
4703 | |||
4704 | /** | ||
4705 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources | ||
4706 | * @phba: pointer to lpfc hba data structure. | ||
4707 | * | ||
4708 | * This routine is invoked to teardown the bootstrap mailbox | ||
4709 | * region and release all host resources. This routine requires | ||
4710 | * the caller to ensure all mailbox commands recovered, no | ||
4711 | * additional mailbox comands are sent, and interrupts are disabled | ||
4712 | * before calling this routine. | ||
4713 | * | ||
4714 | **/ | ||
4715 | static void | ||
4716 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) | ||
4717 | { | ||
4718 | dma_free_coherent(&phba->pcidev->dev, | ||
4719 | phba->sli4_hba.bmbx.bmbx_size, | ||
4720 | phba->sli4_hba.bmbx.dmabuf->virt, | ||
4721 | phba->sli4_hba.bmbx.dmabuf->phys); | ||
4722 | |||
4723 | kfree(phba->sli4_hba.bmbx.dmabuf); | ||
4724 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); | ||
4725 | } | ||
4726 | |||
4727 | /** | ||
4728 | * lpfc_sli4_read_config - Get the config parameters. | ||
4729 | * @phba: pointer to lpfc hba data structure. | ||
4730 | * | ||
4731 | * This routine is invoked to read the configuration parameters from the HBA. | ||
4732 | * The configuration parameters are used to set the base and maximum values | ||
4733 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource | ||
4734 | * allocation for the port. | ||
4735 | * | ||
4736 | * Return codes | ||
4737 | * 0 - sucessful | ||
4738 | * ENOMEM - No availble memory | ||
4739 | * EIO - The mailbox failed to complete successfully. | ||
4740 | **/ | ||
4741 | static int | ||
4742 | lpfc_sli4_read_config(struct lpfc_hba *phba) | ||
4743 | { | ||
4744 | LPFC_MBOXQ_t *pmb; | ||
4745 | struct lpfc_mbx_read_config *rd_config; | ||
4746 | uint32_t rc = 0; | ||
4747 | |||
4748 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
4749 | if (!pmb) { | ||
4750 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
4751 | "2011 Unable to allocate memory for issuing " | ||
4752 | "SLI_CONFIG_SPECIAL mailbox command\n"); | ||
4753 | return -ENOMEM; | ||
4754 | } | ||
4755 | |||
4756 | lpfc_read_config(phba, pmb); | ||
4757 | |||
4758 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | ||
4759 | if (rc != MBX_SUCCESS) { | ||
4760 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
4761 | "2012 Mailbox failed , mbxCmd x%x " | ||
4762 | "READ_CONFIG, mbxStatus x%x\n", | ||
4763 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | ||
4764 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | ||
4765 | rc = -EIO; | ||
4766 | } else { | ||
4767 | rd_config = &pmb->u.mqe.un.rd_config; | ||
4768 | phba->sli4_hba.max_cfg_param.max_xri = | ||
4769 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | ||
4770 | phba->sli4_hba.max_cfg_param.xri_base = | ||
4771 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); | ||
4772 | phba->sli4_hba.max_cfg_param.max_vpi = | ||
4773 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); | ||
4774 | phba->sli4_hba.max_cfg_param.vpi_base = | ||
4775 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); | ||
4776 | phba->sli4_hba.max_cfg_param.max_rpi = | ||
4777 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | ||
4778 | phba->sli4_hba.max_cfg_param.rpi_base = | ||
4779 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); | ||
4780 | phba->sli4_hba.max_cfg_param.max_vfi = | ||
4781 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); | ||
4782 | phba->sli4_hba.max_cfg_param.vfi_base = | ||
4783 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); | ||
4784 | phba->sli4_hba.max_cfg_param.max_fcfi = | ||
4785 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); | ||
4786 | phba->sli4_hba.max_cfg_param.fcfi_base = | ||
4787 | bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config); | ||
4788 | phba->sli4_hba.max_cfg_param.max_eq = | ||
4789 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); | ||
4790 | phba->sli4_hba.max_cfg_param.max_rq = | ||
4791 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); | ||
4792 | phba->sli4_hba.max_cfg_param.max_wq = | ||
4793 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); | ||
4794 | phba->sli4_hba.max_cfg_param.max_cq = | ||
4795 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); | ||
4796 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); | ||
4797 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; | ||
4798 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; | ||
4799 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; | ||
4800 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base; | ||
4801 | phba->max_vpi = phba->sli4_hba.max_cfg_param.max_vpi; | ||
4802 | phba->max_vports = phba->max_vpi; | ||
4803 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | ||
4804 | "2003 cfg params XRI(B:%d M:%d), " | ||
4805 | "VPI(B:%d M:%d) " | ||
4806 | "VFI(B:%d M:%d) " | ||
4807 | "RPI(B:%d M:%d) " | ||
4808 | "FCFI(B:%d M:%d)\n", | ||
4809 | phba->sli4_hba.max_cfg_param.xri_base, | ||
4810 | phba->sli4_hba.max_cfg_param.max_xri, | ||
4811 | phba->sli4_hba.max_cfg_param.vpi_base, | ||
4812 | phba->sli4_hba.max_cfg_param.max_vpi, | ||
4813 | phba->sli4_hba.max_cfg_param.vfi_base, | ||
4814 | phba->sli4_hba.max_cfg_param.max_vfi, | ||
4815 | phba->sli4_hba.max_cfg_param.rpi_base, | ||
4816 | phba->sli4_hba.max_cfg_param.max_rpi, | ||
4817 | phba->sli4_hba.max_cfg_param.fcfi_base, | ||
4818 | phba->sli4_hba.max_cfg_param.max_fcfi); | ||
4819 | } | ||
4820 | mempool_free(pmb, phba->mbox_mem_pool); | ||
4821 | |||
4822 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ | ||
4823 | if (phba->cfg_hba_queue_depth > (phba->sli4_hba.max_cfg_param.max_xri)) | ||
4824 | phba->cfg_hba_queue_depth = | ||
4825 | phba->sli4_hba.max_cfg_param.max_xri; | ||
4826 | return rc; | ||
4827 | } | ||
4828 | |||
4829 | /** | ||
4830 | * lpfc_dev_endian_order_setup - Notify the port of the host's endian order. | ||
4831 | * @phba: pointer to lpfc hba data structure. | ||
4832 | * | ||
4833 | * This routine is invoked to setup the host-side endian order to the | ||
4834 | * HBA consistent with the SLI-4 interface spec. | ||
4835 | * | ||
4836 | * Return codes | ||
4837 | * 0 - sucessful | ||
4838 | * ENOMEM - No availble memory | ||
4839 | * EIO - The mailbox failed to complete successfully. | ||
4840 | **/ | ||
4841 | static int | ||
4842 | lpfc_setup_endian_order(struct lpfc_hba *phba) | ||
4843 | { | ||
4844 | LPFC_MBOXQ_t *mboxq; | ||
4845 | uint32_t rc = 0; | ||
4846 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, | ||
4847 | HOST_ENDIAN_HIGH_WORD1}; | ||
4848 | |||
4849 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
4850 | if (!mboxq) { | ||
4851 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4852 | "0492 Unable to allocate memory for issuing " | ||
4853 | "SLI_CONFIG_SPECIAL mailbox command\n"); | ||
4854 | return -ENOMEM; | ||
4855 | } | ||
4856 | |||
4857 | /* | ||
4858 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first two | ||
4859 | * words to contain special data values and no other data. | ||
4860 | */ | ||
4861 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); | ||
4862 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); | ||
4863 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | ||
4864 | if (rc != MBX_SUCCESS) { | ||
4865 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4866 | "0493 SLI_CONFIG_SPECIAL mailbox failed with " | ||
4867 | "status x%x\n", | ||
4868 | rc); | ||
4869 | rc = -EIO; | ||
4870 | } | ||
4871 | |||
4872 | mempool_free(mboxq, phba->mbox_mem_pool); | ||
4873 | return rc; | ||
4874 | } | ||
4875 | |||
4876 | /** | ||
4877 | * lpfc_sli4_queue_create - Create all the SLI4 queues | ||
4878 | * @phba: pointer to lpfc hba data structure. | ||
4879 | * | ||
4880 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA | ||
4881 | * operation. For each SLI4 queue type, the parameters such as queue entry | ||
4882 | * count (queue depth) shall be taken from the module parameter. For now, | ||
4883 | * we just use some constant number as place holder. | ||
4884 | * | ||
4885 | * Return codes | ||
4886 | * 0 - sucessful | ||
4887 | * ENOMEM - No availble memory | ||
4888 | * EIO - The mailbox failed to complete successfully. | ||
4889 | **/ | ||
4890 | static int | ||
4891 | lpfc_sli4_queue_create(struct lpfc_hba *phba) | ||
4892 | { | ||
4893 | struct lpfc_queue *qdesc; | ||
4894 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | ||
4895 | int cfg_fcp_wq_count; | ||
4896 | int cfg_fcp_eq_count; | ||
4897 | |||
4898 | /* | ||
4899 | * Sanity check for confiugred queue parameters against the run-time | ||
4900 | * device parameters | ||
4901 | */ | ||
4902 | |||
4903 | /* Sanity check on FCP fast-path WQ parameters */ | ||
4904 | cfg_fcp_wq_count = phba->cfg_fcp_wq_count; | ||
4905 | if (cfg_fcp_wq_count > | ||
4906 | (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) { | ||
4907 | cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq - | ||
4908 | LPFC_SP_WQN_DEF; | ||
4909 | if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) { | ||
4910 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4911 | "2581 Not enough WQs (%d) from " | ||
4912 | "the pci function for supporting " | ||
4913 | "FCP WQs (%d)\n", | ||
4914 | phba->sli4_hba.max_cfg_param.max_wq, | ||
4915 | phba->cfg_fcp_wq_count); | ||
4916 | goto out_error; | ||
4917 | } | ||
4918 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
4919 | "2582 Not enough WQs (%d) from the pci " | ||
4920 | "function for supporting the requested " | ||
4921 | "FCP WQs (%d), the actual FCP WQs can " | ||
4922 | "be supported: %d\n", | ||
4923 | phba->sli4_hba.max_cfg_param.max_wq, | ||
4924 | phba->cfg_fcp_wq_count, cfg_fcp_wq_count); | ||
4925 | } | ||
4926 | /* The actual number of FCP work queues adopted */ | ||
4927 | phba->cfg_fcp_wq_count = cfg_fcp_wq_count; | ||
4928 | |||
4929 | /* Sanity check on FCP fast-path EQ parameters */ | ||
4930 | cfg_fcp_eq_count = phba->cfg_fcp_eq_count; | ||
4931 | if (cfg_fcp_eq_count > | ||
4932 | (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) { | ||
4933 | cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq - | ||
4934 | LPFC_SP_EQN_DEF; | ||
4935 | if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) { | ||
4936 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4937 | "2574 Not enough EQs (%d) from the " | ||
4938 | "pci function for supporting FCP " | ||
4939 | "EQs (%d)\n", | ||
4940 | phba->sli4_hba.max_cfg_param.max_eq, | ||
4941 | phba->cfg_fcp_eq_count); | ||
4942 | goto out_error; | ||
4943 | } | ||
4944 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
4945 | "2575 Not enough EQs (%d) from the pci " | ||
4946 | "function for supporting the requested " | ||
4947 | "FCP EQs (%d), the actual FCP EQs can " | ||
4948 | "be supported: %d\n", | ||
4949 | phba->sli4_hba.max_cfg_param.max_eq, | ||
4950 | phba->cfg_fcp_eq_count, cfg_fcp_eq_count); | ||
4951 | } | ||
4952 | /* It does not make sense to have more EQs than WQs */ | ||
4953 | if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) { | ||
4954 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
4955 | "2593 The number of FCP EQs (%d) is more " | ||
4956 | "than the number of FCP WQs (%d), take " | ||
4957 | "the number of FCP EQs same as than of " | ||
4958 | "WQs (%d)\n", cfg_fcp_eq_count, | ||
4959 | phba->cfg_fcp_wq_count, | ||
4960 | phba->cfg_fcp_wq_count); | ||
4961 | cfg_fcp_eq_count = phba->cfg_fcp_wq_count; | ||
4962 | } | ||
4963 | /* The actual number of FCP event queues adopted */ | ||
4964 | phba->cfg_fcp_eq_count = cfg_fcp_eq_count; | ||
4965 | /* The overall number of event queues used */ | ||
4966 | phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF; | ||
4967 | |||
4968 | /* | ||
4969 | * Create Event Queues (EQs) | ||
4970 | */ | ||
4971 | |||
4972 | /* Get EQ depth from module parameter, fake the default for now */ | ||
4973 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; | ||
4974 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; | ||
4975 | |||
4976 | /* Create slow path event queue */ | ||
4977 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | ||
4978 | phba->sli4_hba.eq_ecount); | ||
4979 | if (!qdesc) { | ||
4980 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4981 | "0496 Failed allocate slow-path EQ\n"); | ||
4982 | goto out_error; | ||
4983 | } | ||
4984 | phba->sli4_hba.sp_eq = qdesc; | ||
4985 | |||
4986 | /* Create fast-path FCP Event Queue(s) */ | ||
4987 | phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) * | ||
4988 | phba->cfg_fcp_eq_count), GFP_KERNEL); | ||
4989 | if (!phba->sli4_hba.fp_eq) { | ||
4990 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
4991 | "2576 Failed allocate memory for fast-path " | ||
4992 | "EQ record array\n"); | ||
4993 | goto out_free_sp_eq; | ||
4994 | } | ||
4995 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | ||
4996 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | ||
4997 | phba->sli4_hba.eq_ecount); | ||
4998 | if (!qdesc) { | ||
4999 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5000 | "0497 Failed allocate fast-path EQ\n"); | ||
5001 | goto out_free_fp_eq; | ||
5002 | } | ||
5003 | phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc; | ||
5004 | } | ||
5005 | |||
5006 | /* | ||
5007 | * Create Complete Queues (CQs) | ||
5008 | */ | ||
5009 | |||
5010 | /* Get CQ depth from module parameter, fake the default for now */ | ||
5011 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; | ||
5012 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; | ||
5013 | |||
5014 | /* Create slow-path Mailbox Command Complete Queue */ | ||
5015 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | ||
5016 | phba->sli4_hba.cq_ecount); | ||
5017 | if (!qdesc) { | ||
5018 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5019 | "0500 Failed allocate slow-path mailbox CQ\n"); | ||
5020 | goto out_free_fp_eq; | ||
5021 | } | ||
5022 | phba->sli4_hba.mbx_cq = qdesc; | ||
5023 | |||
5024 | /* Create slow-path ELS Complete Queue */ | ||
5025 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | ||
5026 | phba->sli4_hba.cq_ecount); | ||
5027 | if (!qdesc) { | ||
5028 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5029 | "0501 Failed allocate slow-path ELS CQ\n"); | ||
5030 | goto out_free_mbx_cq; | ||
5031 | } | ||
5032 | phba->sli4_hba.els_cq = qdesc; | ||
5033 | |||
5034 | /* Create slow-path Unsolicited Receive Complete Queue */ | ||
5035 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | ||
5036 | phba->sli4_hba.cq_ecount); | ||
5037 | if (!qdesc) { | ||
5038 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5039 | "0502 Failed allocate slow-path USOL RX CQ\n"); | ||
5040 | goto out_free_els_cq; | ||
5041 | } | ||
5042 | phba->sli4_hba.rxq_cq = qdesc; | ||
5043 | |||
5044 | /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */ | ||
5045 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * | ||
5046 | phba->cfg_fcp_eq_count), GFP_KERNEL); | ||
5047 | if (!phba->sli4_hba.fcp_cq) { | ||
5048 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5049 | "2577 Failed allocate memory for fast-path " | ||
5050 | "CQ record array\n"); | ||
5051 | goto out_free_rxq_cq; | ||
5052 | } | ||
5053 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) { | ||
5054 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | ||
5055 | phba->sli4_hba.cq_ecount); | ||
5056 | if (!qdesc) { | ||
5057 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5058 | "0499 Failed allocate fast-path FCP " | ||
5059 | "CQ (%d)\n", fcp_cqidx); | ||
5060 | goto out_free_fcp_cq; | ||
5061 | } | ||
5062 | phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc; | ||
5063 | } | ||
5064 | |||
5065 | /* Create Mailbox Command Queue */ | ||
5066 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; | ||
5067 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; | ||
5068 | |||
5069 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, | ||
5070 | phba->sli4_hba.mq_ecount); | ||
5071 | if (!qdesc) { | ||
5072 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5073 | "0505 Failed allocate slow-path MQ\n"); | ||
5074 | goto out_free_fcp_cq; | ||
5075 | } | ||
5076 | phba->sli4_hba.mbx_wq = qdesc; | ||
5077 | |||
5078 | /* | ||
5079 | * Create all the Work Queues (WQs) | ||
5080 | */ | ||
5081 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; | ||
5082 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; | ||
5083 | |||
5084 | /* Create slow-path ELS Work Queue */ | ||
5085 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | ||
5086 | phba->sli4_hba.wq_ecount); | ||
5087 | if (!qdesc) { | ||
5088 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5089 | "0504 Failed allocate slow-path ELS WQ\n"); | ||
5090 | goto out_free_mbx_wq; | ||
5091 | } | ||
5092 | phba->sli4_hba.els_wq = qdesc; | ||
5093 | |||
5094 | /* Create fast-path FCP Work Queue(s) */ | ||
5095 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * | ||
5096 | phba->cfg_fcp_wq_count), GFP_KERNEL); | ||
5097 | if (!phba->sli4_hba.fcp_wq) { | ||
5098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5099 | "2578 Failed allocate memory for fast-path " | ||
5100 | "WQ record array\n"); | ||
5101 | goto out_free_els_wq; | ||
5102 | } | ||
5103 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | ||
5104 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | ||
5105 | phba->sli4_hba.wq_ecount); | ||
5106 | if (!qdesc) { | ||
5107 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5108 | "0503 Failed allocate fast-path FCP " | ||
5109 | "WQ (%d)\n", fcp_wqidx); | ||
5110 | goto out_free_fcp_wq; | ||
5111 | } | ||
5112 | phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc; | ||
5113 | } | ||
5114 | |||
5115 | /* | ||
5116 | * Create Receive Queue (RQ) | ||
5117 | */ | ||
5118 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; | ||
5119 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; | ||
5120 | |||
5121 | /* Create Receive Queue for header */ | ||
5122 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | ||
5123 | phba->sli4_hba.rq_ecount); | ||
5124 | if (!qdesc) { | ||
5125 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5126 | "0506 Failed allocate receive HRQ\n"); | ||
5127 | goto out_free_fcp_wq; | ||
5128 | } | ||
5129 | phba->sli4_hba.hdr_rq = qdesc; | ||
5130 | |||
5131 | /* Create Receive Queue for data */ | ||
5132 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | ||
5133 | phba->sli4_hba.rq_ecount); | ||
5134 | if (!qdesc) { | ||
5135 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5136 | "0507 Failed allocate receive DRQ\n"); | ||
5137 | goto out_free_hdr_rq; | ||
5138 | } | ||
5139 | phba->sli4_hba.dat_rq = qdesc; | ||
5140 | |||
5141 | return 0; | ||
5142 | |||
5143 | out_free_hdr_rq: | ||
5144 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | ||
5145 | phba->sli4_hba.hdr_rq = NULL; | ||
5146 | out_free_fcp_wq: | ||
5147 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) { | ||
5148 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]); | ||
5149 | phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL; | ||
5150 | } | ||
5151 | kfree(phba->sli4_hba.fcp_wq); | ||
5152 | out_free_els_wq: | ||
5153 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | ||
5154 | phba->sli4_hba.els_wq = NULL; | ||
5155 | out_free_mbx_wq: | ||
5156 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | ||
5157 | phba->sli4_hba.mbx_wq = NULL; | ||
5158 | out_free_fcp_cq: | ||
5159 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) { | ||
5160 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]); | ||
5161 | phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL; | ||
5162 | } | ||
5163 | kfree(phba->sli4_hba.fcp_cq); | ||
5164 | out_free_rxq_cq: | ||
5165 | lpfc_sli4_queue_free(phba->sli4_hba.rxq_cq); | ||
5166 | phba->sli4_hba.rxq_cq = NULL; | ||
5167 | out_free_els_cq: | ||
5168 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | ||
5169 | phba->sli4_hba.els_cq = NULL; | ||
5170 | out_free_mbx_cq: | ||
5171 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | ||
5172 | phba->sli4_hba.mbx_cq = NULL; | ||
5173 | out_free_fp_eq: | ||
5174 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) { | ||
5175 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]); | ||
5176 | phba->sli4_hba.fp_eq[fcp_eqidx] = NULL; | ||
5177 | } | ||
5178 | kfree(phba->sli4_hba.fp_eq); | ||
5179 | out_free_sp_eq: | ||
5180 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | ||
5181 | phba->sli4_hba.sp_eq = NULL; | ||
5182 | out_error: | ||
5183 | return -ENOMEM; | ||
5184 | } | ||
5185 | |||
5186 | /** | ||
5187 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues | ||
5188 | * @phba: pointer to lpfc hba data structure. | ||
5189 | * | ||
5190 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA | ||
5191 | * operation. | ||
5192 | * | ||
5193 | * Return codes | ||
5194 | * 0 - sucessful | ||
5195 | * ENOMEM - No availble memory | ||
5196 | * EIO - The mailbox failed to complete successfully. | ||
5197 | **/ | ||
5198 | static void | ||
5199 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) | ||
5200 | { | ||
5201 | int fcp_qidx; | ||
5202 | |||
5203 | /* Release mailbox command work queue */ | ||
5204 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | ||
5205 | phba->sli4_hba.mbx_wq = NULL; | ||
5206 | |||
5207 | /* Release ELS work queue */ | ||
5208 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | ||
5209 | phba->sli4_hba.els_wq = NULL; | ||
5210 | |||
5211 | /* Release FCP work queue */ | ||
5212 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | ||
5213 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]); | ||
5214 | kfree(phba->sli4_hba.fcp_wq); | ||
5215 | phba->sli4_hba.fcp_wq = NULL; | ||
5216 | |||
5217 | /* Release unsolicited receive queue */ | ||
5218 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | ||
5219 | phba->sli4_hba.hdr_rq = NULL; | ||
5220 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); | ||
5221 | phba->sli4_hba.dat_rq = NULL; | ||
5222 | |||
5223 | /* Release unsolicited receive complete queue */ | ||
5224 | lpfc_sli4_queue_free(phba->sli4_hba.rxq_cq); | ||
5225 | phba->sli4_hba.rxq_cq = NULL; | ||
5226 | |||
5227 | /* Release ELS complete queue */ | ||
5228 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | ||
5229 | phba->sli4_hba.els_cq = NULL; | ||
5230 | |||
5231 | /* Release mailbox command complete queue */ | ||
5232 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | ||
5233 | phba->sli4_hba.mbx_cq = NULL; | ||
5234 | |||
5235 | /* Release FCP response complete queue */ | ||
5236 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | ||
5237 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]); | ||
5238 | kfree(phba->sli4_hba.fcp_cq); | ||
5239 | phba->sli4_hba.fcp_cq = NULL; | ||
5240 | |||
5241 | /* Release fast-path event queue */ | ||
5242 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | ||
5243 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]); | ||
5244 | kfree(phba->sli4_hba.fp_eq); | ||
5245 | phba->sli4_hba.fp_eq = NULL; | ||
5246 | |||
5247 | /* Release slow-path event queue */ | ||
5248 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | ||
5249 | phba->sli4_hba.sp_eq = NULL; | ||
5250 | |||
5251 | return; | ||
5252 | } | ||
5253 | |||
5254 | /** | ||
5255 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues | ||
5256 | * @phba: pointer to lpfc hba data structure. | ||
5257 | * | ||
5258 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA | ||
5259 | * operation. | ||
5260 | * | ||
5261 | * Return codes | ||
5262 | * 0 - sucessful | ||
5263 | * ENOMEM - No availble memory | ||
5264 | * EIO - The mailbox failed to complete successfully. | ||
5265 | **/ | ||
5266 | int | ||
5267 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) | ||
5268 | { | ||
5269 | int rc = -ENOMEM; | ||
5270 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | ||
5271 | int fcp_cq_index = 0; | ||
5272 | |||
5273 | /* | ||
5274 | * Set up Event Queues (EQs) | ||
5275 | */ | ||
5276 | |||
5277 | /* Set up slow-path event queue */ | ||
5278 | if (!phba->sli4_hba.sp_eq) { | ||
5279 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5280 | "0520 Slow-path EQ not allocated\n"); | ||
5281 | goto out_error; | ||
5282 | } | ||
5283 | rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq, | ||
5284 | LPFC_SP_DEF_IMAX); | ||
5285 | if (rc) { | ||
5286 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5287 | "0521 Failed setup of slow-path EQ: " | ||
5288 | "rc = 0x%x\n", rc); | ||
5289 | goto out_error; | ||
5290 | } | ||
5291 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
5292 | "2583 Slow-path EQ setup: queue-id=%d\n", | ||
5293 | phba->sli4_hba.sp_eq->queue_id); | ||
5294 | |||
5295 | /* Set up fast-path event queue */ | ||
5296 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | ||
5297 | if (!phba->sli4_hba.fp_eq[fcp_eqidx]) { | ||
5298 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5299 | "0522 Fast-path EQ (%d) not " | ||
5300 | "allocated\n", fcp_eqidx); | ||
5301 | goto out_destroy_fp_eq; | ||
5302 | } | ||
5303 | rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx], | ||
5304 | phba->cfg_fcp_imax); | ||
5305 | if (rc) { | ||
5306 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5307 | "0523 Failed setup of fast-path EQ " | ||
5308 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); | ||
5309 | goto out_destroy_fp_eq; | ||
5310 | } | ||
5311 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
5312 | "2584 Fast-path EQ setup: " | ||
5313 | "queue[%d]-id=%d\n", fcp_eqidx, | ||
5314 | phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id); | ||
5315 | } | ||
5316 | |||
5317 | /* | ||
5318 | * Set up Complete Queues (CQs) | ||
5319 | */ | ||
5320 | |||
5321 | /* Set up slow-path MBOX Complete Queue as the first CQ */ | ||
5322 | if (!phba->sli4_hba.mbx_cq) { | ||
5323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5324 | "0528 Mailbox CQ not allocated\n"); | ||
5325 | goto out_destroy_fp_eq; | ||
5326 | } | ||
5327 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq, | ||
5328 | LPFC_MCQ, LPFC_MBOX); | ||
5329 | if (rc) { | ||
5330 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5331 | "0529 Failed setup of slow-path mailbox CQ: " | ||
5332 | "rc = 0x%x\n", rc); | ||
5333 | goto out_destroy_fp_eq; | ||
5334 | } | ||
5335 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
5336 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", | ||
5337 | phba->sli4_hba.mbx_cq->queue_id, | ||
5338 | phba->sli4_hba.sp_eq->queue_id); | ||
5339 | |||
5340 | /* Set up slow-path ELS Complete Queue */ | ||
5341 | if (!phba->sli4_hba.els_cq) { | ||
5342 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5343 | "0530 ELS CQ not allocated\n"); | ||
5344 | goto out_destroy_mbx_cq; | ||
5345 | } | ||
5346 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq, | ||
5347 | LPFC_WCQ, LPFC_ELS); | ||
5348 | if (rc) { | ||
5349 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5350 | "0531 Failed setup of slow-path ELS CQ: " | ||
5351 | "rc = 0x%x\n", rc); | ||
5352 | goto out_destroy_mbx_cq; | ||
5353 | } | ||
5354 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
5355 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", | ||
5356 | phba->sli4_hba.els_cq->queue_id, | ||
5357 | phba->sli4_hba.sp_eq->queue_id); | ||
5358 | |||
5359 | /* Set up slow-path Unsolicited Receive Complete Queue */ | ||
5360 | if (!phba->sli4_hba.rxq_cq) { | ||
5361 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5362 | "0532 USOL RX CQ not allocated\n"); | ||
5363 | goto out_destroy_els_cq; | ||
5364 | } | ||
5365 | rc = lpfc_cq_create(phba, phba->sli4_hba.rxq_cq, phba->sli4_hba.sp_eq, | ||
5366 | LPFC_RCQ, LPFC_USOL); | ||
5367 | if (rc) { | ||
5368 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5369 | "0533 Failed setup of slow-path USOL RX CQ: " | ||
5370 | "rc = 0x%x\n", rc); | ||
5371 | goto out_destroy_els_cq; | ||
5372 | } | ||
5373 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
5374 | "2587 USL CQ setup: cq-id=%d, parent eq-id=%d\n", | ||
5375 | phba->sli4_hba.rxq_cq->queue_id, | ||
5376 | phba->sli4_hba.sp_eq->queue_id); | ||
5377 | |||
5378 | /* Set up fast-path FCP Response Complete Queue */ | ||
5379 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) { | ||
5380 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { | ||
5381 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5382 | "0526 Fast-path FCP CQ (%d) not " | ||
5383 | "allocated\n", fcp_cqidx); | ||
5384 | goto out_destroy_fcp_cq; | ||
5385 | } | ||
5386 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], | ||
5387 | phba->sli4_hba.fp_eq[fcp_cqidx], | ||
5388 | LPFC_WCQ, LPFC_FCP); | ||
5389 | if (rc) { | ||
5390 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5391 | "0527 Failed setup of fast-path FCP " | ||
5392 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); | ||
5393 | goto out_destroy_fcp_cq; | ||
5394 | } | ||
5395 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
5396 | "2588 FCP CQ setup: cq[%d]-id=%d, " | ||
5397 | "parent eq[%d]-id=%d\n", | ||
5398 | fcp_cqidx, | ||
5399 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, | ||
5400 | fcp_cqidx, | ||
5401 | phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id); | ||
5402 | } | ||
5403 | |||
5404 | /* | ||
5405 | * Set up all the Work Queues (WQs) | ||
5406 | */ | ||
5407 | |||
5408 | /* Set up Mailbox Command Queue */ | ||
5409 | if (!phba->sli4_hba.mbx_wq) { | ||
5410 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5411 | "0538 Slow-path MQ not allocated\n"); | ||
5412 | goto out_destroy_fcp_cq; | ||
5413 | } | ||
5414 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, | ||
5415 | phba->sli4_hba.mbx_cq, LPFC_MBOX); | ||
5416 | if (rc) { | ||
5417 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5418 | "0539 Failed setup of slow-path MQ: " | ||
5419 | "rc = 0x%x\n", rc); | ||
5420 | goto out_destroy_fcp_cq; | ||
5421 | } | ||
5422 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
5423 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", | ||
5424 | phba->sli4_hba.mbx_wq->queue_id, | ||
5425 | phba->sli4_hba.mbx_cq->queue_id); | ||
5426 | |||
5427 | /* Set up slow-path ELS Work Queue */ | ||
5428 | if (!phba->sli4_hba.els_wq) { | ||
5429 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5430 | "0536 Slow-path ELS WQ not allocated\n"); | ||
5431 | goto out_destroy_mbx_wq; | ||
5432 | } | ||
5433 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, | ||
5434 | phba->sli4_hba.els_cq, LPFC_ELS); | ||
5435 | if (rc) { | ||
5436 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5437 | "0537 Failed setup of slow-path ELS WQ: " | ||
5438 | "rc = 0x%x\n", rc); | ||
5439 | goto out_destroy_mbx_wq; | ||
5440 | } | ||
5441 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
5442 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", | ||
5443 | phba->sli4_hba.els_wq->queue_id, | ||
5444 | phba->sli4_hba.els_cq->queue_id); | ||
5445 | |||
5446 | /* Set up fast-path FCP Work Queue */ | ||
5447 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | ||
5448 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { | ||
5449 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5450 | "0534 Fast-path FCP WQ (%d) not " | ||
5451 | "allocated\n", fcp_wqidx); | ||
5452 | goto out_destroy_fcp_wq; | ||
5453 | } | ||
5454 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], | ||
5455 | phba->sli4_hba.fcp_cq[fcp_cq_index], | ||
5456 | LPFC_FCP); | ||
5457 | if (rc) { | ||
5458 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5459 | "0535 Failed setup of fast-path FCP " | ||
5460 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); | ||
5461 | goto out_destroy_fcp_wq; | ||
5462 | } | ||
5463 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
5464 | "2591 FCP WQ setup: wq[%d]-id=%d, " | ||
5465 | "parent cq[%d]-id=%d\n", | ||
5466 | fcp_wqidx, | ||
5467 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, | ||
5468 | fcp_cq_index, | ||
5469 | phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id); | ||
5470 | /* Round robin FCP Work Queue's Completion Queue assignment */ | ||
5471 | fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count); | ||
5472 | } | ||
5473 | |||
5474 | /* | ||
5475 | * Create Receive Queue (RQ) | ||
5476 | */ | ||
5477 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { | ||
5478 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5479 | "0540 Receive Queue not allocated\n"); | ||
5480 | goto out_destroy_fcp_wq; | ||
5481 | } | ||
5482 | rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | ||
5483 | phba->sli4_hba.rxq_cq, LPFC_USOL); | ||
5484 | if (rc) { | ||
5485 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5486 | "0541 Failed setup of Receive Queue: " | ||
5487 | "rc = 0x%x\n", rc); | ||
5488 | goto out_destroy_fcp_wq; | ||
5489 | } | ||
5490 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
5491 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " | ||
5492 | "parent cq-id=%d\n", | ||
5493 | phba->sli4_hba.hdr_rq->queue_id, | ||
5494 | phba->sli4_hba.dat_rq->queue_id, | ||
5495 | phba->sli4_hba.rxq_cq->queue_id); | ||
5496 | return 0; | ||
5497 | |||
5498 | out_destroy_fcp_wq: | ||
5499 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) | ||
5500 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); | ||
5501 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | ||
5502 | out_destroy_mbx_wq: | ||
5503 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | ||
5504 | out_destroy_fcp_cq: | ||
5505 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) | ||
5506 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); | ||
5507 | lpfc_cq_destroy(phba, phba->sli4_hba.rxq_cq); | ||
5508 | out_destroy_els_cq: | ||
5509 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); | ||
5510 | out_destroy_mbx_cq: | ||
5511 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | ||
5512 | out_destroy_fp_eq: | ||
5513 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) | ||
5514 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]); | ||
5515 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | ||
5516 | out_error: | ||
5517 | return rc; | ||
5518 | } | ||
5519 | |||
5520 | /** | ||
5521 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues | ||
5522 | * @phba: pointer to lpfc hba data structure. | ||
5523 | * | ||
5524 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA | ||
5525 | * operation. | ||
5526 | * | ||
5527 | * Return codes | ||
5528 | * 0 - sucessful | ||
5529 | * ENOMEM - No availble memory | ||
5530 | * EIO - The mailbox failed to complete successfully. | ||
5531 | **/ | ||
5532 | void | ||
5533 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) | ||
5534 | { | ||
5535 | int fcp_qidx; | ||
5536 | |||
5537 | /* Unset mailbox command work queue */ | ||
5538 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | ||
5539 | /* Unset ELS work queue */ | ||
5540 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | ||
5541 | /* Unset unsolicited receive queue */ | ||
5542 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); | ||
5543 | /* Unset FCP work queue */ | ||
5544 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | ||
5545 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); | ||
5546 | /* Unset mailbox command complete queue */ | ||
5547 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | ||
5548 | /* Unset ELS complete queue */ | ||
5549 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); | ||
5550 | /* Unset unsolicited receive complete queue */ | ||
5551 | lpfc_cq_destroy(phba, phba->sli4_hba.rxq_cq); | ||
5552 | /* Unset FCP response complete queue */ | ||
5553 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | ||
5554 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); | ||
5555 | /* Unset fast-path event queue */ | ||
5556 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | ||
5557 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]); | ||
5558 | /* Unset slow-path event queue */ | ||
5559 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | ||
5560 | } | ||
5561 | |||
5562 | /** | ||
5563 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool | ||
5564 | * @phba: pointer to lpfc hba data structure. | ||
5565 | * | ||
5566 | * This routine is invoked to allocate and set up a pool of completion queue | ||
5567 | * events. The body of the completion queue event is a completion queue entry | ||
5568 | * CQE. For now, this pool is used for the interrupt service routine to queue | ||
5569 | * the following HBA completion queue events for the worker thread to process: | ||
5570 | * - Mailbox asynchronous events | ||
5571 | * - Receive queue completion unsolicited events | ||
5572 | * Later, this can be used for all the slow-path events. | ||
5573 | * | ||
5574 | * Return codes | ||
5575 | * 0 - sucessful | ||
5576 | * -ENOMEM - No availble memory | ||
5577 | **/ | ||
5578 | static int | ||
5579 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) | ||
5580 | { | ||
5581 | struct lpfc_cq_event *cq_event; | ||
5582 | int i; | ||
5583 | |||
5584 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { | ||
5585 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); | ||
5586 | if (!cq_event) | ||
5587 | goto out_pool_create_fail; | ||
5588 | list_add_tail(&cq_event->list, | ||
5589 | &phba->sli4_hba.sp_cqe_event_pool); | ||
5590 | } | ||
5591 | return 0; | ||
5592 | |||
5593 | out_pool_create_fail: | ||
5594 | lpfc_sli4_cq_event_pool_destroy(phba); | ||
5595 | return -ENOMEM; | ||
5596 | } | ||
5597 | |||
5598 | /** | ||
5599 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool | ||
5600 | * @phba: pointer to lpfc hba data structure. | ||
5601 | * | ||
5602 | * This routine is invoked to free the pool of completion queue events at | ||
5603 | * driver unload time. Note that, it is the responsibility of the driver | ||
5604 | * cleanup routine to free all the outstanding completion-queue events | ||
5605 | * allocated from this pool back into the pool before invoking this routine | ||
5606 | * to destroy the pool. | ||
5607 | **/ | ||
5608 | static void | ||
5609 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) | ||
5610 | { | ||
5611 | struct lpfc_cq_event *cq_event, *next_cq_event; | ||
5612 | |||
5613 | list_for_each_entry_safe(cq_event, next_cq_event, | ||
5614 | &phba->sli4_hba.sp_cqe_event_pool, list) { | ||
5615 | list_del(&cq_event->list); | ||
5616 | kfree(cq_event); | ||
5617 | } | ||
5618 | } | ||
5619 | |||
5620 | /** | ||
5621 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | ||
5622 | * @phba: pointer to lpfc hba data structure. | ||
5623 | * | ||
5624 | * This routine is the lock free version of the API invoked to allocate a | ||
5625 | * completion-queue event from the free pool. | ||
5626 | * | ||
5627 | * Return: Pointer to the newly allocated completion-queue event if successful | ||
5628 | * NULL otherwise. | ||
5629 | **/ | ||
5630 | struct lpfc_cq_event * | ||
5631 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | ||
5632 | { | ||
5633 | struct lpfc_cq_event *cq_event = NULL; | ||
5634 | |||
5635 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, | ||
5636 | struct lpfc_cq_event, list); | ||
5637 | return cq_event; | ||
5638 | } | ||
5639 | |||
5640 | /** | ||
5641 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | ||
5642 | * @phba: pointer to lpfc hba data structure. | ||
5643 | * | ||
5644 | * This routine is the lock version of the API invoked to allocate a | ||
5645 | * completion-queue event from the free pool. | ||
5646 | * | ||
5647 | * Return: Pointer to the newly allocated completion-queue event if successful | ||
5648 | * NULL otherwise. | ||
5649 | **/ | ||
5650 | struct lpfc_cq_event * | ||
5651 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | ||
5652 | { | ||
5653 | struct lpfc_cq_event *cq_event; | ||
5654 | unsigned long iflags; | ||
5655 | |||
5656 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
5657 | cq_event = __lpfc_sli4_cq_event_alloc(phba); | ||
5658 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
5659 | return cq_event; | ||
5660 | } | ||
5661 | |||
5662 | /** | ||
5663 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | ||
5664 | * @phba: pointer to lpfc hba data structure. | ||
5665 | * @cq_event: pointer to the completion queue event to be freed. | ||
5666 | * | ||
5667 | * This routine is the lock free version of the API invoked to release a | ||
5668 | * completion-queue event back into the free pool. | ||
5669 | **/ | ||
5670 | void | ||
5671 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | ||
5672 | struct lpfc_cq_event *cq_event) | ||
5673 | { | ||
5674 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); | ||
5675 | } | ||
5676 | |||
5677 | /** | ||
5678 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | ||
5679 | * @phba: pointer to lpfc hba data structure. | ||
5680 | * @cq_event: pointer to the completion queue event to be freed. | ||
5681 | * | ||
5682 | * This routine is the lock version of the API invoked to release a | ||
5683 | * completion-queue event back into the free pool. | ||
5684 | **/ | ||
5685 | void | ||
5686 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | ||
5687 | struct lpfc_cq_event *cq_event) | ||
5688 | { | ||
5689 | unsigned long iflags; | ||
5690 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
5691 | __lpfc_sli4_cq_event_release(phba, cq_event); | ||
5692 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
5693 | } | ||
5694 | |||
5695 | /** | ||
5696 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool | ||
5697 | * @phba: pointer to lpfc hba data structure. | ||
5698 | * | ||
5699 | * This routine is to free all the pending completion-queue events to the | ||
5700 | * back into the free pool for device reset. | ||
5701 | **/ | ||
5702 | static void | ||
5703 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) | ||
5704 | { | ||
5705 | LIST_HEAD(cqelist); | ||
5706 | struct lpfc_cq_event *cqe; | ||
5707 | unsigned long iflags; | ||
5708 | |||
5709 | /* Retrieve all the pending WCQEs from pending WCQE lists */ | ||
5710 | spin_lock_irqsave(&phba->hbalock, iflags); | ||
5711 | /* Pending FCP XRI abort events */ | ||
5712 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | ||
5713 | &cqelist); | ||
5714 | /* Pending ELS XRI abort events */ | ||
5715 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | ||
5716 | &cqelist); | ||
5717 | /* Pending asynnc events */ | ||
5718 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, | ||
5719 | &cqelist); | ||
5720 | spin_unlock_irqrestore(&phba->hbalock, iflags); | ||
5721 | |||
5722 | while (!list_empty(&cqelist)) { | ||
5723 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); | ||
5724 | lpfc_sli4_cq_event_release(phba, cqe); | ||
5725 | } | ||
5726 | } | ||
5727 | |||
5728 | /** | ||
5729 | * lpfc_pci_function_reset - Reset pci function. | ||
5730 | * @phba: pointer to lpfc hba data structure. | ||
5731 | * | ||
5732 | * This routine is invoked to request a PCI function reset. It will destroys | ||
5733 | * all resources assigned to the PCI function which originates this request. | ||
5734 | * | ||
5735 | * Return codes | ||
5736 | * 0 - sucessful | ||
5737 | * ENOMEM - No availble memory | ||
5738 | * EIO - The mailbox failed to complete successfully. | ||
5739 | **/ | ||
5740 | int | ||
5741 | lpfc_pci_function_reset(struct lpfc_hba *phba) | ||
5742 | { | ||
5743 | LPFC_MBOXQ_t *mboxq; | ||
5744 | uint32_t rc = 0; | ||
5745 | uint32_t shdr_status, shdr_add_status; | ||
5746 | union lpfc_sli4_cfg_shdr *shdr; | ||
5747 | |||
5748 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
5749 | if (!mboxq) { | ||
5750 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5751 | "0494 Unable to allocate memory for issuing " | ||
5752 | "SLI_FUNCTION_RESET mailbox command\n"); | ||
5753 | return -ENOMEM; | ||
5754 | } | ||
5755 | |||
5756 | /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */ | ||
5757 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | ||
5758 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, | ||
5759 | LPFC_SLI4_MBX_EMBED); | ||
5760 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | ||
5761 | shdr = (union lpfc_sli4_cfg_shdr *) | ||
5762 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | ||
5763 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
5764 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | ||
5765 | if (rc != MBX_TIMEOUT) | ||
5766 | mempool_free(mboxq, phba->mbox_mem_pool); | ||
5767 | if (shdr_status || shdr_add_status || rc) { | ||
5768 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5769 | "0495 SLI_FUNCTION_RESET mailbox failed with " | ||
5770 | "status x%x add_status x%x, mbx status x%x\n", | ||
5771 | shdr_status, shdr_add_status, rc); | ||
5772 | rc = -ENXIO; | ||
5773 | } | ||
5774 | return rc; | ||
5775 | } | ||
5776 | |||
5777 | /** | ||
5778 | * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands | ||
5779 | * @phba: pointer to lpfc hba data structure. | ||
5780 | * @cnt: number of nop mailbox commands to send. | ||
5781 | * | ||
5782 | * This routine is invoked to send a number @cnt of NOP mailbox command and | ||
5783 | * wait for each command to complete. | ||
5784 | * | ||
5785 | * Return: the number of NOP mailbox command completed. | ||
5786 | **/ | ||
5787 | static int | ||
5788 | lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt) | ||
5789 | { | ||
5790 | LPFC_MBOXQ_t *mboxq; | ||
5791 | int length, cmdsent; | ||
5792 | uint32_t mbox_tmo; | ||
5793 | uint32_t rc = 0; | ||
5794 | uint32_t shdr_status, shdr_add_status; | ||
5795 | union lpfc_sli4_cfg_shdr *shdr; | ||
5796 | |||
5797 | if (cnt == 0) { | ||
5798 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
5799 | "2518 Requested to send 0 NOP mailbox cmd\n"); | ||
5800 | return cnt; | ||
5801 | } | ||
5802 | |||
5803 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
5804 | if (!mboxq) { | ||
5805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
5806 | "2519 Unable to allocate memory for issuing " | ||
5807 | "NOP mailbox command\n"); | ||
5808 | return 0; | ||
5809 | } | ||
5810 | |||
5811 | /* Set up NOP SLI4_CONFIG mailbox-ioctl command */ | ||
5812 | length = (sizeof(struct lpfc_mbx_nop) - | ||
5813 | sizeof(struct lpfc_sli4_cfg_mhdr)); | ||
5814 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | ||
5815 | LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED); | ||
5816 | |||
5817 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | ||
5818 | for (cmdsent = 0; cmdsent < cnt; cmdsent++) { | ||
5819 | if (!phba->sli4_hba.intr_enable) | ||
5820 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | ||
5821 | else | ||
5822 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | ||
5823 | if (rc == MBX_TIMEOUT) | ||
5824 | break; | ||
5825 | /* Check return status */ | ||
5826 | shdr = (union lpfc_sli4_cfg_shdr *) | ||
5827 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | ||
5828 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | ||
5829 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | ||
5830 | &shdr->response); | ||
5831 | if (shdr_status || shdr_add_status || rc) { | ||
5832 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
5833 | "2520 NOP mailbox command failed " | ||
5834 | "status x%x add_status x%x mbx " | ||
5835 | "status x%x\n", shdr_status, | ||
5836 | shdr_add_status, rc); | ||
5837 | break; | ||
5838 | } | ||
5839 | } | ||
5840 | |||
5841 | if (rc != MBX_TIMEOUT) | ||
5842 | mempool_free(mboxq, phba->mbox_mem_pool); | ||
5843 | |||
5844 | return cmdsent; | ||
5845 | } | ||
5846 | |||
5847 | /** | ||
5848 | * lpfc_sli4_fcfi_unreg - Unregister fcfi to device | ||
5849 | * @phba: pointer to lpfc hba data structure. | ||
5850 | * @fcfi: fcf index. | ||
5851 | * | ||
5852 | * This routine is invoked to unregister a FCFI from device. | ||
5853 | **/ | ||
5854 | void | ||
5855 | lpfc_sli4_fcfi_unreg(struct lpfc_hba *phba, uint16_t fcfi) | ||
5856 | { | ||
5857 | LPFC_MBOXQ_t *mbox; | ||
5858 | uint32_t mbox_tmo; | ||
5859 | int rc; | ||
5860 | unsigned long flags; | ||
5861 | |||
5862 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | ||
5863 | |||
5864 | if (!mbox) | ||
5865 | return; | ||
5866 | |||
5867 | lpfc_unreg_fcfi(mbox, fcfi); | ||
5868 | |||
5869 | if (!phba->sli4_hba.intr_enable) | ||
5870 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | ||
5871 | else { | ||
5872 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | ||
5873 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | ||
5874 | } | ||
5875 | if (rc != MBX_TIMEOUT) | ||
5876 | mempool_free(mbox, phba->mbox_mem_pool); | ||
5877 | if (rc != MBX_SUCCESS) | ||
5878 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | ||
5879 | "2517 Unregister FCFI command failed " | ||
5880 | "status %d, mbxStatus x%x\n", rc, | ||
5881 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); | ||
5882 | else { | ||
5883 | spin_lock_irqsave(&phba->hbalock, flags); | ||
5884 | /* Mark the FCFI is no longer registered */ | ||
5885 | phba->fcf.fcf_flag &= | ||
5886 | ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_DISCOVERED); | ||
5887 | spin_unlock_irqrestore(&phba->hbalock, flags); | ||
5888 | } | ||
5889 | } | ||
5890 | |||
5891 | /** | ||
5892 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. | ||
5893 | * @phba: pointer to lpfc hba data structure. | ||
5894 | * | ||
5895 | * This routine is invoked to set up the PCI device memory space for device | ||
5896 | * with SLI-4 interface spec. | ||
5897 | * | ||
5898 | * Return codes | ||
5899 | * 0 - sucessful | ||
5900 | * other values - error | ||
5901 | **/ | ||
5902 | static int | ||
5903 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) | ||
5904 | { | ||
5905 | struct pci_dev *pdev; | ||
5906 | unsigned long bar0map_len, bar1map_len, bar2map_len; | ||
5907 | int error = -ENODEV; | ||
5908 | |||
5909 | /* Obtain PCI device reference */ | ||
5910 | if (!phba->pcidev) | ||
5911 | return error; | ||
5912 | else | ||
5913 | pdev = phba->pcidev; | ||
5914 | |||
5915 | /* Set the device DMA mask size */ | ||
5916 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) | ||
5917 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) | ||
5918 | return error; | ||
5919 | |||
5920 | /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the | ||
5921 | * number of bytes required by each mapping. They are actually | ||
5922 | * mapping to the PCI BAR regions 1, 2, and 4 by the SLI4 device. | ||
5923 | */ | ||
5924 | phba->pci_bar0_map = pci_resource_start(pdev, LPFC_SLI4_BAR0); | ||
5925 | bar0map_len = pci_resource_len(pdev, LPFC_SLI4_BAR0); | ||
5926 | |||
5927 | phba->pci_bar1_map = pci_resource_start(pdev, LPFC_SLI4_BAR1); | ||
5928 | bar1map_len = pci_resource_len(pdev, LPFC_SLI4_BAR1); | ||
5929 | |||
5930 | phba->pci_bar2_map = pci_resource_start(pdev, LPFC_SLI4_BAR2); | ||
5931 | bar2map_len = pci_resource_len(pdev, LPFC_SLI4_BAR2); | ||
5932 | |||
5933 | /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */ | ||
5934 | phba->sli4_hba.conf_regs_memmap_p = | ||
5935 | ioremap(phba->pci_bar0_map, bar0map_len); | ||
5936 | if (!phba->sli4_hba.conf_regs_memmap_p) { | ||
5937 | dev_printk(KERN_ERR, &pdev->dev, | ||
5938 | "ioremap failed for SLI4 PCI config registers.\n"); | ||
5939 | goto out; | ||
5940 | } | ||
5941 | |||
5942 | /* Map SLI4 HBA Control Register base to a kernel virtual address. */ | ||
5943 | phba->sli4_hba.ctrl_regs_memmap_p = | ||
5944 | ioremap(phba->pci_bar1_map, bar1map_len); | ||
5945 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { | ||
5946 | dev_printk(KERN_ERR, &pdev->dev, | ||
5947 | "ioremap failed for SLI4 HBA control registers.\n"); | ||
5948 | goto out_iounmap_conf; | ||
5949 | } | ||
5950 | |||
5951 | /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */ | ||
5952 | phba->sli4_hba.drbl_regs_memmap_p = | ||
5953 | ioremap(phba->pci_bar2_map, bar2map_len); | ||
5954 | if (!phba->sli4_hba.drbl_regs_memmap_p) { | ||
5955 | dev_printk(KERN_ERR, &pdev->dev, | ||
5956 | "ioremap failed for SLI4 HBA doorbell registers.\n"); | ||
5957 | goto out_iounmap_ctrl; | ||
5958 | } | ||
5959 | |||
5960 | /* Set up BAR0 PCI config space register memory map */ | ||
5961 | lpfc_sli4_bar0_register_memmap(phba); | ||
5962 | |||
5963 | /* Set up BAR1 register memory map */ | ||
5964 | lpfc_sli4_bar1_register_memmap(phba); | ||
5965 | |||
5966 | /* Set up BAR2 register memory map */ | ||
5967 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); | ||
5968 | if (error) | ||
5969 | goto out_iounmap_all; | ||
5970 | |||
5971 | return 0; | ||
5972 | |||
5973 | out_iounmap_all: | ||
5974 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | ||
5975 | out_iounmap_ctrl: | ||
5976 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | ||
5977 | out_iounmap_conf: | ||
5978 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | ||
5979 | out: | ||
5980 | return error; | ||
5981 | } | ||
5982 | |||
5983 | /** | ||
5984 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. | ||
5985 | * @phba: pointer to lpfc hba data structure. | ||
5986 | * | ||
5987 | * This routine is invoked to unset the PCI device memory space for device | ||
5988 | * with SLI-4 interface spec. | ||
5989 | **/ | ||
5990 | static void | ||
5991 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) | ||
5992 | { | ||
5993 | struct pci_dev *pdev; | ||
5994 | |||
5995 | /* Obtain PCI device reference */ | ||
5996 | if (!phba->pcidev) | ||
5997 | return; | ||
5998 | else | ||
5999 | pdev = phba->pcidev; | ||
6000 | |||
6001 | /* Free coherent DMA memory allocated */ | ||
6002 | |||
6003 | /* Unmap I/O memory space */ | ||
6004 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | ||
6005 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | ||
6006 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | ||
6007 | |||
6008 | return; | ||
6009 | } | ||
6010 | |||
6011 | /** | ||
6012 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device | ||
6013 | * @phba: pointer to lpfc hba data structure. | ||
6014 | * | ||
6015 | * This routine is invoked to enable the MSI-X interrupt vectors to device | ||
6016 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is | ||
6017 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once | ||
6018 | * invoked, enables either all or nothing, depending on the current | ||
6019 | * availability of PCI vector resources. The device driver is responsible | ||
6020 | * for calling the individual request_irq() to register each MSI-X vector | ||
6021 | * with a interrupt handler, which is done in this function. Note that | ||
2326 | * later when device is unloading, the driver should always call free_irq() | 6022 | * later when device is unloading, the driver should always call free_irq() |
2327 | * on all MSI-X vectors it has done request_irq() on before calling | 6023 | * on all MSI-X vectors it has done request_irq() on before calling |
2328 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device | 6024 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
@@ -2333,7 +6029,7 @@ void lpfc_host_attrib_init(struct Scsi_Host *shost) | |||
2333 | * other values - error | 6029 | * other values - error |
2334 | **/ | 6030 | **/ |
2335 | static int | 6031 | static int |
2336 | lpfc_enable_msix(struct lpfc_hba *phba) | 6032 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
2337 | { | 6033 | { |
2338 | int rc, i; | 6034 | int rc, i; |
2339 | LPFC_MBOXQ_t *pmb; | 6035 | LPFC_MBOXQ_t *pmb; |
@@ -2349,20 +6045,21 @@ lpfc_enable_msix(struct lpfc_hba *phba) | |||
2349 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 6045 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2350 | "0420 PCI enable MSI-X failed (%d)\n", rc); | 6046 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
2351 | goto msi_fail_out; | 6047 | goto msi_fail_out; |
2352 | } else | 6048 | } |
2353 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | 6049 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
2354 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 6050 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2355 | "0477 MSI-X entry[%d]: vector=x%x " | 6051 | "0477 MSI-X entry[%d]: vector=x%x " |
2356 | "message=%d\n", i, | 6052 | "message=%d\n", i, |
2357 | phba->msix_entries[i].vector, | 6053 | phba->msix_entries[i].vector, |
2358 | phba->msix_entries[i].entry); | 6054 | phba->msix_entries[i].entry); |
2359 | /* | 6055 | /* |
2360 | * Assign MSI-X vectors to interrupt handlers | 6056 | * Assign MSI-X vectors to interrupt handlers |
2361 | */ | 6057 | */ |
2362 | 6058 | ||
2363 | /* vector-0 is associated to slow-path handler */ | 6059 | /* vector-0 is associated to slow-path handler */ |
2364 | rc = request_irq(phba->msix_entries[0].vector, &lpfc_sp_intr_handler, | 6060 | rc = request_irq(phba->msix_entries[0].vector, |
2365 | IRQF_SHARED, LPFC_SP_DRIVER_HANDLER_NAME, phba); | 6061 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, |
6062 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | ||
2366 | if (rc) { | 6063 | if (rc) { |
2367 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | 6064 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
2368 | "0421 MSI-X slow-path request_irq failed " | 6065 | "0421 MSI-X slow-path request_irq failed " |
@@ -2371,8 +6068,9 @@ lpfc_enable_msix(struct lpfc_hba *phba) | |||
2371 | } | 6068 | } |
2372 | 6069 | ||
2373 | /* vector-1 is associated to fast-path handler */ | 6070 | /* vector-1 is associated to fast-path handler */ |
2374 | rc = request_irq(phba->msix_entries[1].vector, &lpfc_fp_intr_handler, | 6071 | rc = request_irq(phba->msix_entries[1].vector, |
2375 | IRQF_SHARED, LPFC_FP_DRIVER_HANDLER_NAME, phba); | 6072 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, |
6073 | LPFC_FP_DRIVER_HANDLER_NAME, phba); | ||
2376 | 6074 | ||
2377 | if (rc) { | 6075 | if (rc) { |
2378 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | 6076 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
@@ -2401,7 +6099,7 @@ lpfc_enable_msix(struct lpfc_hba *phba) | |||
2401 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | 6099 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
2402 | "0351 Config MSI mailbox command failed, " | 6100 | "0351 Config MSI mailbox command failed, " |
2403 | "mbxCmd x%x, mbxStatus x%x\n", | 6101 | "mbxCmd x%x, mbxStatus x%x\n", |
2404 | pmb->mb.mbxCommand, pmb->mb.mbxStatus); | 6102 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
2405 | goto mbx_fail_out; | 6103 | goto mbx_fail_out; |
2406 | } | 6104 | } |
2407 | 6105 | ||
@@ -2428,14 +6126,14 @@ msi_fail_out: | |||
2428 | } | 6126 | } |
2429 | 6127 | ||
2430 | /** | 6128 | /** |
2431 | * lpfc_disable_msix - Disable MSI-X interrupt mode | 6129 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. |
2432 | * @phba: pointer to lpfc hba data structure. | 6130 | * @phba: pointer to lpfc hba data structure. |
2433 | * | 6131 | * |
2434 | * This routine is invoked to release the MSI-X vectors and then disable the | 6132 | * This routine is invoked to release the MSI-X vectors and then disable the |
2435 | * MSI-X interrupt mode. | 6133 | * MSI-X interrupt mode to device with SLI-3 interface spec. |
2436 | **/ | 6134 | **/ |
2437 | static void | 6135 | static void |
2438 | lpfc_disable_msix(struct lpfc_hba *phba) | 6136 | lpfc_sli_disable_msix(struct lpfc_hba *phba) |
2439 | { | 6137 | { |
2440 | int i; | 6138 | int i; |
2441 | 6139 | ||
@@ -2444,23 +6142,26 @@ lpfc_disable_msix(struct lpfc_hba *phba) | |||
2444 | free_irq(phba->msix_entries[i].vector, phba); | 6142 | free_irq(phba->msix_entries[i].vector, phba); |
2445 | /* Disable MSI-X */ | 6143 | /* Disable MSI-X */ |
2446 | pci_disable_msix(phba->pcidev); | 6144 | pci_disable_msix(phba->pcidev); |
6145 | |||
6146 | return; | ||
2447 | } | 6147 | } |
2448 | 6148 | ||
2449 | /** | 6149 | /** |
2450 | * lpfc_enable_msi - Enable MSI interrupt mode | 6150 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
2451 | * @phba: pointer to lpfc hba data structure. | 6151 | * @phba: pointer to lpfc hba data structure. |
2452 | * | 6152 | * |
2453 | * This routine is invoked to enable the MSI interrupt mode. The kernel | 6153 | * This routine is invoked to enable the MSI interrupt mode to device with |
2454 | * function pci_enable_msi() is called to enable the MSI vector. The | 6154 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
2455 | * device driver is responsible for calling the request_irq() to register | 6155 | * enable the MSI vector. The device driver is responsible for calling the |
2456 | * MSI vector with a interrupt the handler, which is done in this function. | 6156 | * request_irq() to register MSI vector with a interrupt the handler, which |
6157 | * is done in this function. | ||
2457 | * | 6158 | * |
2458 | * Return codes | 6159 | * Return codes |
2459 | * 0 - sucessful | 6160 | * 0 - sucessful |
2460 | * other values - error | 6161 | * other values - error |
2461 | */ | 6162 | */ |
2462 | static int | 6163 | static int |
2463 | lpfc_enable_msi(struct lpfc_hba *phba) | 6164 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
2464 | { | 6165 | { |
2465 | int rc; | 6166 | int rc; |
2466 | 6167 | ||
@@ -2474,7 +6175,7 @@ lpfc_enable_msi(struct lpfc_hba *phba) | |||
2474 | return rc; | 6175 | return rc; |
2475 | } | 6176 | } |
2476 | 6177 | ||
2477 | rc = request_irq(phba->pcidev->irq, lpfc_intr_handler, | 6178 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
2478 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | 6179 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
2479 | if (rc) { | 6180 | if (rc) { |
2480 | pci_disable_msi(phba->pcidev); | 6181 | pci_disable_msi(phba->pcidev); |
@@ -2485,17 +6186,17 @@ lpfc_enable_msi(struct lpfc_hba *phba) | |||
2485 | } | 6186 | } |
2486 | 6187 | ||
2487 | /** | 6188 | /** |
2488 | * lpfc_disable_msi - Disable MSI interrupt mode | 6189 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. |
2489 | * @phba: pointer to lpfc hba data structure. | 6190 | * @phba: pointer to lpfc hba data structure. |
2490 | * | 6191 | * |
2491 | * This routine is invoked to disable the MSI interrupt mode. The driver | 6192 | * This routine is invoked to disable the MSI interrupt mode to device with |
2492 | * calls free_irq() on MSI vector it has done request_irq() on before | 6193 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has |
2493 | * calling pci_disable_msi(). Failure to do so results in a BUG_ON() and | 6194 | * done request_irq() on before calling pci_disable_msi(). Failure to do so |
2494 | * a device will be left with MSI enabled and leaks its vector. | 6195 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks |
6196 | * its vector. | ||
2495 | */ | 6197 | */ |
2496 | |||
2497 | static void | 6198 | static void |
2498 | lpfc_disable_msi(struct lpfc_hba *phba) | 6199 | lpfc_sli_disable_msi(struct lpfc_hba *phba) |
2499 | { | 6200 | { |
2500 | free_irq(phba->pcidev->irq, phba); | 6201 | free_irq(phba->pcidev->irq, phba); |
2501 | pci_disable_msi(phba->pcidev); | 6202 | pci_disable_msi(phba->pcidev); |
@@ -2503,80 +6204,298 @@ lpfc_disable_msi(struct lpfc_hba *phba) | |||
2503 | } | 6204 | } |
2504 | 6205 | ||
2505 | /** | 6206 | /** |
2506 | * lpfc_log_intr_mode - Log the active interrupt mode | 6207 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
2507 | * @phba: pointer to lpfc hba data structure. | 6208 | * @phba: pointer to lpfc hba data structure. |
2508 | * @intr_mode: active interrupt mode adopted. | ||
2509 | * | 6209 | * |
2510 | * This routine it invoked to log the currently used active interrupt mode | 6210 | * This routine is invoked to enable device interrupt and associate driver's |
2511 | * to the device. | 6211 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
2512 | */ | 6212 | * spec. Depends on the interrupt mode configured to the driver, the driver |
6213 | * will try to fallback from the configured interrupt mode to an interrupt | ||
6214 | * mode which is supported by the platform, kernel, and device in the order | ||
6215 | * of: | ||
6216 | * MSI-X -> MSI -> IRQ. | ||
6217 | * | ||
6218 | * Return codes | ||
6219 | * 0 - sucessful | ||
6220 | * other values - error | ||
6221 | **/ | ||
6222 | static uint32_t | ||
6223 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | ||
6224 | { | ||
6225 | uint32_t intr_mode = LPFC_INTR_ERROR; | ||
6226 | int retval; | ||
6227 | |||
6228 | if (cfg_mode == 2) { | ||
6229 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | ||
6230 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); | ||
6231 | if (!retval) { | ||
6232 | /* Now, try to enable MSI-X interrupt mode */ | ||
6233 | retval = lpfc_sli_enable_msix(phba); | ||
6234 | if (!retval) { | ||
6235 | /* Indicate initialization to MSI-X mode */ | ||
6236 | phba->intr_type = MSIX; | ||
6237 | intr_mode = 2; | ||
6238 | } | ||
6239 | } | ||
6240 | } | ||
6241 | |||
6242 | /* Fallback to MSI if MSI-X initialization failed */ | ||
6243 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | ||
6244 | retval = lpfc_sli_enable_msi(phba); | ||
6245 | if (!retval) { | ||
6246 | /* Indicate initialization to MSI mode */ | ||
6247 | phba->intr_type = MSI; | ||
6248 | intr_mode = 1; | ||
6249 | } | ||
6250 | } | ||
6251 | |||
6252 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | ||
6253 | if (phba->intr_type == NONE) { | ||
6254 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | ||
6255 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | ||
6256 | if (!retval) { | ||
6257 | /* Indicate initialization to INTx mode */ | ||
6258 | phba->intr_type = INTx; | ||
6259 | intr_mode = 0; | ||
6260 | } | ||
6261 | } | ||
6262 | return intr_mode; | ||
6263 | } | ||
6264 | |||
6265 | /** | ||
6266 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. | ||
6267 | * @phba: pointer to lpfc hba data structure. | ||
6268 | * | ||
6269 | * This routine is invoked to disable device interrupt and disassociate the | ||
6270 | * driver's interrupt handler(s) from interrupt vector(s) to device with | ||
6271 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will | ||
6272 | * release the interrupt vector(s) for the message signaled interrupt. | ||
6273 | **/ | ||
2513 | static void | 6274 | static void |
2514 | lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | 6275 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
2515 | { | 6276 | { |
2516 | switch (intr_mode) { | 6277 | /* Disable the currently initialized interrupt mode */ |
2517 | case 0: | 6278 | if (phba->intr_type == MSIX) |
2518 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 6279 | lpfc_sli_disable_msix(phba); |
2519 | "0470 Enable INTx interrupt mode.\n"); | 6280 | else if (phba->intr_type == MSI) |
2520 | break; | 6281 | lpfc_sli_disable_msi(phba); |
2521 | case 1: | 6282 | else if (phba->intr_type == INTx) |
6283 | free_irq(phba->pcidev->irq, phba); | ||
6284 | |||
6285 | /* Reset interrupt management states */ | ||
6286 | phba->intr_type = NONE; | ||
6287 | phba->sli.slistat.sli_intr = 0; | ||
6288 | |||
6289 | return; | ||
6290 | } | ||
6291 | |||
6292 | /** | ||
6293 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device | ||
6294 | * @phba: pointer to lpfc hba data structure. | ||
6295 | * | ||
6296 | * This routine is invoked to enable the MSI-X interrupt vectors to device | ||
6297 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called | ||
6298 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, | ||
6299 | * enables either all or nothing, depending on the current availability of | ||
6300 | * PCI vector resources. The device driver is responsible for calling the | ||
6301 | * individual request_irq() to register each MSI-X vector with a interrupt | ||
6302 | * handler, which is done in this function. Note that later when device is | ||
6303 | * unloading, the driver should always call free_irq() on all MSI-X vectors | ||
6304 | * it has done request_irq() on before calling pci_disable_msix(). Failure | ||
6305 | * to do so results in a BUG_ON() and a device will be left with MSI-X | ||
6306 | * enabled and leaks its vectors. | ||
6307 | * | ||
6308 | * Return codes | ||
6309 | * 0 - sucessful | ||
6310 | * other values - error | ||
6311 | **/ | ||
6312 | static int | ||
6313 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) | ||
6314 | { | ||
6315 | int rc, index; | ||
6316 | |||
6317 | /* Set up MSI-X multi-message vectors */ | ||
6318 | for (index = 0; index < phba->sli4_hba.cfg_eqn; index++) | ||
6319 | phba->sli4_hba.msix_entries[index].entry = index; | ||
6320 | |||
6321 | /* Configure MSI-X capability structure */ | ||
6322 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, | ||
6323 | phba->sli4_hba.cfg_eqn); | ||
6324 | if (rc) { | ||
2522 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 6325 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2523 | "0481 Enabled MSI interrupt mode.\n"); | 6326 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
2524 | break; | 6327 | goto msi_fail_out; |
2525 | case 2: | 6328 | } |
6329 | /* Log MSI-X vector assignment */ | ||
6330 | for (index = 0; index < phba->sli4_hba.cfg_eqn; index++) | ||
2526 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 6331 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2527 | "0480 Enabled MSI-X interrupt mode.\n"); | 6332 | "0489 MSI-X entry[%d]: vector=x%x " |
2528 | break; | 6333 | "message=%d\n", index, |
2529 | default: | 6334 | phba->sli4_hba.msix_entries[index].vector, |
2530 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 6335 | phba->sli4_hba.msix_entries[index].entry); |
2531 | "0482 Illegal interrupt mode.\n"); | 6336 | /* |
2532 | break; | 6337 | * Assign MSI-X vectors to interrupt handlers |
6338 | */ | ||
6339 | |||
6340 | /* The first vector must associated to slow-path handler for MQ */ | ||
6341 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | ||
6342 | &lpfc_sli4_sp_intr_handler, IRQF_SHARED, | ||
6343 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | ||
6344 | if (rc) { | ||
6345 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
6346 | "0485 MSI-X slow-path request_irq failed " | ||
6347 | "(%d)\n", rc); | ||
6348 | goto msi_fail_out; | ||
2533 | } | 6349 | } |
2534 | return; | 6350 | |
6351 | /* The rest of the vector(s) are associated to fast-path handler(s) */ | ||
6352 | for (index = 1; index < phba->sli4_hba.cfg_eqn; index++) { | ||
6353 | phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1; | ||
6354 | phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba; | ||
6355 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, | ||
6356 | &lpfc_sli4_fp_intr_handler, IRQF_SHARED, | ||
6357 | LPFC_FP_DRIVER_HANDLER_NAME, | ||
6358 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | ||
6359 | if (rc) { | ||
6360 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
6361 | "0486 MSI-X fast-path (%d) " | ||
6362 | "request_irq failed (%d)\n", index, rc); | ||
6363 | goto cfg_fail_out; | ||
6364 | } | ||
6365 | } | ||
6366 | |||
6367 | return rc; | ||
6368 | |||
6369 | cfg_fail_out: | ||
6370 | /* free the irq already requested */ | ||
6371 | for (--index; index >= 1; index--) | ||
6372 | free_irq(phba->sli4_hba.msix_entries[index - 1].vector, | ||
6373 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | ||
6374 | |||
6375 | /* free the irq already requested */ | ||
6376 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | ||
6377 | |||
6378 | msi_fail_out: | ||
6379 | /* Unconfigure MSI-X capability structure */ | ||
6380 | pci_disable_msix(phba->pcidev); | ||
6381 | return rc; | ||
2535 | } | 6382 | } |
2536 | 6383 | ||
6384 | /** | ||
6385 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device | ||
6386 | * @phba: pointer to lpfc hba data structure. | ||
6387 | * | ||
6388 | * This routine is invoked to release the MSI-X vectors and then disable the | ||
6389 | * MSI-X interrupt mode to device with SLI-4 interface spec. | ||
6390 | **/ | ||
2537 | static void | 6391 | static void |
2538 | lpfc_stop_port(struct lpfc_hba *phba) | 6392 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) |
2539 | { | 6393 | { |
2540 | /* Clear all interrupt enable conditions */ | 6394 | int index; |
2541 | writel(0, phba->HCregaddr); | ||
2542 | readl(phba->HCregaddr); /* flush */ | ||
2543 | /* Clear all pending interrupts */ | ||
2544 | writel(0xffffffff, phba->HAregaddr); | ||
2545 | readl(phba->HAregaddr); /* flush */ | ||
2546 | 6395 | ||
2547 | /* Reset some HBA SLI setup states */ | 6396 | /* Free up MSI-X multi-message vectors */ |
2548 | lpfc_stop_phba_timers(phba); | 6397 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); |
2549 | phba->pport->work_port_events = 0; | 6398 | |
6399 | for (index = 1; index < phba->sli4_hba.cfg_eqn; index++) | ||
6400 | free_irq(phba->sli4_hba.msix_entries[index].vector, | ||
6401 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | ||
6402 | /* Disable MSI-X */ | ||
6403 | pci_disable_msix(phba->pcidev); | ||
6404 | |||
6405 | return; | ||
6406 | } | ||
6407 | |||
6408 | /** | ||
6409 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device | ||
6410 | * @phba: pointer to lpfc hba data structure. | ||
6411 | * | ||
6412 | * This routine is invoked to enable the MSI interrupt mode to device with | ||
6413 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called | ||
6414 | * to enable the MSI vector. The device driver is responsible for calling | ||
6415 | * the request_irq() to register MSI vector with a interrupt the handler, | ||
6416 | * which is done in this function. | ||
6417 | * | ||
6418 | * Return codes | ||
6419 | * 0 - sucessful | ||
6420 | * other values - error | ||
6421 | **/ | ||
6422 | static int | ||
6423 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) | ||
6424 | { | ||
6425 | int rc, index; | ||
6426 | |||
6427 | rc = pci_enable_msi(phba->pcidev); | ||
6428 | if (!rc) | ||
6429 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
6430 | "0487 PCI enable MSI mode success.\n"); | ||
6431 | else { | ||
6432 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
6433 | "0488 PCI enable MSI mode failed (%d)\n", rc); | ||
6434 | return rc; | ||
6435 | } | ||
6436 | |||
6437 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | ||
6438 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | ||
6439 | if (rc) { | ||
6440 | pci_disable_msi(phba->pcidev); | ||
6441 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | ||
6442 | "0490 MSI request_irq failed (%d)\n", rc); | ||
6443 | } | ||
6444 | |||
6445 | for (index = 0; index < phba->cfg_fcp_eq_count; index++) { | ||
6446 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | ||
6447 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | ||
6448 | } | ||
6449 | |||
6450 | return rc; | ||
6451 | } | ||
2550 | 6452 | ||
6453 | /** | ||
6454 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device | ||
6455 | * @phba: pointer to lpfc hba data structure. | ||
6456 | * | ||
6457 | * This routine is invoked to disable the MSI interrupt mode to device with | ||
6458 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has | ||
6459 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | ||
6460 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | ||
6461 | * its vector. | ||
6462 | **/ | ||
6463 | static void | ||
6464 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) | ||
6465 | { | ||
6466 | free_irq(phba->pcidev->irq, phba); | ||
6467 | pci_disable_msi(phba->pcidev); | ||
2551 | return; | 6468 | return; |
2552 | } | 6469 | } |
2553 | 6470 | ||
2554 | /** | 6471 | /** |
2555 | * lpfc_enable_intr - Enable device interrupt | 6472 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
2556 | * @phba: pointer to lpfc hba data structure. | 6473 | * @phba: pointer to lpfc hba data structure. |
2557 | * | 6474 | * |
2558 | * This routine is invoked to enable device interrupt and associate driver's | 6475 | * This routine is invoked to enable device interrupt and associate driver's |
2559 | * interrupt handler(s) to interrupt vector(s). Depends on the interrupt | 6476 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
2560 | * mode configured to the driver, the driver will try to fallback from the | 6477 | * interface spec. Depends on the interrupt mode configured to the driver, |
2561 | * configured interrupt mode to an interrupt mode which is supported by the | 6478 | * the driver will try to fallback from the configured interrupt mode to an |
2562 | * platform, kernel, and device in the order of: MSI-X -> MSI -> IRQ. | 6479 | * interrupt mode which is supported by the platform, kernel, and device in |
6480 | * the order of: | ||
6481 | * MSI-X -> MSI -> IRQ. | ||
2563 | * | 6482 | * |
2564 | * Return codes | 6483 | * Return codes |
2565 | * 0 - sucessful | 6484 | * 0 - sucessful |
2566 | * other values - error | 6485 | * other values - error |
2567 | **/ | 6486 | **/ |
2568 | static uint32_t | 6487 | static uint32_t |
2569 | lpfc_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | 6488 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
2570 | { | 6489 | { |
2571 | uint32_t intr_mode = LPFC_INTR_ERROR; | 6490 | uint32_t intr_mode = LPFC_INTR_ERROR; |
2572 | int retval; | 6491 | int retval, index; |
2573 | 6492 | ||
2574 | if (cfg_mode == 2) { | 6493 | if (cfg_mode == 2) { |
2575 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | 6494 | /* Preparation before conf_msi mbox cmd */ |
2576 | retval = lpfc_sli_config_port(phba, 3); | 6495 | retval = 0; |
2577 | if (!retval) { | 6496 | if (!retval) { |
2578 | /* Now, try to enable MSI-X interrupt mode */ | 6497 | /* Now, try to enable MSI-X interrupt mode */ |
2579 | retval = lpfc_enable_msix(phba); | 6498 | retval = lpfc_sli4_enable_msix(phba); |
2580 | if (!retval) { | 6499 | if (!retval) { |
2581 | /* Indicate initialization to MSI-X mode */ | 6500 | /* Indicate initialization to MSI-X mode */ |
2582 | phba->intr_type = MSIX; | 6501 | phba->intr_type = MSIX; |
@@ -2587,7 +6506,7 @@ lpfc_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |||
2587 | 6506 | ||
2588 | /* Fallback to MSI if MSI-X initialization failed */ | 6507 | /* Fallback to MSI if MSI-X initialization failed */ |
2589 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | 6508 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
2590 | retval = lpfc_enable_msi(phba); | 6509 | retval = lpfc_sli4_enable_msi(phba); |
2591 | if (!retval) { | 6510 | if (!retval) { |
2592 | /* Indicate initialization to MSI mode */ | 6511 | /* Indicate initialization to MSI mode */ |
2593 | phba->intr_type = MSI; | 6512 | phba->intr_type = MSI; |
@@ -2597,34 +6516,39 @@ lpfc_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |||
2597 | 6516 | ||
2598 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | 6517 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
2599 | if (phba->intr_type == NONE) { | 6518 | if (phba->intr_type == NONE) { |
2600 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, | 6519 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
2601 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | 6520 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
2602 | if (!retval) { | 6521 | if (!retval) { |
2603 | /* Indicate initialization to INTx mode */ | 6522 | /* Indicate initialization to INTx mode */ |
2604 | phba->intr_type = INTx; | 6523 | phba->intr_type = INTx; |
2605 | intr_mode = 0; | 6524 | intr_mode = 0; |
6525 | for (index = 0; index < phba->cfg_fcp_eq_count; | ||
6526 | index++) { | ||
6527 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | ||
6528 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | ||
6529 | } | ||
2606 | } | 6530 | } |
2607 | } | 6531 | } |
2608 | return intr_mode; | 6532 | return intr_mode; |
2609 | } | 6533 | } |
2610 | 6534 | ||
2611 | /** | 6535 | /** |
2612 | * lpfc_disable_intr - Disable device interrupt | 6536 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
2613 | * @phba: pointer to lpfc hba data structure. | 6537 | * @phba: pointer to lpfc hba data structure. |
2614 | * | 6538 | * |
2615 | * This routine is invoked to disable device interrupt and disassociate the | 6539 | * This routine is invoked to disable device interrupt and disassociate |
2616 | * driver's interrupt handler(s) from interrupt vector(s). Depending on the | 6540 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
2617 | * interrupt mode, the driver will release the interrupt vector(s) for the | 6541 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
2618 | * message signaled interrupt. | 6542 | * will release the interrupt vector(s) for the message signaled interrupt. |
2619 | **/ | 6543 | **/ |
2620 | static void | 6544 | static void |
2621 | lpfc_disable_intr(struct lpfc_hba *phba) | 6545 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
2622 | { | 6546 | { |
2623 | /* Disable the currently initialized interrupt mode */ | 6547 | /* Disable the currently initialized interrupt mode */ |
2624 | if (phba->intr_type == MSIX) | 6548 | if (phba->intr_type == MSIX) |
2625 | lpfc_disable_msix(phba); | 6549 | lpfc_sli4_disable_msix(phba); |
2626 | else if (phba->intr_type == MSI) | 6550 | else if (phba->intr_type == MSI) |
2627 | lpfc_disable_msi(phba); | 6551 | lpfc_sli4_disable_msi(phba); |
2628 | else if (phba->intr_type == INTx) | 6552 | else if (phba->intr_type == INTx) |
2629 | free_irq(phba->pcidev->irq, phba); | 6553 | free_irq(phba->pcidev->irq, phba); |
2630 | 6554 | ||
@@ -2636,263 +6560,233 @@ lpfc_disable_intr(struct lpfc_hba *phba) | |||
2636 | } | 6560 | } |
2637 | 6561 | ||
2638 | /** | 6562 | /** |
2639 | * lpfc_pci_probe_one - lpfc PCI probe func to register device to PCI subsystem | 6563 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
2640 | * @pdev: pointer to PCI device | 6564 | * @phba: pointer to lpfc hba data structure. |
2641 | * @pid: pointer to PCI device identifier | ||
2642 | * | ||
2643 | * This routine is to be registered to the kernel's PCI subsystem. When an | ||
2644 | * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at | ||
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 | * | 6565 | * |
2651 | * Return code | 6566 | * This routine is invoked to unset the HBA device initialization steps to |
2652 | * 0 - driver can claim the device | 6567 | * a device with SLI-3 interface spec. |
2653 | * negative value - driver can not claim the device | ||
2654 | **/ | 6568 | **/ |
2655 | static int __devinit | 6569 | static void |
2656 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | 6570 | lpfc_unset_hba(struct lpfc_hba *phba) |
2657 | { | 6571 | { |
2658 | struct lpfc_vport *vport = NULL; | 6572 | struct lpfc_vport *vport = phba->pport; |
2659 | struct lpfc_hba *phba; | 6573 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
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; | ||
2668 | uint32_t cfg_mode, intr_mode; | ||
2669 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | ||
2670 | struct lpfc_adapter_event_header adapter_event; | ||
2671 | |||
2672 | if (pci_enable_device_mem(pdev)) | ||
2673 | goto out; | ||
2674 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | ||
2675 | goto out_disable_device; | ||
2676 | 6574 | ||
2677 | phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL); | 6575 | spin_lock_irq(shost->host_lock); |
2678 | if (!phba) | 6576 | vport->load_flag |= FC_UNLOADING; |
2679 | goto out_release_regions; | 6577 | spin_unlock_irq(shost->host_lock); |
2680 | 6578 | ||
2681 | atomic_set(&phba->fast_event_count, 0); | 6579 | lpfc_stop_hba_timers(phba); |
2682 | spin_lock_init(&phba->hbalock); | ||
2683 | 6580 | ||
2684 | /* Initialize ndlp management spinlock */ | 6581 | phba->pport->work_port_events = 0; |
2685 | spin_lock_init(&phba->ndlp_lock); | ||
2686 | 6582 | ||
2687 | phba->pcidev = pdev; | 6583 | lpfc_sli_hba_down(phba); |
2688 | 6584 | ||
2689 | /* Assign an unused board number */ | 6585 | lpfc_sli_brdrestart(phba); |
2690 | if ((phba->brd_no = lpfc_get_instance()) < 0) | ||
2691 | goto out_free_phba; | ||
2692 | 6586 | ||
2693 | INIT_LIST_HEAD(&phba->port_list); | 6587 | lpfc_sli_disable_intr(phba); |
2694 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | ||
2695 | /* | ||
2696 | * Get all the module params for configuring this host and then | ||
2697 | * establish the host. | ||
2698 | */ | ||
2699 | lpfc_get_cfgparam(phba); | ||
2700 | phba->max_vpi = LPFC_MAX_VPI; | ||
2701 | 6588 | ||
2702 | /* Initialize timers used by driver */ | 6589 | return; |
2703 | init_timer(&phba->hb_tmofunc); | 6590 | } |
2704 | phba->hb_tmofunc.function = lpfc_hb_timeout; | ||
2705 | phba->hb_tmofunc.data = (unsigned long)phba; | ||
2706 | 6591 | ||
2707 | psli = &phba->sli; | 6592 | /** |
2708 | init_timer(&psli->mbox_tmo); | 6593 | * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization. |
2709 | psli->mbox_tmo.function = lpfc_mbox_timeout; | 6594 | * @phba: pointer to lpfc hba data structure. |
2710 | psli->mbox_tmo.data = (unsigned long) phba; | 6595 | * |
2711 | init_timer(&phba->fcp_poll_timer); | 6596 | * This routine is invoked to unset the HBA device initialization steps to |
2712 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | 6597 | * a device with SLI-4 interface spec. |
2713 | phba->fcp_poll_timer.data = (unsigned long) phba; | 6598 | **/ |
2714 | init_timer(&phba->fabric_block_timer); | 6599 | static void |
2715 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | 6600 | lpfc_sli4_unset_hba(struct lpfc_hba *phba) |
2716 | phba->fabric_block_timer.data = (unsigned long) phba; | 6601 | { |
2717 | init_timer(&phba->eratt_poll); | 6602 | struct lpfc_vport *vport = phba->pport; |
2718 | phba->eratt_poll.function = lpfc_poll_eratt; | 6603 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2719 | phba->eratt_poll.data = (unsigned long) phba; | ||
2720 | 6604 | ||
2721 | pci_set_master(pdev); | 6605 | spin_lock_irq(shost->host_lock); |
2722 | pci_save_state(pdev); | 6606 | vport->load_flag |= FC_UNLOADING; |
2723 | pci_try_set_mwi(pdev); | 6607 | spin_unlock_irq(shost->host_lock); |
2724 | 6608 | ||
2725 | if (pci_set_dma_mask(phba->pcidev, DMA_BIT_MASK(64)) != 0) | 6609 | phba->pport->work_port_events = 0; |
2726 | if (pci_set_dma_mask(phba->pcidev, DMA_BIT_MASK(32)) != 0) | ||
2727 | goto out_idr_remove; | ||
2728 | 6610 | ||
2729 | /* | 6611 | lpfc_sli4_hba_down(phba); |
2730 | * Get the bus address of Bar0 and Bar2 and the number of bytes | ||
2731 | * required by each mapping. | ||
2732 | */ | ||
2733 | phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0); | ||
2734 | bar0map_len = pci_resource_len(phba->pcidev, 0); | ||
2735 | 6612 | ||
2736 | phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2); | 6613 | lpfc_sli4_disable_intr(phba); |
2737 | bar2map_len = pci_resource_len(phba->pcidev, 2); | ||
2738 | 6614 | ||
2739 | /* Map HBA SLIM to a kernel virtual address. */ | 6615 | return; |
2740 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | 6616 | } |
2741 | if (!phba->slim_memmap_p) { | ||
2742 | error = -ENODEV; | ||
2743 | dev_printk(KERN_ERR, &pdev->dev, | ||
2744 | "ioremap failed for SLIM memory.\n"); | ||
2745 | goto out_idr_remove; | ||
2746 | } | ||
2747 | |||
2748 | /* Map HBA Control Registers to a kernel virtual address. */ | ||
2749 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | ||
2750 | if (!phba->ctrl_regs_memmap_p) { | ||
2751 | error = -ENODEV; | ||
2752 | dev_printk(KERN_ERR, &pdev->dev, | ||
2753 | "ioremap failed for HBA control registers.\n"); | ||
2754 | goto out_iounmap_slim; | ||
2755 | } | ||
2756 | 6617 | ||
2757 | /* Allocate memory for SLI-2 structures */ | 6618 | /** |
2758 | phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev, | 6619 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
2759 | SLI2_SLIM_SIZE, | 6620 | * @phba: Pointer to HBA context object. |
2760 | &phba->slim2p.phys, | 6621 | * |
2761 | GFP_KERNEL); | 6622 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
2762 | if (!phba->slim2p.virt) | 6623 | * function. The caller is not required to hold any lock. This routine |
2763 | goto out_iounmap; | 6624 | * issues PCI function reset mailbox command to reset the FCoE function. |
6625 | * At the end of the function, it calls lpfc_hba_down_post function to | ||
6626 | * free any pending commands. | ||
6627 | **/ | ||
6628 | static void | ||
6629 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) | ||
6630 | { | ||
6631 | int wait_cnt = 0; | ||
6632 | LPFC_MBOXQ_t *mboxq; | ||
2764 | 6633 | ||
2765 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); | 6634 | lpfc_stop_hba_timers(phba); |
2766 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); | 6635 | phba->sli4_hba.intr_enable = 0; |
2767 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); | ||
2768 | phba->IOCBs = (phba->slim2p.virt + | ||
2769 | offsetof(struct lpfc_sli2_slim, IOCBs)); | ||
2770 | 6636 | ||
2771 | phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev, | 6637 | /* |
2772 | lpfc_sli_hbq_size(), | 6638 | * Gracefully wait out the potential current outstanding asynchronous |
2773 | &phba->hbqslimp.phys, | 6639 | * mailbox command. |
2774 | GFP_KERNEL); | 6640 | */ |
2775 | if (!phba->hbqslimp.virt) | ||
2776 | goto out_free_slim; | ||
2777 | 6641 | ||
2778 | hbq_count = lpfc_sli_hbq_count(); | 6642 | /* First, block any pending async mailbox command from posted */ |
2779 | ptr = phba->hbqslimp.virt; | 6643 | spin_lock_irq(&phba->hbalock); |
2780 | for (i = 0; i < hbq_count; ++i) { | 6644 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
2781 | phba->hbqs[i].hbq_virt = ptr; | 6645 | spin_unlock_irq(&phba->hbalock); |
2782 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | 6646 | /* Now, trying to wait it out if we can */ |
2783 | ptr += (lpfc_hbq_defs[i]->entry_count * | 6647 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
2784 | sizeof(struct lpfc_hbq_entry)); | 6648 | msleep(10); |
6649 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) | ||
6650 | break; | ||
2785 | } | 6651 | } |
2786 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | 6652 | /* Forcefully release the outstanding mailbox command if timed out */ |
2787 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | 6653 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
2788 | 6654 | spin_lock_irq(&phba->hbalock); | |
2789 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | 6655 | mboxq = phba->sli.mbox_active; |
2790 | 6656 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
2791 | INIT_LIST_HEAD(&phba->hbqbuf_in_list); | 6657 | __lpfc_mbox_cmpl_put(phba, mboxq); |
2792 | 6658 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
2793 | /* Initialize the SLI Layer to run with lpfc HBAs. */ | 6659 | phba->sli.mbox_active = NULL; |
2794 | lpfc_sli_setup(phba); | 6660 | spin_unlock_irq(&phba->hbalock); |
2795 | lpfc_sli_queue_setup(phba); | ||
2796 | |||
2797 | retval = lpfc_mem_alloc(phba); | ||
2798 | if (retval) { | ||
2799 | error = retval; | ||
2800 | goto out_free_hbqslimp; | ||
2801 | } | 6661 | } |
2802 | 6662 | ||
2803 | /* Initialize and populate the iocb list per host. */ | 6663 | /* Tear down the queues in the HBA */ |
2804 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | 6664 | lpfc_sli4_queue_unset(phba); |
2805 | for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) { | ||
2806 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); | ||
2807 | if (iocbq_entry == NULL) { | ||
2808 | printk(KERN_ERR "%s: only allocated %d iocbs of " | ||
2809 | "expected %d count. Unloading driver.\n", | ||
2810 | __func__, i, LPFC_IOCB_LIST_CNT); | ||
2811 | error = -ENOMEM; | ||
2812 | goto out_free_iocbq; | ||
2813 | } | ||
2814 | 6665 | ||
2815 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); | 6666 | /* Disable PCI subsystem interrupt */ |
2816 | if (iotag == 0) { | 6667 | lpfc_sli4_disable_intr(phba); |
2817 | kfree (iocbq_entry); | ||
2818 | printk(KERN_ERR "%s: failed to allocate IOTAG. " | ||
2819 | "Unloading driver.\n", | ||
2820 | __func__); | ||
2821 | error = -ENOMEM; | ||
2822 | goto out_free_iocbq; | ||
2823 | } | ||
2824 | 6668 | ||
2825 | spin_lock_irq(&phba->hbalock); | 6669 | /* Stop kthread signal shall trigger work_done one more time */ |
2826 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); | 6670 | kthread_stop(phba->worker_thread); |
2827 | phba->total_iocbq_bufs++; | ||
2828 | spin_unlock_irq(&phba->hbalock); | ||
2829 | } | ||
2830 | 6671 | ||
2831 | /* Initialize HBA structure */ | 6672 | /* Stop the SLI4 device port */ |
2832 | phba->fc_edtov = FF_DEF_EDTOV; | 6673 | phba->pport->work_port_events = 0; |
2833 | phba->fc_ratov = FF_DEF_RATOV; | 6674 | } |
2834 | phba->fc_altov = FF_DEF_ALTOV; | ||
2835 | phba->fc_arbtov = FF_DEF_ARBTOV; | ||
2836 | 6675 | ||
2837 | INIT_LIST_HEAD(&phba->work_list); | 6676 | /** |
2838 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | 6677 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
2839 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | 6678 | * @pdev: pointer to PCI device |
6679 | * @pid: pointer to PCI device identifier | ||
6680 | * | ||
6681 | * This routine is to be called to attach a device with SLI-3 interface spec | ||
6682 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | ||
6683 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | ||
6684 | * information of the device and driver to see if the driver state that it can | ||
6685 | * support this kind of device. If the match is successful, the driver core | ||
6686 | * invokes this routine. If this routine determines it can claim the HBA, it | ||
6687 | * does all the initialization that it needs to do to handle the HBA properly. | ||
6688 | * | ||
6689 | * Return code | ||
6690 | * 0 - driver can claim the device | ||
6691 | * negative value - driver can not claim the device | ||
6692 | **/ | ||
6693 | static int __devinit | ||
6694 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) | ||
6695 | { | ||
6696 | struct lpfc_hba *phba; | ||
6697 | struct lpfc_vport *vport = NULL; | ||
6698 | int error; | ||
6699 | uint32_t cfg_mode, intr_mode; | ||
2840 | 6700 | ||
2841 | /* Initialize the wait queue head for the kernel thread */ | 6701 | /* Allocate memory for HBA structure */ |
2842 | init_waitqueue_head(&phba->work_waitq); | 6702 | phba = lpfc_hba_alloc(pdev); |
6703 | if (!phba) | ||
6704 | return -ENOMEM; | ||
2843 | 6705 | ||
2844 | /* Startup the kernel thread for this host adapter. */ | 6706 | /* Perform generic PCI device enabling operation */ |
2845 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | 6707 | error = lpfc_enable_pci_dev(phba); |
2846 | "lpfc_worker_%d", phba->brd_no); | 6708 | if (error) { |
2847 | if (IS_ERR(phba->worker_thread)) { | 6709 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2848 | error = PTR_ERR(phba->worker_thread); | 6710 | "1401 Failed to enable pci device.\n"); |
2849 | goto out_free_iocbq; | 6711 | goto out_free_phba; |
2850 | } | 6712 | } |
2851 | 6713 | ||
2852 | /* Initialize the list of scsi buffers used by driver for scsi IO. */ | 6714 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
2853 | spin_lock_init(&phba->scsi_buf_list_lock); | 6715 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
2854 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | 6716 | if (error) |
6717 | goto out_disable_pci_dev; | ||
2855 | 6718 | ||
2856 | /* Initialize list of fabric iocbs */ | 6719 | /* Set up SLI-3 specific device PCI memory space */ |
2857 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | 6720 | error = lpfc_sli_pci_mem_setup(phba); |
6721 | if (error) { | ||
6722 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
6723 | "1402 Failed to set up pci memory space.\n"); | ||
6724 | goto out_disable_pci_dev; | ||
6725 | } | ||
2858 | 6726 | ||
2859 | /* Initialize list to save ELS buffers */ | 6727 | /* Set up phase-1 common device driver resources */ |
2860 | INIT_LIST_HEAD(&phba->elsbuf); | 6728 | error = lpfc_setup_driver_resource_phase1(phba); |
6729 | if (error) { | ||
6730 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
6731 | "1403 Failed to set up driver resource.\n"); | ||
6732 | goto out_unset_pci_mem_s3; | ||
6733 | } | ||
2861 | 6734 | ||
2862 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); | 6735 | /* Set up SLI-3 specific device driver resources */ |
2863 | if (!vport) | 6736 | error = lpfc_sli_driver_resource_setup(phba); |
2864 | goto out_kthread_stop; | 6737 | if (error) { |
6738 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
6739 | "1404 Failed to set up driver resource.\n"); | ||
6740 | goto out_unset_pci_mem_s3; | ||
6741 | } | ||
2865 | 6742 | ||
2866 | shost = lpfc_shost_from_vport(vport); | 6743 | /* Initialize and populate the iocb list per host */ |
2867 | phba->pport = vport; | 6744 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
2868 | lpfc_debugfs_initialize(vport); | 6745 | if (error) { |
6746 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
6747 | "1405 Failed to initialize iocb list.\n"); | ||
6748 | goto out_unset_driver_resource_s3; | ||
6749 | } | ||
2869 | 6750 | ||
2870 | pci_set_drvdata(pdev, shost); | 6751 | /* Set up common device driver resources */ |
6752 | error = lpfc_setup_driver_resource_phase2(phba); | ||
6753 | if (error) { | ||
6754 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
6755 | "1406 Failed to set up driver resource.\n"); | ||
6756 | goto out_free_iocb_list; | ||
6757 | } | ||
2871 | 6758 | ||
2872 | phba->MBslimaddr = phba->slim_memmap_p; | 6759 | /* Create SCSI host to the physical port */ |
2873 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | 6760 | error = lpfc_create_shost(phba); |
2874 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | 6761 | if (error) { |
2875 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | 6762 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2876 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | 6763 | "1407 Failed to create scsi host.\n"); |
6764 | goto out_unset_driver_resource; | ||
6765 | } | ||
2877 | 6766 | ||
2878 | /* Configure sysfs attributes */ | 6767 | /* Configure sysfs attributes */ |
2879 | if (lpfc_alloc_sysfs_attr(vport)) { | 6768 | vport = phba->pport; |
6769 | error = lpfc_alloc_sysfs_attr(vport); | ||
6770 | if (error) { | ||
2880 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 6771 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2881 | "1476 Failed to allocate sysfs attr\n"); | 6772 | "1476 Failed to allocate sysfs attr\n"); |
2882 | error = -ENOMEM; | 6773 | goto out_destroy_shost; |
2883 | goto out_destroy_port; | ||
2884 | } | 6774 | } |
2885 | 6775 | ||
6776 | /* Now, trying to enable interrupt and bring up the device */ | ||
2886 | cfg_mode = phba->cfg_use_msi; | 6777 | cfg_mode = phba->cfg_use_msi; |
2887 | while (true) { | 6778 | while (true) { |
6779 | /* Put device to a known state before enabling interrupt */ | ||
6780 | lpfc_stop_port(phba); | ||
2888 | /* Configure and enable interrupt */ | 6781 | /* Configure and enable interrupt */ |
2889 | intr_mode = lpfc_enable_intr(phba, cfg_mode); | 6782 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
2890 | if (intr_mode == LPFC_INTR_ERROR) { | 6783 | if (intr_mode == LPFC_INTR_ERROR) { |
2891 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 6784 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2892 | "0426 Failed to enable interrupt.\n"); | 6785 | "0431 Failed to enable interrupt.\n"); |
6786 | error = -ENODEV; | ||
2893 | goto out_free_sysfs_attr; | 6787 | goto out_free_sysfs_attr; |
2894 | } | 6788 | } |
2895 | /* HBA SLI setup */ | 6789 | /* SLI-3 HBA setup */ |
2896 | if (lpfc_sli_hba_setup(phba)) { | 6790 | if (lpfc_sli_hba_setup(phba)) { |
2897 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 6791 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2898 | "1477 Failed to set up hba\n"); | 6792 | "1477 Failed to set up hba\n"); |
@@ -2902,185 +6796,65 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |||
2902 | 6796 | ||
2903 | /* Wait 50ms for the interrupts of previous mailbox commands */ | 6797 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
2904 | msleep(50); | 6798 | msleep(50); |
2905 | /* Check active interrupts received */ | 6799 | /* Check active interrupts on message signaled interrupts */ |
2906 | if (phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | 6800 | if (intr_mode == 0 || |
6801 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | ||
2907 | /* Log the current active interrupt mode */ | 6802 | /* Log the current active interrupt mode */ |
2908 | phba->intr_mode = intr_mode; | 6803 | phba->intr_mode = intr_mode; |
2909 | lpfc_log_intr_mode(phba, intr_mode); | 6804 | lpfc_log_intr_mode(phba, intr_mode); |
2910 | break; | 6805 | break; |
2911 | } else { | 6806 | } else { |
2912 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | 6807 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2913 | "0451 Configure interrupt mode (%d) " | 6808 | "0447 Configure interrupt mode (%d) " |
2914 | "failed active interrupt test.\n", | 6809 | "failed active interrupt test.\n", |
2915 | intr_mode); | 6810 | 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 */ | 6811 | /* Disable the current interrupt mode */ |
2926 | lpfc_disable_intr(phba); | 6812 | lpfc_sli_disable_intr(phba); |
2927 | /* Try next level of interrupt mode */ | 6813 | /* Try next level of interrupt mode */ |
2928 | cfg_mode = --intr_mode; | 6814 | cfg_mode = --intr_mode; |
2929 | } | 6815 | } |
2930 | } | 6816 | } |
2931 | 6817 | ||
2932 | /* | 6818 | /* Perform post initialization setup */ |
2933 | * hba setup may have changed the hba_queue_depth so we need to adjust | 6819 | 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 | 6820 | ||
2944 | scsi_host_set_prot(shost, lpfc_prot_mask); | 6821 | /* Check if there are static vports to be created. */ |
2945 | scsi_host_set_guard(shost, lpfc_prot_guard); | 6822 | 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 | 6823 | ||
3025 | return 0; | 6824 | return 0; |
3026 | 6825 | ||
3027 | out_remove_device: | 6826 | out_remove_device: |
3028 | spin_lock_irq(shost->host_lock); | 6827 | 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: | 6828 | out_free_sysfs_attr: |
3037 | lpfc_free_sysfs_attr(vport); | 6829 | lpfc_free_sysfs_attr(vport); |
3038 | out_destroy_port: | 6830 | out_destroy_shost: |
3039 | destroy_port(vport); | 6831 | lpfc_destroy_shost(phba); |
3040 | out_kthread_stop: | 6832 | out_unset_driver_resource: |
3041 | kthread_stop(phba->worker_thread); | 6833 | lpfc_unset_driver_resource_phase2(phba); |
3042 | out_free_iocbq: | 6834 | out_free_iocb_list: |
3043 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | 6835 | lpfc_free_iocb_list(phba); |
3044 | &phba->lpfc_iocb_list, list) { | 6836 | out_unset_driver_resource_s3: |
3045 | kfree(iocbq_entry); | 6837 | lpfc_sli_driver_resource_unset(phba); |
3046 | phba->total_iocbq_bufs--; | 6838 | out_unset_pci_mem_s3: |
3047 | } | 6839 | lpfc_sli_pci_mem_unset(phba); |
3048 | lpfc_mem_free(phba); | 6840 | out_disable_pci_dev: |
3049 | out_free_hbqslimp: | 6841 | 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: | 6842 | out_free_phba: |
3062 | kfree(phba); | 6843 | 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; | 6844 | return error; |
3072 | } | 6845 | } |
3073 | 6846 | ||
3074 | /** | 6847 | /** |
3075 | * lpfc_pci_remove_one - lpfc PCI func to unregister device from PCI subsystem | 6848 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. |
3076 | * @pdev: pointer to PCI device | 6849 | * @pdev: pointer to PCI device |
3077 | * | 6850 | * |
3078 | * This routine is to be registered to the kernel's PCI subsystem. When an | 6851 | * 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 | 6852 | * 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. | 6853 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
6854 | * device to be removed from the PCI subsystem properly. | ||
3081 | **/ | 6855 | **/ |
3082 | static void __devexit | 6856 | static void __devexit |
3083 | lpfc_pci_remove_one(struct pci_dev *pdev) | 6857 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
3084 | { | 6858 | { |
3085 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 6859 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3086 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | 6860 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
@@ -3098,7 +6872,7 @@ lpfc_pci_remove_one(struct pci_dev *pdev) | |||
3098 | /* Release all the vports against this physical port */ | 6872 | /* Release all the vports against this physical port */ |
3099 | vports = lpfc_create_vport_work_array(phba); | 6873 | vports = lpfc_create_vport_work_array(phba); |
3100 | if (vports != NULL) | 6874 | if (vports != NULL) |
3101 | for (i = 1; i <= phba->max_vpi && vports[i] != NULL; i++) | 6875 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) |
3102 | fc_vport_terminate(vports[i]->fc_vport); | 6876 | fc_vport_terminate(vports[i]->fc_vport); |
3103 | lpfc_destroy_vport_work_array(phba, vports); | 6877 | lpfc_destroy_vport_work_array(phba, vports); |
3104 | 6878 | ||
@@ -3120,7 +6894,7 @@ lpfc_pci_remove_one(struct pci_dev *pdev) | |||
3120 | /* Final cleanup of txcmplq and reset the HBA */ | 6894 | /* Final cleanup of txcmplq and reset the HBA */ |
3121 | lpfc_sli_brdrestart(phba); | 6895 | lpfc_sli_brdrestart(phba); |
3122 | 6896 | ||
3123 | lpfc_stop_phba_timers(phba); | 6897 | lpfc_stop_hba_timers(phba); |
3124 | spin_lock_irq(&phba->hbalock); | 6898 | spin_lock_irq(&phba->hbalock); |
3125 | list_del_init(&vport->listentry); | 6899 | list_del_init(&vport->listentry); |
3126 | spin_unlock_irq(&phba->hbalock); | 6900 | spin_unlock_irq(&phba->hbalock); |
@@ -3128,7 +6902,7 @@ lpfc_pci_remove_one(struct pci_dev *pdev) | |||
3128 | lpfc_debugfs_terminate(vport); | 6902 | lpfc_debugfs_terminate(vport); |
3129 | 6903 | ||
3130 | /* Disable interrupt */ | 6904 | /* Disable interrupt */ |
3131 | lpfc_disable_intr(phba); | 6905 | lpfc_sli_disable_intr(phba); |
3132 | 6906 | ||
3133 | pci_set_drvdata(pdev, NULL); | 6907 | pci_set_drvdata(pdev, NULL); |
3134 | scsi_host_put(shost); | 6908 | scsi_host_put(shost); |
@@ -3138,7 +6912,7 @@ lpfc_pci_remove_one(struct pci_dev *pdev) | |||
3138 | * corresponding pools here. | 6912 | * corresponding pools here. |
3139 | */ | 6913 | */ |
3140 | lpfc_scsi_free(phba); | 6914 | lpfc_scsi_free(phba); |
3141 | lpfc_mem_free(phba); | 6915 | lpfc_mem_free_all(phba); |
3142 | 6916 | ||
3143 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | 6917 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
3144 | phba->hbqslimp.virt, phba->hbqslimp.phys); | 6918 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
@@ -3151,36 +6925,35 @@ lpfc_pci_remove_one(struct pci_dev *pdev) | |||
3151 | iounmap(phba->ctrl_regs_memmap_p); | 6925 | iounmap(phba->ctrl_regs_memmap_p); |
3152 | iounmap(phba->slim_memmap_p); | 6926 | iounmap(phba->slim_memmap_p); |
3153 | 6927 | ||
3154 | idr_remove(&lpfc_hba_index, phba->brd_no); | 6928 | lpfc_hba_free(phba); |
3155 | |||
3156 | kfree(phba); | ||
3157 | 6929 | ||
3158 | pci_release_selected_regions(pdev, bars); | 6930 | pci_release_selected_regions(pdev, bars); |
3159 | pci_disable_device(pdev); | 6931 | pci_disable_device(pdev); |
3160 | } | 6932 | } |
3161 | 6933 | ||
3162 | /** | 6934 | /** |
3163 | * lpfc_pci_suspend_one - lpfc PCI func to suspend device for power management | 6935 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt |
3164 | * @pdev: pointer to PCI device | 6936 | * @pdev: pointer to PCI device |
3165 | * @msg: power management message | 6937 | * @msg: power management message |
3166 | * | 6938 | * |
3167 | * This routine is to be registered to the kernel's PCI subsystem to support | 6939 | * 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 | 6940 | * 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 | 6941 | * 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 | 6942 | * 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 | 6943 | * and bring the device offline. Note that as the driver implements the |
3172 | * support for suspend/resume -- all the possible PM messages (SUSPEND, | 6944 | * 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 | 6945 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
3174 | * and the driver will fully reinitialize its device during resume() method | 6946 | * 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 | 6947 | * fully reinitialize its device during resume() method call, the driver will |
3176 | * instead of setting it according to the @msg provided by the PM. | 6948 | * set device to PCI_D3hot state in PCI config space instead of setting it |
6949 | * according to the @msg provided by the PM. | ||
3177 | * | 6950 | * |
3178 | * Return code | 6951 | * Return code |
3179 | * 0 - driver suspended the device | 6952 | * 0 - driver suspended the device |
3180 | * Error otherwise | 6953 | * Error otherwise |
3181 | **/ | 6954 | **/ |
3182 | static int | 6955 | static int |
3183 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | 6956 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) |
3184 | { | 6957 | { |
3185 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 6958 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3186 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 6959 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
@@ -3194,7 +6967,7 @@ lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |||
3194 | kthread_stop(phba->worker_thread); | 6967 | kthread_stop(phba->worker_thread); |
3195 | 6968 | ||
3196 | /* Disable interrupt from device */ | 6969 | /* Disable interrupt from device */ |
3197 | lpfc_disable_intr(phba); | 6970 | lpfc_sli_disable_intr(phba); |
3198 | 6971 | ||
3199 | /* Save device state to PCI config space */ | 6972 | /* Save device state to PCI config space */ |
3200 | pci_save_state(pdev); | 6973 | pci_save_state(pdev); |
@@ -3204,25 +6977,26 @@ lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |||
3204 | } | 6977 | } |
3205 | 6978 | ||
3206 | /** | 6979 | /** |
3207 | * lpfc_pci_resume_one - lpfc PCI func to resume device for power management | 6980 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt |
3208 | * @pdev: pointer to PCI device | 6981 | * @pdev: pointer to PCI device |
3209 | * | 6982 | * |
3210 | * This routine is to be registered to the kernel's PCI subsystem to support | 6983 | * 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 | 6984 | * 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 | 6985 | * 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 | 6986 | * 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 | 6987 | * driver implements the minimum PM requirements to a power-aware driver's |
3215 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | 6988 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
3216 | * method call will be treated as SUSPEND and the driver will fully | 6989 | * 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 | 6990 | * driver will fully reinitialize its device during resume() method call, |
3218 | * set to PCI_D0 directly in PCI config space before restoring the state. | 6991 | * the device will be set to PCI_D0 directly in PCI config space before |
6992 | * restoring the state. | ||
3219 | * | 6993 | * |
3220 | * Return code | 6994 | * Return code |
3221 | * 0 - driver suspended the device | 6995 | * 0 - driver suspended the device |
3222 | * Error otherwise | 6996 | * Error otherwise |
3223 | **/ | 6997 | **/ |
3224 | static int | 6998 | static int |
3225 | lpfc_pci_resume_one(struct pci_dev *pdev) | 6999 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
3226 | { | 7000 | { |
3227 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 7001 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3228 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 7002 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
@@ -3250,7 +7024,7 @@ lpfc_pci_resume_one(struct pci_dev *pdev) | |||
3250 | } | 7024 | } |
3251 | 7025 | ||
3252 | /* Configure and enable interrupt */ | 7026 | /* Configure and enable interrupt */ |
3253 | intr_mode = lpfc_enable_intr(phba, phba->intr_mode); | 7027 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
3254 | if (intr_mode == LPFC_INTR_ERROR) { | 7028 | if (intr_mode == LPFC_INTR_ERROR) { |
3255 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 7029 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3256 | "0430 PM resume Failed to enable interrupt\n"); | 7030 | "0430 PM resume Failed to enable interrupt\n"); |
@@ -3269,23 +7043,24 @@ lpfc_pci_resume_one(struct pci_dev *pdev) | |||
3269 | } | 7043 | } |
3270 | 7044 | ||
3271 | /** | 7045 | /** |
3272 | * lpfc_io_error_detected - Driver method for handling PCI I/O error detected | 7046 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error |
3273 | * @pdev: pointer to PCI device. | 7047 | * @pdev: pointer to PCI device. |
3274 | * @state: the current PCI connection state. | 7048 | * @state: the current PCI connection state. |
3275 | * | 7049 | * |
3276 | * This routine is registered to the PCI subsystem for error handling. This | 7050 | * 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 | 7051 | * 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 | 7052 | * 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 | 7053 | * 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 | 7054 | * interrupt(s) to the device. Once that is done, it will return |
3281 | * perform proper recovery as desired. | 7055 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
7056 | * as desired. | ||
3282 | * | 7057 | * |
3283 | * Return codes | 7058 | * Return codes |
3284 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | 7059 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
3285 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | 7060 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
3286 | **/ | 7061 | **/ |
3287 | static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, | 7062 | static pci_ers_result_t |
3288 | pci_channel_state_t state) | 7063 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) |
3289 | { | 7064 | { |
3290 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 7065 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3291 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 7066 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
@@ -3312,30 +7087,32 @@ static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, | |||
3312 | lpfc_sli_abort_iocb_ring(phba, pring); | 7087 | lpfc_sli_abort_iocb_ring(phba, pring); |
3313 | 7088 | ||
3314 | /* Disable interrupt */ | 7089 | /* Disable interrupt */ |
3315 | lpfc_disable_intr(phba); | 7090 | lpfc_sli_disable_intr(phba); |
3316 | 7091 | ||
3317 | /* Request a slot reset. */ | 7092 | /* Request a slot reset. */ |
3318 | return PCI_ERS_RESULT_NEED_RESET; | 7093 | return PCI_ERS_RESULT_NEED_RESET; |
3319 | } | 7094 | } |
3320 | 7095 | ||
3321 | /** | 7096 | /** |
3322 | * lpfc_io_slot_reset - Restart a PCI device from scratch | 7097 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. |
3323 | * @pdev: pointer to PCI device. | 7098 | * @pdev: pointer to PCI device. |
3324 | * | 7099 | * |
3325 | * This routine is registered to the PCI subsystem for error handling. This is | 7100 | * 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, | 7101 | * 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 | 7102 | * 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 | 7103 | * During the PCI subsystem error recovery, after driver returns |
3329 | * proper error recovery and then call this routine before calling the .resume | 7104 | * 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, | 7105 | * 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 | 7106 | * to recover the device. This function will initialize the HBA device, |
3332 | * passing any I/O traffic. | 7107 | * enable the interrupt, but it will just put the HBA to offline state |
7108 | * without passing any I/O traffic. | ||
3333 | * | 7109 | * |
3334 | * Return codes | 7110 | * Return codes |
3335 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | 7111 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
3336 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | 7112 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
3337 | */ | 7113 | */ |
3338 | static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) | 7114 | static pci_ers_result_t |
7115 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) | ||
3339 | { | 7116 | { |
3340 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 7117 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3341 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 7118 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
@@ -3354,11 +7131,11 @@ static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) | |||
3354 | pci_set_master(pdev); | 7131 | pci_set_master(pdev); |
3355 | 7132 | ||
3356 | spin_lock_irq(&phba->hbalock); | 7133 | spin_lock_irq(&phba->hbalock); |
3357 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; | 7134 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
3358 | spin_unlock_irq(&phba->hbalock); | 7135 | spin_unlock_irq(&phba->hbalock); |
3359 | 7136 | ||
3360 | /* Configure and enable interrupt */ | 7137 | /* Configure and enable interrupt */ |
3361 | intr_mode = lpfc_enable_intr(phba, phba->intr_mode); | 7138 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
3362 | if (intr_mode == LPFC_INTR_ERROR) { | 7139 | if (intr_mode == LPFC_INTR_ERROR) { |
3363 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | 7140 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
3364 | "0427 Cannot re-enable interrupt after " | 7141 | "0427 Cannot re-enable interrupt after " |
@@ -3378,20 +7155,713 @@ static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) | |||
3378 | } | 7155 | } |
3379 | 7156 | ||
3380 | /** | 7157 | /** |
3381 | * lpfc_io_resume - Resume PCI I/O operation | 7158 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. |
3382 | * @pdev: pointer to PCI device | 7159 | * @pdev: pointer to PCI device |
3383 | * | 7160 | * |
3384 | * This routine is registered to the PCI subsystem for error handling. It is | 7161 | * 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 | 7162 | * 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, | 7163 | * 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. | 7164 | * error recovery. After this call, traffic can start to flow from this device |
7165 | * again. | ||
3388 | */ | 7166 | */ |
3389 | static void lpfc_io_resume(struct pci_dev *pdev) | 7167 | static void |
7168 | lpfc_io_resume_s3(struct pci_dev *pdev) | ||
7169 | { | ||
7170 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
7171 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
7172 | |||
7173 | lpfc_online(phba); | ||
7174 | } | ||
7175 | |||
7176 | /** | ||
7177 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve | ||
7178 | * @phba: pointer to lpfc hba data structure. | ||
7179 | * | ||
7180 | * returns the number of ELS/CT IOCBs to reserve | ||
7181 | **/ | ||
7182 | int | ||
7183 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) | ||
7184 | { | ||
7185 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; | ||
7186 | |||
7187 | if (max_xri <= 100) | ||
7188 | return 4; | ||
7189 | else if (max_xri <= 256) | ||
7190 | return 8; | ||
7191 | else if (max_xri <= 512) | ||
7192 | return 16; | ||
7193 | else if (max_xri <= 1024) | ||
7194 | return 32; | ||
7195 | else | ||
7196 | return 48; | ||
7197 | } | ||
7198 | |||
7199 | /** | ||
7200 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys | ||
7201 | * @pdev: pointer to PCI device | ||
7202 | * @pid: pointer to PCI device identifier | ||
7203 | * | ||
7204 | * This routine is called from the kernel's PCI subsystem to device with | ||
7205 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | ||
7206 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | ||
7207 | * information of the device and driver to see if the driver state that it | ||
7208 | * can support this kind of device. If the match is successful, the driver | ||
7209 | * core invokes this routine. If this routine determines it can claim the HBA, | ||
7210 | * it does all the initialization that it needs to do to handle the HBA | ||
7211 | * properly. | ||
7212 | * | ||
7213 | * Return code | ||
7214 | * 0 - driver can claim the device | ||
7215 | * negative value - driver can not claim the device | ||
7216 | **/ | ||
7217 | static int __devinit | ||
7218 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) | ||
7219 | { | ||
7220 | struct lpfc_hba *phba; | ||
7221 | struct lpfc_vport *vport = NULL; | ||
7222 | int error; | ||
7223 | uint32_t cfg_mode, intr_mode; | ||
7224 | int mcnt; | ||
7225 | |||
7226 | /* Allocate memory for HBA structure */ | ||
7227 | phba = lpfc_hba_alloc(pdev); | ||
7228 | if (!phba) | ||
7229 | return -ENOMEM; | ||
7230 | |||
7231 | /* Perform generic PCI device enabling operation */ | ||
7232 | error = lpfc_enable_pci_dev(phba); | ||
7233 | if (error) { | ||
7234 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7235 | "1409 Failed to enable pci device.\n"); | ||
7236 | goto out_free_phba; | ||
7237 | } | ||
7238 | |||
7239 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ | ||
7240 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); | ||
7241 | if (error) | ||
7242 | goto out_disable_pci_dev; | ||
7243 | |||
7244 | /* Set up SLI-4 specific device PCI memory space */ | ||
7245 | error = lpfc_sli4_pci_mem_setup(phba); | ||
7246 | if (error) { | ||
7247 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7248 | "1410 Failed to set up pci memory space.\n"); | ||
7249 | goto out_disable_pci_dev; | ||
7250 | } | ||
7251 | |||
7252 | /* Set up phase-1 common device driver resources */ | ||
7253 | error = lpfc_setup_driver_resource_phase1(phba); | ||
7254 | if (error) { | ||
7255 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7256 | "1411 Failed to set up driver resource.\n"); | ||
7257 | goto out_unset_pci_mem_s4; | ||
7258 | } | ||
7259 | |||
7260 | /* Set up SLI-4 Specific device driver resources */ | ||
7261 | error = lpfc_sli4_driver_resource_setup(phba); | ||
7262 | if (error) { | ||
7263 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7264 | "1412 Failed to set up driver resource.\n"); | ||
7265 | goto out_unset_pci_mem_s4; | ||
7266 | } | ||
7267 | |||
7268 | /* Initialize and populate the iocb list per host */ | ||
7269 | error = lpfc_init_iocb_list(phba, | ||
7270 | phba->sli4_hba.max_cfg_param.max_xri); | ||
7271 | if (error) { | ||
7272 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7273 | "1413 Failed to initialize iocb list.\n"); | ||
7274 | goto out_unset_driver_resource_s4; | ||
7275 | } | ||
7276 | |||
7277 | /* Set up common device driver resources */ | ||
7278 | error = lpfc_setup_driver_resource_phase2(phba); | ||
7279 | if (error) { | ||
7280 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7281 | "1414 Failed to set up driver resource.\n"); | ||
7282 | goto out_free_iocb_list; | ||
7283 | } | ||
7284 | |||
7285 | /* Create SCSI host to the physical port */ | ||
7286 | error = lpfc_create_shost(phba); | ||
7287 | if (error) { | ||
7288 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7289 | "1415 Failed to create scsi host.\n"); | ||
7290 | goto out_unset_driver_resource; | ||
7291 | } | ||
7292 | |||
7293 | /* Configure sysfs attributes */ | ||
7294 | vport = phba->pport; | ||
7295 | error = lpfc_alloc_sysfs_attr(vport); | ||
7296 | if (error) { | ||
7297 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7298 | "1416 Failed to allocate sysfs attr\n"); | ||
7299 | goto out_destroy_shost; | ||
7300 | } | ||
7301 | |||
7302 | /* Now, trying to enable interrupt and bring up the device */ | ||
7303 | cfg_mode = phba->cfg_use_msi; | ||
7304 | while (true) { | ||
7305 | /* Put device to a known state before enabling interrupt */ | ||
7306 | lpfc_stop_port(phba); | ||
7307 | /* Configure and enable interrupt */ | ||
7308 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); | ||
7309 | if (intr_mode == LPFC_INTR_ERROR) { | ||
7310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7311 | "0426 Failed to enable interrupt.\n"); | ||
7312 | error = -ENODEV; | ||
7313 | goto out_free_sysfs_attr; | ||
7314 | } | ||
7315 | /* Set up SLI-4 HBA */ | ||
7316 | if (lpfc_sli4_hba_setup(phba)) { | ||
7317 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7318 | "1421 Failed to set up hba\n"); | ||
7319 | error = -ENODEV; | ||
7320 | goto out_disable_intr; | ||
7321 | } | ||
7322 | |||
7323 | /* Send NOP mbx cmds for non-INTx mode active interrupt test */ | ||
7324 | if (intr_mode != 0) | ||
7325 | mcnt = lpfc_sli4_send_nop_mbox_cmds(phba, | ||
7326 | LPFC_ACT_INTR_CNT); | ||
7327 | |||
7328 | /* Check active interrupts received only for MSI/MSI-X */ | ||
7329 | if (intr_mode == 0 || | ||
7330 | phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) { | ||
7331 | /* Log the current active interrupt mode */ | ||
7332 | phba->intr_mode = intr_mode; | ||
7333 | lpfc_log_intr_mode(phba, intr_mode); | ||
7334 | break; | ||
7335 | } | ||
7336 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
7337 | "0451 Configure interrupt mode (%d) " | ||
7338 | "failed active interrupt test.\n", | ||
7339 | intr_mode); | ||
7340 | /* Unset the preivous SLI-4 HBA setup */ | ||
7341 | lpfc_sli4_unset_hba(phba); | ||
7342 | /* Try next level of interrupt mode */ | ||
7343 | cfg_mode = --intr_mode; | ||
7344 | } | ||
7345 | |||
7346 | /* Perform post initialization setup */ | ||
7347 | lpfc_post_init_setup(phba); | ||
7348 | |||
7349 | return 0; | ||
7350 | |||
7351 | out_disable_intr: | ||
7352 | lpfc_sli4_disable_intr(phba); | ||
7353 | out_free_sysfs_attr: | ||
7354 | lpfc_free_sysfs_attr(vport); | ||
7355 | out_destroy_shost: | ||
7356 | lpfc_destroy_shost(phba); | ||
7357 | out_unset_driver_resource: | ||
7358 | lpfc_unset_driver_resource_phase2(phba); | ||
7359 | out_free_iocb_list: | ||
7360 | lpfc_free_iocb_list(phba); | ||
7361 | out_unset_driver_resource_s4: | ||
7362 | lpfc_sli4_driver_resource_unset(phba); | ||
7363 | out_unset_pci_mem_s4: | ||
7364 | lpfc_sli4_pci_mem_unset(phba); | ||
7365 | out_disable_pci_dev: | ||
7366 | lpfc_disable_pci_dev(phba); | ||
7367 | out_free_phba: | ||
7368 | lpfc_hba_free(phba); | ||
7369 | return error; | ||
7370 | } | ||
7371 | |||
7372 | /** | ||
7373 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem | ||
7374 | * @pdev: pointer to PCI device | ||
7375 | * | ||
7376 | * This routine is called from the kernel's PCI subsystem to device with | ||
7377 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | ||
7378 | * removed from PCI bus, it performs all the necessary cleanup for the HBA | ||
7379 | * device to be removed from the PCI subsystem properly. | ||
7380 | **/ | ||
7381 | static void __devexit | ||
7382 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) | ||
7383 | { | ||
7384 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
7385 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | ||
7386 | struct lpfc_vport **vports; | ||
7387 | struct lpfc_hba *phba = vport->phba; | ||
7388 | int i; | ||
7389 | |||
7390 | /* Mark the device unloading flag */ | ||
7391 | spin_lock_irq(&phba->hbalock); | ||
7392 | vport->load_flag |= FC_UNLOADING; | ||
7393 | spin_unlock_irq(&phba->hbalock); | ||
7394 | |||
7395 | /* Free the HBA sysfs attributes */ | ||
7396 | lpfc_free_sysfs_attr(vport); | ||
7397 | |||
7398 | /* Release all the vports against this physical port */ | ||
7399 | vports = lpfc_create_vport_work_array(phba); | ||
7400 | if (vports != NULL) | ||
7401 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) | ||
7402 | fc_vport_terminate(vports[i]->fc_vport); | ||
7403 | lpfc_destroy_vport_work_array(phba, vports); | ||
7404 | |||
7405 | /* Remove FC host and then SCSI host with the physical port */ | ||
7406 | fc_remove_host(shost); | ||
7407 | scsi_remove_host(shost); | ||
7408 | |||
7409 | /* Perform cleanup on the physical port */ | ||
7410 | lpfc_cleanup(vport); | ||
7411 | |||
7412 | /* | ||
7413 | * Bring down the SLI Layer. This step disables all interrupts, | ||
7414 | * clears the rings, discards all mailbox commands, and resets | ||
7415 | * the HBA FCoE function. | ||
7416 | */ | ||
7417 | lpfc_debugfs_terminate(vport); | ||
7418 | lpfc_sli4_hba_unset(phba); | ||
7419 | |||
7420 | spin_lock_irq(&phba->hbalock); | ||
7421 | list_del_init(&vport->listentry); | ||
7422 | spin_unlock_irq(&phba->hbalock); | ||
7423 | |||
7424 | /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi | ||
7425 | * buffers are released to their corresponding pools here. | ||
7426 | */ | ||
7427 | lpfc_scsi_free(phba); | ||
7428 | lpfc_sli4_driver_resource_unset(phba); | ||
7429 | |||
7430 | /* Unmap adapter Control and Doorbell registers */ | ||
7431 | lpfc_sli4_pci_mem_unset(phba); | ||
7432 | |||
7433 | /* Release PCI resources and disable device's PCI function */ | ||
7434 | scsi_host_put(shost); | ||
7435 | lpfc_disable_pci_dev(phba); | ||
7436 | |||
7437 | /* Finally, free the driver's device data structure */ | ||
7438 | lpfc_hba_free(phba); | ||
7439 | |||
7440 | return; | ||
7441 | } | ||
7442 | |||
7443 | /** | ||
7444 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt | ||
7445 | * @pdev: pointer to PCI device | ||
7446 | * @msg: power management message | ||
7447 | * | ||
7448 | * This routine is called from the kernel's PCI subsystem to support system | ||
7449 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes | ||
7450 | * this method, it quiesces the device by stopping the driver's worker | ||
7451 | * thread for the device, turning off device's interrupt and DMA, and bring | ||
7452 | * the device offline. Note that as the driver implements the minimum PM | ||
7453 | * requirements to a power-aware driver's PM support for suspend/resume -- all | ||
7454 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | ||
7455 | * method call will be treated as SUSPEND and the driver will fully | ||
7456 | * reinitialize its device during resume() method call, the driver will set | ||
7457 | * device to PCI_D3hot state in PCI config space instead of setting it | ||
7458 | * according to the @msg provided by the PM. | ||
7459 | * | ||
7460 | * Return code | ||
7461 | * 0 - driver suspended the device | ||
7462 | * Error otherwise | ||
7463 | **/ | ||
7464 | static int | ||
7465 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) | ||
3390 | { | 7466 | { |
3391 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | 7467 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
3392 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | 7468 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
3393 | 7469 | ||
7470 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
7471 | "0298 PCI device Power Management suspend.\n"); | ||
7472 | |||
7473 | /* Bring down the device */ | ||
7474 | lpfc_offline_prep(phba); | ||
7475 | lpfc_offline(phba); | ||
7476 | kthread_stop(phba->worker_thread); | ||
7477 | |||
7478 | /* Disable interrupt from device */ | ||
7479 | lpfc_sli4_disable_intr(phba); | ||
7480 | |||
7481 | /* Save device state to PCI config space */ | ||
7482 | pci_save_state(pdev); | ||
7483 | pci_set_power_state(pdev, PCI_D3hot); | ||
7484 | |||
7485 | return 0; | ||
7486 | } | ||
7487 | |||
7488 | /** | ||
7489 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt | ||
7490 | * @pdev: pointer to PCI device | ||
7491 | * | ||
7492 | * This routine is called from the kernel's PCI subsystem to support system | ||
7493 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes | ||
7494 | * this method, it restores the device's PCI config space state and fully | ||
7495 | * reinitializes the device and brings it online. Note that as the driver | ||
7496 | * implements the minimum PM requirements to a power-aware driver's PM for | ||
7497 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | ||
7498 | * to the suspend() method call will be treated as SUSPEND and the driver | ||
7499 | * will fully reinitialize its device during resume() method call, the device | ||
7500 | * will be set to PCI_D0 directly in PCI config space before restoring the | ||
7501 | * state. | ||
7502 | * | ||
7503 | * Return code | ||
7504 | * 0 - driver suspended the device | ||
7505 | * Error otherwise | ||
7506 | **/ | ||
7507 | static int | ||
7508 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) | ||
7509 | { | ||
7510 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
7511 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
7512 | uint32_t intr_mode; | ||
7513 | int error; | ||
7514 | |||
7515 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | ||
7516 | "0292 PCI device Power Management resume.\n"); | ||
7517 | |||
7518 | /* Restore device state from PCI config space */ | ||
7519 | pci_set_power_state(pdev, PCI_D0); | ||
7520 | pci_restore_state(pdev); | ||
7521 | if (pdev->is_busmaster) | ||
7522 | pci_set_master(pdev); | ||
7523 | |||
7524 | /* Startup the kernel thread for this host adapter. */ | ||
7525 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | ||
7526 | "lpfc_worker_%d", phba->brd_no); | ||
7527 | if (IS_ERR(phba->worker_thread)) { | ||
7528 | error = PTR_ERR(phba->worker_thread); | ||
7529 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7530 | "0293 PM resume failed to start worker " | ||
7531 | "thread: error=x%x.\n", error); | ||
7532 | return error; | ||
7533 | } | ||
7534 | |||
7535 | /* Configure and enable interrupt */ | ||
7536 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | ||
7537 | if (intr_mode == LPFC_INTR_ERROR) { | ||
7538 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7539 | "0294 PM resume Failed to enable interrupt\n"); | ||
7540 | return -EIO; | ||
7541 | } else | ||
7542 | phba->intr_mode = intr_mode; | ||
7543 | |||
7544 | /* Restart HBA and bring it online */ | ||
7545 | lpfc_sli_brdrestart(phba); | ||
3394 | lpfc_online(phba); | 7546 | lpfc_online(phba); |
7547 | |||
7548 | /* Log the current active interrupt mode */ | ||
7549 | lpfc_log_intr_mode(phba, phba->intr_mode); | ||
7550 | |||
7551 | return 0; | ||
7552 | } | ||
7553 | |||
7554 | /** | ||
7555 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device | ||
7556 | * @pdev: pointer to PCI device. | ||
7557 | * @state: the current PCI connection state. | ||
7558 | * | ||
7559 | * This routine is called from the PCI subsystem for error handling to device | ||
7560 | * with SLI-4 interface spec. This function is called by the PCI subsystem | ||
7561 | * after a PCI bus error affecting this device has been detected. When this | ||
7562 | * function is invoked, it will need to stop all the I/Os and interrupt(s) | ||
7563 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET | ||
7564 | * for the PCI subsystem to perform proper recovery as desired. | ||
7565 | * | ||
7566 | * Return codes | ||
7567 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | ||
7568 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | ||
7569 | **/ | ||
7570 | static pci_ers_result_t | ||
7571 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) | ||
7572 | { | ||
7573 | return PCI_ERS_RESULT_NEED_RESET; | ||
7574 | } | ||
7575 | |||
7576 | /** | ||
7577 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch | ||
7578 | * @pdev: pointer to PCI device. | ||
7579 | * | ||
7580 | * This routine is called from the PCI subsystem for error handling to device | ||
7581 | * with SLI-4 interface spec. It is called after PCI bus has been reset to | ||
7582 | * restart the PCI card from scratch, as if from a cold-boot. During the | ||
7583 | * PCI subsystem error recovery, after the driver returns | ||
7584 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error | ||
7585 | * recovery and then call this routine before calling the .resume method to | ||
7586 | * recover the device. This function will initialize the HBA device, enable | ||
7587 | * the interrupt, but it will just put the HBA to offline state without | ||
7588 | * passing any I/O traffic. | ||
7589 | * | ||
7590 | * Return codes | ||
7591 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | ||
7592 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | ||
7593 | */ | ||
7594 | static pci_ers_result_t | ||
7595 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) | ||
7596 | { | ||
7597 | return PCI_ERS_RESULT_RECOVERED; | ||
7598 | } | ||
7599 | |||
7600 | /** | ||
7601 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device | ||
7602 | * @pdev: pointer to PCI device | ||
7603 | * | ||
7604 | * This routine is called from the PCI subsystem for error handling to device | ||
7605 | * with SLI-4 interface spec. It is called when kernel error recovery tells | ||
7606 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus | ||
7607 | * error recovery. After this call, traffic can start to flow from this device | ||
7608 | * again. | ||
7609 | **/ | ||
7610 | static void | ||
7611 | lpfc_io_resume_s4(struct pci_dev *pdev) | ||
7612 | { | ||
7613 | return; | ||
7614 | } | ||
7615 | |||
7616 | /** | ||
7617 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem | ||
7618 | * @pdev: pointer to PCI device | ||
7619 | * @pid: pointer to PCI device identifier | ||
7620 | * | ||
7621 | * This routine is to be registered to the kernel's PCI subsystem. When an | ||
7622 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks | ||
7623 | * at PCI device-specific information of the device and driver to see if the | ||
7624 | * driver state that it can support this kind of device. If the match is | ||
7625 | * successful, the driver core invokes this routine. This routine dispatches | ||
7626 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will | ||
7627 | * do all the initialization that it needs to do to handle the HBA device | ||
7628 | * properly. | ||
7629 | * | ||
7630 | * Return code | ||
7631 | * 0 - driver can claim the device | ||
7632 | * negative value - driver can not claim the device | ||
7633 | **/ | ||
7634 | static int __devinit | ||
7635 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | ||
7636 | { | ||
7637 | int rc; | ||
7638 | uint16_t dev_id; | ||
7639 | |||
7640 | if (pci_read_config_word(pdev, PCI_DEVICE_ID, &dev_id)) | ||
7641 | return -ENODEV; | ||
7642 | |||
7643 | switch (dev_id) { | ||
7644 | case PCI_DEVICE_ID_TIGERSHARK: | ||
7645 | case PCI_DEVICE_ID_TIGERSHARK_S: | ||
7646 | rc = lpfc_pci_probe_one_s4(pdev, pid); | ||
7647 | break; | ||
7648 | default: | ||
7649 | rc = lpfc_pci_probe_one_s3(pdev, pid); | ||
7650 | break; | ||
7651 | } | ||
7652 | return rc; | ||
7653 | } | ||
7654 | |||
7655 | /** | ||
7656 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem | ||
7657 | * @pdev: pointer to PCI device | ||
7658 | * | ||
7659 | * This routine is to be registered to the kernel's PCI subsystem. When an | ||
7660 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. | ||
7661 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device | ||
7662 | * remove routine, which will perform all the necessary cleanup for the | ||
7663 | * device to be removed from the PCI subsystem properly. | ||
7664 | **/ | ||
7665 | static void __devexit | ||
7666 | lpfc_pci_remove_one(struct pci_dev *pdev) | ||
7667 | { | ||
7668 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
7669 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
7670 | |||
7671 | switch (phba->pci_dev_grp) { | ||
7672 | case LPFC_PCI_DEV_LP: | ||
7673 | lpfc_pci_remove_one_s3(pdev); | ||
7674 | break; | ||
7675 | case LPFC_PCI_DEV_OC: | ||
7676 | lpfc_pci_remove_one_s4(pdev); | ||
7677 | break; | ||
7678 | default: | ||
7679 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7680 | "1424 Invalid PCI device group: 0x%x\n", | ||
7681 | phba->pci_dev_grp); | ||
7682 | break; | ||
7683 | } | ||
7684 | return; | ||
7685 | } | ||
7686 | |||
7687 | /** | ||
7688 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management | ||
7689 | * @pdev: pointer to PCI device | ||
7690 | * @msg: power management message | ||
7691 | * | ||
7692 | * This routine is to be registered to the kernel's PCI subsystem to support | ||
7693 | * system Power Management (PM). When PM invokes this method, it dispatches | ||
7694 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will | ||
7695 | * suspend the device. | ||
7696 | * | ||
7697 | * Return code | ||
7698 | * 0 - driver suspended the device | ||
7699 | * Error otherwise | ||
7700 | **/ | ||
7701 | static int | ||
7702 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | ||
7703 | { | ||
7704 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
7705 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
7706 | int rc = -ENODEV; | ||
7707 | |||
7708 | switch (phba->pci_dev_grp) { | ||
7709 | case LPFC_PCI_DEV_LP: | ||
7710 | rc = lpfc_pci_suspend_one_s3(pdev, msg); | ||
7711 | break; | ||
7712 | case LPFC_PCI_DEV_OC: | ||
7713 | rc = lpfc_pci_suspend_one_s4(pdev, msg); | ||
7714 | break; | ||
7715 | default: | ||
7716 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7717 | "1425 Invalid PCI device group: 0x%x\n", | ||
7718 | phba->pci_dev_grp); | ||
7719 | break; | ||
7720 | } | ||
7721 | return rc; | ||
7722 | } | ||
7723 | |||
7724 | /** | ||
7725 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management | ||
7726 | * @pdev: pointer to PCI device | ||
7727 | * | ||
7728 | * This routine is to be registered to the kernel's PCI subsystem to support | ||
7729 | * system Power Management (PM). When PM invokes this method, it dispatches | ||
7730 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will | ||
7731 | * resume the device. | ||
7732 | * | ||
7733 | * Return code | ||
7734 | * 0 - driver suspended the device | ||
7735 | * Error otherwise | ||
7736 | **/ | ||
7737 | static int | ||
7738 | lpfc_pci_resume_one(struct pci_dev *pdev) | ||
7739 | { | ||
7740 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
7741 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
7742 | int rc = -ENODEV; | ||
7743 | |||
7744 | switch (phba->pci_dev_grp) { | ||
7745 | case LPFC_PCI_DEV_LP: | ||
7746 | rc = lpfc_pci_resume_one_s3(pdev); | ||
7747 | break; | ||
7748 | case LPFC_PCI_DEV_OC: | ||
7749 | rc = lpfc_pci_resume_one_s4(pdev); | ||
7750 | break; | ||
7751 | default: | ||
7752 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7753 | "1426 Invalid PCI device group: 0x%x\n", | ||
7754 | phba->pci_dev_grp); | ||
7755 | break; | ||
7756 | } | ||
7757 | return rc; | ||
7758 | } | ||
7759 | |||
7760 | /** | ||
7761 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error | ||
7762 | * @pdev: pointer to PCI device. | ||
7763 | * @state: the current PCI connection state. | ||
7764 | * | ||
7765 | * This routine is registered to the PCI subsystem for error handling. This | ||
7766 | * function is called by the PCI subsystem after a PCI bus error affecting | ||
7767 | * this device has been detected. When this routine is invoked, it dispatches | ||
7768 | * the action to the proper SLI-3 or SLI-4 device error detected handling | ||
7769 | * routine, which will perform the proper error detected operation. | ||
7770 | * | ||
7771 | * Return codes | ||
7772 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | ||
7773 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | ||
7774 | **/ | ||
7775 | static pci_ers_result_t | ||
7776 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | ||
7777 | { | ||
7778 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
7779 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
7780 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | ||
7781 | |||
7782 | switch (phba->pci_dev_grp) { | ||
7783 | case LPFC_PCI_DEV_LP: | ||
7784 | rc = lpfc_io_error_detected_s3(pdev, state); | ||
7785 | break; | ||
7786 | case LPFC_PCI_DEV_OC: | ||
7787 | rc = lpfc_io_error_detected_s4(pdev, state); | ||
7788 | break; | ||
7789 | default: | ||
7790 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7791 | "1427 Invalid PCI device group: 0x%x\n", | ||
7792 | phba->pci_dev_grp); | ||
7793 | break; | ||
7794 | } | ||
7795 | return rc; | ||
7796 | } | ||
7797 | |||
7798 | /** | ||
7799 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch | ||
7800 | * @pdev: pointer to PCI device. | ||
7801 | * | ||
7802 | * This routine is registered to the PCI subsystem for error handling. This | ||
7803 | * function is called after PCI bus has been reset to restart the PCI card | ||
7804 | * from scratch, as if from a cold-boot. When this routine is invoked, it | ||
7805 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling | ||
7806 | * routine, which will perform the proper device reset. | ||
7807 | * | ||
7808 | * Return codes | ||
7809 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | ||
7810 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | ||
7811 | **/ | ||
7812 | static pci_ers_result_t | ||
7813 | lpfc_io_slot_reset(struct pci_dev *pdev) | ||
7814 | { | ||
7815 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
7816 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
7817 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | ||
7818 | |||
7819 | switch (phba->pci_dev_grp) { | ||
7820 | case LPFC_PCI_DEV_LP: | ||
7821 | rc = lpfc_io_slot_reset_s3(pdev); | ||
7822 | break; | ||
7823 | case LPFC_PCI_DEV_OC: | ||
7824 | rc = lpfc_io_slot_reset_s4(pdev); | ||
7825 | break; | ||
7826 | default: | ||
7827 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7828 | "1428 Invalid PCI device group: 0x%x\n", | ||
7829 | phba->pci_dev_grp); | ||
7830 | break; | ||
7831 | } | ||
7832 | return rc; | ||
7833 | } | ||
7834 | |||
7835 | /** | ||
7836 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation | ||
7837 | * @pdev: pointer to PCI device | ||
7838 | * | ||
7839 | * This routine is registered to the PCI subsystem for error handling. It | ||
7840 | * is called when kernel error recovery tells the lpfc driver that it is | ||
7841 | * OK to resume normal PCI operation after PCI bus error recovery. When | ||
7842 | * this routine is invoked, it dispatches the action to the proper SLI-3 | ||
7843 | * or SLI-4 device io_resume routine, which will resume the device operation. | ||
7844 | **/ | ||
7845 | static void | ||
7846 | lpfc_io_resume(struct pci_dev *pdev) | ||
7847 | { | ||
7848 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | ||
7849 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | ||
7850 | |||
7851 | switch (phba->pci_dev_grp) { | ||
7852 | case LPFC_PCI_DEV_LP: | ||
7853 | lpfc_io_resume_s3(pdev); | ||
7854 | break; | ||
7855 | case LPFC_PCI_DEV_OC: | ||
7856 | lpfc_io_resume_s4(pdev); | ||
7857 | break; | ||
7858 | default: | ||
7859 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | ||
7860 | "1429 Invalid PCI device group: 0x%x\n", | ||
7861 | phba->pci_dev_grp); | ||
7862 | break; | ||
7863 | } | ||
7864 | return; | ||
3395 | } | 7865 | } |
3396 | 7866 | ||
3397 | static struct pci_device_id lpfc_id_table[] = { | 7867 | static struct pci_device_id lpfc_id_table[] = { |
@@ -3469,6 +7939,10 @@ static struct pci_device_id lpfc_id_table[] = { | |||
3469 | PCI_ANY_ID, PCI_ANY_ID, }, | 7939 | PCI_ANY_ID, PCI_ANY_ID, }, |
3470 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, | 7940 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
3471 | PCI_ANY_ID, PCI_ANY_ID, }, | 7941 | PCI_ANY_ID, PCI_ANY_ID, }, |
7942 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, | ||
7943 | PCI_ANY_ID, PCI_ANY_ID, }, | ||
7944 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK_S, | ||
7945 | PCI_ANY_ID, PCI_ANY_ID, }, | ||
3472 | { 0 } | 7946 | { 0 } |
3473 | }; | 7947 | }; |
3474 | 7948 | ||
@@ -3486,7 +7960,7 @@ static struct pci_driver lpfc_driver = { | |||
3486 | .probe = lpfc_pci_probe_one, | 7960 | .probe = lpfc_pci_probe_one, |
3487 | .remove = __devexit_p(lpfc_pci_remove_one), | 7961 | .remove = __devexit_p(lpfc_pci_remove_one), |
3488 | .suspend = lpfc_pci_suspend_one, | 7962 | .suspend = lpfc_pci_suspend_one, |
3489 | .resume = lpfc_pci_resume_one, | 7963 | .resume = lpfc_pci_resume_one, |
3490 | .err_handler = &lpfc_err_handler, | 7964 | .err_handler = &lpfc_err_handler, |
3491 | }; | 7965 | }; |
3492 | 7966 | ||