aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_init.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c607
1 files changed, 508 insertions, 99 deletions
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 90b8b0515e23..cb465b253910 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -33,6 +33,7 @@
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/firmware.h> 34#include <linux/firmware.h>
35#include <linux/miscdevice.h> 35#include <linux/miscdevice.h>
36#include <linux/percpu.h>
36 37
37#include <scsi/scsi.h> 38#include <scsi/scsi.h>
38#include <scsi/scsi_device.h> 39#include <scsi/scsi_device.h>
@@ -58,6 +59,9 @@ char *_dump_buf_dif;
58unsigned long _dump_buf_dif_order; 59unsigned long _dump_buf_dif_order;
59spinlock_t _dump_buf_lock; 60spinlock_t _dump_buf_lock;
60 61
62/* Used when mapping IRQ vectors in a driver centric manner */
63uint16_t lpfc_used_cpu[LPFC_MAX_CPU];
64
61static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); 65static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
62static int lpfc_post_rcv_buf(struct lpfc_hba *); 66static int lpfc_post_rcv_buf(struct lpfc_hba *);
63static int lpfc_sli4_queue_verify(struct lpfc_hba *); 67static int lpfc_sli4_queue_verify(struct lpfc_hba *);
@@ -541,13 +545,16 @@ lpfc_config_port_post(struct lpfc_hba *phba)
541 545
542 /* Set up ring-0 (ELS) timer */ 546 /* Set up ring-0 (ELS) timer */
543 timeout = phba->fc_ratov * 2; 547 timeout = phba->fc_ratov * 2;
544 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); 548 mod_timer(&vport->els_tmofunc,
549 jiffies + msecs_to_jiffies(1000 * timeout));
545 /* Set up heart beat (HB) timer */ 550 /* Set up heart beat (HB) timer */
546 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); 551 mod_timer(&phba->hb_tmofunc,
552 jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
547 phba->hb_outstanding = 0; 553 phba->hb_outstanding = 0;
548 phba->last_completion_time = jiffies; 554 phba->last_completion_time = jiffies;
549 /* Set up error attention (ERATT) polling timer */ 555 /* Set up error attention (ERATT) polling timer */
550 mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); 556 mod_timer(&phba->eratt_poll,
557 jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL));
551 558
552 if (phba->hba_flag & LINK_DISABLED) { 559 if (phba->hba_flag & LINK_DISABLED) {
553 lpfc_printf_log(phba, 560 lpfc_printf_log(phba,
@@ -908,9 +915,9 @@ lpfc_hba_down_post_s4(struct lpfc_hba *phba)
908 psb->pCmd = NULL; 915 psb->pCmd = NULL;
909 psb->status = IOSTAT_SUCCESS; 916 psb->status = IOSTAT_SUCCESS;
910 } 917 }
911 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); 918 spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag);
912 list_splice(&aborts, &phba->lpfc_scsi_buf_list); 919 list_splice(&aborts, &phba->lpfc_scsi_buf_list_put);
913 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); 920 spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag);
914 return 0; 921 return 0;
915} 922}
916 923
@@ -1021,7 +1028,8 @@ lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
1021 !(phba->link_state == LPFC_HBA_ERROR) && 1028 !(phba->link_state == LPFC_HBA_ERROR) &&
1022 !(phba->pport->load_flag & FC_UNLOADING)) 1029 !(phba->pport->load_flag & FC_UNLOADING))
1023 mod_timer(&phba->hb_tmofunc, 1030 mod_timer(&phba->hb_tmofunc,
1024 jiffies + HZ * LPFC_HB_MBOX_INTERVAL); 1031 jiffies +
1032 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1025 return; 1033 return;
1026} 1034}
1027 1035
@@ -1064,15 +1072,18 @@ lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1064 1072
1065 spin_lock_irq(&phba->pport->work_port_lock); 1073 spin_lock_irq(&phba->pport->work_port_lock);
1066 1074
1067 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, 1075 if (time_after(phba->last_completion_time +
1068 jiffies)) { 1076 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL),
1077 jiffies)) {
1069 spin_unlock_irq(&phba->pport->work_port_lock); 1078 spin_unlock_irq(&phba->pport->work_port_lock);
1070 if (!phba->hb_outstanding) 1079 if (!phba->hb_outstanding)
1071 mod_timer(&phba->hb_tmofunc, 1080 mod_timer(&phba->hb_tmofunc,
1072 jiffies + HZ * LPFC_HB_MBOX_INTERVAL); 1081 jiffies +
1082 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
1073 else 1083 else
1074 mod_timer(&phba->hb_tmofunc, 1084 mod_timer(&phba->hb_tmofunc,
1075 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); 1085 jiffies +
1086 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1076 return; 1087 return;
1077 } 1088 }
1078 spin_unlock_irq(&phba->pport->work_port_lock); 1089 spin_unlock_irq(&phba->pport->work_port_lock);
@@ -1104,7 +1115,8 @@ lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1104 if (!pmboxq) { 1115 if (!pmboxq) {
1105 mod_timer(&phba->hb_tmofunc, 1116 mod_timer(&phba->hb_tmofunc,
1106 jiffies + 1117 jiffies +
1107 HZ * LPFC_HB_MBOX_INTERVAL); 1118 msecs_to_jiffies(1000 *
1119 LPFC_HB_MBOX_INTERVAL));
1108 return; 1120 return;
1109 } 1121 }
1110 1122
@@ -1120,7 +1132,8 @@ lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1120 phba->mbox_mem_pool); 1132 phba->mbox_mem_pool);
1121 mod_timer(&phba->hb_tmofunc, 1133 mod_timer(&phba->hb_tmofunc,
1122 jiffies + 1134 jiffies +
1123 HZ * LPFC_HB_MBOX_INTERVAL); 1135 msecs_to_jiffies(1000 *
1136 LPFC_HB_MBOX_INTERVAL));
1124 return; 1137 return;
1125 } 1138 }
1126 phba->skipped_hb = 0; 1139 phba->skipped_hb = 0;
@@ -1136,7 +1149,8 @@ lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1136 phba->skipped_hb = jiffies; 1149 phba->skipped_hb = jiffies;
1137 1150
1138 mod_timer(&phba->hb_tmofunc, 1151 mod_timer(&phba->hb_tmofunc,
1139 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); 1152 jiffies +
1153 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1140 return; 1154 return;
1141 } else { 1155 } else {
1142 /* 1156 /*
@@ -1150,7 +1164,8 @@ lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1150 jiffies_to_msecs(jiffies 1164 jiffies_to_msecs(jiffies
1151 - phba->last_completion_time)); 1165 - phba->last_completion_time));
1152 mod_timer(&phba->hb_tmofunc, 1166 mod_timer(&phba->hb_tmofunc,
1153 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); 1167 jiffies +
1168 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT));
1154 } 1169 }
1155 } 1170 }
1156} 1171}
@@ -1191,7 +1206,7 @@ lpfc_offline_eratt(struct lpfc_hba *phba)
1191 * This routine is called to bring a SLI4 HBA offline when HBA hardware error 1206 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1192 * other than Port Error 6 has been detected. 1207 * other than Port Error 6 has been detected.
1193 **/ 1208 **/
1194static void 1209void
1195lpfc_sli4_offline_eratt(struct lpfc_hba *phba) 1210lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
1196{ 1211{
1197 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); 1212 lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT);
@@ -2633,6 +2648,7 @@ lpfc_online(struct lpfc_hba *phba)
2633 struct lpfc_vport *vport; 2648 struct lpfc_vport *vport;
2634 struct lpfc_vport **vports; 2649 struct lpfc_vport **vports;
2635 int i; 2650 int i;
2651 bool vpis_cleared = false;
2636 2652
2637 if (!phba) 2653 if (!phba)
2638 return 0; 2654 return 0;
@@ -2656,6 +2672,10 @@ lpfc_online(struct lpfc_hba *phba)
2656 lpfc_unblock_mgmt_io(phba); 2672 lpfc_unblock_mgmt_io(phba);
2657 return 1; 2673 return 1;
2658 } 2674 }
2675 spin_lock_irq(&phba->hbalock);
2676 if (!phba->sli4_hba.max_cfg_param.vpi_used)
2677 vpis_cleared = true;
2678 spin_unlock_irq(&phba->hbalock);
2659 } else { 2679 } else {
2660 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ 2680 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2661 lpfc_unblock_mgmt_io(phba); 2681 lpfc_unblock_mgmt_io(phba);
@@ -2672,8 +2692,13 @@ lpfc_online(struct lpfc_hba *phba)
2672 vports[i]->fc_flag &= ~FC_OFFLINE_MODE; 2692 vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
2673 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) 2693 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2674 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 2694 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2675 if (phba->sli_rev == LPFC_SLI_REV4) 2695 if (phba->sli_rev == LPFC_SLI_REV4) {
2676 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; 2696 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
2697 if ((vpis_cleared) &&
2698 (vports[i]->port_type !=
2699 LPFC_PHYSICAL_PORT))
2700 vports[i]->vpi = 0;
2701 }
2677 spin_unlock_irq(shost->host_lock); 2702 spin_unlock_irq(shost->host_lock);
2678 } 2703 }
2679 lpfc_destroy_vport_work_array(phba, vports); 2704 lpfc_destroy_vport_work_array(phba, vports);
@@ -2833,16 +2858,30 @@ lpfc_scsi_free(struct lpfc_hba *phba)
2833 struct lpfc_iocbq *io, *io_next; 2858 struct lpfc_iocbq *io, *io_next;
2834 2859
2835 spin_lock_irq(&phba->hbalock); 2860 spin_lock_irq(&phba->hbalock);
2861
2836 /* Release all the lpfc_scsi_bufs maintained by this host. */ 2862 /* Release all the lpfc_scsi_bufs maintained by this host. */
2837 spin_lock(&phba->scsi_buf_list_lock); 2863
2838 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { 2864 spin_lock(&phba->scsi_buf_list_put_lock);
2865 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put,
2866 list) {
2839 list_del(&sb->list); 2867 list_del(&sb->list);
2840 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, 2868 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
2841 sb->dma_handle); 2869 sb->dma_handle);
2842 kfree(sb); 2870 kfree(sb);
2843 phba->total_scsi_bufs--; 2871 phba->total_scsi_bufs--;
2844 } 2872 }
2845 spin_unlock(&phba->scsi_buf_list_lock); 2873 spin_unlock(&phba->scsi_buf_list_put_lock);
2874
2875 spin_lock(&phba->scsi_buf_list_get_lock);
2876 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get,
2877 list) {
2878 list_del(&sb->list);
2879 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
2880 sb->dma_handle);
2881 kfree(sb);
2882 phba->total_scsi_bufs--;
2883 }
2884 spin_unlock(&phba->scsi_buf_list_get_lock);
2846 2885
2847 /* Release all the lpfc_iocbq entries maintained by this host. */ 2886 /* Release all the lpfc_iocbq entries maintained by this host. */
2848 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { 2887 list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
@@ -2978,9 +3017,12 @@ lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
2978 phba->sli4_hba.scsi_xri_cnt, 3017 phba->sli4_hba.scsi_xri_cnt,
2979 phba->sli4_hba.scsi_xri_max); 3018 phba->sli4_hba.scsi_xri_max);
2980 3019
2981 spin_lock_irq(&phba->scsi_buf_list_lock); 3020 spin_lock_irq(&phba->scsi_buf_list_get_lock);
2982 list_splice_init(&phba->lpfc_scsi_buf_list, &scsi_sgl_list); 3021 spin_lock_irq(&phba->scsi_buf_list_put_lock);
2983 spin_unlock_irq(&phba->scsi_buf_list_lock); 3022 list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list);
3023 list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list);
3024 spin_unlock_irq(&phba->scsi_buf_list_put_lock);
3025 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
2984 3026
2985 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { 3027 if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) {
2986 /* max scsi xri shrinked below the allocated scsi buffers */ 3028 /* max scsi xri shrinked below the allocated scsi buffers */
@@ -2994,9 +3036,9 @@ lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
2994 psb->dma_handle); 3036 psb->dma_handle);
2995 kfree(psb); 3037 kfree(psb);
2996 } 3038 }
2997 spin_lock_irq(&phba->scsi_buf_list_lock); 3039 spin_lock_irq(&phba->scsi_buf_list_get_lock);
2998 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; 3040 phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt;
2999 spin_unlock_irq(&phba->scsi_buf_list_lock); 3041 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3000 } 3042 }
3001 3043
3002 /* update xris associated to remaining allocated scsi buffers */ 3044 /* update xris associated to remaining allocated scsi buffers */
@@ -3014,9 +3056,12 @@ lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba)
3014 psb->cur_iocbq.sli4_lxritag = lxri; 3056 psb->cur_iocbq.sli4_lxritag = lxri;
3015 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; 3057 psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri];
3016 } 3058 }
3017 spin_lock_irq(&phba->scsi_buf_list_lock); 3059 spin_lock_irq(&phba->scsi_buf_list_get_lock);
3018 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list); 3060 spin_lock_irq(&phba->scsi_buf_list_put_lock);
3019 spin_unlock_irq(&phba->scsi_buf_list_lock); 3061 list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get);
3062 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
3063 spin_unlock_irq(&phba->scsi_buf_list_put_lock);
3064 spin_unlock_irq(&phba->scsi_buf_list_get_lock);
3020 3065
3021 return 0; 3066 return 0;
3022 3067
@@ -3197,14 +3242,15 @@ int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3197 stat = 1; 3242 stat = 1;
3198 goto finished; 3243 goto finished;
3199 } 3244 }
3200 if (time >= 30 * HZ) { 3245 if (time >= msecs_to_jiffies(30 * 1000)) {
3201 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 3246 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3202 "0461 Scanning longer than 30 " 3247 "0461 Scanning longer than 30 "
3203 "seconds. Continuing initialization\n"); 3248 "seconds. Continuing initialization\n");
3204 stat = 1; 3249 stat = 1;
3205 goto finished; 3250 goto finished;
3206 } 3251 }
3207 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { 3252 if (time >= msecs_to_jiffies(15 * 1000) &&
3253 phba->link_state <= LPFC_LINK_DOWN) {
3208 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 3254 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3209 "0465 Link down longer than 15 " 3255 "0465 Link down longer than 15 "
3210 "seconds. Continuing initialization\n"); 3256 "seconds. Continuing initialization\n");
@@ -3216,7 +3262,7 @@ int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
3216 goto finished; 3262 goto finished;
3217 if (vport->num_disc_nodes || vport->fc_prli_sent) 3263 if (vport->num_disc_nodes || vport->fc_prli_sent)
3218 goto finished; 3264 goto finished;
3219 if (vport->fc_map_cnt == 0 && time < 2 * HZ) 3265 if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000))
3220 goto finished; 3266 goto finished;
3221 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) 3267 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
3222 goto finished; 3268 goto finished;
@@ -4215,7 +4261,8 @@ lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
4215 * If there are other active VLinks present, 4261 * If there are other active VLinks present,
4216 * re-instantiate the Vlink using FDISC. 4262 * re-instantiate the Vlink using FDISC.
4217 */ 4263 */
4218 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); 4264 mod_timer(&ndlp->nlp_delayfunc,
4265 jiffies + msecs_to_jiffies(1000));
4219 shost = lpfc_shost_from_vport(vport); 4266 shost = lpfc_shost_from_vport(vport);
4220 spin_lock_irq(shost->host_lock); 4267 spin_lock_irq(shost->host_lock);
4221 ndlp->nlp_flag |= NLP_DELAY_TMO; 4268 ndlp->nlp_flag |= NLP_DELAY_TMO;
@@ -4707,23 +4754,52 @@ lpfc_sli_driver_resource_setup(struct lpfc_hba *phba)
4707 return -ENOMEM; 4754 return -ENOMEM;
4708 4755
4709 /* 4756 /*
4710 * Since the sg_tablesize is module parameter, the sg_dma_buf_size 4757 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
4711 * used to create the sg_dma_buf_pool must be dynamically calculated. 4758 * used to create the sg_dma_buf_pool must be dynamically calculated.
4712 * 2 segments are added since the IOCB needs a command and response bde.
4713 */ 4759 */
4714 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4715 sizeof(struct fcp_rsp) +
4716 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
4717 4760
4761 /* Initialize the host templates the configured values. */
4762 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4763 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4764
4765 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
4718 if (phba->cfg_enable_bg) { 4766 if (phba->cfg_enable_bg) {
4719 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; 4767 /*
4720 phba->cfg_sg_dma_buf_size += 4768 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
4721 phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); 4769 * the FCP rsp, and a BDE for each. Sice we have no control
4770 * over how many protection data segments the SCSI Layer
4771 * will hand us (ie: there could be one for every block
4772 * in the IO), we just allocate enough BDEs to accomidate
4773 * our max amount and we need to limit lpfc_sg_seg_cnt to
4774 * minimize the risk of running out.
4775 */
4776 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4777 sizeof(struct fcp_rsp) +
4778 (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64));
4779
4780 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF)
4781 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF;
4782
4783 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
4784 phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT;
4785 } else {
4786 /*
4787 * The scsi_buf for a regular I/O will hold the FCP cmnd,
4788 * the FCP rsp, a BDE for each, and a BDE for up to
4789 * cfg_sg_seg_cnt data segments.
4790 */
4791 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4792 sizeof(struct fcp_rsp) +
4793 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
4794
4795 /* Total BDEs in BPL for scsi_sg_list */
4796 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
4722 } 4797 }
4723 4798
4724 /* Also reinitialize the host templates with new values. */ 4799 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
4725 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; 4800 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
4726 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; 4801 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
4802 phba->cfg_total_seg_cnt);
4727 4803
4728 phba->max_vpi = LPFC_MAX_VPI; 4804 phba->max_vpi = LPFC_MAX_VPI;
4729 /* This will be set to correct value after config_port mbox */ 4805 /* This will be set to correct value after config_port mbox */
@@ -4789,13 +4865,13 @@ lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
4789static int 4865static int
4790lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) 4866lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4791{ 4867{
4868 struct lpfc_vector_map_info *cpup;
4792 struct lpfc_sli *psli; 4869 struct lpfc_sli *psli;
4793 LPFC_MBOXQ_t *mboxq; 4870 LPFC_MBOXQ_t *mboxq;
4794 int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size; 4871 int rc, i, hbq_count, max_buf_size;
4795 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; 4872 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
4796 struct lpfc_mqe *mqe; 4873 struct lpfc_mqe *mqe;
4797 int longs, sli_family; 4874 int longs;
4798 int sges_per_segment;
4799 4875
4800 /* Before proceed, wait for POST done and device ready */ 4876 /* Before proceed, wait for POST done and device ready */
4801 rc = lpfc_sli4_post_status_check(phba); 4877 rc = lpfc_sli4_post_status_check(phba);
@@ -4863,11 +4939,6 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4863 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; 4939 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
4864 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; 4940 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
4865 4941
4866 /* With BlockGuard we can have multiple SGEs per Data Segemnt */
4867 sges_per_segment = 1;
4868 if (phba->cfg_enable_bg)
4869 sges_per_segment = 2;
4870
4871 /* 4942 /*
4872 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands 4943 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
4873 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple. 4944 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
@@ -4878,43 +4949,71 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
4878 sizeof(struct lpfc_sli_ring), GFP_KERNEL); 4949 sizeof(struct lpfc_sli_ring), GFP_KERNEL);
4879 if (!phba->sli.ring) 4950 if (!phba->sli.ring)
4880 return -ENOMEM; 4951 return -ENOMEM;
4952
4881 /* 4953 /*
4882 * Since the sg_tablesize is module parameter, the sg_dma_buf_size 4954 * It doesn't matter what family our adapter is in, we are
4955 * limited to 2 Pages, 512 SGEs, for our SGL.
4956 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
4957 */
4958 max_buf_size = (2 * SLI4_PAGE_SIZE);
4959 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2)
4960 phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2;
4961
4962 /*
4963 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
4883 * used to create the sg_dma_buf_pool must be dynamically calculated. 4964 * used to create the sg_dma_buf_pool must be dynamically calculated.
4884 * 2 segments are added since the IOCB needs a command and response bde.
4885 * To insure that the scsi sgl does not cross a 4k page boundary only
4886 * sgl sizes of must be a power of 2.
4887 */ 4965 */
4888 buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) + 4966
4889 (((phba->cfg_sg_seg_cnt * sges_per_segment) + 2) * 4967 if (phba->cfg_enable_bg) {
4890 sizeof(struct sli4_sge))); 4968 /*
4891 4969 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
4892 sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf); 4970 * the FCP rsp, and a SGE for each. Sice we have no control
4893 max_buf_size = LPFC_SLI4_MAX_BUF_SIZE; 4971 * over how many protection data segments the SCSI Layer
4894 switch (sli_family) { 4972 * will hand us (ie: there could be one for every block
4895 case LPFC_SLI_INTF_FAMILY_BE2: 4973 * in the IO), we just allocate enough SGEs to accomidate
4896 case LPFC_SLI_INTF_FAMILY_BE3: 4974 * our max amount and we need to limit lpfc_sg_seg_cnt to
4897 /* There is a single hint for BE - 2 pages per BPL. */ 4975 * minimize the risk of running out.
4898 if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) == 4976 */
4899 LPFC_SLI_INTF_SLI_HINT1_1) 4977 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4900 max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE; 4978 sizeof(struct fcp_rsp) + max_buf_size;
4901 break; 4979
4902 case LPFC_SLI_INTF_FAMILY_LNCR_A0: 4980 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
4903 case LPFC_SLI_INTF_FAMILY_LNCR_B0: 4981 phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT;
4904 default: 4982
4905 break; 4983 if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF)
4984 phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF;
4985 } else {
4986 /*
4987 * The scsi_buf for a regular I/O will hold the FCP cmnd,
4988 * the FCP rsp, a SGE for each, and a SGE for up to
4989 * cfg_sg_seg_cnt data segments.
4990 */
4991 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
4992 sizeof(struct fcp_rsp) +
4993 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
4994
4995 /* Total SGEs for scsi_sg_list */
4996 phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2;
4997 /*
4998 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
4999 * to post 1 page for the SGL.
5000 */
4906 } 5001 }
4907 5002
4908 for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE; 5003 /* Initialize the host templates with the updated values. */
4909 dma_buf_size < max_buf_size && buf_size > dma_buf_size; 5004 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4910 dma_buf_size = dma_buf_size << 1) 5005 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
4911 ; 5006
4912 if (dma_buf_size == max_buf_size) 5007 if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ)
4913 phba->cfg_sg_seg_cnt = (dma_buf_size - 5008 phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ;
4914 sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) - 5009 else
4915 (2 * sizeof(struct sli4_sge))) / 5010 phba->cfg_sg_dma_buf_size =
4916 sizeof(struct sli4_sge); 5011 SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size);
4917 phba->cfg_sg_dma_buf_size = dma_buf_size; 5012
5013 lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP,
5014 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5015 phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size,
5016 phba->cfg_total_seg_cnt);
4918 5017
4919 /* Initialize buffer queue management fields */ 5018 /* Initialize buffer queue management fields */
4920 hbq_count = lpfc_sli_hbq_count(); 5019 hbq_count = lpfc_sli_hbq_count();
@@ -5104,6 +5203,26 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5104 goto out_free_fcp_eq_hdl; 5203 goto out_free_fcp_eq_hdl;
5105 } 5204 }
5106 5205
5206 phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) *
5207 phba->sli4_hba.num_present_cpu),
5208 GFP_KERNEL);
5209 if (!phba->sli4_hba.cpu_map) {
5210 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5211 "3327 Failed allocate memory for msi-x "
5212 "interrupt vector mapping\n");
5213 rc = -ENOMEM;
5214 goto out_free_msix;
5215 }
5216 /* Initialize io channels for round robin */
5217 cpup = phba->sli4_hba.cpu_map;
5218 rc = 0;
5219 for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) {
5220 cpup->channel_id = rc;
5221 rc++;
5222 if (rc >= phba->cfg_fcp_io_channel)
5223 rc = 0;
5224 }
5225
5107 /* 5226 /*
5108 * Enable sr-iov virtual functions if supported and configured 5227 * Enable sr-iov virtual functions if supported and configured
5109 * through the module parameter. 5228 * through the module parameter.
@@ -5123,6 +5242,8 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
5123 5242
5124 return 0; 5243 return 0;
5125 5244
5245out_free_msix:
5246 kfree(phba->sli4_hba.msix_entries);
5126out_free_fcp_eq_hdl: 5247out_free_fcp_eq_hdl:
5127 kfree(phba->sli4_hba.fcp_eq_hdl); 5248 kfree(phba->sli4_hba.fcp_eq_hdl);
5128out_free_fcf_rr_bmask: 5249out_free_fcf_rr_bmask:
@@ -5152,6 +5273,11 @@ lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
5152{ 5273{
5153 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; 5274 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5154 5275
5276 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5277 kfree(phba->sli4_hba.cpu_map);
5278 phba->sli4_hba.num_present_cpu = 0;
5279 phba->sli4_hba.num_online_cpu = 0;
5280
5155 /* Free memory allocated for msi-x interrupt vector entries */ 5281 /* Free memory allocated for msi-x interrupt vector entries */
5156 kfree(phba->sli4_hba.msix_entries); 5282 kfree(phba->sli4_hba.msix_entries);
5157 5283
@@ -5260,8 +5386,10 @@ lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba)
5260 init_waitqueue_head(&phba->work_waitq); 5386 init_waitqueue_head(&phba->work_waitq);
5261 5387
5262 /* Initialize the scsi buffer list used by driver for scsi IO */ 5388 /* Initialize the scsi buffer list used by driver for scsi IO */
5263 spin_lock_init(&phba->scsi_buf_list_lock); 5389 spin_lock_init(&phba->scsi_buf_list_get_lock);
5264 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); 5390 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get);
5391 spin_lock_init(&phba->scsi_buf_list_put_lock);
5392 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put);
5265 5393
5266 /* Initialize the fabric iocb list */ 5394 /* Initialize the fabric iocb list */
5267 INIT_LIST_HEAD(&phba->fabric_iocb_list); 5395 INIT_LIST_HEAD(&phba->fabric_iocb_list);
@@ -6696,6 +6824,7 @@ lpfc_sli4_queue_verify(struct lpfc_hba *phba)
6696 int cfg_fcp_io_channel; 6824 int cfg_fcp_io_channel;
6697 uint32_t cpu; 6825 uint32_t cpu;
6698 uint32_t i = 0; 6826 uint32_t i = 0;
6827 uint32_t j = 0;
6699 6828
6700 6829
6701 /* 6830 /*
@@ -6706,15 +6835,21 @@ lpfc_sli4_queue_verify(struct lpfc_hba *phba)
6706 /* Sanity check on HBA EQ parameters */ 6835 /* Sanity check on HBA EQ parameters */
6707 cfg_fcp_io_channel = phba->cfg_fcp_io_channel; 6836 cfg_fcp_io_channel = phba->cfg_fcp_io_channel;
6708 6837
6709 /* It doesn't make sense to have more io channels then CPUs */ 6838 /* It doesn't make sense to have more io channels then online CPUs */
6710 for_each_online_cpu(cpu) { 6839 for_each_present_cpu(cpu) {
6711 i++; 6840 if (cpu_online(cpu))
6841 i++;
6842 j++;
6712 } 6843 }
6844 phba->sli4_hba.num_online_cpu = i;
6845 phba->sli4_hba.num_present_cpu = j;
6846
6713 if (i < cfg_fcp_io_channel) { 6847 if (i < cfg_fcp_io_channel) {
6714 lpfc_printf_log(phba, 6848 lpfc_printf_log(phba,
6715 KERN_ERR, LOG_INIT, 6849 KERN_ERR, LOG_INIT,
6716 "3188 Reducing IO channels to match number of " 6850 "3188 Reducing IO channels to match number of "
6717 "CPUs: from %d to %d\n", cfg_fcp_io_channel, i); 6851 "online CPUs: from %d to %d\n",
6852 cfg_fcp_io_channel, i);
6718 cfg_fcp_io_channel = i; 6853 cfg_fcp_io_channel = i;
6719 } 6854 }
6720 6855
@@ -7743,8 +7878,13 @@ lpfc_pci_function_reset(struct lpfc_hba *phba)
7743 7878
7744out: 7879out:
7745 /* Catch the not-ready port failure after a port reset. */ 7880 /* Catch the not-ready port failure after a port reset. */
7746 if (num_resets >= MAX_IF_TYPE_2_RESETS) 7881 if (num_resets >= MAX_IF_TYPE_2_RESETS) {
7882 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7883 "3317 HBA not functional: IP Reset Failed "
7884 "after (%d) retries, try: "
7885 "echo fw_reset > board_mode\n", num_resets);
7747 rc = -ENODEV; 7886 rc = -ENODEV;
7887 }
7748 7888
7749 return rc; 7889 return rc;
7750} 7890}
@@ -8209,6 +8349,269 @@ lpfc_sli_disable_intr(struct lpfc_hba *phba)
8209} 8349}
8210 8350
8211/** 8351/**
8352 * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
8353 * @phba: pointer to lpfc hba data structure.
8354 *
8355 * Find next available CPU to use for IRQ to CPU affinity.
8356 */
8357static int
8358lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id)
8359{
8360 struct lpfc_vector_map_info *cpup;
8361 int cpu;
8362
8363 cpup = phba->sli4_hba.cpu_map;
8364 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8365 /* CPU must be online */
8366 if (cpu_online(cpu)) {
8367 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8368 (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) &&
8369 (cpup->phys_id == phys_id)) {
8370 return cpu;
8371 }
8372 }
8373 cpup++;
8374 }
8375
8376 /*
8377 * If we get here, we have used ALL CPUs for the specific
8378 * phys_id. Now we need to clear out lpfc_used_cpu and start
8379 * reusing CPUs.
8380 */
8381
8382 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8383 if (lpfc_used_cpu[cpu] == phys_id)
8384 lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
8385 }
8386
8387 cpup = phba->sli4_hba.cpu_map;
8388 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8389 /* CPU must be online */
8390 if (cpu_online(cpu)) {
8391 if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) &&
8392 (cpup->phys_id == phys_id)) {
8393 return cpu;
8394 }
8395 }
8396 cpup++;
8397 }
8398 return LPFC_VECTOR_MAP_EMPTY;
8399}
8400
8401/**
8402 * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
8403 * @phba: pointer to lpfc hba data structure.
8404 * @vectors: number of HBA vectors
8405 *
8406 * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
8407 * affinization across multple physical CPUs (numa nodes).
8408 * In addition, this routine will assign an IO channel for each CPU
8409 * to use when issuing I/Os.
8410 */
8411static int
8412lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors)
8413{
8414 int i, idx, saved_chann, used_chann, cpu, phys_id;
8415 int max_phys_id, num_io_channel, first_cpu;
8416 struct lpfc_vector_map_info *cpup;
8417#ifdef CONFIG_X86
8418 struct cpuinfo_x86 *cpuinfo;
8419#endif
8420 struct cpumask *mask;
8421 uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1];
8422
8423 /* If there is no mapping, just return */
8424 if (!phba->cfg_fcp_cpu_map)
8425 return 1;
8426
8427 /* Init cpu_map array */
8428 memset(phba->sli4_hba.cpu_map, 0xff,
8429 (sizeof(struct lpfc_vector_map_info) *
8430 phba->sli4_hba.num_present_cpu));
8431
8432 max_phys_id = 0;
8433 phys_id = 0;
8434 num_io_channel = 0;
8435 first_cpu = LPFC_VECTOR_MAP_EMPTY;
8436
8437 /* Update CPU map with physical id and core id of each CPU */
8438 cpup = phba->sli4_hba.cpu_map;
8439 for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) {
8440#ifdef CONFIG_X86
8441 cpuinfo = &cpu_data(cpu);
8442 cpup->phys_id = cpuinfo->phys_proc_id;
8443 cpup->core_id = cpuinfo->cpu_core_id;
8444#else
8445 /* No distinction between CPUs for other platforms */
8446 cpup->phys_id = 0;
8447 cpup->core_id = 0;
8448#endif
8449
8450 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8451 "3328 CPU physid %d coreid %d\n",
8452 cpup->phys_id, cpup->core_id);
8453
8454 if (cpup->phys_id > max_phys_id)
8455 max_phys_id = cpup->phys_id;
8456 cpup++;
8457 }
8458
8459 /* Now associate the HBA vectors with specific CPUs */
8460 for (idx = 0; idx < vectors; idx++) {
8461 cpup = phba->sli4_hba.cpu_map;
8462 cpu = lpfc_find_next_cpu(phba, phys_id);
8463 if (cpu == LPFC_VECTOR_MAP_EMPTY) {
8464
8465 /* Try for all phys_id's */
8466 for (i = 1; i < max_phys_id; i++) {
8467 phys_id++;
8468 if (phys_id > max_phys_id)
8469 phys_id = 0;
8470 cpu = lpfc_find_next_cpu(phba, phys_id);
8471 if (cpu == LPFC_VECTOR_MAP_EMPTY)
8472 continue;
8473 goto found;
8474 }
8475
8476 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8477 "3329 Cannot set affinity:"
8478 "Error mapping vector %d (%d)\n",
8479 idx, vectors);
8480 return 0;
8481 }
8482found:
8483 cpup += cpu;
8484 if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP)
8485 lpfc_used_cpu[cpu] = phys_id;
8486
8487 /* Associate vector with selected CPU */
8488 cpup->irq = phba->sli4_hba.msix_entries[idx].vector;
8489
8490 /* Associate IO channel with selected CPU */
8491 cpup->channel_id = idx;
8492 num_io_channel++;
8493
8494 if (first_cpu == LPFC_VECTOR_MAP_EMPTY)
8495 first_cpu = cpu;
8496
8497 /* Now affinitize to the selected CPU */
8498 mask = &cpup->maskbits;
8499 cpumask_clear(mask);
8500 cpumask_set_cpu(cpu, mask);
8501 i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx].
8502 vector, mask);
8503
8504 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8505 "3330 Set Affinity: CPU %d channel %d "
8506 "irq %d (%x)\n",
8507 cpu, cpup->channel_id,
8508 phba->sli4_hba.msix_entries[idx].vector, i);
8509
8510 /* Spread vector mapping across multple physical CPU nodes */
8511 phys_id++;
8512 if (phys_id > max_phys_id)
8513 phys_id = 0;
8514 }
8515
8516 /*
8517 * Finally fill in the IO channel for any remaining CPUs.
8518 * At this point, all IO channels have been assigned to a specific
8519 * MSIx vector, mapped to a specific CPU.
8520 * Base the remaining IO channel assigned, to IO channels already
8521 * assigned to other CPUs on the same phys_id.
8522 */
8523 for (i = 0; i <= max_phys_id; i++) {
8524 /*
8525 * If there are no io channels already mapped to
8526 * this phys_id, just round robin thru the io_channels.
8527 * Setup chann[] for round robin.
8528 */
8529 for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++)
8530 chann[idx] = idx;
8531
8532 saved_chann = 0;
8533 used_chann = 0;
8534
8535 /*
8536 * First build a list of IO channels already assigned
8537 * to this phys_id before reassigning the same IO
8538 * channels to the remaining CPUs.
8539 */
8540 cpup = phba->sli4_hba.cpu_map;
8541 cpu = first_cpu;
8542 cpup += cpu;
8543 for (idx = 0; idx < phba->sli4_hba.num_present_cpu;
8544 idx++) {
8545 if (cpup->phys_id == i) {
8546 /*
8547 * Save any IO channels that are
8548 * already mapped to this phys_id.
8549 */
8550 if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) {
8551 chann[saved_chann] =
8552 cpup->channel_id;
8553 saved_chann++;
8554 goto out;
8555 }
8556
8557 /* See if we are using round-robin */
8558 if (saved_chann == 0)
8559 saved_chann =
8560 phba->cfg_fcp_io_channel;
8561
8562 /* Associate next IO channel with CPU */
8563 cpup->channel_id = chann[used_chann];
8564 num_io_channel++;
8565 used_chann++;
8566 if (used_chann == saved_chann)
8567 used_chann = 0;
8568
8569 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8570 "3331 Set IO_CHANN "
8571 "CPU %d channel %d\n",
8572 idx, cpup->channel_id);
8573 }
8574out:
8575 cpu++;
8576 if (cpu >= phba->sli4_hba.num_present_cpu) {
8577 cpup = phba->sli4_hba.cpu_map;
8578 cpu = 0;
8579 } else {
8580 cpup++;
8581 }
8582 }
8583 }
8584
8585 if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) {
8586 cpup = phba->sli4_hba.cpu_map;
8587 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
8588 if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) {
8589 cpup->channel_id = 0;
8590 num_io_channel++;
8591
8592 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
8593 "3332 Assign IO_CHANN "
8594 "CPU %d channel %d\n",
8595 idx, cpup->channel_id);
8596 }
8597 cpup++;
8598 }
8599 }
8600
8601 /* Sanity check */
8602 if (num_io_channel != phba->sli4_hba.num_present_cpu)
8603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
8604 "3333 Set affinity mismatch:"
8605 "%d chann != %d cpus: %d vactors\n",
8606 num_io_channel, phba->sli4_hba.num_present_cpu,
8607 vectors);
8608
8609 phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU;
8610 return 1;
8611}
8612
8613
8614/**
8212 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device 8615 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8213 * @phba: pointer to lpfc hba data structure. 8616 * @phba: pointer to lpfc hba data structure.
8214 * 8617 *
@@ -8259,9 +8662,7 @@ enable_msix_vectors:
8259 phba->sli4_hba.msix_entries[index].vector, 8662 phba->sli4_hba.msix_entries[index].vector,
8260 phba->sli4_hba.msix_entries[index].entry); 8663 phba->sli4_hba.msix_entries[index].entry);
8261 8664
8262 /* 8665 /* Assign MSI-X vectors to interrupt handlers */
8263 * Assign MSI-X vectors to interrupt handlers
8264 */
8265 for (index = 0; index < vectors; index++) { 8666 for (index = 0; index < vectors; index++) {
8266 memset(&phba->sli4_hba.handler_name[index], 0, 16); 8667 memset(&phba->sli4_hba.handler_name[index], 0, 16);
8267 sprintf((char *)&phba->sli4_hba.handler_name[index], 8668 sprintf((char *)&phba->sli4_hba.handler_name[index],
@@ -8289,6 +8690,8 @@ enable_msix_vectors:
8289 phba->cfg_fcp_io_channel, vectors); 8690 phba->cfg_fcp_io_channel, vectors);
8290 phba->cfg_fcp_io_channel = vectors; 8691 phba->cfg_fcp_io_channel = vectors;
8291 } 8692 }
8693
8694 lpfc_sli4_set_affinity(phba, vectors);
8292 return rc; 8695 return rc;
8293 8696
8294cfg_fail_out: 8697cfg_fail_out:
@@ -9213,15 +9616,15 @@ lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba)
9213 /* Block all SCSI devices' I/Os on the host */ 9616 /* Block all SCSI devices' I/Os on the host */
9214 lpfc_scsi_dev_block(phba); 9617 lpfc_scsi_dev_block(phba);
9215 9618
9619 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9620 lpfc_sli_flush_fcp_rings(phba);
9621
9216 /* stop all timers */ 9622 /* stop all timers */
9217 lpfc_stop_hba_timers(phba); 9623 lpfc_stop_hba_timers(phba);
9218 9624
9219 /* Disable interrupt and pci device */ 9625 /* Disable interrupt and pci device */
9220 lpfc_sli_disable_intr(phba); 9626 lpfc_sli_disable_intr(phba);
9221 pci_disable_device(phba->pcidev); 9627 pci_disable_device(phba->pcidev);
9222
9223 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9224 lpfc_sli_flush_fcp_rings(phba);
9225} 9628}
9226 9629
9227/** 9630/**
@@ -9966,6 +10369,9 @@ lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
9966 /* Block all SCSI devices' I/Os on the host */ 10369 /* Block all SCSI devices' I/Os on the host */
9967 lpfc_scsi_dev_block(phba); 10370 lpfc_scsi_dev_block(phba);
9968 10371
10372 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10373 lpfc_sli_flush_fcp_rings(phba);
10374
9969 /* stop all timers */ 10375 /* stop all timers */
9970 lpfc_stop_hba_timers(phba); 10376 lpfc_stop_hba_timers(phba);
9971 10377
@@ -9973,9 +10379,6 @@ lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba)
9973 lpfc_sli4_disable_intr(phba); 10379 lpfc_sli4_disable_intr(phba);
9974 lpfc_sli4_queue_destroy(phba); 10380 lpfc_sli4_queue_destroy(phba);
9975 pci_disable_device(phba->pcidev); 10381 pci_disable_device(phba->pcidev);
9976
9977 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9978 lpfc_sli_flush_fcp_rings(phba);
9979} 10382}
9980 10383
9981/** 10384/**
@@ -10535,6 +10938,7 @@ static struct miscdevice lpfc_mgmt_dev = {
10535static int __init 10938static int __init
10536lpfc_init(void) 10939lpfc_init(void)
10537{ 10940{
10941 int cpu;
10538 int error = 0; 10942 int error = 0;
10539 10943
10540 printk(LPFC_MODULE_DESC "\n"); 10944 printk(LPFC_MODULE_DESC "\n");
@@ -10561,6 +10965,11 @@ lpfc_init(void)
10561 return -ENOMEM; 10965 return -ENOMEM;
10562 } 10966 }
10563 } 10967 }
10968
10969 /* Initialize in case vector mapping is needed */
10970 for (cpu = 0; cpu < LPFC_MAX_CPU; cpu++)
10971 lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY;
10972
10564 error = pci_register_driver(&lpfc_driver); 10973 error = pci_register_driver(&lpfc_driver);
10565 if (error) { 10974 if (error) {
10566 fc_release_transport(lpfc_transport_template); 10975 fc_release_transport(lpfc_transport_template);