| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 128bdda | 2018-01-30 15:59:03 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| 23 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/dma-mapping.h> |
| 27 | #include <linux/idr.h> |
| 28 | #include <linux/interrupt.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 29 | #include <linux/module.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | #include <linux/kthread.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/spinlock.h> |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 33 | #include <linux/ctype.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 34 | #include <linux/aer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 36 | #include <linux/firmware.h> |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 37 | #include <linux/miscdevice.h> |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 38 | #include <linux/percpu.h> |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 39 | #include <linux/msi.h> |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 40 | #include <linux/bitops.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 41 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 42 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 43 | #include <scsi/scsi_device.h> |
| 44 | #include <scsi/scsi_host.h> |
| 45 | #include <scsi/scsi_transport_fc.h> |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 46 | #include <scsi/scsi_tcq.h> |
| 47 | #include <scsi/fc/fc_fs.h> |
| 48 | |
| 49 | #include <linux/nvme-fc-driver.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 50 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 51 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 52 | #include "lpfc_hw.h" |
| 53 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 54 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 55 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 56 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 57 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 58 | #include "lpfc_scsi.h" |
| 59 | #include "lpfc_nvme.h" |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 60 | #include "lpfc_nvmet.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 61 | #include "lpfc_logmsg.h" |
| 62 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 63 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 64 | #include "lpfc_version.h" |
James Smart | 12f4445 | 2016-07-06 12:36:03 -0700 | [diff] [blame] | 65 | #include "lpfc_ids.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 66 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 67 | char *_dump_buf_data; |
| 68 | unsigned long _dump_buf_data_order; |
| 69 | char *_dump_buf_dif; |
| 70 | unsigned long _dump_buf_dif_order; |
| 71 | spinlock_t _dump_buf_lock; |
| 72 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 73 | /* Used when mapping IRQ vectors in a driver centric manner */ |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 74 | uint16_t *lpfc_used_cpu; |
| 75 | uint32_t lpfc_present_cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 76 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 77 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 78 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 79 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 80 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
| 81 | static int lpfc_setup_endian_order(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 82 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 83 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 84 | static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 85 | static void lpfc_init_sgl_list(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 86 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); |
| 87 | static void lpfc_free_active_sgl(struct lpfc_hba *); |
| 88 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); |
| 89 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); |
| 90 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); |
| 91 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); |
| 92 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 93 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
| 94 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 95 | static void lpfc_sli4_oas_verify(struct lpfc_hba *phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 96 | |
| 97 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 98 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 99 | static DEFINE_IDR(lpfc_hba_index); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 100 | #define LPFC_NVMET_BUF_POST 254 |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 101 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 102 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 103 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 104 | * @phba: pointer to lpfc hba data structure. |
| 105 | * |
| 106 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 107 | * mailbox command. It retrieves the revision information from the HBA and |
| 108 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 109 | * configuration of the HBA. |
| 110 | * |
| 111 | * Return codes: |
| 112 | * 0 - success. |
| 113 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 114 | * Any other value - indicates an error. |
| 115 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 117 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | { |
| 119 | lpfc_vpd_t *vp = &phba->vpd; |
| 120 | int i = 0, rc; |
| 121 | LPFC_MBOXQ_t *pmb; |
| 122 | MAILBOX_t *mb; |
| 123 | char *lpfc_vpd_data = NULL; |
| 124 | uint16_t offset = 0; |
| 125 | static char licensed[56] = |
| 126 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 127 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 128 | |
| 129 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 130 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 131 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 132 | return -ENOMEM; |
| 133 | } |
| 134 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 135 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 136 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 137 | |
| 138 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 139 | if (init_key) { |
| 140 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 141 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 142 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 143 | *ptext = cpu_to_be32(*ptext); |
| 144 | init_key = 0; |
| 145 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 146 | |
| 147 | lpfc_read_nv(phba, pmb); |
| 148 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 149 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 150 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 151 | sizeof (licensed)); |
| 152 | |
| 153 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 154 | |
| 155 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 156 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 157 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 | "error, mbxCmd x%x READ_NVPARM, " |
| 159 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | mb->mbxCommand, mb->mbxStatus); |
| 161 | mempool_free(pmb, phba->mbox_mem_pool); |
| 162 | return -ERESTART; |
| 163 | } |
| 164 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 165 | sizeof(phba->wwnn)); |
| 166 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 167 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 168 | } |
| 169 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 170 | phba->sli3_options = 0x0; |
| 171 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 172 | /* Setup and issue mailbox READ REV command */ |
| 173 | lpfc_read_rev(phba, pmb); |
| 174 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 175 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 176 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 177 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 178 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 179 | mb->mbxCommand, mb->mbxStatus); |
| 180 | mempool_free( pmb, phba->mbox_mem_pool); |
| 181 | return -ERESTART; |
| 182 | } |
| 183 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 184 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 185 | /* |
| 186 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 187 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 188 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 189 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 190 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 191 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 192 | "0440 Adapter failed to init, READ_REV has " |
| 193 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 194 | mempool_free(pmb, phba->mbox_mem_pool); |
| 195 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 196 | } |
| 197 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 198 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 199 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 200 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 201 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 203 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 204 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 205 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 206 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 207 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 208 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 209 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 211 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 212 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 213 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 214 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 215 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 216 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 217 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 218 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 219 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 220 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 221 | /* If the sli feature level is less then 9, we must |
| 222 | * tear down all RPIs and VPIs on link down if NPIV |
| 223 | * is enabled. |
| 224 | */ |
| 225 | if (vp->rev.feaLevelHigh < 9) |
| 226 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 227 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 228 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 229 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 230 | sizeof (phba->RandomData)); |
| 231 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 232 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 233 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 234 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 235 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 236 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 237 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 239 | |
| 240 | if (rc != MBX_SUCCESS) { |
| 241 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 242 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 245 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 246 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 247 | /* dump mem may return a zero when finished or we got a |
| 248 | * mailbox error, either way we are done. |
| 249 | */ |
| 250 | if (mb->un.varDmp.word_cnt == 0) |
| 251 | break; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 252 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 253 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 254 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 255 | lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 256 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 257 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 258 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 259 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 260 | |
| 261 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 262 | out_free_mbox: |
| 263 | mempool_free(pmb, phba->mbox_mem_pool); |
| 264 | return 0; |
| 265 | } |
| 266 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 267 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 268 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 269 | * @phba: pointer to lpfc hba data structure. |
| 270 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 271 | * |
| 272 | * This is the completion handler for driver's configuring asynchronous event |
| 273 | * mailbox command to the device. If the mailbox command returns successfully, |
| 274 | * it will set internal async event support flag to 1; otherwise, it will |
| 275 | * set internal async event support flag to 0. |
| 276 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 277 | static void |
| 278 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 279 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 280 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 281 | phba->temp_sensor_support = 1; |
| 282 | else |
| 283 | phba->temp_sensor_support = 0; |
| 284 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 285 | return; |
| 286 | } |
| 287 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 288 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 289 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 290 | * @phba: pointer to lpfc hba data structure. |
| 291 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 292 | * |
| 293 | * This is the completion handler for dump mailbox command for getting |
| 294 | * wake up parameters. When this command complete, the response contain |
| 295 | * Option rom version of the HBA. This function translate the version number |
| 296 | * into a human readable string and store it in OptionROMVersion. |
| 297 | **/ |
| 298 | static void |
| 299 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 300 | { |
| 301 | struct prog_id *prg; |
| 302 | uint32_t prog_id_word; |
| 303 | char dist = ' '; |
| 304 | /* character array used for decoding dist type. */ |
| 305 | char dist_char[] = "nabx"; |
| 306 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 307 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 308 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 309 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 310 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 311 | |
| 312 | prg = (struct prog_id *) &prog_id_word; |
| 313 | |
| 314 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 315 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 316 | |
| 317 | /* Decode the Option rom version word to a readable string */ |
| 318 | if (prg->dist < 4) |
| 319 | dist = dist_char[prg->dist]; |
| 320 | |
| 321 | if ((prg->dist == 3) && (prg->num == 0)) |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 322 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 323 | prg->ver, prg->rev, prg->lev); |
| 324 | else |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 325 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 326 | prg->ver, prg->rev, prg->lev, |
| 327 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 328 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 329 | return; |
| 330 | } |
| 331 | |
| 332 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 333 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 334 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 335 | * @vport: pointer to lpfc vport data structure. |
| 336 | * |
| 337 | * |
| 338 | * Return codes |
| 339 | * None. |
| 340 | **/ |
| 341 | void |
| 342 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 343 | { |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 344 | uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level; |
| 345 | u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0]; |
| 346 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 347 | /* If the soft name exists then update it using the service params */ |
| 348 | if (vport->phba->cfg_soft_wwnn) |
| 349 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 350 | vport->fc_sparam.nodeName.u.wwn); |
| 351 | if (vport->phba->cfg_soft_wwpn) |
| 352 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 353 | vport->fc_sparam.portName.u.wwn); |
| 354 | |
| 355 | /* |
| 356 | * If the name is empty or there exists a soft name |
| 357 | * then copy the service params name, otherwise use the fc name |
| 358 | */ |
| 359 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 360 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 361 | sizeof(struct lpfc_name)); |
| 362 | else |
| 363 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 364 | sizeof(struct lpfc_name)); |
| 365 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 366 | /* |
| 367 | * If the port name has changed, then set the Param changes flag |
| 368 | * to unreg the login |
| 369 | */ |
| 370 | if (vport->fc_portname.u.wwn[0] != 0 && |
| 371 | memcmp(&vport->fc_portname, &vport->fc_sparam.portName, |
| 372 | sizeof(struct lpfc_name))) |
| 373 | vport->vport_flag |= FAWWPN_PARAM_CHG; |
| 374 | |
| 375 | if (vport->fc_portname.u.wwn[0] == 0 || |
| 376 | vport->phba->cfg_soft_wwpn || |
| 377 | (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) || |
| 378 | vport->vport_flag & FAWWPN_SET) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 379 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 380 | sizeof(struct lpfc_name)); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 381 | vport->vport_flag &= ~FAWWPN_SET; |
| 382 | if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) |
| 383 | vport->vport_flag |= FAWWPN_SET; |
| 384 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 385 | else |
| 386 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 387 | sizeof(struct lpfc_name)); |
| 388 | } |
| 389 | |
| 390 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 391 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 392 | * @phba: pointer to lpfc hba data structure. |
| 393 | * |
| 394 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 395 | * command call. It performs all internal resource and state setups on the |
| 396 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 397 | * ELS ring timers, etc. |
| 398 | * |
| 399 | * Return codes |
| 400 | * 0 - success. |
| 401 | * Any other value - error. |
| 402 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 403 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 404 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 405 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 406 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 407 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 408 | LPFC_MBOXQ_t *pmb; |
| 409 | MAILBOX_t *mb; |
| 410 | struct lpfc_dmabuf *mp; |
| 411 | struct lpfc_sli *psli = &phba->sli; |
| 412 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 413 | int i, j; |
| 414 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 415 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 416 | spin_lock_irq(&phba->hbalock); |
| 417 | /* |
| 418 | * If the Config port completed correctly the HBA is not |
| 419 | * over heated any more. |
| 420 | */ |
| 421 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 422 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 423 | spin_unlock_irq(&phba->hbalock); |
| 424 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 425 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 426 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 427 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 428 | return -ENOMEM; |
| 429 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 430 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 431 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 432 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 433 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 434 | if (rc) { |
| 435 | mempool_free(pmb, phba->mbox_mem_pool); |
| 436 | return -ENOMEM; |
| 437 | } |
| 438 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 439 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 440 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 441 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 442 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 443 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 444 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 445 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 446 | mp = (struct lpfc_dmabuf *) pmb->context1; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 447 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 448 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 449 | kfree(mp); |
| 450 | return -EIO; |
| 451 | } |
| 452 | |
| 453 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 454 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 455 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 456 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 457 | kfree(mp); |
| 458 | pmb->context1 = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 459 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 460 | |
| 461 | /* Update the fc_host data structures with new wwn. */ |
| 462 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 463 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 464 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 465 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 466 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 467 | /* This should be consolidated into parse_vpd ? - mr */ |
| 468 | if (phba->SerialNumber[0] == 0) { |
| 469 | uint8_t *outptr; |
| 470 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 471 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 472 | for (i = 0; i < 12; i++) { |
| 473 | status = *outptr++; |
| 474 | j = ((status & 0xf0) >> 4); |
| 475 | if (j <= 9) |
| 476 | phba->SerialNumber[i] = |
| 477 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 478 | else |
| 479 | phba->SerialNumber[i] = |
| 480 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 481 | i++; |
| 482 | j = (status & 0xf); |
| 483 | if (j <= 9) |
| 484 | phba->SerialNumber[i] = |
| 485 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 486 | else |
| 487 | phba->SerialNumber[i] = |
| 488 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 489 | } |
| 490 | } |
| 491 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 492 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 493 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 494 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 495 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 496 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 497 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 498 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 499 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 500 | mempool_free( pmb, phba->mbox_mem_pool); |
| 501 | return -EIO; |
| 502 | } |
| 503 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 504 | /* Check if the port is disabled */ |
| 505 | lpfc_sli_read_link_ste(phba); |
| 506 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 507 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 508 | i = (mb->un.varRdConfig.max_xri + 1); |
| 509 | if (phba->cfg_hba_queue_depth > i) { |
| 510 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 511 | "3359 HBA queue depth changed from %d to %d\n", |
| 512 | phba->cfg_hba_queue_depth, i); |
| 513 | phba->cfg_hba_queue_depth = i; |
| 514 | } |
| 515 | |
| 516 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ |
| 517 | i = (mb->un.varRdConfig.max_xri >> 3); |
| 518 | if (phba->pport->cfg_lun_queue_depth > i) { |
| 519 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 520 | "3360 LUN queue depth changed from %d to %d\n", |
| 521 | phba->pport->cfg_lun_queue_depth, i); |
| 522 | phba->pport->cfg_lun_queue_depth = i; |
| 523 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 524 | |
| 525 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 526 | |
| 527 | /* Get the default values for Model Name and Description */ |
| 528 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 529 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 530 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 531 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 532 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 533 | if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr) |
| 534 | psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 535 | if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr) |
| 536 | psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 537 | |
| 538 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 539 | if (phba->sli_rev != 3) |
| 540 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 541 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 542 | /* |
| 543 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 544 | */ |
| 545 | if (phba->intr_type == MSIX) { |
| 546 | rc = lpfc_config_msi(phba, pmb); |
| 547 | if (rc) { |
| 548 | mempool_free(pmb, phba->mbox_mem_pool); |
| 549 | return -EIO; |
| 550 | } |
| 551 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 552 | if (rc != MBX_SUCCESS) { |
| 553 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 554 | "0352 Config MSI mailbox command " |
| 555 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 556 | pmb->u.mb.mbxCommand, |
| 557 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 558 | mempool_free(pmb, phba->mbox_mem_pool); |
| 559 | return -EIO; |
| 560 | } |
| 561 | } |
| 562 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 563 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 564 | /* Initialize ERATT handling flag */ |
| 565 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 566 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 567 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 568 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 569 | spin_unlock_irq(&phba->hbalock); |
| 570 | return -EIO; |
| 571 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 572 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 573 | if (psli->num_rings > 0) |
| 574 | status |= HC_R0INT_ENA; |
| 575 | if (psli->num_rings > 1) |
| 576 | status |= HC_R1INT_ENA; |
| 577 | if (psli->num_rings > 2) |
| 578 | status |= HC_R2INT_ENA; |
| 579 | if (psli->num_rings > 3) |
| 580 | status |= HC_R3INT_ENA; |
| 581 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 582 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 583 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 584 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 585 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 586 | writel(status, phba->HCregaddr); |
| 587 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 588 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 589 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 590 | /* Set up ring-0 (ELS) timer */ |
| 591 | timeout = phba->fc_ratov * 2; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 592 | mod_timer(&vport->els_tmofunc, |
| 593 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 594 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 595 | mod_timer(&phba->hb_tmofunc, |
| 596 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 597 | phba->hb_outstanding = 0; |
| 598 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 599 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 600 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 601 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 602 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 603 | if (phba->hba_flag & LINK_DISABLED) { |
| 604 | lpfc_printf_log(phba, |
| 605 | KERN_ERR, LOG_INIT, |
| 606 | "2598 Adapter Link is disabled.\n"); |
| 607 | lpfc_down_link(phba, pmb); |
| 608 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 609 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 610 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 611 | lpfc_printf_log(phba, |
| 612 | KERN_ERR, LOG_INIT, |
| 613 | "2599 Adapter failed to issue DOWN_LINK" |
| 614 | " mbox command rc 0x%x\n", rc); |
| 615 | |
| 616 | mempool_free(pmb, phba->mbox_mem_pool); |
| 617 | return -EIO; |
| 618 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 619 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 620 | mempool_free(pmb, phba->mbox_mem_pool); |
| 621 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 622 | if (rc) |
| 623 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 624 | } |
| 625 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 626 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 627 | if (!pmb) { |
| 628 | phba->link_state = LPFC_HBA_ERROR; |
| 629 | return -ENOMEM; |
| 630 | } |
| 631 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 632 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 633 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 634 | pmb->vport = phba->pport; |
| 635 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 636 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 637 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 638 | lpfc_printf_log(phba, |
| 639 | KERN_ERR, |
| 640 | LOG_INIT, |
| 641 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 642 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 643 | rc); |
| 644 | mempool_free(pmb, phba->mbox_mem_pool); |
| 645 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 646 | |
| 647 | /* Get Option rom version */ |
| 648 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 649 | if (!pmb) { |
| 650 | phba->link_state = LPFC_HBA_ERROR; |
| 651 | return -ENOMEM; |
| 652 | } |
| 653 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 654 | lpfc_dump_wakeup_param(phba, pmb); |
| 655 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 656 | pmb->vport = phba->pport; |
| 657 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 658 | |
| 659 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 660 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 661 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 662 | mempool_free(pmb, phba->mbox_mem_pool); |
| 663 | } |
| 664 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 665 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 666 | } |
| 667 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 668 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 669 | * lpfc_hba_init_link - Initialize the FC link |
| 670 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 671 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 672 | * |
| 673 | * This routine will issue the INIT_LINK mailbox command call. |
| 674 | * It is available to other drivers through the lpfc_hba data |
| 675 | * structure for use as a delayed link up mechanism with the |
| 676 | * module parameter lpfc_suppress_link_up. |
| 677 | * |
| 678 | * Return code |
| 679 | * 0 - success |
| 680 | * Any other value - error |
| 681 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 682 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 683 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 684 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 685 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 690 | * @phba: pointer to lpfc hba data structure. |
| 691 | * @fc_topology: desired fc topology. |
| 692 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 693 | * |
| 694 | * This routine will issue the INIT_LINK mailbox command call. |
| 695 | * It is available to other drivers through the lpfc_hba data |
| 696 | * structure for use as a delayed link up mechanism with the |
| 697 | * module parameter lpfc_suppress_link_up. |
| 698 | * |
| 699 | * Return code |
| 700 | * 0 - success |
| 701 | * Any other value - error |
| 702 | **/ |
| 703 | int |
| 704 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 705 | uint32_t flag) |
| 706 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 707 | struct lpfc_vport *vport = phba->pport; |
| 708 | LPFC_MBOXQ_t *pmb; |
| 709 | MAILBOX_t *mb; |
| 710 | int rc; |
| 711 | |
| 712 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 713 | if (!pmb) { |
| 714 | phba->link_state = LPFC_HBA_ERROR; |
| 715 | return -ENOMEM; |
| 716 | } |
| 717 | mb = &pmb->u.mb; |
| 718 | pmb->vport = vport; |
| 719 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 720 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 721 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 722 | !(phba->lmt & LMT_1Gb)) || |
| 723 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 724 | !(phba->lmt & LMT_2Gb)) || |
| 725 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 726 | !(phba->lmt & LMT_4Gb)) || |
| 727 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 728 | !(phba->lmt & LMT_8Gb)) || |
| 729 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 730 | !(phba->lmt & LMT_10Gb)) || |
| 731 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 732 | !(phba->lmt & LMT_16Gb)) || |
| 733 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) && |
| 734 | !(phba->lmt & LMT_32Gb))) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 735 | /* Reset link speed to auto */ |
| 736 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 737 | "1302 Invalid speed for this board:%d " |
| 738 | "Reset link speed to auto.\n", |
| 739 | phba->cfg_link_speed); |
| 740 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 741 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 742 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 743 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 744 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 745 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 746 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 747 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 748 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 749 | "0498 Adapter failed to init, mbxCmd x%x " |
| 750 | "INIT_LINK, mbxStatus x%x\n", |
| 751 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 752 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 753 | /* Clear all interrupt enable conditions */ |
| 754 | writel(0, phba->HCregaddr); |
| 755 | readl(phba->HCregaddr); /* flush */ |
| 756 | /* Clear all pending interrupts */ |
| 757 | writel(0xffffffff, phba->HAregaddr); |
| 758 | readl(phba->HAregaddr); /* flush */ |
| 759 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 760 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 761 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 762 | mempool_free(pmb, phba->mbox_mem_pool); |
| 763 | return -EIO; |
| 764 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 765 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 766 | if (flag == MBX_POLL) |
| 767 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 768 | |
| 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 774 | * @phba: pointer to lpfc hba data structure. |
| 775 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 776 | * |
| 777 | * This routine will issue the DOWN_LINK mailbox command call. |
| 778 | * It is available to other drivers through the lpfc_hba data |
| 779 | * structure for use to stop the link. |
| 780 | * |
| 781 | * Return code |
| 782 | * 0 - success |
| 783 | * Any other value - error |
| 784 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 785 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 786 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 787 | { |
| 788 | LPFC_MBOXQ_t *pmb; |
| 789 | int rc; |
| 790 | |
| 791 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 792 | if (!pmb) { |
| 793 | phba->link_state = LPFC_HBA_ERROR; |
| 794 | return -ENOMEM; |
| 795 | } |
| 796 | |
| 797 | lpfc_printf_log(phba, |
| 798 | KERN_ERR, LOG_INIT, |
| 799 | "0491 Adapter Link is disabled.\n"); |
| 800 | lpfc_down_link(phba, pmb); |
| 801 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 802 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 803 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 804 | lpfc_printf_log(phba, |
| 805 | KERN_ERR, LOG_INIT, |
| 806 | "2522 Adapter failed to issue DOWN_LINK" |
| 807 | " mbox command rc 0x%x\n", rc); |
| 808 | |
| 809 | mempool_free(pmb, phba->mbox_mem_pool); |
| 810 | return -EIO; |
| 811 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 812 | if (flag == MBX_POLL) |
| 813 | mempool_free(pmb, phba->mbox_mem_pool); |
| 814 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 819 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 820 | * @phba: pointer to lpfc HBA data structure. |
| 821 | * |
| 822 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 823 | * bringing down the SLI Layer. |
| 824 | * |
| 825 | * Return codes |
| 826 | * 0 - success. |
| 827 | * Any other value - error. |
| 828 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 829 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 830 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 831 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 832 | struct lpfc_vport **vports; |
| 833 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 834 | |
| 835 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 836 | /* Disable interrupts */ |
| 837 | writel(0, phba->HCregaddr); |
| 838 | readl(phba->HCregaddr); /* flush */ |
| 839 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 840 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 841 | if (phba->pport->load_flag & FC_UNLOADING) |
| 842 | lpfc_cleanup_discovery_resources(phba->pport); |
| 843 | else { |
| 844 | vports = lpfc_create_vport_work_array(phba); |
| 845 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 846 | for (i = 0; i <= phba->max_vports && |
| 847 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 848 | lpfc_cleanup_discovery_resources(vports[i]); |
| 849 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 850 | } |
| 851 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 852 | } |
| 853 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 854 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 855 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 856 | * rspiocb which got deferred |
| 857 | * |
| 858 | * @phba: pointer to lpfc HBA data structure. |
| 859 | * |
| 860 | * This routine will cleanup completed slow path events after HBA is reset |
| 861 | * when bringing down the SLI Layer. |
| 862 | * |
| 863 | * |
| 864 | * Return codes |
| 865 | * void. |
| 866 | **/ |
| 867 | static void |
| 868 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 869 | { |
| 870 | struct lpfc_iocbq *rspiocbq; |
| 871 | struct hbq_dmabuf *dmabuf; |
| 872 | struct lpfc_cq_event *cq_event; |
| 873 | |
| 874 | spin_lock_irq(&phba->hbalock); |
| 875 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 876 | spin_unlock_irq(&phba->hbalock); |
| 877 | |
| 878 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 879 | /* Get the response iocb from the head of work queue */ |
| 880 | spin_lock_irq(&phba->hbalock); |
| 881 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 882 | cq_event, struct lpfc_cq_event, list); |
| 883 | spin_unlock_irq(&phba->hbalock); |
| 884 | |
| 885 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 886 | case CQE_CODE_COMPL_WQE: |
| 887 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 888 | cq_event); |
| 889 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 890 | break; |
| 891 | case CQE_CODE_RECEIVE: |
| 892 | case CQE_CODE_RECEIVE_V1: |
| 893 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 894 | cq_event); |
| 895 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 901 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 902 | * @phba: pointer to lpfc HBA data structure. |
| 903 | * |
| 904 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 905 | * when bringing down the SLI Layer. |
| 906 | * |
| 907 | * |
| 908 | * Return codes |
| 909 | * void. |
| 910 | **/ |
| 911 | static void |
| 912 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 913 | { |
| 914 | struct lpfc_sli *psli = &phba->sli; |
| 915 | struct lpfc_sli_ring *pring; |
| 916 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 917 | LIST_HEAD(buflist); |
| 918 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 919 | |
| 920 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 921 | lpfc_sli_hbqbuf_free_all(phba); |
| 922 | else { |
| 923 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 924 | pring = &psli->sli3_ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 925 | spin_lock_irq(&phba->hbalock); |
| 926 | list_splice_init(&pring->postbufq, &buflist); |
| 927 | spin_unlock_irq(&phba->hbalock); |
| 928 | |
| 929 | count = 0; |
| 930 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 931 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 932 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 933 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 934 | kfree(mp); |
| 935 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 936 | |
| 937 | spin_lock_irq(&phba->hbalock); |
| 938 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 939 | spin_unlock_irq(&phba->hbalock); |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 945 | * @phba: pointer to lpfc HBA data structure. |
| 946 | * |
| 947 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 948 | * down the SLI Layer. |
| 949 | * |
| 950 | * Return codes |
| 951 | * void |
| 952 | **/ |
| 953 | static void |
| 954 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 955 | { |
| 956 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 957 | struct lpfc_queue *qp = NULL; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 958 | struct lpfc_sli_ring *pring; |
| 959 | LIST_HEAD(completions); |
| 960 | int i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 961 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 962 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 963 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 964 | for (i = 0; i < psli->num_rings; i++) { |
| 965 | pring = &psli->sli3_ring[i]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 966 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 967 | /* At this point in time the HBA is either reset or DOA |
| 968 | * Nothing should be on txcmplq as it will |
| 969 | * NEVER complete. |
| 970 | */ |
| 971 | list_splice_init(&pring->txcmplq, &completions); |
| 972 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 973 | spin_unlock_irq(&phba->hbalock); |
| 974 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 975 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 976 | } |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 977 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 978 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 979 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
| 980 | return; |
| 981 | } |
| 982 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 983 | pring = qp->pring; |
| 984 | if (!pring) |
| 985 | continue; |
| 986 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 987 | list_for_each_entry_safe(piocb, next_iocb, |
| 988 | &pring->txcmplq, list) |
| 989 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 990 | list_splice_init(&pring->txcmplq, &completions); |
| 991 | pring->txcmplq_cnt = 0; |
| 992 | spin_unlock_irq(&pring->ring_lock); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 993 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 994 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 995 | /* Cancel all the IOCBs from the completions list */ |
| 996 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 997 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1001 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1002 | int i; |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1003 | * @phba: pointer to lpfc HBA data structure. |
| 1004 | * |
| 1005 | * This routine will do uninitialization after the HBA is reset when bring |
| 1006 | * down the SLI Layer. |
| 1007 | * |
| 1008 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1009 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1010 | * Any other value - error. |
| 1011 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1012 | static int |
| 1013 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1014 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1015 | lpfc_hba_free_post_buf(phba); |
| 1016 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1017 | return 0; |
| 1018 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 1019 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1020 | /** |
| 1021 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 1022 | * @phba: pointer to lpfc HBA data structure. |
| 1023 | * |
| 1024 | * This routine will do uninitialization after the HBA is reset when bring |
| 1025 | * down the SLI Layer. |
| 1026 | * |
| 1027 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1028 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1029 | * Any other value - error. |
| 1030 | **/ |
| 1031 | static int |
| 1032 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 1033 | { |
| 1034 | struct lpfc_scsi_buf *psb, *psb_next; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1035 | struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1036 | LIST_HEAD(aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1037 | LIST_HEAD(nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1038 | LIST_HEAD(nvmet_aborts); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1039 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1040 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1041 | int cnt; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1042 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1043 | |
| 1044 | lpfc_sli_hbqbuf_free_all(phba); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1045 | lpfc_hba_clean_txcmplq(phba); |
| 1046 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1047 | /* At this point in time the HBA is either reset or DOA. Either |
| 1048 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1049 | * on the lpfc_els_sgl_list so that it can either be freed if the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1050 | * driver is unloading or reposted if the driver is restarting |
| 1051 | * the port. |
| 1052 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1053 | spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1054 | /* scsl_buf_list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1055 | /* sgl_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1056 | * list. |
| 1057 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1058 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1059 | list_for_each_entry(sglq_entry, |
| 1060 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1061 | sglq_entry->state = SGL_FREED; |
| 1062 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1063 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1064 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1065 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1066 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1067 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1068 | /* abts_scsi_buf_list_lock required because worker thread uses this |
| 1069 | * list. |
| 1070 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1071 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 1072 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 1073 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, |
| 1074 | &aborts); |
| 1075 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 1076 | } |
| 1077 | |
| 1078 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 1079 | spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); |
| 1080 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list, |
| 1081 | &nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1082 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list, |
| 1083 | &nvmet_aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1084 | spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); |
| 1085 | } |
| 1086 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1087 | spin_unlock_irq(&phba->hbalock); |
| 1088 | |
| 1089 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
| 1090 | psb->pCmd = NULL; |
| 1091 | psb->status = IOSTAT_SUCCESS; |
| 1092 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1093 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 1094 | list_splice(&aborts, &phba->lpfc_scsi_buf_list_put); |
| 1095 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1096 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1097 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1098 | cnt = 0; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1099 | list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) { |
| 1100 | psb->pCmd = NULL; |
| 1101 | psb->status = IOSTAT_SUCCESS; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1102 | cnt++; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1103 | } |
| 1104 | spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1105 | phba->put_nvme_bufs += cnt; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1106 | list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put); |
| 1107 | spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag); |
| 1108 | |
| 1109 | list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) { |
| 1110 | ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 1111 | lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1112 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1113 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1114 | |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1115 | lpfc_sli4_free_sp_events(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1116 | return 0; |
| 1117 | } |
| 1118 | |
| 1119 | /** |
| 1120 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1121 | * @phba: pointer to lpfc HBA data structure. |
| 1122 | * |
| 1123 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1124 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1125 | * |
| 1126 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1127 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1128 | * Any other value - error. |
| 1129 | **/ |
| 1130 | int |
| 1131 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1132 | { |
| 1133 | return (*phba->lpfc_hba_down_post)(phba); |
| 1134 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1135 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1136 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1137 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1138 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1139 | * |
| 1140 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1141 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1142 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1143 | * event will be used by the worker thread to invoke the actual timeout |
| 1144 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1145 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1146 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1147 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1148 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1149 | lpfc_hb_timeout(struct timer_list *t) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1150 | { |
| 1151 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1152 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1153 | unsigned long iflag; |
| 1154 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1155 | phba = from_timer(phba, t, hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1156 | |
| 1157 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1158 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1159 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1160 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1161 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1162 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1163 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1164 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1165 | if (!tmo_posted) |
| 1166 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1167 | return; |
| 1168 | } |
| 1169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1170 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1171 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 1172 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1173 | * |
| 1174 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1175 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1176 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1177 | * event will be used by the worker thread to invoke the actual timeout |
| 1178 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1179 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1180 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1181 | **/ |
| 1182 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1183 | lpfc_rrq_timeout(struct timer_list *t) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1184 | { |
| 1185 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1186 | unsigned long iflag; |
| 1187 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1188 | phba = from_timer(phba, t, rrq_tmr); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1189 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1190 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1191 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1192 | else |
| 1193 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1194 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1195 | |
| 1196 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1197 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1201 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1202 | * @phba: pointer to lpfc hba data structure. |
| 1203 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1204 | * |
| 1205 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1206 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1207 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1208 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1209 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1210 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1211 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1212 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1213 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1214 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1215 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1216 | static void |
| 1217 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1218 | { |
| 1219 | unsigned long drvr_flag; |
| 1220 | |
| 1221 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1222 | phba->hb_outstanding = 0; |
| 1223 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1224 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1225 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1226 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1227 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1228 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1229 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1230 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1231 | jiffies + |
| 1232 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1233 | return; |
| 1234 | } |
| 1235 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1236 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1237 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1238 | * @phba: pointer to lpfc hba data structure. |
| 1239 | * |
| 1240 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1241 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1242 | * handler performs any periodic operations needed for the device. If such |
| 1243 | * periodic event has already been attended to either in the interrupt handler |
| 1244 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1245 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1246 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1247 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1248 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1249 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1250 | * to offline. |
| 1251 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1252 | void |
| 1253 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1254 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1255 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1256 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1257 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1258 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1259 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1260 | LIST_HEAD(completions); |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 1261 | struct lpfc_queue *qp; |
| 1262 | unsigned long time_elapsed; |
| 1263 | uint32_t tick_cqe, max_cqe, val; |
| 1264 | uint64_t tot, data1, data2, data3; |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 1265 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 1266 | struct lpfc_register reg_data; |
| 1267 | void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1268 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1269 | vports = lpfc_create_vport_work_array(phba); |
| 1270 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1271 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1272 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1273 | lpfc_fdmi_num_disc_check(vports[i]); |
| 1274 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1275 | lpfc_destroy_vport_work_array(phba, vports); |
| 1276 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1277 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1278 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1279 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1280 | return; |
| 1281 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 1282 | if (phba->cfg_auto_imax) { |
| 1283 | if (!phba->last_eqdelay_time) { |
| 1284 | phba->last_eqdelay_time = jiffies; |
| 1285 | goto skip_eqdelay; |
| 1286 | } |
| 1287 | time_elapsed = jiffies - phba->last_eqdelay_time; |
| 1288 | phba->last_eqdelay_time = jiffies; |
| 1289 | |
| 1290 | tot = 0xffff; |
| 1291 | /* Check outstanding IO count */ |
| 1292 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 1293 | if (phba->nvmet_support) { |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 1294 | tgtp = phba->targetport->private; |
| 1295 | /* Calculate outstanding IOs */ |
| 1296 | tot = atomic_read(&tgtp->rcv_fcp_cmd_drop); |
| 1297 | tot += atomic_read(&tgtp->xmt_fcp_release); |
| 1298 | tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 1299 | } else { |
| 1300 | tot = atomic_read(&phba->fc4NvmeIoCmpls); |
| 1301 | data1 = atomic_read( |
| 1302 | &phba->fc4NvmeInputRequests); |
| 1303 | data2 = atomic_read( |
| 1304 | &phba->fc4NvmeOutputRequests); |
| 1305 | data3 = atomic_read( |
| 1306 | &phba->fc4NvmeControlRequests); |
| 1307 | tot = (data1 + data2 + data3) - tot; |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | /* Interrupts per sec per EQ */ |
| 1312 | val = phba->cfg_fcp_imax / phba->io_channel_irqs; |
| 1313 | tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */ |
| 1314 | |
| 1315 | /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */ |
| 1316 | max_cqe = time_elapsed * tick_cqe; |
| 1317 | |
| 1318 | for (i = 0; i < phba->io_channel_irqs; i++) { |
| 1319 | /* Fast-path EQ */ |
| 1320 | qp = phba->sli4_hba.hba_eq[i]; |
| 1321 | if (!qp) |
| 1322 | continue; |
| 1323 | |
| 1324 | /* Use no EQ delay if we don't have many outstanding |
| 1325 | * IOs, or if we are only processing 1 CQE/ISR or less. |
| 1326 | * Otherwise, assume we can process up to lpfc_fcp_imax |
| 1327 | * interrupts per HBA. |
| 1328 | */ |
| 1329 | if (tot < LPFC_NODELAY_MAX_IO || |
| 1330 | qp->EQ_cqe_cnt <= max_cqe) |
| 1331 | val = 0; |
| 1332 | else |
| 1333 | val = phba->cfg_fcp_imax; |
| 1334 | |
| 1335 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 1336 | /* Use EQ Delay Register method */ |
| 1337 | |
| 1338 | /* Convert for EQ Delay register */ |
| 1339 | if (val) { |
| 1340 | /* First, interrupts per sec per EQ */ |
| 1341 | val = phba->cfg_fcp_imax / |
| 1342 | phba->io_channel_irqs; |
| 1343 | |
| 1344 | /* us delay between each interrupt */ |
| 1345 | val = LPFC_SEC_TO_USEC / val; |
| 1346 | } |
| 1347 | if (val != qp->q_mode) { |
| 1348 | reg_data.word0 = 0; |
| 1349 | bf_set(lpfc_sliport_eqdelay_id, |
| 1350 | ®_data, qp->queue_id); |
| 1351 | bf_set(lpfc_sliport_eqdelay_delay, |
| 1352 | ®_data, val); |
| 1353 | writel(reg_data.word0, eqdreg); |
| 1354 | } |
| 1355 | } else { |
| 1356 | /* Use mbox command method */ |
| 1357 | if (val != qp->q_mode) |
| 1358 | lpfc_modify_hba_eq_delay(phba, i, |
| 1359 | 1, val); |
| 1360 | } |
| 1361 | |
| 1362 | /* |
| 1363 | * val is cfg_fcp_imax or 0 for mbox delay or us delay |
| 1364 | * between interrupts for EQDR. |
| 1365 | */ |
| 1366 | qp->q_mode = val; |
| 1367 | qp->EQ_cqe_cnt = 0; |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | skip_eqdelay: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1372 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1373 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1374 | if (time_after(phba->last_completion_time + |
| 1375 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1376 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1377 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1378 | if (!phba->hb_outstanding) |
| 1379 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1380 | jiffies + |
| 1381 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1382 | else |
| 1383 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1384 | jiffies + |
| 1385 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1386 | return; |
| 1387 | } |
| 1388 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1389 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1390 | if (phba->elsbuf_cnt && |
| 1391 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1392 | spin_lock_irq(&phba->hbalock); |
| 1393 | list_splice_init(&phba->elsbuf, &completions); |
| 1394 | phba->elsbuf_cnt = 0; |
| 1395 | phba->elsbuf_prev_cnt = 0; |
| 1396 | spin_unlock_irq(&phba->hbalock); |
| 1397 | |
| 1398 | while (!list_empty(&completions)) { |
| 1399 | list_remove_head(&completions, buf_ptr, |
| 1400 | struct lpfc_dmabuf, list); |
| 1401 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1402 | kfree(buf_ptr); |
| 1403 | } |
| 1404 | } |
| 1405 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1406 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1407 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1408 | if (phba->cfg_enable_hba_heartbeat) { |
| 1409 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1410 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1411 | (list_empty(&psli->mboxq))) { |
| 1412 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1413 | GFP_KERNEL); |
| 1414 | if (!pmboxq) { |
| 1415 | mod_timer(&phba->hb_tmofunc, |
| 1416 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1417 | msecs_to_jiffies(1000 * |
| 1418 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1419 | return; |
| 1420 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1421 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1422 | lpfc_heart_beat(phba, pmboxq); |
| 1423 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1424 | pmboxq->vport = phba->pport; |
| 1425 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1426 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1427 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1428 | if (retval != MBX_BUSY && |
| 1429 | retval != MBX_SUCCESS) { |
| 1430 | mempool_free(pmboxq, |
| 1431 | phba->mbox_mem_pool); |
| 1432 | mod_timer(&phba->hb_tmofunc, |
| 1433 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1434 | msecs_to_jiffies(1000 * |
| 1435 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1436 | return; |
| 1437 | } |
| 1438 | phba->skipped_hb = 0; |
| 1439 | phba->hb_outstanding = 1; |
| 1440 | } else if (time_before_eq(phba->last_completion_time, |
| 1441 | phba->skipped_hb)) { |
| 1442 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1443 | "2857 Last completion time not " |
| 1444 | " updated in %d ms\n", |
| 1445 | jiffies_to_msecs(jiffies |
| 1446 | - phba->last_completion_time)); |
| 1447 | } else |
| 1448 | phba->skipped_hb = jiffies; |
| 1449 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1450 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1451 | jiffies + |
| 1452 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1453 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1454 | } else { |
| 1455 | /* |
| 1456 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1457 | * we need to give the hb mailbox cmd a chance to |
| 1458 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1459 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1460 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1461 | "0459 Adapter heartbeat still out" |
| 1462 | "standing:last compl time was %d ms.\n", |
| 1463 | jiffies_to_msecs(jiffies |
| 1464 | - phba->last_completion_time)); |
| 1465 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1466 | jiffies + |
| 1467 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1468 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1469 | } else { |
| 1470 | mod_timer(&phba->hb_tmofunc, |
| 1471 | jiffies + |
| 1472 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1473 | } |
| 1474 | } |
| 1475 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1476 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1477 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1478 | * @phba: pointer to lpfc hba data structure. |
| 1479 | * |
| 1480 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1481 | * other than Port Error 6 has been detected. |
| 1482 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1483 | static void |
| 1484 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1485 | { |
| 1486 | struct lpfc_sli *psli = &phba->sli; |
| 1487 | |
| 1488 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1489 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1490 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1491 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1492 | |
| 1493 | lpfc_offline(phba); |
| 1494 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1495 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1496 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1497 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1498 | lpfc_hba_down_post(phba); |
| 1499 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1500 | lpfc_unblock_mgmt_io(phba); |
| 1501 | phba->link_state = LPFC_HBA_ERROR; |
| 1502 | return; |
| 1503 | } |
| 1504 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1505 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1506 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1507 | * @phba: pointer to lpfc hba data structure. |
| 1508 | * |
| 1509 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1510 | * other than Port Error 6 has been detected. |
| 1511 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1512 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1513 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1514 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1515 | spin_lock_irq(&phba->hbalock); |
| 1516 | phba->link_state = LPFC_HBA_ERROR; |
| 1517 | spin_unlock_irq(&phba->hbalock); |
| 1518 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1519 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1520 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1521 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1522 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1526 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1527 | * @phba: pointer to lpfc hba data structure. |
| 1528 | * |
| 1529 | * This routine is invoked to handle the deferred HBA hardware error |
| 1530 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1531 | * and another ER bit in the host status register. The driver will |
| 1532 | * wait until the ER1 bit clears before handling the error condition. |
| 1533 | **/ |
| 1534 | static void |
| 1535 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1536 | { |
| 1537 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1538 | struct lpfc_sli *psli = &phba->sli; |
| 1539 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1540 | /* If the pci channel is offline, ignore possible errors, |
| 1541 | * since we cannot communicate with the pci card anyway. |
| 1542 | */ |
| 1543 | if (pci_channel_offline(phba->pcidev)) { |
| 1544 | spin_lock_irq(&phba->hbalock); |
| 1545 | phba->hba_flag &= ~DEFER_ERATT; |
| 1546 | spin_unlock_irq(&phba->hbalock); |
| 1547 | return; |
| 1548 | } |
| 1549 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1550 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1551 | "0479 Deferred Adapter Hardware Error " |
| 1552 | "Data: x%x x%x x%x\n", |
| 1553 | phba->work_hs, |
| 1554 | phba->work_status[0], phba->work_status[1]); |
| 1555 | |
| 1556 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1557 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1558 | spin_unlock_irq(&phba->hbalock); |
| 1559 | |
| 1560 | |
| 1561 | /* |
| 1562 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1563 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1564 | * SCSI layer retry it after re-establishing link. |
| 1565 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1566 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1567 | |
| 1568 | /* |
| 1569 | * There was a firmware error. Take the hba offline and then |
| 1570 | * attempt to restart it. |
| 1571 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1572 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1573 | lpfc_offline(phba); |
| 1574 | |
| 1575 | /* Wait for the ER1 bit to clear.*/ |
| 1576 | while (phba->work_hs & HS_FFER1) { |
| 1577 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1578 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1579 | phba->work_hs = UNPLUG_ERR ; |
| 1580 | break; |
| 1581 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1582 | /* If driver is unloading let the worker thread continue */ |
| 1583 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1584 | phba->work_hs = 0; |
| 1585 | break; |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | /* |
| 1590 | * This is to ptrotect against a race condition in which |
| 1591 | * first write to the host attention register clear the |
| 1592 | * host status register. |
| 1593 | */ |
| 1594 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1595 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1596 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1597 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1598 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1599 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1600 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1601 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1602 | } |
| 1603 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1604 | static void |
| 1605 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1606 | { |
| 1607 | struct lpfc_board_event_header board_event; |
| 1608 | struct Scsi_Host *shost; |
| 1609 | |
| 1610 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1611 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1612 | shost = lpfc_shost_from_vport(phba->pport); |
| 1613 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1614 | sizeof(board_event), |
| 1615 | (char *) &board_event, |
| 1616 | LPFC_NL_VENDOR_ID); |
| 1617 | } |
| 1618 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1619 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1620 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1621 | * @phba: pointer to lpfc hba data structure. |
| 1622 | * |
| 1623 | * This routine is invoked to handle the following HBA hardware error |
| 1624 | * conditions: |
| 1625 | * 1 - HBA error attention interrupt |
| 1626 | * 2 - DMA ring index out of range |
| 1627 | * 3 - Mailbox command came back as unknown |
| 1628 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1629 | static void |
| 1630 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1631 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1632 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1633 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1634 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1635 | unsigned long temperature; |
| 1636 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1637 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1638 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1639 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1640 | * since we cannot communicate with the pci card anyway. |
| 1641 | */ |
| 1642 | if (pci_channel_offline(phba->pcidev)) { |
| 1643 | spin_lock_irq(&phba->hbalock); |
| 1644 | phba->hba_flag &= ~DEFER_ERATT; |
| 1645 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1646 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1647 | } |
| 1648 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1649 | /* If resets are disabled then leave the HBA alone and return */ |
| 1650 | if (!phba->cfg_enable_hba_reset) |
| 1651 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1652 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1653 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1654 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1655 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1656 | if (phba->hba_flag & DEFER_ERATT) |
| 1657 | lpfc_handle_deferred_eratt(phba); |
| 1658 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1659 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1660 | if (phba->work_hs & HS_FFER6) |
| 1661 | /* Re-establishing Link */ |
| 1662 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1663 | "1301 Re-establishing Link " |
| 1664 | "Data: x%x x%x x%x\n", |
| 1665 | phba->work_hs, phba->work_status[0], |
| 1666 | phba->work_status[1]); |
| 1667 | if (phba->work_hs & HS_FFER8) |
| 1668 | /* Device Zeroization */ |
| 1669 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1670 | "2861 Host Authentication device " |
| 1671 | "zeroization Data:x%x x%x x%x\n", |
| 1672 | phba->work_hs, phba->work_status[0], |
| 1673 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1674 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1675 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1676 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1677 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1678 | |
| 1679 | /* |
| 1680 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1681 | * That could cause the I/Os dropped by the firmware. |
| 1682 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1683 | * retry it after re-establishing link. |
| 1684 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1685 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1686 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | /* |
| 1688 | * There was a firmware error. Take the hba offline and then |
| 1689 | * attempt to restart it. |
| 1690 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1691 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1693 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1694 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1695 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1696 | return; |
| 1697 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1698 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1699 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1700 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1701 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1702 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1703 | temp_event_data.data = (uint32_t)temperature; |
| 1704 | |
| 1705 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1706 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1707 | "(%ld), taking this port offline " |
| 1708 | "Data: x%x x%x x%x\n", |
| 1709 | temperature, phba->work_hs, |
| 1710 | phba->work_status[0], phba->work_status[1]); |
| 1711 | |
| 1712 | shost = lpfc_shost_from_vport(phba->pport); |
| 1713 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1714 | sizeof(temp_event_data), |
| 1715 | (char *) &temp_event_data, |
| 1716 | SCSI_NL_VID_TYPE_PCI |
| 1717 | | PCI_VENDOR_ID_EMULEX); |
| 1718 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1719 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1720 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1721 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1722 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1723 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1724 | } else { |
| 1725 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1726 | * failure is a value other than FFER6. Do not call the offline |
| 1727 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1728 | */ |
| 1729 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1730 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1731 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1732 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1733 | phba->work_status[0], phba->work_status[1]); |
| 1734 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1735 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1736 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1737 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1738 | sizeof(event_data), (char *) &event_data, |
| 1739 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1740 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1741 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1742 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1743 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1744 | } |
| 1745 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1746 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1747 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1748 | * @phba: pointer to lpfc hba data structure. |
| 1749 | * @mbx_action: flag for mailbox shutdown action. |
| 1750 | * |
| 1751 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1752 | * response to port status register polling attention. It waits for port |
| 1753 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1754 | * During this process, interrupt vectors are freed and later requested |
| 1755 | * for handling possible port resource change. |
| 1756 | **/ |
| 1757 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1758 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1759 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1760 | { |
| 1761 | int rc; |
| 1762 | uint32_t intr_mode; |
| 1763 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1764 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 1765 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1766 | /* |
| 1767 | * On error status condition, driver need to wait for port |
| 1768 | * ready before performing reset. |
| 1769 | */ |
| 1770 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1771 | if (rc) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1772 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1773 | } |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1774 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1775 | /* need reset: attempt for port recovery */ |
| 1776 | if (en_rn_msg) |
| 1777 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1778 | "2887 Reset Needed: Attempting Port " |
| 1779 | "Recovery...\n"); |
| 1780 | lpfc_offline_prep(phba, mbx_action); |
| 1781 | lpfc_offline(phba); |
| 1782 | /* release interrupt for possible resource change */ |
| 1783 | lpfc_sli4_disable_intr(phba); |
| 1784 | lpfc_sli_brdrestart(phba); |
| 1785 | /* request and enable interrupt */ |
| 1786 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1787 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1788 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1789 | "3175 Failed to enable interrupt\n"); |
| 1790 | return -EIO; |
| 1791 | } |
| 1792 | phba->intr_mode = intr_mode; |
| 1793 | rc = lpfc_online(phba); |
| 1794 | if (rc == 0) |
| 1795 | lpfc_unblock_mgmt_io(phba); |
| 1796 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1797 | return rc; |
| 1798 | } |
| 1799 | |
| 1800 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1801 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1802 | * @phba: pointer to lpfc hba data structure. |
| 1803 | * |
| 1804 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1805 | * conditions. |
| 1806 | **/ |
| 1807 | static void |
| 1808 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1809 | { |
| 1810 | struct lpfc_vport *vport = phba->pport; |
| 1811 | uint32_t event_data; |
| 1812 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1813 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1814 | struct lpfc_register portstat_reg = {0}; |
| 1815 | uint32_t reg_err1, reg_err2; |
| 1816 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1817 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1818 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1819 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1820 | struct lpfc_register portsmphr_reg; |
| 1821 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1822 | |
| 1823 | /* If the pci channel is offline, ignore possible errors, since |
| 1824 | * we cannot communicate with the pci card anyway. |
| 1825 | */ |
| 1826 | if (pci_channel_offline(phba->pcidev)) |
| 1827 | return; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1828 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1829 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1830 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1831 | switch (if_type) { |
| 1832 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1833 | pci_rd_rc1 = lpfc_readl( |
| 1834 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1835 | &uerrlo_reg); |
| 1836 | pci_rd_rc2 = lpfc_readl( |
| 1837 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1838 | &uemasklo_reg); |
| 1839 | /* consider PCI bus read error as pci_channel_offline */ |
| 1840 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1841 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1842 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1843 | lpfc_sli4_offline_eratt(phba); |
| 1844 | return; |
| 1845 | } |
| 1846 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1847 | "7623 Checking UE recoverable"); |
| 1848 | |
| 1849 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1850 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1851 | &portsmphr_reg.word0)) |
| 1852 | continue; |
| 1853 | |
| 1854 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1855 | &portsmphr_reg); |
| 1856 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1857 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1858 | break; |
| 1859 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1860 | msleep(1000); |
| 1861 | } |
| 1862 | |
| 1863 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1864 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1865 | smphr_port_status, i); |
| 1866 | |
| 1867 | /* Recoverable UE, reset the HBA device */ |
| 1868 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1869 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1870 | for (i = 0; i < 20; i++) { |
| 1871 | msleep(1000); |
| 1872 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1873 | &portsmphr_reg.word0) && |
| 1874 | (LPFC_POST_STAGE_PORT_READY == |
| 1875 | bf_get(lpfc_port_smphr_port_status, |
| 1876 | &portsmphr_reg))) { |
| 1877 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 1878 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 1879 | if (rc == 0) |
| 1880 | return; |
| 1881 | lpfc_printf_log(phba, |
| 1882 | KERN_ERR, LOG_INIT, |
| 1883 | "4215 Failed to recover UE"); |
| 1884 | break; |
| 1885 | } |
| 1886 | } |
| 1887 | } |
| 1888 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1889 | "7624 Firmware not ready: Failing UE recovery," |
| 1890 | " waited %dSec", i); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1891 | lpfc_sli4_offline_eratt(phba); |
| 1892 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1893 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1894 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1895 | pci_rd_rc1 = lpfc_readl( |
| 1896 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1897 | &portstat_reg.word0); |
| 1898 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1899 | if (pci_rd_rc1 == -EIO) { |
| 1900 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1901 | "3151 PCI bus read access failure: x%x\n", |
| 1902 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1903 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1904 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1905 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1906 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1907 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1908 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1909 | "2889 Port Overtemperature event, " |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1910 | "taking port offline Data: x%x x%x\n", |
| 1911 | reg_err1, reg_err2); |
| 1912 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 1913 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1914 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1915 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1916 | temp_event_data.data = 0xFFFFFFFF; |
| 1917 | |
| 1918 | shost = lpfc_shost_from_vport(phba->pport); |
| 1919 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1920 | sizeof(temp_event_data), |
| 1921 | (char *)&temp_event_data, |
| 1922 | SCSI_NL_VID_TYPE_PCI |
| 1923 | | PCI_VENDOR_ID_EMULEX); |
| 1924 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1925 | spin_lock_irq(&phba->hbalock); |
| 1926 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1927 | spin_unlock_irq(&phba->hbalock); |
| 1928 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1929 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1930 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1931 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1932 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1933 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1934 | "3143 Port Down: Firmware Update " |
| 1935 | "Detected\n"); |
| 1936 | en_rn_msg = false; |
| 1937 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1938 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1939 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1940 | "3144 Port Down: Debug Dump\n"); |
| 1941 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1942 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1943 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1944 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1945 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1946 | /* If resets are disabled then leave the HBA alone and return */ |
| 1947 | if (!phba->cfg_enable_hba_reset) |
| 1948 | return; |
| 1949 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1950 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1951 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 1952 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1953 | if (rc == 0) { |
| 1954 | /* don't report event on forced debug dump */ |
| 1955 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1956 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1957 | return; |
| 1958 | else |
| 1959 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1960 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1961 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1962 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1963 | "3152 Unrecoverable error, bring the port " |
| 1964 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1965 | lpfc_sli4_offline_eratt(phba); |
| 1966 | break; |
| 1967 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1968 | default: |
| 1969 | break; |
| 1970 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1971 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1972 | "3123 Report dump event to upper layer\n"); |
| 1973 | /* Send an internal error event to mgmt application */ |
| 1974 | lpfc_board_errevt_to_mgmt(phba); |
| 1975 | |
| 1976 | event_data = FC_REG_DUMP_EVENT; |
| 1977 | shost = lpfc_shost_from_vport(vport); |
| 1978 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1979 | sizeof(event_data), (char *) &event_data, |
| 1980 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | /** |
| 1984 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 1985 | * @phba: pointer to lpfc HBA data structure. |
| 1986 | * |
| 1987 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 1988 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 1989 | * |
| 1990 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1991 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1992 | * Any other value - error. |
| 1993 | **/ |
| 1994 | void |
| 1995 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 1996 | { |
| 1997 | (*phba->lpfc_handle_eratt)(phba); |
| 1998 | } |
| 1999 | |
| 2000 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2001 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2002 | * @phba: pointer to lpfc hba data structure. |
| 2003 | * |
| 2004 | * This routine is invoked from the worker thread to handle a HBA host |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2005 | * attention link event. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2006 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2007 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2008 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2009 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2010 | struct lpfc_vport *vport = phba->pport; |
| 2011 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2012 | LPFC_MBOXQ_t *pmb; |
| 2013 | volatile uint32_t control; |
| 2014 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2015 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2016 | |
| 2017 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2018 | if (!pmb) { |
| 2019 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2020 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2021 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2022 | |
| 2023 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2024 | if (!mp) { |
| 2025 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2026 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2027 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2028 | |
| 2029 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2030 | if (!mp->virt) { |
| 2031 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2032 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2033 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2034 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 2035 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2036 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | |
| 2038 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2039 | lpfc_read_topology(phba, pmb, mp); |
| 2040 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2041 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2042 | /* Block ELS IOCBs until we have processed this mbox command */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2043 | phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2044 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2045 | if (rc == MBX_NOT_FINISHED) { |
| 2046 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2047 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2048 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | |
| 2050 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2051 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2052 | writel(HA_LATT, phba->HAregaddr); |
| 2053 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2054 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2055 | |
| 2056 | return; |
| 2057 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2058 | lpfc_handle_latt_free_mbuf: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2059 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2060 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2061 | lpfc_handle_latt_free_mp: |
| 2062 | kfree(mp); |
| 2063 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2064 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2065 | lpfc_handle_latt_err_exit: |
| 2066 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2067 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2068 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 2069 | control = readl(phba->HCregaddr); |
| 2070 | control |= HC_LAINT_ENA; |
| 2071 | writel(control, phba->HCregaddr); |
| 2072 | readl(phba->HCregaddr); /* flush */ |
| 2073 | |
| 2074 | /* Clear Link Attention in HA REG */ |
| 2075 | writel(HA_LATT, phba->HAregaddr); |
| 2076 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2077 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2079 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2080 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2081 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 2082 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | |
| 2084 | return; |
| 2085 | } |
| 2086 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2087 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2088 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2089 | * @phba: pointer to lpfc hba data structure. |
| 2090 | * @vpd: pointer to the vital product data. |
| 2091 | * @len: length of the vital product data in bytes. |
| 2092 | * |
| 2093 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 2094 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 2095 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 2096 | * |
| 2097 | * Return codes |
| 2098 | * 0 - pointer to the VPD passed in is NULL |
| 2099 | * 1 - success |
| 2100 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2101 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2102 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2103 | { |
| 2104 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 2105 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2106 | int i, j; |
| 2107 | int finished = 0; |
| 2108 | int index = 0; |
| 2109 | |
| 2110 | if (!vpd) |
| 2111 | return 0; |
| 2112 | |
| 2113 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2114 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2115 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 2117 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2118 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | switch (vpd[index]) { |
| 2120 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2121 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | index += 1; |
| 2123 | lenlo = vpd[index]; |
| 2124 | index += 1; |
| 2125 | lenhi = vpd[index]; |
| 2126 | index += 1; |
| 2127 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 2128 | index += i; |
| 2129 | break; |
| 2130 | case 0x90: |
| 2131 | index += 1; |
| 2132 | lenlo = vpd[index]; |
| 2133 | index += 1; |
| 2134 | lenhi = vpd[index]; |
| 2135 | index += 1; |
| 2136 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2137 | if (Length > len - index) |
| 2138 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | while (Length > 0) { |
| 2140 | /* Look for Serial Number */ |
| 2141 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 2142 | index += 2; |
| 2143 | i = vpd[index]; |
| 2144 | index += 1; |
| 2145 | j = 0; |
| 2146 | Length -= (3+i); |
| 2147 | while(i--) { |
| 2148 | phba->SerialNumber[j++] = vpd[index++]; |
| 2149 | if (j == 31) |
| 2150 | break; |
| 2151 | } |
| 2152 | phba->SerialNumber[j] = 0; |
| 2153 | continue; |
| 2154 | } |
| 2155 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 2156 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 2157 | index += 2; |
| 2158 | i = vpd[index]; |
| 2159 | index += 1; |
| 2160 | j = 0; |
| 2161 | Length -= (3+i); |
| 2162 | while(i--) { |
| 2163 | phba->ModelDesc[j++] = vpd[index++]; |
| 2164 | if (j == 255) |
| 2165 | break; |
| 2166 | } |
| 2167 | phba->ModelDesc[j] = 0; |
| 2168 | continue; |
| 2169 | } |
| 2170 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 2171 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 2172 | index += 2; |
| 2173 | i = vpd[index]; |
| 2174 | index += 1; |
| 2175 | j = 0; |
| 2176 | Length -= (3+i); |
| 2177 | while(i--) { |
| 2178 | phba->ModelName[j++] = vpd[index++]; |
| 2179 | if (j == 79) |
| 2180 | break; |
| 2181 | } |
| 2182 | phba->ModelName[j] = 0; |
| 2183 | continue; |
| 2184 | } |
| 2185 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2186 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2187 | index += 2; |
| 2188 | i = vpd[index]; |
| 2189 | index += 1; |
| 2190 | j = 0; |
| 2191 | Length -= (3+i); |
| 2192 | while(i--) { |
| 2193 | phba->ProgramType[j++] = vpd[index++]; |
| 2194 | if (j == 255) |
| 2195 | break; |
| 2196 | } |
| 2197 | phba->ProgramType[j] = 0; |
| 2198 | continue; |
| 2199 | } |
| 2200 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2201 | phba->vpd_flag |= VPD_PORT; |
| 2202 | index += 2; |
| 2203 | i = vpd[index]; |
| 2204 | index += 1; |
| 2205 | j = 0; |
| 2206 | Length -= (3+i); |
| 2207 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2208 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2209 | (phba->sli4_hba.pport_name_sta == |
| 2210 | LPFC_SLI4_PPNAME_GET)) { |
| 2211 | j++; |
| 2212 | index++; |
| 2213 | } else |
| 2214 | phba->Port[j++] = vpd[index++]; |
| 2215 | if (j == 19) |
| 2216 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2217 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2218 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 2219 | (phba->sli4_hba.pport_name_sta == |
| 2220 | LPFC_SLI4_PPNAME_NON)) |
| 2221 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2222 | continue; |
| 2223 | } |
| 2224 | else { |
| 2225 | index += 2; |
| 2226 | i = vpd[index]; |
| 2227 | index += 1; |
| 2228 | index += i; |
| 2229 | Length -= (3 + i); |
| 2230 | } |
| 2231 | } |
| 2232 | finished = 0; |
| 2233 | break; |
| 2234 | case 0x78: |
| 2235 | finished = 1; |
| 2236 | break; |
| 2237 | default: |
| 2238 | index ++; |
| 2239 | break; |
| 2240 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2241 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2242 | |
| 2243 | return(1); |
| 2244 | } |
| 2245 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2246 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2247 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2248 | * @phba: pointer to lpfc hba data structure. |
| 2249 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2250 | * @descp: pointer to the data structure to hold the derived description. |
| 2251 | * |
| 2252 | * This routine retrieves HBA's description based on its registered PCI device |
| 2253 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2254 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2255 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2256 | * function returns, the @mdp will be filled with the model name. |
| 2257 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2258 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2259 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2260 | { |
| 2261 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2262 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2263 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2264 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2265 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2266 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2267 | char *name; |
| 2268 | char *bus; |
| 2269 | char *function; |
| 2270 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2271 | |
| 2272 | if (mdp && mdp[0] != '\0' |
| 2273 | && descp && descp[0] != '\0') |
| 2274 | return; |
| 2275 | |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2276 | if (phba->lmt & LMT_32Gb) |
| 2277 | max_speed = 32; |
| 2278 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2279 | max_speed = 16; |
| 2280 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2281 | max_speed = 10; |
| 2282 | else if (phba->lmt & LMT_8Gb) |
| 2283 | max_speed = 8; |
| 2284 | else if (phba->lmt & LMT_4Gb) |
| 2285 | max_speed = 4; |
| 2286 | else if (phba->lmt & LMT_2Gb) |
| 2287 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2288 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2289 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2290 | else |
| 2291 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2292 | |
| 2293 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2294 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2295 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2296 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2297 | m = (typeof(m)){"LP6000", "PCI", |
| 2298 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2299 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2300 | case PCI_DEVICE_ID_SUPERFLY: |
| 2301 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2302 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2303 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2304 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2305 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2306 | break; |
| 2307 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2308 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2309 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2310 | break; |
| 2311 | case PCI_DEVICE_ID_CENTAUR: |
| 2312 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2313 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2314 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2315 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2316 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2317 | break; |
| 2318 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2319 | m = (typeof(m)){"LP952", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2320 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2321 | break; |
| 2322 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2323 | m = (typeof(m)){"LP9802", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2324 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | break; |
| 2326 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2327 | m = (typeof(m)){"LP10000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2328 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2329 | break; |
| 2330 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2331 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2332 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | break; |
| 2334 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2335 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2336 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2337 | break; |
| 2338 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2339 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2340 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2341 | break; |
| 2342 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2343 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2344 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2346 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2347 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2348 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2349 | break; |
| 2350 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2351 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2352 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2353 | break; |
| 2354 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2355 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2356 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2357 | break; |
| 2358 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2359 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2360 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2361 | break; |
| 2362 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2363 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2364 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2365 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2366 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2367 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2368 | break; |
| 2369 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2370 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2371 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | break; |
| 2373 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2374 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2375 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2376 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2377 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2378 | break; |
| 2379 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2380 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2381 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2382 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2383 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2384 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2385 | break; |
| 2386 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2387 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2388 | break; |
| 2389 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2390 | m = (typeof(m)){"LP101", "PCI-X", |
| 2391 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2392 | break; |
| 2393 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2394 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2395 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2396 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2397 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2398 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2399 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2400 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2401 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2402 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2403 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2404 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2405 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2406 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2407 | break; |
| 2408 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2409 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2410 | break; |
| 2411 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2412 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2413 | break; |
| 2414 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2415 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2416 | break; |
| 2417 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2418 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2419 | break; |
| 2420 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2421 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2422 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2423 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2424 | m = (typeof(m)){"LP21000", "PCIe", |
| 2425 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2426 | GE = 1; |
| 2427 | break; |
| 2428 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2429 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2430 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2431 | break; |
| 2432 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2433 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2434 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2435 | break; |
| 2436 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2437 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2438 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2439 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2440 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2441 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2442 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2443 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2444 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2445 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2446 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2447 | break; |
| 2448 | case PCI_DEVICE_ID_FALCON: |
| 2449 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2450 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2451 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2452 | case PCI_DEVICE_ID_BALIUS: |
| 2453 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2454 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2455 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2456 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2457 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2458 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2459 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2460 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2461 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2462 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2463 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2464 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2465 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2466 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2467 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2468 | oneConnect = 1; |
| 2469 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2470 | "Obsolete, Unsupported FCoE"}; |
| 2471 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2472 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2473 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2474 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2475 | case PCI_DEVICE_ID_SKYHAWK: |
| 2476 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2477 | oneConnect = 1; |
| 2478 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2479 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2480 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2481 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2482 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2483 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2484 | |
| 2485 | if (mdp && mdp[0] == '\0') |
| 2486 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2487 | /* |
| 2488 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2489 | * and we put the port number on the end |
| 2490 | */ |
| 2491 | if (descp && descp[0] == '\0') { |
| 2492 | if (oneConnect) |
| 2493 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2494 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2495 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2496 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2497 | else if (max_speed == 0) |
| 2498 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2499 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2500 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2501 | else |
| 2502 | snprintf(descp, 255, |
| 2503 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2504 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2505 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2506 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2507 | } |
| 2508 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2509 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2510 | * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2511 | * @phba: pointer to lpfc hba data structure. |
| 2512 | * @pring: pointer to a IOCB ring. |
| 2513 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2514 | * |
| 2515 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2516 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2517 | * |
| 2518 | * Return codes |
| 2519 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2520 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2521 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2522 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2523 | { |
| 2524 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2525 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2526 | struct lpfc_dmabuf *mp1, *mp2; |
| 2527 | |
| 2528 | cnt += pring->missbufcnt; |
| 2529 | |
| 2530 | /* While there are buffers to post */ |
| 2531 | while (cnt > 0) { |
| 2532 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2533 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2534 | if (iocb == NULL) { |
| 2535 | pring->missbufcnt = cnt; |
| 2536 | return cnt; |
| 2537 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2538 | icmd = &iocb->iocb; |
| 2539 | |
| 2540 | /* 2 buffers can be posted per command */ |
| 2541 | /* Allocate buffer to post */ |
| 2542 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2543 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2544 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2545 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2546 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2547 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2548 | pring->missbufcnt = cnt; |
| 2549 | return cnt; |
| 2550 | } |
| 2551 | |
| 2552 | INIT_LIST_HEAD(&mp1->list); |
| 2553 | /* Allocate buffer to post */ |
| 2554 | if (cnt > 1) { |
| 2555 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2556 | if (mp2) |
| 2557 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2558 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2559 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2560 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2561 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2562 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2563 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2564 | pring->missbufcnt = cnt; |
| 2565 | return cnt; |
| 2566 | } |
| 2567 | |
| 2568 | INIT_LIST_HEAD(&mp2->list); |
| 2569 | } else { |
| 2570 | mp2 = NULL; |
| 2571 | } |
| 2572 | |
| 2573 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2574 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2575 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2576 | icmd->ulpBdeCount = 1; |
| 2577 | cnt--; |
| 2578 | if (mp2) { |
| 2579 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2580 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2581 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2582 | cnt--; |
| 2583 | icmd->ulpBdeCount = 2; |
| 2584 | } |
| 2585 | |
| 2586 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2587 | icmd->ulpLe = 1; |
| 2588 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2589 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2590 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2591 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2592 | kfree(mp1); |
| 2593 | cnt++; |
| 2594 | if (mp2) { |
| 2595 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2596 | kfree(mp2); |
| 2597 | cnt++; |
| 2598 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2599 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | return cnt; |
| 2602 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2603 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2604 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2605 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2606 | } |
| 2607 | pring->missbufcnt = 0; |
| 2608 | return 0; |
| 2609 | } |
| 2610 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2611 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2612 | * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2613 | * @phba: pointer to lpfc hba data structure. |
| 2614 | * |
| 2615 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2616 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2617 | * set to 64 IOCBs. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2618 | * |
| 2619 | * Return codes |
| 2620 | * 0 - success (currently always success) |
| 2621 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2622 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2623 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | { |
| 2625 | struct lpfc_sli *psli = &phba->sli; |
| 2626 | |
| 2627 | /* Ring 0, ELS / CT buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2628 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2629 | /* Ring 2 - FCP no buffers needed */ |
| 2630 | |
| 2631 | return 0; |
| 2632 | } |
| 2633 | |
| 2634 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2635 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2636 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2637 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2638 | * @HashResultPointer: pointer to an array as hash table. |
| 2639 | * |
| 2640 | * This routine sets up the initial values to the array of hash table entries |
| 2641 | * for the LC HBAs. |
| 2642 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | static void |
| 2644 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2645 | { |
| 2646 | HashResultPointer[0] = 0x67452301; |
| 2647 | HashResultPointer[1] = 0xEFCDAB89; |
| 2648 | HashResultPointer[2] = 0x98BADCFE; |
| 2649 | HashResultPointer[3] = 0x10325476; |
| 2650 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2651 | } |
| 2652 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2653 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2654 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2655 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2656 | * @HashWorkingPointer: pointer to an working hash table. |
| 2657 | * |
| 2658 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2659 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2660 | * The results are putting back to the initial hash table, returned through |
| 2661 | * the @HashResultPointer as the result hash table. |
| 2662 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | static void |
| 2664 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2665 | { |
| 2666 | int t; |
| 2667 | uint32_t TEMP; |
| 2668 | uint32_t A, B, C, D, E; |
| 2669 | t = 16; |
| 2670 | do { |
| 2671 | HashWorkingPointer[t] = |
| 2672 | S(1, |
| 2673 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2674 | 8] ^ |
| 2675 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2676 | } while (++t <= 79); |
| 2677 | t = 0; |
| 2678 | A = HashResultPointer[0]; |
| 2679 | B = HashResultPointer[1]; |
| 2680 | C = HashResultPointer[2]; |
| 2681 | D = HashResultPointer[3]; |
| 2682 | E = HashResultPointer[4]; |
| 2683 | |
| 2684 | do { |
| 2685 | if (t < 20) { |
| 2686 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2687 | } else if (t < 40) { |
| 2688 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2689 | } else if (t < 60) { |
| 2690 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2691 | } else { |
| 2692 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2693 | } |
| 2694 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2695 | E = D; |
| 2696 | D = C; |
| 2697 | C = S(30, B); |
| 2698 | B = A; |
| 2699 | A = TEMP; |
| 2700 | } while (++t <= 79); |
| 2701 | |
| 2702 | HashResultPointer[0] += A; |
| 2703 | HashResultPointer[1] += B; |
| 2704 | HashResultPointer[2] += C; |
| 2705 | HashResultPointer[3] += D; |
| 2706 | HashResultPointer[4] += E; |
| 2707 | |
| 2708 | } |
| 2709 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2710 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2711 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2712 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2713 | * @HashWorking: pointer to the entry of the working hash array. |
| 2714 | * |
| 2715 | * This routine calculates the working hash array referred by @HashWorking |
| 2716 | * from the challenge random numbers associated with the host, referred by |
| 2717 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2718 | * array and returned by reference through @HashWorking. |
| 2719 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2720 | static void |
| 2721 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2722 | { |
| 2723 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2724 | } |
| 2725 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2726 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2727 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2728 | * @phba: pointer to lpfc hba data structure. |
| 2729 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2730 | * |
| 2731 | * This routine performs the special handling for LC HBA initialization. |
| 2732 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2733 | void |
| 2734 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2735 | { |
| 2736 | int t; |
| 2737 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2738 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2740 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | if (!HashWorking) |
| 2742 | return; |
| 2743 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2744 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2745 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2746 | |
| 2747 | for (t = 0; t < 7; t++) |
| 2748 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2749 | |
| 2750 | lpfc_sha_init(hbainit); |
| 2751 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2752 | kfree(HashWorking); |
| 2753 | } |
| 2754 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2755 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2756 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2757 | * @vport: pointer to a virtual N_Port data structure. |
| 2758 | * |
| 2759 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2760 | * It invokes the discovery state machine to perform necessary state |
| 2761 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2762 | * the physical port is treated as @vport 0. |
| 2763 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2764 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2765 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2766 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2767 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2768 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2769 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2770 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2771 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2772 | lpfc_port_link_failure(vport); |
| 2773 | |
| 2774 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2775 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2776 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2777 | NLP_STE_UNUSED_NODE); |
| 2778 | if (!ndlp) |
| 2779 | continue; |
| 2780 | spin_lock_irq(&phba->ndlp_lock); |
| 2781 | NLP_SET_FREE_REQ(ndlp); |
| 2782 | spin_unlock_irq(&phba->ndlp_lock); |
| 2783 | /* Trigger the release of the ndlp memory */ |
| 2784 | lpfc_nlp_put(ndlp); |
| 2785 | continue; |
| 2786 | } |
| 2787 | spin_lock_irq(&phba->ndlp_lock); |
| 2788 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2789 | /* The ndlp should not be in memory free mode already */ |
| 2790 | spin_unlock_irq(&phba->ndlp_lock); |
| 2791 | continue; |
| 2792 | } else |
| 2793 | /* Indicate request for freeing ndlp memory */ |
| 2794 | NLP_SET_FREE_REQ(ndlp); |
| 2795 | spin_unlock_irq(&phba->ndlp_lock); |
| 2796 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2797 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2798 | ndlp->nlp_DID == Fabric_DID) { |
| 2799 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2800 | lpfc_nlp_put(ndlp); |
| 2801 | continue; |
| 2802 | } |
| 2803 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2804 | /* take care of nodes in unused state before the state |
| 2805 | * machine taking action. |
| 2806 | */ |
| 2807 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2808 | lpfc_nlp_put(ndlp); |
| 2809 | continue; |
| 2810 | } |
| 2811 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2812 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2813 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2814 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2815 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2816 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2817 | NLP_EVT_DEVICE_RM); |
| 2818 | } |
| 2819 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2820 | /* At this point, ALL ndlp's should be gone |
| 2821 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2822 | * Lets wait for this to happen, if needed. |
| 2823 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2824 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2825 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2826 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2827 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2828 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2829 | &vport->fc_nodes, nlp_listp) { |
| 2830 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2831 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2832 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2833 | "usgmap:x%x refcnt:%d\n", |
| 2834 | ndlp->nlp_DID, (void *)ndlp, |
| 2835 | ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 2836 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2837 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2838 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2839 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2840 | |
| 2841 | /* Wait for any activity on ndlps to settle */ |
| 2842 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2843 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2844 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2845 | } |
| 2846 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2847 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2848 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2849 | * @vport: pointer to a virtual N_Port data structure. |
| 2850 | * |
| 2851 | * This routine stops all the timers associated with a @vport. This function |
| 2852 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2853 | * port is treated as @vport 0. |
| 2854 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2855 | void |
| 2856 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2858 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2859 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2860 | lpfc_can_disctmo(vport); |
| 2861 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | } |
| 2863 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2864 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2865 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2866 | * @phba: pointer to lpfc hba data structure. |
| 2867 | * |
| 2868 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2869 | * caller of this routine should already hold the host lock. |
| 2870 | **/ |
| 2871 | void |
| 2872 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2873 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2874 | /* Clear pending FCF rediscovery wait flag */ |
| 2875 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2876 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2877 | /* Now, try to stop the timer */ |
| 2878 | del_timer(&phba->fcf.redisc_wait); |
| 2879 | } |
| 2880 | |
| 2881 | /** |
| 2882 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2883 | * @phba: pointer to lpfc hba data structure. |
| 2884 | * |
| 2885 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2886 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2887 | * lock held before proceeding with disabling the timer and clearing the |
| 2888 | * wait timer pendig flag. |
| 2889 | **/ |
| 2890 | void |
| 2891 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2892 | { |
| 2893 | spin_lock_irq(&phba->hbalock); |
| 2894 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2895 | /* FCF rediscovery timer already fired or stopped */ |
| 2896 | spin_unlock_irq(&phba->hbalock); |
| 2897 | return; |
| 2898 | } |
| 2899 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2900 | /* Clear failover in progress flags */ |
| 2901 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2902 | spin_unlock_irq(&phba->hbalock); |
| 2903 | } |
| 2904 | |
| 2905 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2906 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2907 | * @phba: pointer to lpfc hba data structure. |
| 2908 | * |
| 2909 | * This routine stops all the timers associated with a HBA. This function is |
| 2910 | * invoked before either putting a HBA offline or unloading the driver. |
| 2911 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2912 | void |
| 2913 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2914 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2915 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2916 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2917 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2918 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2919 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2920 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2921 | del_timer_sync(&phba->rrq_tmr); |
| 2922 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2923 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2924 | phba->hb_outstanding = 0; |
| 2925 | |
| 2926 | switch (phba->pci_dev_grp) { |
| 2927 | case LPFC_PCI_DEV_LP: |
| 2928 | /* Stop any LightPulse device specific driver timers */ |
| 2929 | del_timer_sync(&phba->fcp_poll_timer); |
| 2930 | break; |
| 2931 | case LPFC_PCI_DEV_OC: |
| 2932 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2933 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2934 | break; |
| 2935 | default: |
| 2936 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2937 | "0297 Invalid device group (x%x)\n", |
| 2938 | phba->pci_dev_grp); |
| 2939 | break; |
| 2940 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2941 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2942 | } |
| 2943 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2944 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2945 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2946 | * @phba: pointer to lpfc hba data structure. |
| 2947 | * |
| 2948 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2949 | * management interface is marked as blocked, all the user space access to |
| 2950 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2951 | * all be blocked. The HBA is set to block the management interface when the |
| 2952 | * driver prepares the HBA interface for online or offline. |
| 2953 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2954 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2955 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2956 | { |
| 2957 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2958 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2959 | unsigned long timeout; |
| 2960 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2961 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2962 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2963 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2964 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 2965 | return; |
| 2966 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 2967 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2968 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2969 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2970 | /* Determine how long we might wait for the active mailbox |
| 2971 | * command to be gracefully completed by firmware. |
| 2972 | */ |
| 2973 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2974 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2975 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2976 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2977 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2978 | /* Wait for the outstnading mailbox command to complete */ |
| 2979 | while (phba->sli.mbox_active) { |
| 2980 | /* Check active mailbox complete status every 2ms */ |
| 2981 | msleep(2); |
| 2982 | if (time_after(jiffies, timeout)) { |
| 2983 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 2984 | "2813 Mgmt IO is Blocked %x " |
| 2985 | "- mbox cmd %x still active\n", |
| 2986 | phba->sli.sli_flag, actcmd); |
| 2987 | break; |
| 2988 | } |
| 2989 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2990 | } |
| 2991 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2992 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2993 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 2994 | * @phba: pointer to lpfc hba data structure. |
| 2995 | * |
| 2996 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 2997 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 2998 | * is to fixup the temporary rpi assignments. |
| 2999 | **/ |
| 3000 | void |
| 3001 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 3002 | { |
| 3003 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3004 | struct lpfc_vport **vports; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3005 | int i, rpi; |
| 3006 | unsigned long flags; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3007 | |
| 3008 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 3009 | return; |
| 3010 | |
| 3011 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3012 | if (vports == NULL) |
| 3013 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3014 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3015 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3016 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3017 | continue; |
| 3018 | |
| 3019 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3020 | &vports[i]->fc_nodes, |
| 3021 | nlp_listp) { |
| 3022 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3023 | continue; |
| 3024 | rpi = lpfc_sli4_alloc_rpi(phba); |
| 3025 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
| 3026 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3027 | NLP_CLR_NODE_ACT(ndlp); |
| 3028 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3029 | continue; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3030 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3031 | ndlp->nlp_rpi = rpi; |
| 3032 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3033 | "0009 rpi:%x DID:%x " |
| 3034 | "flg:%x map:%x %p\n", ndlp->nlp_rpi, |
| 3035 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3036 | ndlp->nlp_usg_map, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3037 | } |
| 3038 | } |
| 3039 | lpfc_destroy_vport_work_array(phba, vports); |
| 3040 | } |
| 3041 | |
| 3042 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3043 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3044 | * @phba: pointer to lpfc hba data structure. |
| 3045 | * |
| 3046 | * This routine initializes the HBA and brings a HBA online. During this |
| 3047 | * process, the management interface is blocked to prevent user space access |
| 3048 | * to the HBA interfering with the driver initialization. |
| 3049 | * |
| 3050 | * Return codes |
| 3051 | * 0 - successful |
| 3052 | * 1 - failed |
| 3053 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3054 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3055 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3056 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3057 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3058 | struct lpfc_vport **vports; |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3059 | int i, error = 0; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3060 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3061 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3062 | if (!phba) |
| 3063 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3064 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3066 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3067 | return 0; |
| 3068 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3069 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3070 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3071 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3072 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3073 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3074 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3075 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 3076 | lpfc_unblock_mgmt_io(phba); |
| 3077 | return 1; |
| 3078 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3079 | spin_lock_irq(&phba->hbalock); |
| 3080 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 3081 | vpis_cleared = true; |
| 3082 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3083 | |
| 3084 | /* Reestablish the local initiator port. |
| 3085 | * The offline process destroyed the previous lport. |
| 3086 | */ |
| 3087 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
| 3088 | !phba->nvmet_support) { |
| 3089 | error = lpfc_nvme_create_localport(phba->pport); |
| 3090 | if (error) |
| 3091 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3092 | "6132 NVME restore reg failed " |
| 3093 | "on nvmei error x%x\n", error); |
| 3094 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3095 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3096 | lpfc_sli_queue_init(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3097 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 3098 | lpfc_unblock_mgmt_io(phba); |
| 3099 | return 1; |
| 3100 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3101 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3102 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3103 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3104 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3105 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3106 | struct Scsi_Host *shost; |
| 3107 | shost = lpfc_shost_from_vport(vports[i]); |
| 3108 | spin_lock_irq(shost->host_lock); |
| 3109 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 3110 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3111 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3112 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3113 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3114 | if ((vpis_cleared) && |
| 3115 | (vports[i]->port_type != |
| 3116 | LPFC_PHYSICAL_PORT)) |
| 3117 | vports[i]->vpi = 0; |
| 3118 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3119 | spin_unlock_irq(shost->host_lock); |
| 3120 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3121 | } |
| 3122 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3123 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3124 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3125 | return 0; |
| 3126 | } |
| 3127 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3128 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3129 | * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3130 | * @phba: pointer to lpfc hba data structure. |
| 3131 | * |
| 3132 | * This routine marks a HBA's management interface as not blocked. Once the |
| 3133 | * HBA's management interface is marked as not blocked, all the user space |
| 3134 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 3135 | * interface will be allowed. The HBA is set to block the management interface |
| 3136 | * when the driver prepares the HBA interface for online or offline and then |
| 3137 | * set to unblock the management interface afterwards. |
| 3138 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3139 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3140 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 3141 | { |
| 3142 | unsigned long iflag; |
| 3143 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3144 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3145 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 3146 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3147 | } |
| 3148 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3149 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3150 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3151 | * @phba: pointer to lpfc hba data structure. |
| 3152 | * |
| 3153 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 3154 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 3155 | * queue to make it ready to be brought offline. |
| 3156 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3157 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3158 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3159 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3160 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3161 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3162 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3163 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3164 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3165 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3166 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3167 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3168 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3169 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3170 | |
| 3171 | lpfc_linkdown(phba); |
| 3172 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3173 | /* Issue an unreg_login to all nodes on all vports */ |
| 3174 | vports = lpfc_create_vport_work_array(phba); |
| 3175 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3176 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3177 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3178 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3179 | shost = lpfc_shost_from_vport(vports[i]); |
| 3180 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3181 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3182 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 3183 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3184 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3185 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3186 | shost = lpfc_shost_from_vport(vports[i]); |
| 3187 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3188 | &vports[i]->fc_nodes, |
| 3189 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3190 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3191 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3192 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 3193 | continue; |
| 3194 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3195 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3196 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 3197 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3198 | NULL, NLP_EVT_DEVICE_RM); |
| 3199 | } |
| 3200 | spin_lock_irq(shost->host_lock); |
| 3201 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3202 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3203 | /* |
| 3204 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3205 | * RPI. Get a new RPI when the adapter port |
| 3206 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3207 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3208 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3209 | lpfc_printf_vlog(ndlp->vport, |
| 3210 | KERN_INFO, LOG_NODE, |
| 3211 | "0011 lpfc_offline: " |
| 3212 | "ndlp:x%p did %x " |
| 3213 | "usgmap:x%x rpi:%x\n", |
| 3214 | ndlp, ndlp->nlp_DID, |
| 3215 | ndlp->nlp_usg_map, |
| 3216 | ndlp->nlp_rpi); |
| 3217 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3218 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3219 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3220 | lpfc_unreg_rpi(vports[i], ndlp); |
| 3221 | } |
| 3222 | } |
| 3223 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3224 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3225 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3226 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 3227 | |
| 3228 | if (phba->wq) |
| 3229 | flush_workqueue(phba->wq); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3230 | } |
| 3231 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3232 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3233 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3234 | * @phba: pointer to lpfc hba data structure. |
| 3235 | * |
| 3236 | * This routine actually brings a HBA offline. It stops all the timers |
| 3237 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3238 | * marks the HBA as in offline state for the upper layer protocol. |
| 3239 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3240 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3241 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3242 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3243 | struct Scsi_Host *shost; |
| 3244 | struct lpfc_vport **vports; |
| 3245 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3246 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3247 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3248 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3249 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3250 | /* stop port and all timers associated with this hba */ |
| 3251 | lpfc_stop_port(phba); |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 3252 | |
| 3253 | /* Tear down the local and target port registrations. The |
| 3254 | * nvme transports need to cleanup. |
| 3255 | */ |
| 3256 | lpfc_nvmet_destroy_targetport(phba); |
| 3257 | lpfc_nvme_destroy_localport(phba->pport); |
| 3258 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3259 | vports = lpfc_create_vport_work_array(phba); |
| 3260 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3261 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3262 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3263 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3264 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3265 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3266 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3267 | now. */ |
| 3268 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3269 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3270 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3271 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3272 | vports = lpfc_create_vport_work_array(phba); |
| 3273 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3274 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3275 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3276 | spin_lock_irq(shost->host_lock); |
| 3277 | vports[i]->work_port_events = 0; |
| 3278 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3279 | spin_unlock_irq(shost->host_lock); |
| 3280 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3281 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3282 | } |
| 3283 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3284 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3285 | * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3286 | * @phba: pointer to lpfc hba data structure. |
| 3287 | * |
| 3288 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3289 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3290 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3291 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3292 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3293 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3294 | { |
| 3295 | struct lpfc_scsi_buf *sb, *sb_next; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3296 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3297 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3298 | return; |
| 3299 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3300 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3301 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3302 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3303 | |
| 3304 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3305 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3306 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3307 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3308 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3309 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3310 | kfree(sb); |
| 3311 | phba->total_scsi_bufs--; |
| 3312 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3313 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3314 | |
| 3315 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3316 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3317 | list) { |
| 3318 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3319 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3320 | sb->dma_handle); |
| 3321 | kfree(sb); |
| 3322 | phba->total_scsi_bufs--; |
| 3323 | } |
| 3324 | spin_unlock(&phba->scsi_buf_list_get_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3325 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3326 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3327 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3328 | * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists |
| 3329 | * @phba: pointer to lpfc hba data structure. |
| 3330 | * |
| 3331 | * This routine is to free all the NVME buffers and IOCBs from the driver |
| 3332 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3333 | * the internal resources before the device is removed from the system. |
| 3334 | **/ |
| 3335 | static void |
| 3336 | lpfc_nvme_free(struct lpfc_hba *phba) |
| 3337 | { |
| 3338 | struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3339 | |
| 3340 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) |
| 3341 | return; |
| 3342 | |
| 3343 | spin_lock_irq(&phba->hbalock); |
| 3344 | |
| 3345 | /* Release all the lpfc_nvme_bufs maintained by this host. */ |
| 3346 | spin_lock(&phba->nvme_buf_list_put_lock); |
| 3347 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3348 | &phba->lpfc_nvme_buf_list_put, list) { |
| 3349 | list_del(&lpfc_ncmd->list); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3350 | phba->put_nvme_bufs--; |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3351 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3352 | lpfc_ncmd->dma_handle); |
| 3353 | kfree(lpfc_ncmd); |
| 3354 | phba->total_nvme_bufs--; |
| 3355 | } |
| 3356 | spin_unlock(&phba->nvme_buf_list_put_lock); |
| 3357 | |
| 3358 | spin_lock(&phba->nvme_buf_list_get_lock); |
| 3359 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3360 | &phba->lpfc_nvme_buf_list_get, list) { |
| 3361 | list_del(&lpfc_ncmd->list); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3362 | phba->get_nvme_bufs--; |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3363 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3364 | lpfc_ncmd->dma_handle); |
| 3365 | kfree(lpfc_ncmd); |
| 3366 | phba->total_nvme_bufs--; |
| 3367 | } |
| 3368 | spin_unlock(&phba->nvme_buf_list_get_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3369 | spin_unlock_irq(&phba->hbalock); |
| 3370 | } |
| 3371 | /** |
| 3372 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3373 | * @phba: pointer to lpfc hba data structure. |
| 3374 | * |
| 3375 | * This routine first calculates the sizes of the current els and allocated |
| 3376 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3377 | * XRIs assigned due to port function reset. During port initialization, the |
| 3378 | * current els and allocated scsi sgl lists are 0s. |
| 3379 | * |
| 3380 | * Return codes |
| 3381 | * 0 - successful (for now, it always returns 0) |
| 3382 | **/ |
| 3383 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3384 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3385 | { |
| 3386 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3387 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3388 | LIST_HEAD(els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3389 | int rc; |
| 3390 | |
| 3391 | /* |
| 3392 | * update on pci function's els xri-sgl list |
| 3393 | */ |
| 3394 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3395 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3396 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3397 | /* els xri-sgl expanded */ |
| 3398 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3399 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3400 | "3157 ELS xri-sgl count increased from " |
| 3401 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3402 | els_xri_cnt); |
| 3403 | /* allocate the additional els sgls */ |
| 3404 | for (i = 0; i < xri_cnt; i++) { |
| 3405 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3406 | GFP_KERNEL); |
| 3407 | if (sglq_entry == NULL) { |
| 3408 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3409 | "2562 Failure to allocate an " |
| 3410 | "ELS sgl entry:%d\n", i); |
| 3411 | rc = -ENOMEM; |
| 3412 | goto out_free_mem; |
| 3413 | } |
| 3414 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3415 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3416 | &sglq_entry->phys); |
| 3417 | if (sglq_entry->virt == NULL) { |
| 3418 | kfree(sglq_entry); |
| 3419 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3420 | "2563 Failure to allocate an " |
| 3421 | "ELS mbuf:%d\n", i); |
| 3422 | rc = -ENOMEM; |
| 3423 | goto out_free_mem; |
| 3424 | } |
| 3425 | sglq_entry->sgl = sglq_entry->virt; |
| 3426 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3427 | sglq_entry->state = SGL_FREED; |
| 3428 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3429 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3430 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3431 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3432 | list_splice_init(&els_sgl_list, |
| 3433 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3434 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3435 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3436 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3437 | /* els xri-sgl shrinked */ |
| 3438 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3439 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3440 | "3158 ELS xri-sgl count decreased from " |
| 3441 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3442 | els_xri_cnt); |
| 3443 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3444 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3445 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, |
| 3446 | &els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3447 | /* release extra els sgls from list */ |
| 3448 | for (i = 0; i < xri_cnt; i++) { |
| 3449 | list_remove_head(&els_sgl_list, |
| 3450 | sglq_entry, struct lpfc_sglq, list); |
| 3451 | if (sglq_entry) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3452 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3453 | sglq_entry->phys); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3454 | kfree(sglq_entry); |
| 3455 | } |
| 3456 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3457 | list_splice_init(&els_sgl_list, |
| 3458 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3459 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3460 | spin_unlock_irq(&phba->hbalock); |
| 3461 | } else |
| 3462 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3463 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3464 | els_xri_cnt); |
| 3465 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3466 | |
| 3467 | /* update xris to els sgls on the list */ |
| 3468 | sglq_entry = NULL; |
| 3469 | sglq_entry_next = NULL; |
| 3470 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3471 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3472 | lxri = lpfc_sli4_next_xritag(phba); |
| 3473 | if (lxri == NO_XRI) { |
| 3474 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3475 | "2400 Failed to allocate xri for " |
| 3476 | "ELS sgl\n"); |
| 3477 | rc = -ENOMEM; |
| 3478 | goto out_free_mem; |
| 3479 | } |
| 3480 | sglq_entry->sli4_lxritag = lxri; |
| 3481 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3482 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3483 | return 0; |
| 3484 | |
| 3485 | out_free_mem: |
| 3486 | lpfc_free_els_sgl_list(phba); |
| 3487 | return rc; |
| 3488 | } |
| 3489 | |
| 3490 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3491 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping |
| 3492 | * @phba: pointer to lpfc hba data structure. |
| 3493 | * |
| 3494 | * This routine first calculates the sizes of the current els and allocated |
| 3495 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3496 | * XRIs assigned due to port function reset. During port initialization, the |
| 3497 | * current els and allocated scsi sgl lists are 0s. |
| 3498 | * |
| 3499 | * Return codes |
| 3500 | * 0 - successful (for now, it always returns 0) |
| 3501 | **/ |
| 3502 | int |
| 3503 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) |
| 3504 | { |
| 3505 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3506 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3507 | uint16_t nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3508 | LIST_HEAD(nvmet_sgl_list); |
| 3509 | int rc; |
| 3510 | |
| 3511 | /* |
| 3512 | * update on pci function's nvmet xri-sgl list |
| 3513 | */ |
| 3514 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 3515 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3516 | /* For NVMET, ALL remaining XRIs are dedicated for IO processing */ |
| 3517 | nvmet_xri_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3518 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { |
| 3519 | /* els xri-sgl expanded */ |
| 3520 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; |
| 3521 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3522 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", |
| 3523 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); |
| 3524 | /* allocate the additional nvmet sgls */ |
| 3525 | for (i = 0; i < xri_cnt; i++) { |
| 3526 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3527 | GFP_KERNEL); |
| 3528 | if (sglq_entry == NULL) { |
| 3529 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3530 | "6303 Failure to allocate an " |
| 3531 | "NVMET sgl entry:%d\n", i); |
| 3532 | rc = -ENOMEM; |
| 3533 | goto out_free_mem; |
| 3534 | } |
| 3535 | sglq_entry->buff_type = NVMET_BUFF_TYPE; |
| 3536 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, |
| 3537 | &sglq_entry->phys); |
| 3538 | if (sglq_entry->virt == NULL) { |
| 3539 | kfree(sglq_entry); |
| 3540 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3541 | "6304 Failure to allocate an " |
| 3542 | "NVMET buf:%d\n", i); |
| 3543 | rc = -ENOMEM; |
| 3544 | goto out_free_mem; |
| 3545 | } |
| 3546 | sglq_entry->sgl = sglq_entry->virt; |
| 3547 | memset(sglq_entry->sgl, 0, |
| 3548 | phba->cfg_sg_dma_buf_size); |
| 3549 | sglq_entry->state = SGL_FREED; |
| 3550 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); |
| 3551 | } |
| 3552 | spin_lock_irq(&phba->hbalock); |
| 3553 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3554 | list_splice_init(&nvmet_sgl_list, |
| 3555 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3556 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3557 | spin_unlock_irq(&phba->hbalock); |
| 3558 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { |
| 3559 | /* nvmet xri-sgl shrunk */ |
| 3560 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; |
| 3561 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3562 | "6305 NVMET xri-sgl count decreased from " |
| 3563 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, |
| 3564 | nvmet_xri_cnt); |
| 3565 | spin_lock_irq(&phba->hbalock); |
| 3566 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3567 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 3568 | &nvmet_sgl_list); |
| 3569 | /* release extra nvmet sgls from list */ |
| 3570 | for (i = 0; i < xri_cnt; i++) { |
| 3571 | list_remove_head(&nvmet_sgl_list, |
| 3572 | sglq_entry, struct lpfc_sglq, list); |
| 3573 | if (sglq_entry) { |
| 3574 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, |
| 3575 | sglq_entry->phys); |
| 3576 | kfree(sglq_entry); |
| 3577 | } |
| 3578 | } |
| 3579 | list_splice_init(&nvmet_sgl_list, |
| 3580 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3581 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3582 | spin_unlock_irq(&phba->hbalock); |
| 3583 | } else |
| 3584 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3585 | "6306 NVMET xri-sgl count unchanged: %d\n", |
| 3586 | nvmet_xri_cnt); |
| 3587 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; |
| 3588 | |
| 3589 | /* update xris to nvmet sgls on the list */ |
| 3590 | sglq_entry = NULL; |
| 3591 | sglq_entry_next = NULL; |
| 3592 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3593 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { |
| 3594 | lxri = lpfc_sli4_next_xritag(phba); |
| 3595 | if (lxri == NO_XRI) { |
| 3596 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3597 | "6307 Failed to allocate xri for " |
| 3598 | "NVMET sgl\n"); |
| 3599 | rc = -ENOMEM; |
| 3600 | goto out_free_mem; |
| 3601 | } |
| 3602 | sglq_entry->sli4_lxritag = lxri; |
| 3603 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3604 | } |
| 3605 | return 0; |
| 3606 | |
| 3607 | out_free_mem: |
| 3608 | lpfc_free_nvmet_sgl_list(phba); |
| 3609 | return rc; |
| 3610 | } |
| 3611 | |
| 3612 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3613 | * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping |
| 3614 | * @phba: pointer to lpfc hba data structure. |
| 3615 | * |
| 3616 | * This routine first calculates the sizes of the current els and allocated |
| 3617 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3618 | * XRIs assigned due to port function reset. During port initialization, the |
| 3619 | * current els and allocated scsi sgl lists are 0s. |
| 3620 | * |
| 3621 | * Return codes |
| 3622 | * 0 - successful (for now, it always returns 0) |
| 3623 | **/ |
| 3624 | int |
| 3625 | lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba) |
| 3626 | { |
| 3627 | struct lpfc_scsi_buf *psb, *psb_next; |
| 3628 | uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt; |
| 3629 | LIST_HEAD(scsi_sgl_list); |
| 3630 | int rc; |
| 3631 | |
| 3632 | /* |
| 3633 | * update on pci function's els xri-sgl list |
| 3634 | */ |
| 3635 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 3636 | phba->total_scsi_bufs = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3637 | |
| 3638 | /* |
| 3639 | * update on pci function's allocated scsi xri-sgl list |
| 3640 | */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3641 | /* maximum number of xris available for scsi buffers */ |
| 3642 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - |
| 3643 | els_xri_cnt; |
| 3644 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3645 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3646 | return 0; |
| 3647 | |
| 3648 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3649 | phba->sli4_hba.scsi_xri_max = /* Split them up */ |
| 3650 | (phba->sli4_hba.scsi_xri_max * |
| 3651 | phba->cfg_xri_split) / 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3652 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3653 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3654 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3655 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list); |
| 3656 | list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3657 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3658 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3659 | |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 3660 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3661 | "6060 Current allocated SCSI xri-sgl count:%d, " |
| 3662 | "maximum SCSI xri count:%d (split:%d)\n", |
| 3663 | phba->sli4_hba.scsi_xri_cnt, |
| 3664 | phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split); |
| 3665 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3666 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { |
| 3667 | /* max scsi xri shrinked below the allocated scsi buffers */ |
| 3668 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - |
| 3669 | phba->sli4_hba.scsi_xri_max; |
| 3670 | /* release the extra allocated scsi buffers */ |
| 3671 | for (i = 0; i < scsi_xri_cnt; i++) { |
| 3672 | list_remove_head(&scsi_sgl_list, psb, |
| 3673 | struct lpfc_scsi_buf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 3674 | if (psb) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3675 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 3676 | psb->data, psb->dma_handle); |
| 3677 | kfree(psb); |
| 3678 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3679 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3680 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3681 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3682 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | /* update xris associated to remaining allocated scsi buffers */ |
| 3686 | psb = NULL; |
| 3687 | psb_next = NULL; |
| 3688 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { |
| 3689 | lxri = lpfc_sli4_next_xritag(phba); |
| 3690 | if (lxri == NO_XRI) { |
| 3691 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3692 | "2560 Failed to allocate xri for " |
| 3693 | "scsi buffer\n"); |
| 3694 | rc = -ENOMEM; |
| 3695 | goto out_free_mem; |
| 3696 | } |
| 3697 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 3698 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3699 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3700 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3701 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3702 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get); |
| 3703 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3704 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3705 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3706 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3707 | |
| 3708 | out_free_mem: |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3709 | lpfc_scsi_free(phba); |
| 3710 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3711 | } |
| 3712 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3713 | static uint64_t |
| 3714 | lpfc_get_wwpn(struct lpfc_hba *phba) |
| 3715 | { |
| 3716 | uint64_t wwn; |
| 3717 | int rc; |
| 3718 | LPFC_MBOXQ_t *mboxq; |
| 3719 | MAILBOX_t *mb; |
| 3720 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3721 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 3722 | GFP_KERNEL); |
| 3723 | if (!mboxq) |
| 3724 | return (uint64_t)-1; |
| 3725 | |
| 3726 | /* First get WWN of HBA instance */ |
| 3727 | lpfc_read_nv(phba, mboxq); |
| 3728 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 3729 | if (rc != MBX_SUCCESS) { |
| 3730 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3731 | "6019 Mailbox failed , mbxCmd x%x " |
| 3732 | "READ_NV, mbxStatus x%x\n", |
| 3733 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 3734 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 3735 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 3736 | return (uint64_t) -1; |
| 3737 | } |
| 3738 | mb = &mboxq->u.mb; |
| 3739 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t)); |
| 3740 | /* wwn is WWPN of HBA instance */ |
| 3741 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 3742 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3743 | return be64_to_cpu(wwn); |
| 3744 | else |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 3745 | return rol64(wwn, 32); |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3746 | } |
| 3747 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3748 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3749 | * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping |
| 3750 | * @phba: pointer to lpfc hba data structure. |
| 3751 | * |
| 3752 | * This routine first calculates the sizes of the current els and allocated |
| 3753 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3754 | * XRIs assigned due to port function reset. During port initialization, the |
| 3755 | * current els and allocated scsi sgl lists are 0s. |
| 3756 | * |
| 3757 | * Return codes |
| 3758 | * 0 - successful (for now, it always returns 0) |
| 3759 | **/ |
| 3760 | int |
| 3761 | lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba) |
| 3762 | { |
| 3763 | struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; |
| 3764 | uint16_t i, lxri, els_xri_cnt; |
| 3765 | uint16_t nvme_xri_cnt, nvme_xri_max; |
| 3766 | LIST_HEAD(nvme_sgl_list); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3767 | int rc, cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3768 | |
| 3769 | phba->total_nvme_bufs = 0; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3770 | phba->get_nvme_bufs = 0; |
| 3771 | phba->put_nvme_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3772 | |
| 3773 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) |
| 3774 | return 0; |
| 3775 | /* |
| 3776 | * update on pci function's allocated nvme xri-sgl list |
| 3777 | */ |
| 3778 | |
| 3779 | /* maximum number of xris available for nvme buffers */ |
| 3780 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 3781 | nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 3782 | phba->sli4_hba.nvme_xri_max = nvme_xri_max; |
| 3783 | phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max; |
| 3784 | |
| 3785 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3786 | "6074 Current allocated NVME xri-sgl count:%d, " |
| 3787 | "maximum NVME xri count:%d\n", |
| 3788 | phba->sli4_hba.nvme_xri_cnt, |
| 3789 | phba->sli4_hba.nvme_xri_max); |
| 3790 | |
| 3791 | spin_lock_irq(&phba->nvme_buf_list_get_lock); |
| 3792 | spin_lock(&phba->nvme_buf_list_put_lock); |
| 3793 | list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list); |
| 3794 | list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3795 | cnt = phba->get_nvme_bufs + phba->put_nvme_bufs; |
| 3796 | phba->get_nvme_bufs = 0; |
| 3797 | phba->put_nvme_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3798 | spin_unlock(&phba->nvme_buf_list_put_lock); |
| 3799 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); |
| 3800 | |
| 3801 | if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) { |
| 3802 | /* max nvme xri shrunk below the allocated nvme buffers */ |
| 3803 | spin_lock_irq(&phba->nvme_buf_list_get_lock); |
| 3804 | nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt - |
| 3805 | phba->sli4_hba.nvme_xri_max; |
| 3806 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); |
| 3807 | /* release the extra allocated nvme buffers */ |
| 3808 | for (i = 0; i < nvme_xri_cnt; i++) { |
| 3809 | list_remove_head(&nvme_sgl_list, lpfc_ncmd, |
| 3810 | struct lpfc_nvme_buf, list); |
| 3811 | if (lpfc_ncmd) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3812 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3813 | lpfc_ncmd->data, |
| 3814 | lpfc_ncmd->dma_handle); |
| 3815 | kfree(lpfc_ncmd); |
| 3816 | } |
| 3817 | } |
| 3818 | spin_lock_irq(&phba->nvme_buf_list_get_lock); |
| 3819 | phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt; |
| 3820 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); |
| 3821 | } |
| 3822 | |
| 3823 | /* update xris associated to remaining allocated nvme buffers */ |
| 3824 | lpfc_ncmd = NULL; |
| 3825 | lpfc_ncmd_next = NULL; |
| 3826 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3827 | &nvme_sgl_list, list) { |
| 3828 | lxri = lpfc_sli4_next_xritag(phba); |
| 3829 | if (lxri == NO_XRI) { |
| 3830 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3831 | "6075 Failed to allocate xri for " |
| 3832 | "nvme buffer\n"); |
| 3833 | rc = -ENOMEM; |
| 3834 | goto out_free_mem; |
| 3835 | } |
| 3836 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; |
| 3837 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3838 | } |
| 3839 | spin_lock_irq(&phba->nvme_buf_list_get_lock); |
| 3840 | spin_lock(&phba->nvme_buf_list_put_lock); |
| 3841 | list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3842 | phba->get_nvme_bufs = cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3843 | INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put); |
| 3844 | spin_unlock(&phba->nvme_buf_list_put_lock); |
| 3845 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); |
| 3846 | return 0; |
| 3847 | |
| 3848 | out_free_mem: |
| 3849 | lpfc_nvme_free(phba); |
| 3850 | return rc; |
| 3851 | } |
| 3852 | |
| 3853 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3854 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3855 | * @phba: pointer to lpfc hba data structure. |
| 3856 | * @instance: a unique integer ID to this FC port. |
| 3857 | * @dev: pointer to the device data structure. |
| 3858 | * |
| 3859 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 3860 | * can be created on top of either a physical port or a virtual port provided |
| 3861 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 3862 | * and associates the FC port created before adding the shost into the SCSI |
| 3863 | * layer. |
| 3864 | * |
| 3865 | * Return codes |
| 3866 | * @vport - pointer to the virtual N_Port data structure. |
| 3867 | * NULL - port create failed. |
| 3868 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3869 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3870 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3871 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3872 | struct lpfc_vport *vport; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3873 | struct Scsi_Host *shost = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3874 | int error = 0; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3875 | int i; |
| 3876 | uint64_t wwn; |
| 3877 | bool use_no_reset_hba = false; |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 3878 | int rc; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3879 | |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 3880 | if (lpfc_no_hba_reset_cnt) { |
| 3881 | if (phba->sli_rev < LPFC_SLI_REV4 && |
| 3882 | dev == &phba->pcidev->dev) { |
| 3883 | /* Reset the port first */ |
| 3884 | lpfc_sli_brdrestart(phba); |
| 3885 | rc = lpfc_sli_chipset_init(phba); |
| 3886 | if (rc) |
| 3887 | return NULL; |
| 3888 | } |
| 3889 | wwn = lpfc_get_wwpn(phba); |
| 3890 | } |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3891 | |
| 3892 | for (i = 0; i < lpfc_no_hba_reset_cnt; i++) { |
| 3893 | if (wwn == lpfc_no_hba_reset[i]) { |
| 3894 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3895 | "6020 Setting use_no_reset port=%llx\n", |
| 3896 | wwn); |
| 3897 | use_no_reset_hba = true; |
| 3898 | break; |
| 3899 | } |
| 3900 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3901 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3902 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 3903 | if (dev != &phba->pcidev->dev) { |
| 3904 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 3905 | sizeof(struct lpfc_vport)); |
| 3906 | } else { |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3907 | if (!use_no_reset_hba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3908 | shost = scsi_host_alloc(&lpfc_template, |
| 3909 | sizeof(struct lpfc_vport)); |
| 3910 | else |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3911 | shost = scsi_host_alloc(&lpfc_template_no_hr, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3912 | sizeof(struct lpfc_vport)); |
| 3913 | } |
| 3914 | } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 3915 | shost = scsi_host_alloc(&lpfc_template_nvme, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 3916 | sizeof(struct lpfc_vport)); |
| 3917 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3918 | if (!shost) |
| 3919 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3920 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3921 | vport = (struct lpfc_vport *) shost->hostdata; |
| 3922 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3923 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3924 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3925 | vport->fc_rscn_flush = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3926 | lpfc_get_vport_cfgparam(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3927 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3928 | shost->unique_id = instance; |
| 3929 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3930 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3931 | shost->this_id = -1; |
| 3932 | shost->max_cmd_len = 16; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3933 | shost->nr_hw_queues = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3934 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3935 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 3936 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3937 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 3938 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3939 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3940 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3941 | * Set initial can_queue value since 0 is no longer supported and |
| 3942 | * scsi_add_host will fail. This will be adjusted later based on the |
| 3943 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3944 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3945 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3946 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3947 | shost->transportt = lpfc_vport_transport_template; |
| 3948 | vport->port_type = LPFC_NPIV_PORT; |
| 3949 | } else { |
| 3950 | shost->transportt = lpfc_transport_template; |
| 3951 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 3952 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3953 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3954 | /* Initialize all internally managed lists. */ |
| 3955 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3956 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3957 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3958 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3959 | timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3960 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3961 | timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3962 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3963 | timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3964 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 3965 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3966 | if (error) |
| 3967 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3968 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3969 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3970 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3971 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3972 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3973 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3974 | out_put_shost: |
| 3975 | scsi_host_put(shost); |
| 3976 | out: |
| 3977 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3978 | } |
| 3979 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3980 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3981 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3982 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 3983 | * |
| 3984 | * This routine destroys a FC port from the upper layer protocol. All the |
| 3985 | * resources associated with the port are released. |
| 3986 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3987 | void |
| 3988 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3989 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3990 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 3991 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3992 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3993 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3994 | fc_remove_host(shost); |
| 3995 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3996 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3997 | spin_lock_irq(&phba->hbalock); |
| 3998 | list_del_init(&vport->listentry); |
| 3999 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4000 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4001 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4002 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4003 | } |
| 4004 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4005 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4006 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4007 | * |
| 4008 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 4009 | * uses the kernel idr facility to perform the task. |
| 4010 | * |
| 4011 | * Return codes: |
| 4012 | * instance - a unique integer ID allocated as the new instance. |
| 4013 | * -1 - lpfc get instance failed. |
| 4014 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4015 | int |
| 4016 | lpfc_get_instance(void) |
| 4017 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4018 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4019 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4020 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 4021 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4022 | } |
| 4023 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4024 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4025 | * lpfc_scan_finished - method for SCSI layer to detect whether scan is done |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4026 | * @shost: pointer to SCSI host data structure. |
| 4027 | * @time: elapsed time of the scan in jiffies. |
| 4028 | * |
| 4029 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 4030 | * whether the scan host is finished. |
| 4031 | * |
| 4032 | * Note: there is no scan_start function as adapter initialization will have |
| 4033 | * asynchronously kicked off the link initialization. |
| 4034 | * |
| 4035 | * Return codes |
| 4036 | * 0 - SCSI host scan is not over yet. |
| 4037 | * 1 - SCSI host scan is over. |
| 4038 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4039 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 4040 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4041 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4042 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4043 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4044 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4045 | spin_lock_irq(shost->host_lock); |
| 4046 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4047 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4048 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4049 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4050 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4051 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4052 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4053 | "0461 Scanning longer than 30 " |
| 4054 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4055 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4056 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4057 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4058 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 4059 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4060 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4061 | "0465 Link down longer than 15 " |
| 4062 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4063 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4064 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4065 | } |
| 4066 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4067 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4068 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4069 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4070 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4071 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4072 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4073 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4074 | goto finished; |
| 4075 | |
| 4076 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4077 | |
| 4078 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4079 | spin_unlock_irq(shost->host_lock); |
| 4080 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4081 | } |
| 4082 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4083 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4084 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4085 | * @shost: pointer to SCSI host data structure. |
| 4086 | * |
| 4087 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 4088 | * SCSI host can be either on top of a physical port or a virtual port. |
| 4089 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4090 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 4091 | { |
| 4092 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4093 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4094 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4095 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4096 | */ |
| 4097 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4098 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 4099 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4100 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 4101 | |
| 4102 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4103 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4104 | fc_host_supported_fc4s(shost)[2] = 1; |
| 4105 | fc_host_supported_fc4s(shost)[7] = 1; |
| 4106 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4107 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 4108 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4109 | |
| 4110 | fc_host_supported_speeds(shost) = 0; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4111 | if (phba->lmt & LMT_32Gb) |
| 4112 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4113 | if (phba->lmt & LMT_16Gb) |
| 4114 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4115 | if (phba->lmt & LMT_10Gb) |
| 4116 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4117 | if (phba->lmt & LMT_8Gb) |
| 4118 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4119 | if (phba->lmt & LMT_4Gb) |
| 4120 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 4121 | if (phba->lmt & LMT_2Gb) |
| 4122 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 4123 | if (phba->lmt & LMT_1Gb) |
| 4124 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 4125 | |
| 4126 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4127 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 4128 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4129 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 4130 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 4131 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4132 | /* This value is also unchanging */ |
| 4133 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4134 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4135 | fc_host_active_fc4s(shost)[2] = 1; |
| 4136 | fc_host_active_fc4s(shost)[7] = 1; |
| 4137 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4138 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4139 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4140 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4141 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4142 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4143 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4144 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4145 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4146 | * @phba: pointer to lpfc hba data structure. |
| 4147 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4148 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 4149 | * from generating interrupts and stops the device driver's timers for the |
| 4150 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4151 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4152 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4153 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4154 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4155 | /* Clear all interrupt enable conditions */ |
| 4156 | writel(0, phba->HCregaddr); |
| 4157 | readl(phba->HCregaddr); /* flush */ |
| 4158 | /* Clear all pending interrupts */ |
| 4159 | writel(0xffffffff, phba->HAregaddr); |
| 4160 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4161 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4162 | /* Reset some HBA SLI setup states */ |
| 4163 | lpfc_stop_hba_timers(phba); |
| 4164 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4165 | } |
| 4166 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4167 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4168 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4169 | * @phba: pointer to lpfc hba data structure. |
| 4170 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4171 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 4172 | * from generating interrupts and stops the device driver's timers for the |
| 4173 | * device. |
| 4174 | **/ |
| 4175 | static void |
| 4176 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 4177 | { |
| 4178 | /* Reset some HBA SLI4 setup states */ |
| 4179 | lpfc_stop_hba_timers(phba); |
| 4180 | phba->pport->work_port_events = 0; |
| 4181 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | /** |
| 4185 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 4186 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4187 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4188 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 4189 | * the API jump table function pointer from the lpfc_hba struct. |
| 4190 | **/ |
| 4191 | void |
| 4192 | lpfc_stop_port(struct lpfc_hba *phba) |
| 4193 | { |
| 4194 | phba->lpfc_stop_port(phba); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 4195 | |
| 4196 | if (phba->wq) |
| 4197 | flush_workqueue(phba->wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4201 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 4202 | * @phba: Pointer to hba for which this call is being executed. |
| 4203 | * |
| 4204 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 4205 | **/ |
| 4206 | void |
| 4207 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 4208 | { |
| 4209 | unsigned long fcf_redisc_wait_tmo = |
| 4210 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 4211 | /* Start fcf rediscovery wait period timer */ |
| 4212 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 4213 | spin_lock_irq(&phba->hbalock); |
| 4214 | /* Allow action to new fcf asynchronous event */ |
| 4215 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 4216 | /* Mark the FCF rediscovery pending state */ |
| 4217 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 4218 | spin_unlock_irq(&phba->hbalock); |
| 4219 | } |
| 4220 | |
| 4221 | /** |
| 4222 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 4223 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4224 | * |
| 4225 | * This routine is invoked when waiting for FCF table rediscover has been |
| 4226 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 4227 | * wait period, a new FCF event shall be added to the FCOE async event |
| 4228 | * list, and then worker thread shall be waked up for processing from the |
| 4229 | * worker thread context. |
| 4230 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 4231 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4232 | lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4233 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4234 | struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4235 | |
| 4236 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 4237 | spin_lock_irq(&phba->hbalock); |
| 4238 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 4239 | spin_unlock_irq(&phba->hbalock); |
| 4240 | return; |
| 4241 | } |
| 4242 | /* Clear FCF rediscovery timer pending flag */ |
| 4243 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 4244 | /* FCF rediscovery event to worker thread */ |
| 4245 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 4246 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4247 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4248 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4249 | /* wake up worker thread */ |
| 4250 | lpfc_worker_wake_up(phba); |
| 4251 | } |
| 4252 | |
| 4253 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4254 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 4255 | * @phba: pointer to lpfc hba data structure. |
| 4256 | * @acqe_link: pointer to the async link completion queue entry. |
| 4257 | * |
| 4258 | * This routine is to parse the SLI4 link-attention link fault code and |
| 4259 | * translate it into the base driver's read link attention mailbox command |
| 4260 | * status. |
| 4261 | * |
| 4262 | * Return: Link-attention status in terms of base driver's coding. |
| 4263 | **/ |
| 4264 | static uint16_t |
| 4265 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 4266 | struct lpfc_acqe_link *acqe_link) |
| 4267 | { |
| 4268 | uint16_t latt_fault; |
| 4269 | |
| 4270 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 4271 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 4272 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 4273 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
| 4274 | latt_fault = 0; |
| 4275 | break; |
| 4276 | default: |
| 4277 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4278 | "0398 Invalid link fault code: x%x\n", |
| 4279 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
| 4280 | latt_fault = MBXERR_ERROR; |
| 4281 | break; |
| 4282 | } |
| 4283 | return latt_fault; |
| 4284 | } |
| 4285 | |
| 4286 | /** |
| 4287 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 4288 | * @phba: pointer to lpfc hba data structure. |
| 4289 | * @acqe_link: pointer to the async link completion queue entry. |
| 4290 | * |
| 4291 | * This routine is to parse the SLI4 link attention type and translate it |
| 4292 | * into the base driver's link attention type coding. |
| 4293 | * |
| 4294 | * Return: Link attention type in terms of base driver's coding. |
| 4295 | **/ |
| 4296 | static uint8_t |
| 4297 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 4298 | struct lpfc_acqe_link *acqe_link) |
| 4299 | { |
| 4300 | uint8_t att_type; |
| 4301 | |
| 4302 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 4303 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 4304 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4305 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4306 | break; |
| 4307 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 4308 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4309 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4310 | break; |
| 4311 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4312 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4313 | break; |
| 4314 | default: |
| 4315 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4316 | "0399 Invalid link attention type: x%x\n", |
| 4317 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4318 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4319 | break; |
| 4320 | } |
| 4321 | return att_type; |
| 4322 | } |
| 4323 | |
| 4324 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4325 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 4326 | * @phba: pointer to lpfc hba data structure. |
| 4327 | * |
| 4328 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 4329 | * |
| 4330 | * Return: link speed in terms of Mbps. |
| 4331 | **/ |
| 4332 | uint32_t |
| 4333 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 4334 | { |
| 4335 | uint32_t link_speed; |
| 4336 | |
| 4337 | if (!lpfc_is_link_up(phba)) |
| 4338 | return 0; |
| 4339 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4340 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 4341 | switch (phba->fc_linkspeed) { |
| 4342 | case LPFC_LINK_SPEED_1GHZ: |
| 4343 | link_speed = 1000; |
| 4344 | break; |
| 4345 | case LPFC_LINK_SPEED_2GHZ: |
| 4346 | link_speed = 2000; |
| 4347 | break; |
| 4348 | case LPFC_LINK_SPEED_4GHZ: |
| 4349 | link_speed = 4000; |
| 4350 | break; |
| 4351 | case LPFC_LINK_SPEED_8GHZ: |
| 4352 | link_speed = 8000; |
| 4353 | break; |
| 4354 | case LPFC_LINK_SPEED_10GHZ: |
| 4355 | link_speed = 10000; |
| 4356 | break; |
| 4357 | case LPFC_LINK_SPEED_16GHZ: |
| 4358 | link_speed = 16000; |
| 4359 | break; |
| 4360 | default: |
| 4361 | link_speed = 0; |
| 4362 | } |
| 4363 | } else { |
| 4364 | if (phba->sli4_hba.link_state.logical_speed) |
| 4365 | link_speed = |
| 4366 | phba->sli4_hba.link_state.logical_speed; |
| 4367 | else |
| 4368 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4369 | } |
| 4370 | return link_speed; |
| 4371 | } |
| 4372 | |
| 4373 | /** |
| 4374 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 4375 | * @phba: pointer to lpfc hba data structure. |
| 4376 | * @evt_code: asynchronous event code. |
| 4377 | * @speed_code: asynchronous event link speed code. |
| 4378 | * |
| 4379 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4380 | * value of Mbps for the link speed. |
| 4381 | * |
| 4382 | * Return: link speed in terms of Mbps. |
| 4383 | **/ |
| 4384 | static uint32_t |
| 4385 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 4386 | uint8_t speed_code) |
| 4387 | { |
| 4388 | uint32_t port_speed; |
| 4389 | |
| 4390 | switch (evt_code) { |
| 4391 | case LPFC_TRAILER_CODE_LINK: |
| 4392 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4393 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4394 | port_speed = 0; |
| 4395 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4396 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4397 | port_speed = 10; |
| 4398 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4399 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4400 | port_speed = 100; |
| 4401 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4402 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4403 | port_speed = 1000; |
| 4404 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4405 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4406 | port_speed = 10000; |
| 4407 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4408 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 4409 | port_speed = 20000; |
| 4410 | break; |
| 4411 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 4412 | port_speed = 25000; |
| 4413 | break; |
| 4414 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 4415 | port_speed = 40000; |
| 4416 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4417 | default: |
| 4418 | port_speed = 0; |
| 4419 | } |
| 4420 | break; |
| 4421 | case LPFC_TRAILER_CODE_FC: |
| 4422 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4423 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4424 | port_speed = 0; |
| 4425 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4426 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4427 | port_speed = 1000; |
| 4428 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4429 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4430 | port_speed = 2000; |
| 4431 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4432 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4433 | port_speed = 4000; |
| 4434 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4435 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4436 | port_speed = 8000; |
| 4437 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4438 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4439 | port_speed = 10000; |
| 4440 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4441 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4442 | port_speed = 16000; |
| 4443 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4444 | case LPFC_FC_LA_SPEED_32G: |
| 4445 | port_speed = 32000; |
| 4446 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4447 | default: |
| 4448 | port_speed = 0; |
| 4449 | } |
| 4450 | break; |
| 4451 | default: |
| 4452 | port_speed = 0; |
| 4453 | } |
| 4454 | return port_speed; |
| 4455 | } |
| 4456 | |
| 4457 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4458 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4459 | * @phba: pointer to lpfc hba data structure. |
| 4460 | * @acqe_link: pointer to the async link completion queue entry. |
| 4461 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4462 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4463 | **/ |
| 4464 | static void |
| 4465 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 4466 | struct lpfc_acqe_link *acqe_link) |
| 4467 | { |
| 4468 | struct lpfc_dmabuf *mp; |
| 4469 | LPFC_MBOXQ_t *pmb; |
| 4470 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4471 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4472 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4473 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4474 | |
| 4475 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4476 | if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4477 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 4478 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4479 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4480 | if (!pmb) { |
| 4481 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4482 | "0395 The mboxq allocation failed\n"); |
| 4483 | return; |
| 4484 | } |
| 4485 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4486 | if (!mp) { |
| 4487 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4488 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 4489 | goto out_free_pmb; |
| 4490 | } |
| 4491 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4492 | if (!mp->virt) { |
| 4493 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4494 | "0397 The mbuf allocation failed\n"); |
| 4495 | goto out_free_dmabuf; |
| 4496 | } |
| 4497 | |
| 4498 | /* Cleanup any outstanding ELS commands */ |
| 4499 | lpfc_els_flush_all_cmd(phba); |
| 4500 | |
| 4501 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4502 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4503 | |
| 4504 | /* Update link event statistics */ |
| 4505 | phba->sli.slistat.link_event++; |
| 4506 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4507 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 4508 | lpfc_read_topology(phba, pmb, mp); |
| 4509 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4510 | pmb->vport = phba->pport; |
| 4511 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4512 | /* Keep the link status for extra SLI4 state machine reference */ |
| 4513 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4514 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 4515 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4516 | phba->sli4_hba.link_state.duplex = |
| 4517 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 4518 | phba->sli4_hba.link_state.status = |
| 4519 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4520 | phba->sli4_hba.link_state.type = |
| 4521 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 4522 | phba->sli4_hba.link_state.number = |
| 4523 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4524 | phba->sli4_hba.link_state.fault = |
| 4525 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4526 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4527 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 4528 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4529 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 4530 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 4531 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 4532 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4533 | phba->sli4_hba.link_state.speed, |
| 4534 | phba->sli4_hba.link_state.topology, |
| 4535 | phba->sli4_hba.link_state.status, |
| 4536 | phba->sli4_hba.link_state.type, |
| 4537 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4538 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4539 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4540 | /* |
| 4541 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 4542 | * topology info. Note: Optional for non FC-AL ports. |
| 4543 | */ |
| 4544 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 4545 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4546 | if (rc == MBX_NOT_FINISHED) |
| 4547 | goto out_free_dmabuf; |
| 4548 | return; |
| 4549 | } |
| 4550 | /* |
| 4551 | * For FCoE Mode: fill in all the topology information we need and call |
| 4552 | * the READ_TOPOLOGY completion routine to continue without actually |
| 4553 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 4554 | */ |
| 4555 | /* Parse and translate status field */ |
| 4556 | mb = &pmb->u.mb; |
| 4557 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); |
| 4558 | |
| 4559 | /* Parse and translate link attention fields */ |
| 4560 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 4561 | la->eventTag = acqe_link->event_tag; |
| 4562 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 4563 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4564 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4565 | |
| 4566 | /* Fake the the following irrelvant fields */ |
| 4567 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 4568 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 4569 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 4570 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 4571 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 4572 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4573 | |
| 4574 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4575 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4576 | |
| 4577 | return; |
| 4578 | |
| 4579 | out_free_dmabuf: |
| 4580 | kfree(mp); |
| 4581 | out_free_pmb: |
| 4582 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4583 | } |
| 4584 | |
| 4585 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4586 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 4587 | * @phba: pointer to lpfc hba data structure. |
| 4588 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 4589 | * |
| 4590 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 4591 | * that the event was received and then issue a read_topology mailbox command so |
| 4592 | * that the rest of the driver will treat it the same as SLI3. |
| 4593 | **/ |
| 4594 | static void |
| 4595 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 4596 | { |
| 4597 | struct lpfc_dmabuf *mp; |
| 4598 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4599 | MAILBOX_t *mb; |
| 4600 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4601 | int rc; |
| 4602 | |
| 4603 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 4604 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 4605 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4606 | "2895 Non FC link Event detected.(%d)\n", |
| 4607 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 4608 | return; |
| 4609 | } |
| 4610 | /* Keep the link status for extra SLI4 state machine reference */ |
| 4611 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4612 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 4613 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4614 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 4615 | phba->sli4_hba.link_state.topology = |
| 4616 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 4617 | phba->sli4_hba.link_state.status = |
| 4618 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 4619 | phba->sli4_hba.link_state.type = |
| 4620 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 4621 | phba->sli4_hba.link_state.number = |
| 4622 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 4623 | phba->sli4_hba.link_state.fault = |
| 4624 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
| 4625 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4626 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4627 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4628 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 4629 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 4630 | "%dMbps Fault:%d\n", |
| 4631 | phba->sli4_hba.link_state.speed, |
| 4632 | phba->sli4_hba.link_state.topology, |
| 4633 | phba->sli4_hba.link_state.status, |
| 4634 | phba->sli4_hba.link_state.type, |
| 4635 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4636 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4637 | phba->sli4_hba.link_state.fault); |
| 4638 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4639 | if (!pmb) { |
| 4640 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4641 | "2897 The mboxq allocation failed\n"); |
| 4642 | return; |
| 4643 | } |
| 4644 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4645 | if (!mp) { |
| 4646 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4647 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 4648 | goto out_free_pmb; |
| 4649 | } |
| 4650 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4651 | if (!mp->virt) { |
| 4652 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4653 | "2899 The mbuf allocation failed\n"); |
| 4654 | goto out_free_dmabuf; |
| 4655 | } |
| 4656 | |
| 4657 | /* Cleanup any outstanding ELS commands */ |
| 4658 | lpfc_els_flush_all_cmd(phba); |
| 4659 | |
| 4660 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4661 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4662 | |
| 4663 | /* Update link event statistics */ |
| 4664 | phba->sli.slistat.link_event++; |
| 4665 | |
| 4666 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 4667 | lpfc_read_topology(phba, pmb, mp); |
| 4668 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 4669 | pmb->vport = phba->pport; |
| 4670 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4671 | if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) { |
James Smart | ae9e28f | 2017-05-15 15:20:51 -0700 | [diff] [blame] | 4672 | phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK); |
| 4673 | |
| 4674 | switch (phba->sli4_hba.link_state.status) { |
| 4675 | case LPFC_FC_LA_TYPE_MDS_LINK_DOWN: |
| 4676 | phba->link_flag |= LS_MDS_LINK_DOWN; |
| 4677 | break; |
| 4678 | case LPFC_FC_LA_TYPE_MDS_LOOPBACK: |
| 4679 | phba->link_flag |= LS_MDS_LOOPBACK; |
| 4680 | break; |
| 4681 | default: |
| 4682 | break; |
| 4683 | } |
| 4684 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4685 | /* Parse and translate status field */ |
| 4686 | mb = &pmb->u.mb; |
| 4687 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, |
| 4688 | (void *)acqe_fc); |
| 4689 | |
| 4690 | /* Parse and translate link attention fields */ |
| 4691 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 4692 | la->eventTag = acqe_fc->event_tag; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4693 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 4694 | if (phba->sli4_hba.link_state.status == |
| 4695 | LPFC_FC_LA_TYPE_UNEXP_WWPN) { |
| 4696 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 4697 | LPFC_FC_LA_TYPE_UNEXP_WWPN); |
| 4698 | } else { |
| 4699 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 4700 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 4701 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4702 | /* Invoke the mailbox command callback function */ |
| 4703 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 4704 | |
| 4705 | return; |
| 4706 | } |
| 4707 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4708 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4709 | if (rc == MBX_NOT_FINISHED) |
| 4710 | goto out_free_dmabuf; |
| 4711 | return; |
| 4712 | |
| 4713 | out_free_dmabuf: |
| 4714 | kfree(mp); |
| 4715 | out_free_pmb: |
| 4716 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4717 | } |
| 4718 | |
| 4719 | /** |
| 4720 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 4721 | * @phba: pointer to lpfc hba data structure. |
| 4722 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 4723 | * |
| 4724 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 4725 | **/ |
| 4726 | static void |
| 4727 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 4728 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4729 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 4730 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4731 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4732 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4733 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4734 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4735 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4736 | struct Scsi_Host *shost; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4737 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4738 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 4739 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4740 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4741 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 4742 | "x%08x SLI Event Type:%d\n", |
| 4743 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 4744 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4745 | |
| 4746 | port_name = phba->Port[0]; |
| 4747 | if (port_name == 0x00) |
| 4748 | port_name = '?'; /* get port name is empty */ |
| 4749 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4750 | switch (evt_type) { |
| 4751 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 4752 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 4753 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 4754 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 4755 | |
| 4756 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4757 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 4758 | acqe_sli->event_data1, port_name); |
| 4759 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4760 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4761 | shost = lpfc_shost_from_vport(phba->pport); |
| 4762 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4763 | sizeof(temp_event_data), |
| 4764 | (char *)&temp_event_data, |
| 4765 | SCSI_NL_VID_TYPE_PCI |
| 4766 | | PCI_VENDOR_ID_EMULEX); |
| 4767 | break; |
| 4768 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 4769 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 4770 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 4771 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 4772 | |
| 4773 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4774 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 4775 | acqe_sli->event_data1, port_name); |
| 4776 | |
| 4777 | shost = lpfc_shost_from_vport(phba->pport); |
| 4778 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4779 | sizeof(temp_event_data), |
| 4780 | (char *)&temp_event_data, |
| 4781 | SCSI_NL_VID_TYPE_PCI |
| 4782 | | PCI_VENDOR_ID_EMULEX); |
| 4783 | break; |
| 4784 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 4785 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4786 | &acqe_sli->event_data1; |
| 4787 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4788 | /* fetch the status for this port */ |
| 4789 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4790 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4791 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 4792 | &misconfigured->theEvent); |
| 4793 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4794 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4795 | break; |
| 4796 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4797 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 4798 | &misconfigured->theEvent); |
| 4799 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4800 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4801 | break; |
| 4802 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4803 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 4804 | &misconfigured->theEvent); |
| 4805 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4806 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4807 | break; |
| 4808 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4809 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 4810 | &misconfigured->theEvent); |
| 4811 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4812 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4813 | break; |
| 4814 | default: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4815 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4816 | "3296 " |
| 4817 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 4818 | "event: Invalid link %d", |
| 4819 | phba->sli4_hba.lnk_info.lnk_no); |
| 4820 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4821 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4822 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4823 | /* Skip if optic state unchanged */ |
| 4824 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 4825 | return; |
| 4826 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4827 | switch (status) { |
| 4828 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4829 | sprintf(message, "Physical Link is functional"); |
| 4830 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4831 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 4832 | sprintf(message, "Optics faulted/incorrectly " |
| 4833 | "installed/not installed - Reseat optics, " |
| 4834 | "if issue not resolved, replace."); |
| 4835 | break; |
| 4836 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 4837 | sprintf(message, |
| 4838 | "Optics of two types installed - Remove one " |
| 4839 | "optic or install matching pair of optics."); |
| 4840 | break; |
| 4841 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 4842 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 4843 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4844 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4845 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 4846 | sprintf(message, "Unqualified optics - Replace with " |
| 4847 | "Avago optics for Warranty and Technical " |
| 4848 | "Support - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4849 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4850 | break; |
| 4851 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 4852 | sprintf(message, "Uncertified optics - Replace with " |
| 4853 | "Avago-certified optics to enable link " |
| 4854 | "operation - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4855 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4856 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4857 | default: |
| 4858 | /* firmware is reporting a status we don't know about */ |
| 4859 | sprintf(message, "Unknown event status x%02x", status); |
| 4860 | break; |
| 4861 | } |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4862 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4863 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4864 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4865 | break; |
| 4866 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 4867 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4868 | "3192 Remote DPort Test Initiated - " |
| 4869 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 4870 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4871 | break; |
| 4872 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4873 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4874 | "3193 Async SLI event - Event Data1:x%08x Event Data2:" |
| 4875 | "x%08x SLI Event Type:%d\n", |
| 4876 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 4877 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4878 | break; |
| 4879 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4880 | } |
| 4881 | |
| 4882 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4883 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 4884 | * @vport: pointer to vport data structure. |
| 4885 | * |
| 4886 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 4887 | * response to a CVL event. |
| 4888 | * |
| 4889 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 4890 | * return NULL. |
| 4891 | **/ |
| 4892 | static struct lpfc_nodelist * |
| 4893 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 4894 | { |
| 4895 | struct lpfc_nodelist *ndlp; |
| 4896 | struct Scsi_Host *shost; |
| 4897 | struct lpfc_hba *phba; |
| 4898 | |
| 4899 | if (!vport) |
| 4900 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4901 | phba = vport->phba; |
| 4902 | if (!phba) |
| 4903 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 4904 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 4905 | if (!ndlp) { |
| 4906 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4907 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 4908 | if (!ndlp) |
| 4909 | return 0; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 4910 | /* Set the node type */ |
| 4911 | ndlp->nlp_type |= NLP_FABRIC; |
| 4912 | /* Put ndlp onto node list */ |
| 4913 | lpfc_enqueue_node(vport, ndlp); |
| 4914 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4915 | /* re-setup ndlp without removing from node list */ |
| 4916 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 4917 | if (!ndlp) |
| 4918 | return 0; |
| 4919 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4920 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 4921 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4922 | return NULL; |
| 4923 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4924 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 4925 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4926 | return NULL; |
| 4927 | shost = lpfc_shost_from_vport(vport); |
| 4928 | if (!shost) |
| 4929 | return NULL; |
| 4930 | lpfc_linkdown_port(vport); |
| 4931 | lpfc_cleanup_pending_mbox(vport); |
| 4932 | spin_lock_irq(shost->host_lock); |
| 4933 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 4934 | spin_unlock_irq(shost->host_lock); |
| 4935 | |
| 4936 | return ndlp; |
| 4937 | } |
| 4938 | |
| 4939 | /** |
| 4940 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 4941 | * @vport: pointer to lpfc hba data structure. |
| 4942 | * |
| 4943 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 4944 | * response to a FCF dead event. |
| 4945 | **/ |
| 4946 | static void |
| 4947 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 4948 | { |
| 4949 | struct lpfc_vport **vports; |
| 4950 | int i; |
| 4951 | |
| 4952 | vports = lpfc_create_vport_work_array(phba); |
| 4953 | if (vports) |
| 4954 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 4955 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 4956 | lpfc_destroy_vport_work_array(phba, vports); |
| 4957 | } |
| 4958 | |
| 4959 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4960 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4961 | * @phba: pointer to lpfc hba data structure. |
| 4962 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 4963 | * |
| 4964 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 4965 | **/ |
| 4966 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4967 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4968 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4969 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4970 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4971 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4972 | struct lpfc_vport *vport; |
| 4973 | struct lpfc_nodelist *ndlp; |
| 4974 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4975 | int active_vlink_present; |
| 4976 | struct lpfc_vport **vports; |
| 4977 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4978 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4979 | phba->fc_eventTag = acqe_fip->event_tag; |
| 4980 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4981 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4982 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 4983 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 4984 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4985 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 4986 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4987 | "2546 New FCF event, evt_tag:x%x, " |
| 4988 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4989 | acqe_fip->event_tag, |
| 4990 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 4991 | else |
| 4992 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 4993 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4994 | "2788 FCF param modified event, " |
| 4995 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4996 | acqe_fip->event_tag, |
| 4997 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 4998 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4999 | /* |
| 5000 | * During period of FCF discovery, read the FCF |
| 5001 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5002 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5003 | */ |
| 5004 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5005 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5006 | "2779 Read FCF (x%x) for updating " |
| 5007 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5008 | acqe_fip->index); |
| 5009 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5010 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5011 | |
| 5012 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5013 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5014 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5015 | spin_unlock_irq(&phba->hbalock); |
| 5016 | break; |
| 5017 | } |
| 5018 | /* If fast FCF failover rescan event is pending, do nothing */ |
| 5019 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
| 5020 | spin_unlock_irq(&phba->hbalock); |
| 5021 | break; |
| 5022 | } |
| 5023 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5024 | /* If the FCF has been in discovered state, do nothing. */ |
| 5025 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5026 | spin_unlock_irq(&phba->hbalock); |
| 5027 | break; |
| 5028 | } |
| 5029 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5030 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5031 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 5032 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5033 | "2770 Start FCF table scan per async FCF " |
| 5034 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5035 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5036 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 5037 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5038 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5039 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5040 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5041 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5042 | break; |
| 5043 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5044 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5045 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 5046 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5047 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 5048 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5049 | break; |
| 5050 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5051 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5052 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5053 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5054 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5055 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5056 | /* |
| 5057 | * If we are in the middle of FCF failover process, clear |
| 5058 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5059 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5060 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame] | 5061 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 5062 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5063 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5064 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5065 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5066 | break; |
| 5067 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5068 | spin_unlock_irq(&phba->hbalock); |
| 5069 | |
| 5070 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5071 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5072 | break; |
| 5073 | |
| 5074 | /* |
| 5075 | * Otherwise, request the port to rediscover the entire FCF |
| 5076 | * table for a fast recovery from case that the current FCF |
| 5077 | * is no longer valid as we are not in the middle of FCF |
| 5078 | * failover process already. |
| 5079 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5080 | spin_lock_irq(&phba->hbalock); |
| 5081 | /* Mark the fast failover process in progress */ |
| 5082 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 5083 | spin_unlock_irq(&phba->hbalock); |
| 5084 | |
| 5085 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 5086 | "2771 Start FCF fast failover process due to " |
| 5087 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 5088 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 5089 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 5090 | if (rc) { |
| 5091 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5092 | LOG_DISCOVERY, |
| 5093 | "2772 Issue FCF rediscover mabilbox " |
| 5094 | "command failed, fail through to FCF " |
| 5095 | "dead event\n"); |
| 5096 | spin_lock_irq(&phba->hbalock); |
| 5097 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 5098 | spin_unlock_irq(&phba->hbalock); |
| 5099 | /* |
| 5100 | * Last resort will fail over by treating this |
| 5101 | * as a link down to FCF registration. |
| 5102 | */ |
| 5103 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 5104 | } else { |
| 5105 | /* Reset FCF roundrobin bmask for new discovery */ |
| 5106 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 5107 | /* |
| 5108 | * Handling fast FCF failover to a DEAD FCF event is |
| 5109 | * considered equalivant to receiving CVL to all vports. |
| 5110 | */ |
| 5111 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 5112 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5113 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5114 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5115 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5116 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5117 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5118 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5119 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5120 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5121 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5122 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5123 | if (!ndlp) |
| 5124 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5125 | active_vlink_present = 0; |
| 5126 | |
| 5127 | vports = lpfc_create_vport_work_array(phba); |
| 5128 | if (vports) { |
| 5129 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5130 | i++) { |
| 5131 | if ((!(vports[i]->fc_flag & |
| 5132 | FC_VPORT_CVL_RCVD)) && |
| 5133 | (vports[i]->port_state > LPFC_FDISC)) { |
| 5134 | active_vlink_present = 1; |
| 5135 | break; |
| 5136 | } |
| 5137 | } |
| 5138 | lpfc_destroy_vport_work_array(phba, vports); |
| 5139 | } |
| 5140 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 5141 | /* |
| 5142 | * Don't re-instantiate if vport is marked for deletion. |
| 5143 | * If we are here first then vport_delete is going to wait |
| 5144 | * for discovery to complete. |
| 5145 | */ |
| 5146 | if (!(vport->load_flag & FC_UNLOADING) && |
| 5147 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5148 | /* |
| 5149 | * If there are other active VLinks present, |
| 5150 | * re-instantiate the Vlink using FDISC. |
| 5151 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 5152 | mod_timer(&ndlp->nlp_delayfunc, |
| 5153 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5154 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5155 | spin_lock_irq(shost->host_lock); |
| 5156 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 5157 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5158 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 5159 | vport->port_state = LPFC_FDISC; |
| 5160 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5161 | /* |
| 5162 | * Otherwise, we request port to rediscover |
| 5163 | * the entire FCF table for a fast recovery |
| 5164 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5165 | * is no longer valid if we are not already |
| 5166 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5167 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5168 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5169 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5170 | spin_unlock_irq(&phba->hbalock); |
| 5171 | break; |
| 5172 | } |
| 5173 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5174 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5175 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5176 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5177 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5178 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5179 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5180 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5181 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5182 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5183 | LOG_DISCOVERY, |
| 5184 | "2774 Issue FCF rediscover " |
| 5185 | "mabilbox command failed, " |
| 5186 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5187 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5188 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5189 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5190 | /* |
| 5191 | * Last resort will be re-try on the |
| 5192 | * the current registered FCF entry. |
| 5193 | */ |
| 5194 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5195 | } else |
| 5196 | /* |
| 5197 | * Reset FCF roundrobin bmask for new |
| 5198 | * discovery. |
| 5199 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 5200 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5201 | } |
| 5202 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5203 | default: |
| 5204 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5205 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5206 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5207 | break; |
| 5208 | } |
| 5209 | } |
| 5210 | |
| 5211 | /** |
| 5212 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 5213 | * @phba: pointer to lpfc hba data structure. |
| 5214 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 5215 | * |
| 5216 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 5217 | **/ |
| 5218 | static void |
| 5219 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 5220 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 5221 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5222 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5223 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5224 | "0290 The SLI4 DCBX asynchronous event is not " |
| 5225 | "handled yet\n"); |
| 5226 | } |
| 5227 | |
| 5228 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5229 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 5230 | * @phba: pointer to lpfc hba data structure. |
| 5231 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 5232 | * |
| 5233 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 5234 | * is an asynchronous notified of a logical link speed change. The Port |
| 5235 | * reports the logical link speed in units of 10Mbps. |
| 5236 | **/ |
| 5237 | static void |
| 5238 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 5239 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 5240 | { |
| 5241 | uint16_t prev_ll_spd; |
| 5242 | |
| 5243 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 5244 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 5245 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 5246 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5247 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5248 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5249 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5250 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 5251 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5255 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 5256 | * @phba: pointer to lpfc hba data structure. |
| 5257 | * |
| 5258 | * This routine is invoked by the worker thread to process all the pending |
| 5259 | * SLI4 asynchronous events. |
| 5260 | **/ |
| 5261 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 5262 | { |
| 5263 | struct lpfc_cq_event *cq_event; |
| 5264 | |
| 5265 | /* First, declare the async event has been handled */ |
| 5266 | spin_lock_irq(&phba->hbalock); |
| 5267 | phba->hba_flag &= ~ASYNC_EVENT; |
| 5268 | spin_unlock_irq(&phba->hbalock); |
| 5269 | /* Now, handle all the async events */ |
| 5270 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 5271 | /* Get the first event from the head of the event queue */ |
| 5272 | spin_lock_irq(&phba->hbalock); |
| 5273 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 5274 | cq_event, struct lpfc_cq_event, list); |
| 5275 | spin_unlock_irq(&phba->hbalock); |
| 5276 | /* Process the asynchronous event */ |
| 5277 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 5278 | case LPFC_TRAILER_CODE_LINK: |
| 5279 | lpfc_sli4_async_link_evt(phba, |
| 5280 | &cq_event->cqe.acqe_link); |
| 5281 | break; |
| 5282 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5283 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5284 | break; |
| 5285 | case LPFC_TRAILER_CODE_DCBX: |
| 5286 | lpfc_sli4_async_dcbx_evt(phba, |
| 5287 | &cq_event->cqe.acqe_dcbx); |
| 5288 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5289 | case LPFC_TRAILER_CODE_GRP5: |
| 5290 | lpfc_sli4_async_grp5_evt(phba, |
| 5291 | &cq_event->cqe.acqe_grp5); |
| 5292 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5293 | case LPFC_TRAILER_CODE_FC: |
| 5294 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 5295 | break; |
| 5296 | case LPFC_TRAILER_CODE_SLI: |
| 5297 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 5298 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5299 | default: |
| 5300 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5301 | "1804 Invalid asynchrous event code: " |
| 5302 | "x%x\n", bf_get(lpfc_trailer_code, |
| 5303 | &cq_event->cqe.mcqe_cmpl)); |
| 5304 | break; |
| 5305 | } |
| 5306 | /* Free the completion event processed to the free pool */ |
| 5307 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 5308 | } |
| 5309 | } |
| 5310 | |
| 5311 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5312 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 5313 | * @phba: pointer to lpfc hba data structure. |
| 5314 | * |
| 5315 | * This routine is invoked by the worker thread to process FCF table |
| 5316 | * rediscovery pending completion event. |
| 5317 | **/ |
| 5318 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 5319 | { |
| 5320 | int rc; |
| 5321 | |
| 5322 | spin_lock_irq(&phba->hbalock); |
| 5323 | /* Clear FCF rediscovery timeout event */ |
| 5324 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 5325 | /* Clear driver fast failover FCF record flag */ |
| 5326 | phba->fcf.failover_rec.flag = 0; |
| 5327 | /* Set state for FCF fast failover */ |
| 5328 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 5329 | spin_unlock_irq(&phba->hbalock); |
| 5330 | |
| 5331 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5332 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5333 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5334 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5335 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5336 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5337 | "2747 Issue FCF scan read FCF mailbox " |
| 5338 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5339 | } |
| 5340 | |
| 5341 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5342 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 5343 | * @phba: pointer to lpfc hba data structure. |
| 5344 | * @dev_grp: The HBA PCI-Device group number. |
| 5345 | * |
| 5346 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 5347 | * API jump table entries. |
| 5348 | * |
| 5349 | * Return: 0 if success, otherwise -ENODEV |
| 5350 | **/ |
| 5351 | int |
| 5352 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5353 | { |
| 5354 | int rc; |
| 5355 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5356 | /* Set up lpfc PCI-device group */ |
| 5357 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5358 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5359 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 5360 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 5361 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5362 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5363 | /* Set up device INIT API function jump table */ |
| 5364 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 5365 | if (rc) |
| 5366 | return -ENODEV; |
| 5367 | /* Set up SCSI API function jump table */ |
| 5368 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 5369 | if (rc) |
| 5370 | return -ENODEV; |
| 5371 | /* Set up SLI API function jump table */ |
| 5372 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 5373 | if (rc) |
| 5374 | return -ENODEV; |
| 5375 | /* Set up MBOX API function jump table */ |
| 5376 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 5377 | if (rc) |
| 5378 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5379 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5380 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5384 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5385 | * @phba: pointer to lpfc hba data structure. |
| 5386 | * @intr_mode: active interrupt mode adopted. |
| 5387 | * |
| 5388 | * This routine it invoked to log the currently used active interrupt mode |
| 5389 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5390 | **/ |
| 5391 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5392 | { |
| 5393 | switch (intr_mode) { |
| 5394 | case 0: |
| 5395 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5396 | "0470 Enable INTx interrupt mode.\n"); |
| 5397 | break; |
| 5398 | case 1: |
| 5399 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5400 | "0481 Enabled MSI interrupt mode.\n"); |
| 5401 | break; |
| 5402 | case 2: |
| 5403 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5404 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 5405 | break; |
| 5406 | default: |
| 5407 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5408 | "0482 Illegal interrupt mode.\n"); |
| 5409 | break; |
| 5410 | } |
| 5411 | return; |
| 5412 | } |
| 5413 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5414 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5415 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5416 | * @phba: pointer to lpfc hba data structure. |
| 5417 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5418 | * This routine is invoked to enable the PCI device that is common to all |
| 5419 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5420 | * |
| 5421 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5422 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5423 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5424 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5425 | static int |
| 5426 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5427 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5428 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5429 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5430 | /* Obtain PCI device reference */ |
| 5431 | if (!phba->pcidev) |
| 5432 | goto out_error; |
| 5433 | else |
| 5434 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5435 | /* Enable PCI device */ |
| 5436 | if (pci_enable_device_mem(pdev)) |
| 5437 | goto out_error; |
| 5438 | /* Request PCI resource for the device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 5439 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5440 | goto out_disable_device; |
| 5441 | /* Set up device as PCI master and save state for EEH */ |
| 5442 | pci_set_master(pdev); |
| 5443 | pci_try_set_mwi(pdev); |
| 5444 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5445 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5446 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 5447 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5448 | pdev->needs_freset = 1; |
| 5449 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5450 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5451 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5452 | out_disable_device: |
| 5453 | pci_disable_device(pdev); |
| 5454 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 5455 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 5456 | "1401 Failed to enable pci device\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5457 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5461 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5462 | * @phba: pointer to lpfc hba data structure. |
| 5463 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5464 | * This routine is invoked to disable the PCI device that is common to all |
| 5465 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5466 | **/ |
| 5467 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5468 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5469 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5470 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5471 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5472 | /* Obtain PCI device reference */ |
| 5473 | if (!phba->pcidev) |
| 5474 | return; |
| 5475 | else |
| 5476 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5477 | /* Release PCI resource and disable PCI device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 5478 | pci_release_mem_regions(pdev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5479 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5480 | |
| 5481 | return; |
| 5482 | } |
| 5483 | |
| 5484 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5485 | * lpfc_reset_hba - Reset a hba |
| 5486 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5487 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5488 | * This routine is invoked to reset a hba device. It brings the HBA |
| 5489 | * offline, performs a board restart, and then brings the board back |
| 5490 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 5491 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5492 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5493 | void |
| 5494 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5495 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5496 | /* If resets are disabled then set error state and return. */ |
| 5497 | if (!phba->cfg_enable_hba_reset) { |
| 5498 | phba->link_state = LPFC_HBA_ERROR; |
| 5499 | return; |
| 5500 | } |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 5501 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 5502 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
| 5503 | else |
| 5504 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5505 | lpfc_offline(phba); |
| 5506 | lpfc_sli_brdrestart(phba); |
| 5507 | lpfc_online(phba); |
| 5508 | lpfc_unblock_mgmt_io(phba); |
| 5509 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5510 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5511 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 5512 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 5513 | * @phba: pointer to lpfc hba data structure. |
| 5514 | * |
| 5515 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 5516 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 5517 | * enable the number of virtual functions to the physical function. As |
| 5518 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 5519 | * API call does not considered as an error condition for most of the device. |
| 5520 | **/ |
| 5521 | uint16_t |
| 5522 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 5523 | { |
| 5524 | struct pci_dev *pdev = phba->pcidev; |
| 5525 | uint16_t nr_virtfn; |
| 5526 | int pos; |
| 5527 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 5528 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 5529 | if (pos == 0) |
| 5530 | return 0; |
| 5531 | |
| 5532 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 5533 | return nr_virtfn; |
| 5534 | } |
| 5535 | |
| 5536 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5537 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 5538 | * @phba: pointer to lpfc hba data structure. |
| 5539 | * @nr_vfn: number of virtual functions to be enabled. |
| 5540 | * |
| 5541 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 5542 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 5543 | * enable the number of virtual functions to the physical function. As |
| 5544 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 5545 | * API call does not considered as an error condition for most of the device. |
| 5546 | **/ |
| 5547 | int |
| 5548 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 5549 | { |
| 5550 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 5551 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5552 | int rc; |
| 5553 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 5554 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 5555 | if (nr_vfn > max_nr_vfn) { |
| 5556 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5557 | "3057 Requested vfs (%d) greater than " |
| 5558 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 5559 | return -EINVAL; |
| 5560 | } |
| 5561 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5562 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 5563 | if (rc) { |
| 5564 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5565 | "2806 Failed to enable sriov on this device " |
| 5566 | "with vfn number nr_vf:%d, rc:%d\n", |
| 5567 | nr_vfn, rc); |
| 5568 | } else |
| 5569 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5570 | "2807 Successful enable sriov on this device " |
| 5571 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 5572 | return rc; |
| 5573 | } |
| 5574 | |
| 5575 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5576 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5577 | * @phba: pointer to lpfc hba data structure. |
| 5578 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5579 | * This routine is invoked to set up the driver internal resources before the |
| 5580 | * device specific resource setup to support the HBA device it attached to. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5581 | * |
| 5582 | * Return codes |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5583 | * 0 - successful |
| 5584 | * other values - error |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5585 | **/ |
| 5586 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5587 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5588 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5589 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5590 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5591 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5592 | * Driver resources common to all SLI revisions |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5593 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5594 | atomic_set(&phba->fast_event_count, 0); |
| 5595 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5596 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5597 | /* Initialize ndlp management spinlock */ |
| 5598 | spin_lock_init(&phba->ndlp_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5599 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5600 | INIT_LIST_HEAD(&phba->port_list); |
| 5601 | INIT_LIST_HEAD(&phba->work_list); |
| 5602 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| 5603 | |
| 5604 | /* Initialize the wait queue head for the kernel thread */ |
| 5605 | init_waitqueue_head(&phba->work_waitq); |
| 5606 | |
| 5607 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 5608 | "1403 Protocols supported %s %s %s\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5609 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
| 5610 | "SCSI" : " "), |
| 5611 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 5612 | "NVME" : " "), |
| 5613 | (phba->nvmet_support ? "NVMET" : " ")); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5614 | |
| 5615 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 5616 | /* Initialize the scsi buffer list used by driver for scsi IO */ |
| 5617 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 5618 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 5619 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 5620 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 5621 | } |
| 5622 | |
| 5623 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 5624 | (phba->nvmet_support == 0)) { |
| 5625 | /* Initialize the NVME buffer list used by driver for NVME IO */ |
| 5626 | spin_lock_init(&phba->nvme_buf_list_get_lock); |
| 5627 | INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 5628 | phba->get_nvme_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5629 | spin_lock_init(&phba->nvme_buf_list_put_lock); |
| 5630 | INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 5631 | phba->put_nvme_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5632 | } |
| 5633 | |
| 5634 | /* Initialize the fabric iocb list */ |
| 5635 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 5636 | |
| 5637 | /* Initialize list to save ELS buffers */ |
| 5638 | INIT_LIST_HEAD(&phba->elsbuf); |
| 5639 | |
| 5640 | /* Initialize FCF connection rec list */ |
| 5641 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| 5642 | |
| 5643 | /* Initialize OAS configuration list */ |
| 5644 | spin_lock_init(&phba->devicelock); |
| 5645 | INIT_LIST_HEAD(&phba->luns); |
| 5646 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5647 | /* MBOX heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5648 | timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5649 | /* Fabric block timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5650 | timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5651 | /* EA polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5652 | timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5653 | /* Heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5654 | timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5655 | |
| 5656 | return 0; |
| 5657 | } |
| 5658 | |
| 5659 | /** |
| 5660 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev |
| 5661 | * @phba: pointer to lpfc hba data structure. |
| 5662 | * |
| 5663 | * This routine is invoked to set up the driver internal resources specific to |
| 5664 | * support the SLI-3 HBA device it attached to. |
| 5665 | * |
| 5666 | * Return codes |
| 5667 | * 0 - successful |
| 5668 | * other values - error |
| 5669 | **/ |
| 5670 | static int |
| 5671 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 5672 | { |
| 5673 | int rc; |
| 5674 | |
| 5675 | /* |
| 5676 | * Initialize timers used by driver |
| 5677 | */ |
| 5678 | |
| 5679 | /* FCP polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5680 | timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5681 | |
| 5682 | /* Host attention work mask setup */ |
| 5683 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 5684 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 5685 | |
| 5686 | /* Get all the module params for configuring this host */ |
| 5687 | lpfc_get_cfgparam(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5688 | /* Set up phase-1 common device driver resources */ |
| 5689 | |
| 5690 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 5691 | if (rc) |
| 5692 | return -ENODEV; |
| 5693 | |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5694 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 5695 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 5696 | /* check for menlo minimum sg count */ |
| 5697 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 5698 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 5699 | } |
| 5700 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5701 | if (!phba->sli.sli3_ring) |
| 5702 | phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5703 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5704 | if (!phba->sli.sli3_ring) |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5705 | return -ENOMEM; |
| 5706 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5707 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5708 | * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5709 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5710 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5711 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5712 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5713 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 5714 | lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5715 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5716 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5717 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 5718 | if (phba->cfg_enable_bg) { |
| 5719 | /* |
| 5720 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 5721 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 5722 | * over how many protection data segments the SCSI Layer |
| 5723 | * will hand us (ie: there could be one for every block |
| 5724 | * in the IO), we just allocate enough BDEs to accomidate |
| 5725 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 5726 | * minimize the risk of running out. |
| 5727 | */ |
| 5728 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5729 | sizeof(struct fcp_rsp) + |
| 5730 | (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64)); |
| 5731 | |
| 5732 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 5733 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 5734 | |
| 5735 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 5736 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 5737 | } else { |
| 5738 | /* |
| 5739 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 5740 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 5741 | * cfg_sg_seg_cnt data segments. |
| 5742 | */ |
| 5743 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5744 | sizeof(struct fcp_rsp) + |
| 5745 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
| 5746 | |
| 5747 | /* Total BDEs in BPL for scsi_sg_list */ |
| 5748 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 5749 | } |
| 5750 | |
| 5751 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5752 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 5753 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5754 | phba->cfg_total_seg_cnt); |
| 5755 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5756 | phba->max_vpi = LPFC_MAX_VPI; |
| 5757 | /* This will be set to correct value after config_port mbox */ |
| 5758 | phba->max_vports = 0; |
| 5759 | |
| 5760 | /* |
| 5761 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 5762 | */ |
| 5763 | lpfc_sli_setup(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5764 | lpfc_sli_queue_init(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5765 | |
| 5766 | /* Allocate device driver memory */ |
| 5767 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 5768 | return -ENOMEM; |
| 5769 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5770 | /* |
| 5771 | * Enable sr-iov virtual functions if supported and configured |
| 5772 | * through the module parameter. |
| 5773 | */ |
| 5774 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 5775 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 5776 | phba->cfg_sriov_nr_virtfn); |
| 5777 | if (rc) { |
| 5778 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5779 | "2808 Requested number of SR-IOV " |
| 5780 | "virtual functions (%d) is not " |
| 5781 | "supported\n", |
| 5782 | phba->cfg_sriov_nr_virtfn); |
| 5783 | phba->cfg_sriov_nr_virtfn = 0; |
| 5784 | } |
| 5785 | } |
| 5786 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5787 | return 0; |
| 5788 | } |
| 5789 | |
| 5790 | /** |
| 5791 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 5792 | * @phba: pointer to lpfc hba data structure. |
| 5793 | * |
| 5794 | * This routine is invoked to unset the driver internal resources set up |
| 5795 | * specific for supporting the SLI-3 HBA device it attached to. |
| 5796 | **/ |
| 5797 | static void |
| 5798 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 5799 | { |
| 5800 | /* Free device driver memory allocated */ |
| 5801 | lpfc_mem_free_all(phba); |
| 5802 | |
| 5803 | return; |
| 5804 | } |
| 5805 | |
| 5806 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5807 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 5808 | * @phba: pointer to lpfc hba data structure. |
| 5809 | * |
| 5810 | * This routine is invoked to set up the driver internal resources specific to |
| 5811 | * support the SLI-4 HBA device it attached to. |
| 5812 | * |
| 5813 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5814 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5815 | * other values - error |
| 5816 | **/ |
| 5817 | static int |
| 5818 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 5819 | { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5820 | LPFC_MBOXQ_t *mboxq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 5821 | MAILBOX_t *mb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5822 | int rc, i, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5823 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 5824 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5825 | int longs; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5826 | int fof_vectors = 0; |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5827 | int extra; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 5828 | uint64_t wwn; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5829 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5830 | phba->sli4_hba.num_online_cpu = num_online_cpus(); |
| 5831 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
| 5832 | phba->sli4_hba.curr_disp_cpu = 0; |
| 5833 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 5834 | /* Get all the module params for configuring this host */ |
| 5835 | lpfc_get_cfgparam(phba); |
| 5836 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5837 | /* Set up phase-1 common device driver resources */ |
| 5838 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 5839 | if (rc) |
| 5840 | return -ENODEV; |
| 5841 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5842 | /* Before proceed, wait for POST done and device ready */ |
| 5843 | rc = lpfc_sli4_post_status_check(phba); |
| 5844 | if (rc) |
| 5845 | return -ENODEV; |
| 5846 | |
| 5847 | /* |
| 5848 | * Initialize timers used by driver |
| 5849 | */ |
| 5850 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5851 | timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5852 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5853 | /* FCF rediscover timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5854 | timer_setup(&phba->fcf.redisc_wait, lpfc_sli4_fcf_redisc_wait_tmo, 0); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5855 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5856 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 5857 | * Control structure for handling external multi-buffer mailbox |
| 5858 | * command pass-through. |
| 5859 | */ |
| 5860 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 5861 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 5862 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 5863 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5864 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5865 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5866 | /* This will be set to correct value after the read_config mbox */ |
| 5867 | phba->max_vports = 0; |
| 5868 | |
| 5869 | /* Program the default value of vlan_id and fc_map */ |
| 5870 | phba->valid_vlan = 0; |
| 5871 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5872 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5873 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5874 | |
| 5875 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5876 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5877 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
| 5878 | * The WQ create will allocate the ring. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5879 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5880 | |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5881 | /* |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5882 | * 1 for cmd, 1 for rsp, NVME adds an extra one |
| 5883 | * for boundary conditions in its max_sgl_segment template. |
| 5884 | */ |
| 5885 | extra = 2; |
| 5886 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 5887 | extra++; |
| 5888 | |
| 5889 | /* |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5890 | * It doesn't matter what family our adapter is in, we are |
| 5891 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 5892 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 5893 | */ |
| 5894 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5895 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - extra) |
| 5896 | phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - extra; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5897 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5898 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5899 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
| 5900 | * used to create the sg_dma_buf_pool must be calculated. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5901 | */ |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5902 | if (phba->cfg_enable_bg) { |
| 5903 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5904 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
| 5905 | * the FCP rsp, and a SGE. Sice we have no control |
| 5906 | * over how many protection segments the SCSI Layer |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5907 | * will hand us (ie: there could be one for every block |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5908 | * in the IO), just allocate enough SGEs to accomidate |
| 5909 | * our max amount and we need to limit lpfc_sg_seg_cnt |
| 5910 | * to minimize the risk of running out. |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5911 | */ |
| 5912 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5913 | sizeof(struct fcp_rsp) + max_buf_size; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5914 | |
| 5915 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 5916 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 5917 | |
| 5918 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5919 | phba->cfg_sg_seg_cnt = |
| 5920 | LPFC_MAX_SG_SLI4_SEG_CNT_DIF; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5921 | } else { |
| 5922 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5923 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5924 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 5925 | * cfg_sg_seg_cnt data segments. |
| 5926 | */ |
| 5927 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5928 | sizeof(struct fcp_rsp) + |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5929 | ((phba->cfg_sg_seg_cnt + extra) * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5930 | sizeof(struct sli4_sge)); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5931 | |
| 5932 | /* Total SGEs for scsi_sg_list */ |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5933 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5934 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5935 | /* |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5936 | * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5937 | * need to post 1 page for the SGL. |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5938 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5939 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 5940 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5941 | /* Initialize the host templates with the updated values. */ |
| 5942 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5943 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 5944 | lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5945 | |
| 5946 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 5947 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 5948 | else |
| 5949 | phba->cfg_sg_dma_buf_size = |
| 5950 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 5951 | |
| 5952 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5953 | "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n", |
| 5954 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5955 | phba->cfg_total_seg_cnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5956 | |
| 5957 | /* Initialize buffer queue management fields */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5958 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5959 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 5960 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 5961 | |
| 5962 | /* |
| 5963 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 5964 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5965 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 5966 | /* Initialize the Abort scsi buffer list used by driver */ |
| 5967 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 5968 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 5969 | } |
| 5970 | |
| 5971 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 5972 | /* Initialize the Abort nvme buffer list used by driver */ |
| 5973 | spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock); |
| 5974 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 5975 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 5976 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5977 | } |
| 5978 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5979 | /* This abort list used by worker thread */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5980 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 5981 | spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5982 | |
| 5983 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5984 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5985 | */ |
| 5986 | |
| 5987 | /* Driver internel slow-path CQ Event pool */ |
| 5988 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 5989 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 5990 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5991 | /* Asynchronous event CQ Event work queue list */ |
| 5992 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 5993 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 5994 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 5995 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 5996 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 5997 | /* Receive queue CQ Event work queue list */ |
| 5998 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 5999 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6000 | /* Initialize extent block lists. */ |
| 6001 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 6002 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 6003 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 6004 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 6005 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6006 | /* Initialize mboxq lists. If the early init routines fail |
| 6007 | * these lists need to be correctly initialized. |
| 6008 | */ |
| 6009 | INIT_LIST_HEAD(&phba->sli.mboxq); |
| 6010 | INIT_LIST_HEAD(&phba->sli.mboxq_cmpl); |
| 6011 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6012 | /* initialize optic_state to 0xFF */ |
| 6013 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 6014 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6015 | /* Allocate device driver memory */ |
| 6016 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 6017 | if (rc) |
| 6018 | return -ENOMEM; |
| 6019 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6020 | /* IF Type 2 ports get initialized now. */ |
| 6021 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6022 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 6023 | rc = lpfc_pci_function_reset(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6024 | if (unlikely(rc)) { |
| 6025 | rc = -ENODEV; |
| 6026 | goto out_free_mem; |
| 6027 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6028 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6029 | } |
| 6030 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6031 | /* Create the bootstrap mailbox command */ |
| 6032 | rc = lpfc_create_bootstrap_mbox(phba); |
| 6033 | if (unlikely(rc)) |
| 6034 | goto out_free_mem; |
| 6035 | |
| 6036 | /* Set up the host's endian order with the device. */ |
| 6037 | rc = lpfc_setup_endian_order(phba); |
| 6038 | if (unlikely(rc)) |
| 6039 | goto out_free_bsmbx; |
| 6040 | |
| 6041 | /* Set up the hba's configuration parameters. */ |
| 6042 | rc = lpfc_sli4_read_config(phba); |
| 6043 | if (unlikely(rc)) |
| 6044 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6045 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 6046 | if (unlikely(rc)) |
| 6047 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6048 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6049 | /* IF Type 0 ports get initialized now. */ |
| 6050 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6051 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6052 | rc = lpfc_pci_function_reset(phba); |
| 6053 | if (unlikely(rc)) |
| 6054 | goto out_free_bsmbx; |
| 6055 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6056 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6057 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6058 | GFP_KERNEL); |
| 6059 | if (!mboxq) { |
| 6060 | rc = -ENOMEM; |
| 6061 | goto out_free_bsmbx; |
| 6062 | } |
| 6063 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6064 | /* Check for NVMET being configured */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6065 | phba->nvmet_support = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6066 | if (lpfc_enable_nvmet_cnt) { |
| 6067 | |
| 6068 | /* First get WWN of HBA instance */ |
| 6069 | lpfc_read_nv(phba, mboxq); |
| 6070 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6071 | if (rc != MBX_SUCCESS) { |
| 6072 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6073 | "6016 Mailbox failed , mbxCmd x%x " |
| 6074 | "READ_NV, mbxStatus x%x\n", |
| 6075 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 6076 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6077 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6078 | rc = -EIO; |
| 6079 | goto out_free_bsmbx; |
| 6080 | } |
| 6081 | mb = &mboxq->u.mb; |
| 6082 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, |
| 6083 | sizeof(uint64_t)); |
| 6084 | wwn = cpu_to_be64(wwn); |
| 6085 | phba->sli4_hba.wwnn.u.name = wwn; |
| 6086 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, |
| 6087 | sizeof(uint64_t)); |
| 6088 | /* wwn is WWPN of HBA instance */ |
| 6089 | wwn = cpu_to_be64(wwn); |
| 6090 | phba->sli4_hba.wwpn.u.name = wwn; |
| 6091 | |
| 6092 | /* Check to see if it matches any module parameter */ |
| 6093 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { |
| 6094 | if (wwn == lpfc_enable_nvmet[i]) { |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6095 | #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6096 | if (lpfc_nvmet_mem_alloc(phba)) |
| 6097 | break; |
| 6098 | |
| 6099 | phba->nvmet_support = 1; /* a match */ |
| 6100 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6101 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6102 | "6017 NVME Target %016llx\n", |
| 6103 | wwn); |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6104 | #else |
| 6105 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6106 | "6021 Can't enable NVME Target." |
| 6107 | " NVME_TARGET_FC infrastructure" |
| 6108 | " is not in kernel\n"); |
| 6109 | #endif |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6110 | break; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6111 | } |
| 6112 | } |
| 6113 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6114 | |
| 6115 | lpfc_nvme_mod_param_dep(phba); |
| 6116 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6117 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6118 | lpfc_supported_pages(mboxq); |
| 6119 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6120 | if (!rc) { |
| 6121 | mqe = &mboxq->u.mqe; |
| 6122 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 6123 | LPFC_MAX_SUPPORTED_PAGES); |
| 6124 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 6125 | switch (pn_page[i]) { |
| 6126 | case LPFC_SLI4_PARAMETERS: |
| 6127 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 6128 | break; |
| 6129 | default: |
| 6130 | break; |
| 6131 | } |
| 6132 | } |
| 6133 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 6134 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 6135 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 6136 | if (rc) { |
| 6137 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6138 | rc = -EIO; |
| 6139 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6140 | } |
| 6141 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6142 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6143 | /* |
| 6144 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6145 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 6146 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6147 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6148 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 6149 | if (rc) { |
| 6150 | if (phba->sli4_hba.extents_in_use && |
| 6151 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 6152 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6153 | "2999 Unsupported SLI4 Parameters " |
| 6154 | "Extents and RPI headers enabled.\n"); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6155 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6156 | mempool_free(mboxq, phba->mbox_mem_pool); |
Stefano Brivio | 5c75606 | 2017-09-06 11:02:56 +0200 | [diff] [blame] | 6157 | rc = -EIO; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6158 | goto out_free_bsmbx; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6159 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6160 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6161 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6162 | |
| 6163 | /* Verify OAS is supported */ |
| 6164 | lpfc_sli4_oas_verify(phba); |
| 6165 | if (phba->cfg_fof) |
| 6166 | fof_vectors = 1; |
| 6167 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6168 | /* Verify all the SLI4 queues */ |
| 6169 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6170 | if (rc) |
| 6171 | goto out_free_bsmbx; |
| 6172 | |
| 6173 | /* Create driver internal CQE event pool */ |
| 6174 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 6175 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6176 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6177 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6178 | /* Initialize sgl lists per host */ |
| 6179 | lpfc_init_sgl_list(phba); |
| 6180 | |
| 6181 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6182 | rc = lpfc_init_active_sgl_array(phba); |
| 6183 | if (rc) { |
| 6184 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6185 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6186 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6187 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6188 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 6189 | if (rc) { |
| 6190 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6191 | "1432 Failed to initialize rpi headers.\n"); |
| 6192 | goto out_free_active_sgl; |
| 6193 | } |
| 6194 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6195 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6196 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
| 6197 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), |
| 6198 | GFP_KERNEL); |
| 6199 | if (!phba->fcf.fcf_rr_bmask) { |
| 6200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6201 | "2759 Failed allocate memory for FCF round " |
| 6202 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6203 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6204 | goto out_remove_rpi_hdrs; |
| 6205 | } |
| 6206 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6207 | phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs, |
| 6208 | sizeof(struct lpfc_hba_eq_hdl), |
| 6209 | GFP_KERNEL); |
| 6210 | if (!phba->sli4_hba.hba_eq_hdl) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6211 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6212 | "2572 Failed allocate memory for " |
| 6213 | "fast-path per-EQ handle array\n"); |
| 6214 | rc = -ENOMEM; |
| 6215 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6216 | } |
| 6217 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6218 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu, |
| 6219 | sizeof(struct lpfc_vector_map_info), |
| 6220 | GFP_KERNEL); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6221 | if (!phba->sli4_hba.cpu_map) { |
| 6222 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6223 | "3327 Failed allocate memory for msi-x " |
| 6224 | "interrupt vector mapping\n"); |
| 6225 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6226 | goto out_free_hba_eq_hdl; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6227 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6228 | if (lpfc_used_cpu == NULL) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6229 | lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t), |
| 6230 | GFP_KERNEL); |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6231 | if (!lpfc_used_cpu) { |
| 6232 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6233 | "3335 Failed allocate memory for msi-x " |
| 6234 | "interrupt vector mapping\n"); |
| 6235 | kfree(phba->sli4_hba.cpu_map); |
| 6236 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6237 | goto out_free_hba_eq_hdl; |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6238 | } |
| 6239 | for (i = 0; i < lpfc_present_cpu; i++) |
| 6240 | lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY; |
| 6241 | } |
| 6242 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6243 | /* |
| 6244 | * Enable sr-iov virtual functions if supported and configured |
| 6245 | * through the module parameter. |
| 6246 | */ |
| 6247 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6248 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6249 | phba->cfg_sriov_nr_virtfn); |
| 6250 | if (rc) { |
| 6251 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6252 | "3020 Requested number of SR-IOV " |
| 6253 | "virtual functions (%d) is not " |
| 6254 | "supported\n", |
| 6255 | phba->cfg_sriov_nr_virtfn); |
| 6256 | phba->cfg_sriov_nr_virtfn = 0; |
| 6257 | } |
| 6258 | } |
| 6259 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 6260 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6261 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6262 | out_free_hba_eq_hdl: |
| 6263 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6264 | out_free_fcf_rr_bmask: |
| 6265 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6266 | out_remove_rpi_hdrs: |
| 6267 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 6268 | out_free_active_sgl: |
| 6269 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6270 | out_destroy_cq_event_pool: |
| 6271 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6272 | out_free_bsmbx: |
| 6273 | lpfc_destroy_bootstrap_mbox(phba); |
| 6274 | out_free_mem: |
| 6275 | lpfc_mem_free(phba); |
| 6276 | return rc; |
| 6277 | } |
| 6278 | |
| 6279 | /** |
| 6280 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 6281 | * @phba: pointer to lpfc hba data structure. |
| 6282 | * |
| 6283 | * This routine is invoked to unset the driver internal resources set up |
| 6284 | * specific for supporting the SLI-4 HBA device it attached to. |
| 6285 | **/ |
| 6286 | static void |
| 6287 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 6288 | { |
| 6289 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6290 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6291 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 6292 | kfree(phba->sli4_hba.cpu_map); |
| 6293 | phba->sli4_hba.num_present_cpu = 0; |
| 6294 | phba->sli4_hba.num_online_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 6295 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6296 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6297 | /* Free memory allocated for fast-path work queue handles */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6298 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6299 | |
| 6300 | /* Free the allocated rpi headers. */ |
| 6301 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 6302 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6303 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6304 | /* Free eligible FCF index bmask */ |
| 6305 | kfree(phba->fcf.fcf_rr_bmask); |
| 6306 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6307 | /* Free the ELS sgl list */ |
| 6308 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6309 | lpfc_free_els_sgl_list(phba); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6310 | lpfc_free_nvmet_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6311 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6312 | /* Free the completion queue EQ event pool */ |
| 6313 | lpfc_sli4_cq_event_release_all(phba); |
| 6314 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 6315 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6316 | /* Release resource identifiers. */ |
| 6317 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6318 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6319 | /* Free the bsmbx region. */ |
| 6320 | lpfc_destroy_bootstrap_mbox(phba); |
| 6321 | |
| 6322 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 6323 | lpfc_mem_free_all(phba); |
| 6324 | |
| 6325 | /* Free the current connect table */ |
| 6326 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6327 | &phba->fcf_conn_rec_list, list) { |
| 6328 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6329 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6330 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6331 | |
| 6332 | return; |
| 6333 | } |
| 6334 | |
| 6335 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6336 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6337 | * @phba: The hba struct for which this call is being executed. |
| 6338 | * @dev_grp: The HBA PCI-Device group number. |
| 6339 | * |
| 6340 | * This routine sets up the device INIT interface API function jump table |
| 6341 | * in @phba struct. |
| 6342 | * |
| 6343 | * Returns: 0 - success, -ENODEV - failure. |
| 6344 | **/ |
| 6345 | int |
| 6346 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 6347 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 6348 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 6349 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 6350 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6351 | switch (dev_grp) { |
| 6352 | case LPFC_PCI_DEV_LP: |
| 6353 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 6354 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 6355 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 6356 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6357 | case LPFC_PCI_DEV_OC: |
| 6358 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 6359 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 6360 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 6361 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6362 | default: |
| 6363 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6364 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 6365 | dev_grp); |
| 6366 | return -ENODEV; |
| 6367 | break; |
| 6368 | } |
| 6369 | return 0; |
| 6370 | } |
| 6371 | |
| 6372 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6373 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 6374 | * @phba: pointer to lpfc hba data structure. |
| 6375 | * |
| 6376 | * This routine is invoked to set up the driver internal resources after the |
| 6377 | * device specific resource setup to support the HBA device it attached to. |
| 6378 | * |
| 6379 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6380 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6381 | * other values - error |
| 6382 | **/ |
| 6383 | static int |
| 6384 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 6385 | { |
| 6386 | int error; |
| 6387 | |
| 6388 | /* Startup the kernel thread for this host adapter. */ |
| 6389 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 6390 | "lpfc_worker_%d", phba->brd_no); |
| 6391 | if (IS_ERR(phba->worker_thread)) { |
| 6392 | error = PTR_ERR(phba->worker_thread); |
| 6393 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 6394 | } |
| 6395 | |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 6396 | /* workqueue for deferred irq use */ |
| 6397 | phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); |
| 6398 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6399 | return 0; |
| 6400 | } |
| 6401 | |
| 6402 | /** |
| 6403 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 6404 | * @phba: pointer to lpfc hba data structure. |
| 6405 | * |
| 6406 | * This routine is invoked to unset the driver internal resources set up after |
| 6407 | * the device specific resource setup for supporting the HBA device it |
| 6408 | * attached to. |
| 6409 | **/ |
| 6410 | static void |
| 6411 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 6412 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 6413 | if (phba->wq) { |
| 6414 | flush_workqueue(phba->wq); |
| 6415 | destroy_workqueue(phba->wq); |
| 6416 | phba->wq = NULL; |
| 6417 | } |
| 6418 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6419 | /* Stop kernel worker thread */ |
| 6420 | kthread_stop(phba->worker_thread); |
| 6421 | } |
| 6422 | |
| 6423 | /** |
| 6424 | * lpfc_free_iocb_list - Free iocb list. |
| 6425 | * @phba: pointer to lpfc hba data structure. |
| 6426 | * |
| 6427 | * This routine is invoked to free the driver's IOCB list and memory. |
| 6428 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6429 | void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6430 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 6431 | { |
| 6432 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 6433 | |
| 6434 | spin_lock_irq(&phba->hbalock); |
| 6435 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 6436 | &phba->lpfc_iocb_list, list) { |
| 6437 | list_del(&iocbq_entry->list); |
| 6438 | kfree(iocbq_entry); |
| 6439 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 6440 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6441 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6442 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6443 | return; |
| 6444 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6445 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6446 | /** |
| 6447 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 6448 | * @phba: pointer to lpfc hba data structure. |
| 6449 | * |
| 6450 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 6451 | * list and set up the IOCB tag array accordingly. |
| 6452 | * |
| 6453 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6454 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6455 | * other values - error |
| 6456 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6457 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6458 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 6459 | { |
| 6460 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 6461 | uint16_t iotag; |
| 6462 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6463 | |
| 6464 | /* Initialize and populate the iocb list per host. */ |
| 6465 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6466 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 6467 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6468 | if (iocbq_entry == NULL) { |
| 6469 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 6470 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 6471 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6472 | goto out_free_iocbq; |
| 6473 | } |
| 6474 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 6475 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 6476 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6477 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 6478 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6479 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 6480 | goto out_free_iocbq; |
| 6481 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6482 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6483 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6484 | |
| 6485 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6486 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 6487 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6488 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6489 | } |
| 6490 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6491 | return 0; |
| 6492 | |
| 6493 | out_free_iocbq: |
| 6494 | lpfc_free_iocb_list(phba); |
| 6495 | |
| 6496 | return -ENOMEM; |
| 6497 | } |
| 6498 | |
| 6499 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6500 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6501 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6502 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6503 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6504 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6505 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6506 | void |
| 6507 | lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6508 | { |
| 6509 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6510 | |
| 6511 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 6512 | list_del(&sglq_entry->list); |
| 6513 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 6514 | kfree(sglq_entry); |
| 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | /** |
| 6519 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 6520 | * @phba: pointer to lpfc hba data structure. |
| 6521 | * |
| 6522 | * This routine is invoked to free the driver's els sgl list and memory. |
| 6523 | **/ |
| 6524 | static void |
| 6525 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 6526 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6527 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6528 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6529 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6530 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6531 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6532 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); |
| 6533 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6534 | spin_unlock_irq(&phba->hbalock); |
| 6535 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6536 | /* Now free the sgl list */ |
| 6537 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6541 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. |
| 6542 | * @phba: pointer to lpfc hba data structure. |
| 6543 | * |
| 6544 | * This routine is invoked to free the driver's nvmet sgl list and memory. |
| 6545 | **/ |
| 6546 | static void |
| 6547 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) |
| 6548 | { |
| 6549 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6550 | LIST_HEAD(sglq_list); |
| 6551 | |
| 6552 | /* Retrieve all nvmet sgls from driver list */ |
| 6553 | spin_lock_irq(&phba->hbalock); |
| 6554 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6555 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); |
| 6556 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 6557 | spin_unlock_irq(&phba->hbalock); |
| 6558 | |
| 6559 | /* Now free the sgl list */ |
| 6560 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { |
| 6561 | list_del(&sglq_entry->list); |
| 6562 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 6563 | kfree(sglq_entry); |
| 6564 | } |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 6565 | |
| 6566 | /* Update the nvmet_xri_cnt to reflect no current sgls. |
| 6567 | * The next initialization cycle sets the count and allocates |
| 6568 | * the sgls over again. |
| 6569 | */ |
| 6570 | phba->sli4_hba.nvmet_xri_cnt = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6571 | } |
| 6572 | |
| 6573 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6574 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 6575 | * @phba: pointer to lpfc hba data structure. |
| 6576 | * |
| 6577 | * This routine is invoked to allocate the driver's active sgl memory. |
| 6578 | * This array will hold the sglq_entry's for active IOs. |
| 6579 | **/ |
| 6580 | static int |
| 6581 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 6582 | { |
| 6583 | int size; |
| 6584 | size = sizeof(struct lpfc_sglq *); |
| 6585 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 6586 | |
| 6587 | phba->sli4_hba.lpfc_sglq_active_list = |
| 6588 | kzalloc(size, GFP_KERNEL); |
| 6589 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 6590 | return -ENOMEM; |
| 6591 | return 0; |
| 6592 | } |
| 6593 | |
| 6594 | /** |
| 6595 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 6596 | * @phba: pointer to lpfc hba data structure. |
| 6597 | * |
| 6598 | * This routine is invoked to walk through the array of active sglq entries |
| 6599 | * and free all of the resources. |
| 6600 | * This is just a place holder for now. |
| 6601 | **/ |
| 6602 | static void |
| 6603 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 6604 | { |
| 6605 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 6606 | } |
| 6607 | |
| 6608 | /** |
| 6609 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 6610 | * @phba: pointer to lpfc hba data structure. |
| 6611 | * |
| 6612 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 6613 | * list and set up the sgl xritag tag array accordingly. |
| 6614 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6615 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6616 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6617 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 6618 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6619 | /* Initialize and populate the sglq list per host/VF. */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6620 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6621 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6622 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 6623 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6624 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6625 | /* els xri-sgl book keeping */ |
| 6626 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6627 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6628 | /* scsi xri-buffer book keeping */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6629 | phba->sli4_hba.scsi_xri_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6630 | |
| 6631 | /* nvme xri-buffer book keeping */ |
| 6632 | phba->sli4_hba.nvme_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6633 | } |
| 6634 | |
| 6635 | /** |
| 6636 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 6637 | * @phba: pointer to lpfc hba data structure. |
| 6638 | * |
| 6639 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6640 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6641 | * posts a PAGE_SIZE memory region to the port to hold up to |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6642 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 6643 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6644 | * |
| 6645 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6646 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6647 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6648 | **/ |
| 6649 | int |
| 6650 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 6651 | { |
| 6652 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6653 | struct lpfc_rpi_hdr *rpi_hdr; |
| 6654 | |
| 6655 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6656 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6657 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6658 | if (phba->sli4_hba.extents_in_use) |
| 6659 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6660 | |
| 6661 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 6662 | if (!rpi_hdr) { |
| 6663 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6664 | "0391 Error during rpi post operation\n"); |
| 6665 | lpfc_sli4_remove_rpis(phba); |
| 6666 | rc = -ENODEV; |
| 6667 | } |
| 6668 | |
| 6669 | return rc; |
| 6670 | } |
| 6671 | |
| 6672 | /** |
| 6673 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 6674 | * @phba: pointer to lpfc hba data structure. |
| 6675 | * |
| 6676 | * This routine is invoked to allocate a single 4KB memory region to |
| 6677 | * support rpis and stores them in the phba. This single region |
| 6678 | * provides support for up to 64 rpis. The region is used globally |
| 6679 | * by the device. |
| 6680 | * |
| 6681 | * Returns: |
| 6682 | * A valid rpi hdr on success. |
| 6683 | * A NULL pointer on any failure. |
| 6684 | **/ |
| 6685 | struct lpfc_rpi_hdr * |
| 6686 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 6687 | { |
| 6688 | uint16_t rpi_limit, curr_rpi_range; |
| 6689 | struct lpfc_dmabuf *dmabuf; |
| 6690 | struct lpfc_rpi_hdr *rpi_hdr; |
| 6691 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6692 | /* |
| 6693 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 6694 | * required. Set the expected maximum count and let the actual value |
| 6695 | * get set when extents are fully allocated. |
| 6696 | */ |
| 6697 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6698 | return NULL; |
| 6699 | if (phba->sli4_hba.extents_in_use) |
| 6700 | return NULL; |
| 6701 | |
| 6702 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 6703 | rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6704 | |
| 6705 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6706 | /* |
| 6707 | * Establish the starting RPI in this header block. The starting |
| 6708 | * rpi is normalized to a zero base because the physical rpi is |
| 6709 | * port based. |
| 6710 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6711 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6712 | spin_unlock_irq(&phba->hbalock); |
| 6713 | |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 6714 | /* Reached full RPI range */ |
| 6715 | if (curr_rpi_range == rpi_limit) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6716 | return NULL; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 6717 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6718 | /* |
| 6719 | * First allocate the protocol header region for the port. The |
| 6720 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 6721 | */ |
| 6722 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6723 | if (!dmabuf) |
| 6724 | return NULL; |
| 6725 | |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 6726 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 6727 | LPFC_HDR_TEMPLATE_SIZE, |
| 6728 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6729 | if (!dmabuf->virt) { |
| 6730 | rpi_hdr = NULL; |
| 6731 | goto err_free_dmabuf; |
| 6732 | } |
| 6733 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6734 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 6735 | rpi_hdr = NULL; |
| 6736 | goto err_free_coherent; |
| 6737 | } |
| 6738 | |
| 6739 | /* Save the rpi header data for cleanup later. */ |
| 6740 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 6741 | if (!rpi_hdr) |
| 6742 | goto err_free_coherent; |
| 6743 | |
| 6744 | rpi_hdr->dmabuf = dmabuf; |
| 6745 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 6746 | rpi_hdr->page_count = 1; |
| 6747 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6748 | |
| 6749 | /* The rpi_hdr stores the logical index only. */ |
| 6750 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 6751 | rpi_hdr->next_rpi = phba->sli4_hba.next_rpi + LPFC_RPI_HDR_COUNT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6752 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 6753 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6754 | spin_unlock_irq(&phba->hbalock); |
| 6755 | return rpi_hdr; |
| 6756 | |
| 6757 | err_free_coherent: |
| 6758 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 6759 | dmabuf->virt, dmabuf->phys); |
| 6760 | err_free_dmabuf: |
| 6761 | kfree(dmabuf); |
| 6762 | return NULL; |
| 6763 | } |
| 6764 | |
| 6765 | /** |
| 6766 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 6767 | * @phba: pointer to lpfc hba data structure. |
| 6768 | * |
| 6769 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6770 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 6771 | * presumes the caller has released all rpis consumed by fabric or port |
| 6772 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6773 | **/ |
| 6774 | void |
| 6775 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 6776 | { |
| 6777 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 6778 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6779 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6780 | goto exit; |
| 6781 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6782 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 6783 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 6784 | list_del(&rpi_hdr->list); |
| 6785 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 6786 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 6787 | kfree(rpi_hdr->dmabuf); |
| 6788 | kfree(rpi_hdr); |
| 6789 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6790 | exit: |
| 6791 | /* There are no rpis available to the port now. */ |
| 6792 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6793 | } |
| 6794 | |
| 6795 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6796 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 6797 | * @pdev: pointer to pci device data structure. |
| 6798 | * |
| 6799 | * This routine is invoked to allocate the driver hba data structure for an |
| 6800 | * HBA device. If the allocation is successful, the phba reference to the |
| 6801 | * PCI device data structure is set. |
| 6802 | * |
| 6803 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6804 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6805 | * NULL - error |
| 6806 | **/ |
| 6807 | static struct lpfc_hba * |
| 6808 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 6809 | { |
| 6810 | struct lpfc_hba *phba; |
| 6811 | |
| 6812 | /* Allocate memory for HBA structure */ |
| 6813 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 6814 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 6815 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6816 | return NULL; |
| 6817 | } |
| 6818 | |
| 6819 | /* Set reference to PCI device in HBA structure */ |
| 6820 | phba->pcidev = pdev; |
| 6821 | |
| 6822 | /* Assign an unused board number */ |
| 6823 | phba->brd_no = lpfc_get_instance(); |
| 6824 | if (phba->brd_no < 0) { |
| 6825 | kfree(phba); |
| 6826 | return NULL; |
| 6827 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6828 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6829 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 6830 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 6831 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 6832 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6833 | return phba; |
| 6834 | } |
| 6835 | |
| 6836 | /** |
| 6837 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 6838 | * @phba: pointer to lpfc hba data structure. |
| 6839 | * |
| 6840 | * This routine is invoked to free the driver hba data structure with an |
| 6841 | * HBA device. |
| 6842 | **/ |
| 6843 | static void |
| 6844 | lpfc_hba_free(struct lpfc_hba *phba) |
| 6845 | { |
| 6846 | /* Release the driver assigned board number */ |
| 6847 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 6848 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6849 | /* Free memory allocated with sli3 rings */ |
| 6850 | kfree(phba->sli.sli3_ring); |
| 6851 | phba->sli.sli3_ring = NULL; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6852 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6853 | kfree(phba); |
| 6854 | return; |
| 6855 | } |
| 6856 | |
| 6857 | /** |
| 6858 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 6859 | * @phba: pointer to lpfc hba data structure. |
| 6860 | * |
| 6861 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 6862 | * host with it. |
| 6863 | * |
| 6864 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6865 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6866 | * other values - error |
| 6867 | **/ |
| 6868 | static int |
| 6869 | lpfc_create_shost(struct lpfc_hba *phba) |
| 6870 | { |
| 6871 | struct lpfc_vport *vport; |
| 6872 | struct Scsi_Host *shost; |
| 6873 | |
| 6874 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6875 | phba->fc_edtov = FF_DEF_EDTOV; |
| 6876 | phba->fc_ratov = FF_DEF_RATOV; |
| 6877 | phba->fc_altov = FF_DEF_ALTOV; |
| 6878 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 6879 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 6880 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 6881 | atomic_set(&phba->fc4ScsiInputRequests, 0); |
| 6882 | atomic_set(&phba->fc4ScsiOutputRequests, 0); |
| 6883 | atomic_set(&phba->fc4ScsiControlRequests, 0); |
| 6884 | atomic_set(&phba->fc4ScsiIoCmpls, 0); |
| 6885 | atomic_set(&phba->fc4NvmeInputRequests, 0); |
| 6886 | atomic_set(&phba->fc4NvmeOutputRequests, 0); |
| 6887 | atomic_set(&phba->fc4NvmeControlRequests, 0); |
| 6888 | atomic_set(&phba->fc4NvmeIoCmpls, 0); |
| 6889 | atomic_set(&phba->fc4NvmeLsRequests, 0); |
| 6890 | atomic_set(&phba->fc4NvmeLsCmpls, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6891 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6892 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6893 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6894 | |
| 6895 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6896 | phba->pport = vport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 6897 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6898 | if (phba->nvmet_support) { |
| 6899 | /* Only 1 vport (pport) will support NVME target */ |
| 6900 | if (phba->txrdy_payload_pool == NULL) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 6901 | phba->txrdy_payload_pool = dma_pool_create( |
| 6902 | "txrdy_pool", &phba->pcidev->dev, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6903 | TXRDY_PAYLOAD_LEN, 16, 0); |
| 6904 | if (phba->txrdy_payload_pool) { |
| 6905 | phba->targetport = NULL; |
| 6906 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; |
| 6907 | lpfc_printf_log(phba, KERN_INFO, |
| 6908 | LOG_INIT | LOG_NVME_DISC, |
| 6909 | "6076 NVME Target Found\n"); |
| 6910 | } |
| 6911 | } |
| 6912 | } |
| 6913 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6914 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6915 | /* Put reference to SCSI host to driver's device private data */ |
| 6916 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6917 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6918 | /* |
| 6919 | * At this point we are fully registered with PSA. In addition, |
| 6920 | * any initial discovery should be completed. |
| 6921 | */ |
| 6922 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 6923 | if (phba->cfg_enable_SmartSAN || |
| 6924 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6925 | |
| 6926 | /* Setup appropriate attribute masks */ |
| 6927 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 6928 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6929 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 6930 | else |
| 6931 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 6932 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6933 | return 0; |
| 6934 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6935 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6936 | /** |
| 6937 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 6938 | * @phba: pointer to lpfc hba data structure. |
| 6939 | * |
| 6940 | * This routine is invoked to destroy HBA physical port and the associated |
| 6941 | * SCSI host. |
| 6942 | **/ |
| 6943 | static void |
| 6944 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 6945 | { |
| 6946 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6947 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6948 | /* Destroy physical port that associated with the SCSI host */ |
| 6949 | destroy_port(vport); |
| 6950 | |
| 6951 | return; |
| 6952 | } |
| 6953 | |
| 6954 | /** |
| 6955 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 6956 | * @phba: pointer to lpfc hba data structure. |
| 6957 | * @shost: the shost to be used to detect Block guard settings. |
| 6958 | * |
| 6959 | * This routine sets up the local Block guard protocol settings for @shost. |
| 6960 | * This routine also allocates memory for debugging bg buffers. |
| 6961 | **/ |
| 6962 | static void |
| 6963 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 6964 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6965 | uint32_t old_mask; |
| 6966 | uint32_t old_guard; |
| 6967 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6968 | int pagecnt = 10; |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 6969 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6970 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6971 | "1478 Registering BlockGuard with the " |
| 6972 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6973 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 6974 | old_mask = phba->cfg_prot_mask; |
| 6975 | old_guard = phba->cfg_prot_guard; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6976 | |
| 6977 | /* Only allow supported values */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 6978 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6979 | SHOST_DIX_TYPE0_PROTECTION | |
| 6980 | SHOST_DIX_TYPE1_PROTECTION); |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 6981 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
| 6982 | SHOST_DIX_GUARD_CRC); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6983 | |
| 6984 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 6985 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 6986 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6987 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 6988 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
| 6989 | if ((old_mask != phba->cfg_prot_mask) || |
| 6990 | (old_guard != phba->cfg_prot_guard)) |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6991 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6992 | "1475 Registering BlockGuard with the " |
| 6993 | "SCSI layer: mask %d guard %d\n", |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 6994 | phba->cfg_prot_mask, |
| 6995 | phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6996 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 6997 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
| 6998 | scsi_host_set_guard(shost, phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6999 | } else |
| 7000 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7001 | "1479 Not Registering BlockGuard with the SCSI " |
| 7002 | "layer, Bad protection parameters: %d %d\n", |
| 7003 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7004 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7005 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7006 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7007 | while (pagecnt) { |
| 7008 | spin_lock_init(&_dump_buf_lock); |
| 7009 | _dump_buf_data = |
| 7010 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 7011 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7012 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7013 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7014 | "_dump_buf_data at 0x%p\n", |
| 7015 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7016 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7017 | memset(_dump_buf_data, 0, |
| 7018 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7019 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7020 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7021 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7022 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7023 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7024 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7025 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7026 | "memory for hexdump\n"); |
| 7027 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7028 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7029 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7030 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7031 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7032 | while (pagecnt) { |
| 7033 | _dump_buf_dif = |
| 7034 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 7035 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7036 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7037 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7038 | "_dump_buf_dif at 0x%p\n", |
| 7039 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7040 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7041 | memset(_dump_buf_dif, 0, |
| 7042 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7043 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7044 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7045 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7046 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7047 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7048 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7049 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7050 | "memory for hexdump\n"); |
| 7051 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7052 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7053 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7054 | _dump_buf_dif); |
| 7055 | } |
| 7056 | |
| 7057 | /** |
| 7058 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 7059 | * @phba: pointer to lpfc hba data structure. |
| 7060 | * |
| 7061 | * This routine is invoked to perform all the necessary post initialization |
| 7062 | * setup for the device. |
| 7063 | **/ |
| 7064 | static void |
| 7065 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 7066 | { |
| 7067 | struct Scsi_Host *shost; |
| 7068 | struct lpfc_adapter_event_header adapter_event; |
| 7069 | |
| 7070 | /* Get the default values for Model Name and Description */ |
| 7071 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 7072 | |
| 7073 | /* |
| 7074 | * hba setup may have changed the hba_queue_depth so we need to |
| 7075 | * adjust the value of can_queue. |
| 7076 | */ |
| 7077 | shost = pci_get_drvdata(phba->pcidev); |
| 7078 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 7079 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 7080 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7081 | |
| 7082 | lpfc_host_attrib_init(shost); |
| 7083 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7084 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 7085 | spin_lock_irq(shost->host_lock); |
| 7086 | lpfc_poll_start_timer(phba); |
| 7087 | spin_unlock_irq(shost->host_lock); |
| 7088 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 7089 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7090 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7091 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7092 | /* Send board arrival event to upper layer */ |
| 7093 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 7094 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 7095 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7096 | sizeof(adapter_event), |
| 7097 | (char *) &adapter_event, |
| 7098 | LPFC_NL_VENDOR_ID); |
| 7099 | return; |
| 7100 | } |
| 7101 | |
| 7102 | /** |
| 7103 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 7104 | * @phba: pointer to lpfc hba data structure. |
| 7105 | * |
| 7106 | * This routine is invoked to set up the PCI device memory space for device |
| 7107 | * with SLI-3 interface spec. |
| 7108 | * |
| 7109 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7110 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7111 | * other values - error |
| 7112 | **/ |
| 7113 | static int |
| 7114 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 7115 | { |
| 7116 | struct pci_dev *pdev; |
| 7117 | unsigned long bar0map_len, bar2map_len; |
| 7118 | int i, hbq_count; |
| 7119 | void *ptr; |
| 7120 | int error = -ENODEV; |
| 7121 | |
| 7122 | /* Obtain PCI device reference */ |
| 7123 | if (!phba->pcidev) |
| 7124 | return error; |
| 7125 | else |
| 7126 | pdev = phba->pcidev; |
| 7127 | |
| 7128 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7129 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 7130 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 7131 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 7132 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7133 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7134 | } |
| 7135 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7136 | |
| 7137 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 7138 | * required by each mapping. |
| 7139 | */ |
| 7140 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7141 | bar0map_len = pci_resource_len(pdev, 0); |
| 7142 | |
| 7143 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 7144 | bar2map_len = pci_resource_len(pdev, 2); |
| 7145 | |
| 7146 | /* Map HBA SLIM to a kernel virtual address. */ |
| 7147 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 7148 | if (!phba->slim_memmap_p) { |
| 7149 | dev_printk(KERN_ERR, &pdev->dev, |
| 7150 | "ioremap failed for SLIM memory.\n"); |
| 7151 | goto out; |
| 7152 | } |
| 7153 | |
| 7154 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 7155 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 7156 | if (!phba->ctrl_regs_memmap_p) { |
| 7157 | dev_printk(KERN_ERR, &pdev->dev, |
| 7158 | "ioremap failed for HBA control registers.\n"); |
| 7159 | goto out_iounmap_slim; |
| 7160 | } |
| 7161 | |
| 7162 | /* Allocate memory for SLI-2 structures */ |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 7163 | phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7164 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7165 | if (!phba->slim2p.virt) |
| 7166 | goto out_iounmap; |
| 7167 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7168 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7169 | phba->mbox_ext = (phba->slim2p.virt + |
| 7170 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7171 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 7172 | phba->IOCBs = (phba->slim2p.virt + |
| 7173 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 7174 | |
| 7175 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 7176 | lpfc_sli_hbq_size(), |
| 7177 | &phba->hbqslimp.phys, |
| 7178 | GFP_KERNEL); |
| 7179 | if (!phba->hbqslimp.virt) |
| 7180 | goto out_free_slim; |
| 7181 | |
| 7182 | hbq_count = lpfc_sli_hbq_count(); |
| 7183 | ptr = phba->hbqslimp.virt; |
| 7184 | for (i = 0; i < hbq_count; ++i) { |
| 7185 | phba->hbqs[i].hbq_virt = ptr; |
| 7186 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 7187 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 7188 | sizeof(struct lpfc_hbq_entry)); |
| 7189 | } |
| 7190 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 7191 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 7192 | |
| 7193 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 7194 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7195 | phba->MBslimaddr = phba->slim_memmap_p; |
| 7196 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 7197 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 7198 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 7199 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7200 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7201 | return 0; |
| 7202 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7203 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7204 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7205 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7206 | out_iounmap: |
| 7207 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7208 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7209 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7210 | out: |
| 7211 | return error; |
| 7212 | } |
| 7213 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7214 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7215 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 7216 | * @phba: pointer to lpfc hba data structure. |
| 7217 | * |
| 7218 | * This routine is invoked to unset the PCI device memory space for device |
| 7219 | * with SLI-3 interface spec. |
| 7220 | **/ |
| 7221 | static void |
| 7222 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 7223 | { |
| 7224 | struct pci_dev *pdev; |
| 7225 | |
| 7226 | /* Obtain PCI device reference */ |
| 7227 | if (!phba->pcidev) |
| 7228 | return; |
| 7229 | else |
| 7230 | pdev = phba->pcidev; |
| 7231 | |
| 7232 | /* Free coherent DMA memory allocated */ |
| 7233 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 7234 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 7235 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7236 | phba->slim2p.virt, phba->slim2p.phys); |
| 7237 | |
| 7238 | /* I/O memory unmap */ |
| 7239 | iounmap(phba->ctrl_regs_memmap_p); |
| 7240 | iounmap(phba->slim_memmap_p); |
| 7241 | |
| 7242 | return; |
| 7243 | } |
| 7244 | |
| 7245 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7246 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 7247 | * @phba: pointer to lpfc hba data structure. |
| 7248 | * |
| 7249 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 7250 | * done and check status. |
| 7251 | * |
| 7252 | * Return 0 if successful, otherwise -ENODEV. |
| 7253 | **/ |
| 7254 | int |
| 7255 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 7256 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7257 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 7258 | struct lpfc_register reg_data; |
| 7259 | int i, port_error = 0; |
| 7260 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7261 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7262 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 7263 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7264 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7265 | return -ENODEV; |
| 7266 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7267 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 7268 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7269 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 7270 | &portsmphr_reg.word0) || |
| 7271 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7272 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7273 | port_error = -ENODEV; |
| 7274 | break; |
| 7275 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7276 | if (LPFC_POST_STAGE_PORT_READY == |
| 7277 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7278 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7279 | msleep(10); |
| 7280 | } |
| 7281 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7282 | /* |
| 7283 | * If there was a port error during POST, then don't proceed with |
| 7284 | * other register reads as the data may not be valid. Just exit. |
| 7285 | */ |
| 7286 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7287 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7288 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 7289 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 7290 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 7291 | portsmphr_reg.word0, |
| 7292 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 7293 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 7294 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 7295 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 7296 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 7297 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 7298 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 7299 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 7300 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7301 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7302 | "2534 Device Info: SLIFamily=0x%x, " |
| 7303 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 7304 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7305 | bf_get(lpfc_sli_intf_sli_family, |
| 7306 | &phba->sli4_hba.sli_intf), |
| 7307 | bf_get(lpfc_sli_intf_slirev, |
| 7308 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7309 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7310 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7311 | bf_get(lpfc_sli_intf_sli_hint1, |
| 7312 | &phba->sli4_hba.sli_intf), |
| 7313 | bf_get(lpfc_sli_intf_sli_hint2, |
| 7314 | &phba->sli4_hba.sli_intf), |
| 7315 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7316 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7317 | /* |
| 7318 | * Check for other Port errors during the initialization |
| 7319 | * process. Fail the load if the port did not come up |
| 7320 | * correctly. |
| 7321 | */ |
| 7322 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7323 | &phba->sli4_hba.sli_intf); |
| 7324 | switch (if_type) { |
| 7325 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7326 | phba->sli4_hba.ue_mask_lo = |
| 7327 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 7328 | phba->sli4_hba.ue_mask_hi = |
| 7329 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 7330 | uerrlo_reg.word0 = |
| 7331 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 7332 | uerrhi_reg.word0 = |
| 7333 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 7334 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 7335 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 7336 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7337 | "1422 Unrecoverable Error " |
| 7338 | "Detected during POST " |
| 7339 | "uerr_lo_reg=0x%x, " |
| 7340 | "uerr_hi_reg=0x%x, " |
| 7341 | "ue_mask_lo_reg=0x%x, " |
| 7342 | "ue_mask_hi_reg=0x%x\n", |
| 7343 | uerrlo_reg.word0, |
| 7344 | uerrhi_reg.word0, |
| 7345 | phba->sli4_hba.ue_mask_lo, |
| 7346 | phba->sli4_hba.ue_mask_hi); |
| 7347 | port_error = -ENODEV; |
| 7348 | } |
| 7349 | break; |
| 7350 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7351 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7352 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 7353 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7354 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 7355 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7356 | phba->work_status[0] = |
| 7357 | readl(phba->sli4_hba.u.if_type2. |
| 7358 | ERR1regaddr); |
| 7359 | phba->work_status[1] = |
| 7360 | readl(phba->sli4_hba.u.if_type2. |
| 7361 | ERR2regaddr); |
| 7362 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7363 | "2888 Unrecoverable port error " |
| 7364 | "following POST: port status reg " |
| 7365 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7366 | "error 1=0x%x, error 2=0x%x\n", |
| 7367 | reg_data.word0, |
| 7368 | portsmphr_reg.word0, |
| 7369 | phba->work_status[0], |
| 7370 | phba->work_status[1]); |
| 7371 | port_error = -ENODEV; |
| 7372 | } |
| 7373 | break; |
| 7374 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7375 | default: |
| 7376 | break; |
| 7377 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7378 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7379 | return port_error; |
| 7380 | } |
| 7381 | |
| 7382 | /** |
| 7383 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 7384 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7385 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7386 | * |
| 7387 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 7388 | * memory map. |
| 7389 | **/ |
| 7390 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7391 | lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7392 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7393 | switch (if_type) { |
| 7394 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7395 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 7396 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 7397 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 7398 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 7399 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 7400 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 7401 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 7402 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 7403 | phba->sli4_hba.SLIINTFregaddr = |
| 7404 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 7405 | break; |
| 7406 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 7407 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 7408 | phba->sli4_hba.conf_regs_memmap_p + |
| 7409 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7410 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7411 | phba->sli4_hba.conf_regs_memmap_p + |
| 7412 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7413 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7414 | phba->sli4_hba.conf_regs_memmap_p + |
| 7415 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7416 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7417 | phba->sli4_hba.conf_regs_memmap_p + |
| 7418 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7419 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7420 | phba->sli4_hba.conf_regs_memmap_p + |
| 7421 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7422 | phba->sli4_hba.SLIINTFregaddr = |
| 7423 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 7424 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7425 | phba->sli4_hba.conf_regs_memmap_p + |
| 7426 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7427 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7428 | phba->sli4_hba.conf_regs_memmap_p + |
| 7429 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7430 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7431 | phba->sli4_hba.conf_regs_memmap_p + |
| 7432 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7433 | phba->sli4_hba.EQCQDBregaddr = |
| 7434 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
| 7435 | phba->sli4_hba.MQDBregaddr = |
| 7436 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 7437 | phba->sli4_hba.BMBXregaddr = |
| 7438 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 7439 | break; |
| 7440 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7441 | default: |
| 7442 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 7443 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 7444 | if_type); |
| 7445 | break; |
| 7446 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7447 | } |
| 7448 | |
| 7449 | /** |
| 7450 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 7451 | * @phba: pointer to lpfc hba data structure. |
| 7452 | * |
| 7453 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) |
| 7454 | * memory map. |
| 7455 | **/ |
| 7456 | static void |
| 7457 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) |
| 7458 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7459 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 7460 | LPFC_SLIPORT_IF0_SMPHR; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7461 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7462 | LPFC_HST_ISR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7463 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7464 | LPFC_HST_IMR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7465 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7466 | LPFC_HST_ISCR0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7467 | } |
| 7468 | |
| 7469 | /** |
| 7470 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 7471 | * @phba: pointer to lpfc hba data structure. |
| 7472 | * @vf: virtual function number |
| 7473 | * |
| 7474 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 7475 | * based on the given viftual function number, @vf. |
| 7476 | * |
| 7477 | * Return 0 if successful, otherwise -ENODEV. |
| 7478 | **/ |
| 7479 | static int |
| 7480 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 7481 | { |
| 7482 | if (vf > LPFC_VIR_FUNC_MAX) |
| 7483 | return -ENODEV; |
| 7484 | |
| 7485 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7486 | vf * LPFC_VFR_PAGE_SIZE + |
| 7487 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7488 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7489 | vf * LPFC_VFR_PAGE_SIZE + |
| 7490 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7491 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 7492 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); |
| 7493 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 7494 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 7495 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 7496 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 7497 | return 0; |
| 7498 | } |
| 7499 | |
| 7500 | /** |
| 7501 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 7502 | * @phba: pointer to lpfc hba data structure. |
| 7503 | * |
| 7504 | * This routine is invoked to create the bootstrap mailbox |
| 7505 | * region consistent with the SLI-4 interface spec. This |
| 7506 | * routine allocates all memory necessary to communicate |
| 7507 | * mailbox commands to the port and sets up all alignment |
| 7508 | * needs. No locks are expected to be held when calling |
| 7509 | * this routine. |
| 7510 | * |
| 7511 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7512 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7513 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7514 | **/ |
| 7515 | static int |
| 7516 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 7517 | { |
| 7518 | uint32_t bmbx_size; |
| 7519 | struct lpfc_dmabuf *dmabuf; |
| 7520 | struct dma_address *dma_address; |
| 7521 | uint32_t pa_addr; |
| 7522 | uint64_t phys_addr; |
| 7523 | |
| 7524 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 7525 | if (!dmabuf) |
| 7526 | return -ENOMEM; |
| 7527 | |
| 7528 | /* |
| 7529 | * The bootstrap mailbox region is comprised of 2 parts |
| 7530 | * plus an alignment restriction of 16 bytes. |
| 7531 | */ |
| 7532 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 7533 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 7534 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7535 | if (!dmabuf->virt) { |
| 7536 | kfree(dmabuf); |
| 7537 | return -ENOMEM; |
| 7538 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7539 | |
| 7540 | /* |
| 7541 | * Initialize the bootstrap mailbox pointers now so that the register |
| 7542 | * operations are simple later. The mailbox dma address is required |
| 7543 | * to be 16-byte aligned. Also align the virtual memory as each |
| 7544 | * maibox is copied into the bmbx mailbox region before issuing the |
| 7545 | * command to the port. |
| 7546 | */ |
| 7547 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 7548 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 7549 | |
| 7550 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 7551 | LPFC_ALIGN_16_BYTE); |
| 7552 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 7553 | LPFC_ALIGN_16_BYTE); |
| 7554 | |
| 7555 | /* |
| 7556 | * Set the high and low physical addresses now. The SLI4 alignment |
| 7557 | * requirement is 16 bytes and the mailbox is posted to the port |
| 7558 | * as two 30-bit addresses. The other data is a bit marking whether |
| 7559 | * the 30-bit address is the high or low address. |
| 7560 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 7561 | * clean on 32 bit machines. |
| 7562 | */ |
| 7563 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7564 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 7565 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 7566 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 7567 | LPFC_BMBX_BIT1_ADDR_HI); |
| 7568 | |
| 7569 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 7570 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 7571 | LPFC_BMBX_BIT1_ADDR_LO); |
| 7572 | return 0; |
| 7573 | } |
| 7574 | |
| 7575 | /** |
| 7576 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 7577 | * @phba: pointer to lpfc hba data structure. |
| 7578 | * |
| 7579 | * This routine is invoked to teardown the bootstrap mailbox |
| 7580 | * region and release all host resources. This routine requires |
| 7581 | * the caller to ensure all mailbox commands recovered, no |
| 7582 | * additional mailbox comands are sent, and interrupts are disabled |
| 7583 | * before calling this routine. |
| 7584 | * |
| 7585 | **/ |
| 7586 | static void |
| 7587 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 7588 | { |
| 7589 | dma_free_coherent(&phba->pcidev->dev, |
| 7590 | phba->sli4_hba.bmbx.bmbx_size, |
| 7591 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 7592 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 7593 | |
| 7594 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 7595 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 7596 | } |
| 7597 | |
| 7598 | /** |
| 7599 | * lpfc_sli4_read_config - Get the config parameters. |
| 7600 | * @phba: pointer to lpfc hba data structure. |
| 7601 | * |
| 7602 | * This routine is invoked to read the configuration parameters from the HBA. |
| 7603 | * The configuration parameters are used to set the base and maximum values |
| 7604 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 7605 | * allocation for the port. |
| 7606 | * |
| 7607 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7608 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7609 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7610 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7611 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7612 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7613 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 7614 | { |
| 7615 | LPFC_MBOXQ_t *pmb; |
| 7616 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7617 | union lpfc_sli4_cfg_shdr *shdr; |
| 7618 | uint32_t shdr_status, shdr_add_status; |
| 7619 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 7620 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7621 | char *pdesc_0; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 7622 | uint16_t forced_link_speed; |
| 7623 | uint32_t if_type; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7624 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7625 | |
| 7626 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7627 | if (!pmb) { |
| 7628 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7629 | "2011 Unable to allocate memory for issuing " |
| 7630 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 7631 | return -ENOMEM; |
| 7632 | } |
| 7633 | |
| 7634 | lpfc_read_config(phba, pmb); |
| 7635 | |
| 7636 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 7637 | if (rc != MBX_SUCCESS) { |
| 7638 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7639 | "2012 Mailbox failed , mbxCmd x%x " |
| 7640 | "READ_CONFIG, mbxStatus x%x\n", |
| 7641 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 7642 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 7643 | rc = -EIO; |
| 7644 | } else { |
| 7645 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7646 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 7647 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 7648 | phba->sli4_hba.lnk_info.lnk_tp = |
| 7649 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 7650 | phba->sli4_hba.lnk_info.lnk_no = |
| 7651 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 7652 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 7653 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 7654 | phba->sli4_hba.lnk_info.lnk_tp, |
| 7655 | phba->sli4_hba.lnk_info.lnk_no); |
| 7656 | } else |
| 7657 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 7658 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 7659 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 7660 | if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) { |
| 7661 | phba->bbcredit_support = 1; |
| 7662 | phba->sli4_hba.bbscn_params.word0 = rd_config->word8; |
| 7663 | } |
| 7664 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7665 | phba->sli4_hba.extents_in_use = |
| 7666 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7667 | phba->sli4_hba.max_cfg_param.max_xri = |
| 7668 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 7669 | phba->sli4_hba.max_cfg_param.xri_base = |
| 7670 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 7671 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 7672 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
| 7673 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 7674 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 7675 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 7676 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 7677 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 7678 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 7679 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 7680 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 7681 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 7682 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 7683 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 7684 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7685 | phba->sli4_hba.max_cfg_param.max_eq = |
| 7686 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 7687 | phba->sli4_hba.max_cfg_param.max_rq = |
| 7688 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 7689 | phba->sli4_hba.max_cfg_param.max_wq = |
| 7690 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 7691 | phba->sli4_hba.max_cfg_param.max_cq = |
| 7692 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 7693 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 7694 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 7695 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 7696 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7697 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 7698 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7699 | phba->max_vports = phba->max_vpi; |
| 7700 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7701 | "2003 cfg params Extents? %d " |
| 7702 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7703 | "VPI(B:%d M:%d) " |
| 7704 | "VFI(B:%d M:%d) " |
| 7705 | "RPI(B:%d M:%d) " |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7706 | "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n", |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7707 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7708 | phba->sli4_hba.max_cfg_param.xri_base, |
| 7709 | phba->sli4_hba.max_cfg_param.max_xri, |
| 7710 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 7711 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 7712 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 7713 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 7714 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 7715 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7716 | phba->sli4_hba.max_cfg_param.max_fcfi, |
| 7717 | phba->sli4_hba.max_cfg_param.max_eq, |
| 7718 | phba->sli4_hba.max_cfg_param.max_cq, |
| 7719 | phba->sli4_hba.max_cfg_param.max_wq, |
| 7720 | phba->sli4_hba.max_cfg_param.max_rq); |
| 7721 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7722 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7723 | |
| 7724 | if (rc) |
| 7725 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7726 | |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 7727 | /* Update link speed if forced link speed is supported */ |
| 7728 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7729 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 7730 | forced_link_speed = |
| 7731 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); |
| 7732 | if (forced_link_speed) { |
| 7733 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; |
| 7734 | |
| 7735 | switch (forced_link_speed) { |
| 7736 | case LINK_SPEED_1G: |
| 7737 | phba->cfg_link_speed = |
| 7738 | LPFC_USER_LINK_SPEED_1G; |
| 7739 | break; |
| 7740 | case LINK_SPEED_2G: |
| 7741 | phba->cfg_link_speed = |
| 7742 | LPFC_USER_LINK_SPEED_2G; |
| 7743 | break; |
| 7744 | case LINK_SPEED_4G: |
| 7745 | phba->cfg_link_speed = |
| 7746 | LPFC_USER_LINK_SPEED_4G; |
| 7747 | break; |
| 7748 | case LINK_SPEED_8G: |
| 7749 | phba->cfg_link_speed = |
| 7750 | LPFC_USER_LINK_SPEED_8G; |
| 7751 | break; |
| 7752 | case LINK_SPEED_10G: |
| 7753 | phba->cfg_link_speed = |
| 7754 | LPFC_USER_LINK_SPEED_10G; |
| 7755 | break; |
| 7756 | case LINK_SPEED_16G: |
| 7757 | phba->cfg_link_speed = |
| 7758 | LPFC_USER_LINK_SPEED_16G; |
| 7759 | break; |
| 7760 | case LINK_SPEED_32G: |
| 7761 | phba->cfg_link_speed = |
| 7762 | LPFC_USER_LINK_SPEED_32G; |
| 7763 | break; |
| 7764 | case 0xffff: |
| 7765 | phba->cfg_link_speed = |
| 7766 | LPFC_USER_LINK_SPEED_AUTO; |
| 7767 | break; |
| 7768 | default: |
| 7769 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7770 | "0047 Unrecognized link " |
| 7771 | "speed : %d\n", |
| 7772 | forced_link_speed); |
| 7773 | phba->cfg_link_speed = |
| 7774 | LPFC_USER_LINK_SPEED_AUTO; |
| 7775 | } |
| 7776 | } |
| 7777 | } |
| 7778 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7779 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7780 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 7781 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 7782 | if (phba->cfg_hba_queue_depth > length) { |
| 7783 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7784 | "3361 HBA queue depth changed from %d to %d\n", |
| 7785 | phba->cfg_hba_queue_depth, length); |
| 7786 | phba->cfg_hba_queue_depth = length; |
| 7787 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7788 | |
| 7789 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 7790 | LPFC_SLI_INTF_IF_TYPE_2) |
| 7791 | goto read_cfg_out; |
| 7792 | |
| 7793 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 7794 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 7795 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 7796 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7797 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 7798 | length, LPFC_SLI4_MBX_EMBED); |
| 7799 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7800 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7801 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7802 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7803 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7804 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7805 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7806 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7807 | "3026 Mailbox failed , mbxCmd x%x " |
| 7808 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 7809 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 7810 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7811 | goto read_cfg_out; |
| 7812 | } |
| 7813 | |
| 7814 | /* search for fc_fcoe resrouce descriptor */ |
| 7815 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7816 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7817 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 7818 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 7819 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 7820 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 7821 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 7822 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 7823 | goto read_cfg_out; |
| 7824 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7825 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7826 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7827 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7828 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7829 | phba->sli4_hba.iov.pf_number = |
| 7830 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 7831 | phba->sli4_hba.iov.vf_number = |
| 7832 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 7833 | break; |
| 7834 | } |
| 7835 | } |
| 7836 | |
| 7837 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 7838 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 7839 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 7840 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 7841 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7842 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7843 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7844 | "3028 GET_FUNCTION_CONFIG: failed to find " |
| 7845 | "Resrouce Descriptor:x%x\n", |
| 7846 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7847 | |
| 7848 | read_cfg_out: |
| 7849 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7850 | return rc; |
| 7851 | } |
| 7852 | |
| 7853 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7854 | * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7855 | * @phba: pointer to lpfc hba data structure. |
| 7856 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7857 | * This routine is invoked to setup the port-side endian order when |
| 7858 | * the port if_type is 0. This routine has no function for other |
| 7859 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7860 | * |
| 7861 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7862 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7863 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7864 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7865 | **/ |
| 7866 | static int |
| 7867 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 7868 | { |
| 7869 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7870 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7871 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 7872 | HOST_ENDIAN_HIGH_WORD1}; |
| 7873 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7874 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7875 | switch (if_type) { |
| 7876 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7877 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7878 | GFP_KERNEL); |
| 7879 | if (!mboxq) { |
| 7880 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7881 | "0492 Unable to allocate memory for " |
| 7882 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 7883 | "command\n"); |
| 7884 | return -ENOMEM; |
| 7885 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7886 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7887 | /* |
| 7888 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 7889 | * two words to contain special data values and no other data. |
| 7890 | */ |
| 7891 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 7892 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 7893 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7894 | if (rc != MBX_SUCCESS) { |
| 7895 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7896 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 7897 | "failed with status x%x\n", |
| 7898 | rc); |
| 7899 | rc = -EIO; |
| 7900 | } |
| 7901 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 7902 | break; |
| 7903 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7904 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7905 | default: |
| 7906 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7907 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7908 | return rc; |
| 7909 | } |
| 7910 | |
| 7911 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7912 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7913 | * @phba: pointer to lpfc hba data structure. |
| 7914 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7915 | * This routine is invoked to check the user settable queue counts for EQs. |
| 7916 | * After this routine is called the counts will be set to valid values that |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7917 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 7918 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7919 | * |
| 7920 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7921 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7922 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7923 | **/ |
| 7924 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7925 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7926 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7927 | int io_channel; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7928 | int fof_vectors = phba->cfg_fof ? 1 : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7929 | |
| 7930 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7931 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7932 | * device parameters |
| 7933 | */ |
| 7934 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7935 | /* Sanity check on HBA EQ parameters */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7936 | io_channel = phba->io_channel_irqs; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7937 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7938 | if (phba->sli4_hba.num_online_cpu < io_channel) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 7939 | lpfc_printf_log(phba, |
| 7940 | KERN_ERR, LOG_INIT, |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7941 | "3188 Reducing IO channels to match number of " |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7942 | "online CPUs: from %d to %d\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7943 | io_channel, phba->sli4_hba.num_online_cpu); |
| 7944 | io_channel = phba->sli4_hba.num_online_cpu; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 7945 | } |
| 7946 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7947 | if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 7948 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7949 | "2575 Reducing IO channels to match number of " |
| 7950 | "available EQs: from %d to %d\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7951 | io_channel, |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 7952 | phba->sli4_hba.max_cfg_param.max_eq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7953 | io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7954 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7955 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7956 | /* The actual number of FCP / NVME event queues adopted */ |
| 7957 | if (io_channel != phba->io_channel_irqs) |
| 7958 | phba->io_channel_irqs = io_channel; |
| 7959 | if (phba->cfg_fcp_io_channel > io_channel) |
| 7960 | phba->cfg_fcp_io_channel = io_channel; |
| 7961 | if (phba->cfg_nvme_io_channel > io_channel) |
| 7962 | phba->cfg_nvme_io_channel = io_channel; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 7963 | if (phba->nvmet_support) { |
| 7964 | if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq) |
| 7965 | phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel; |
| 7966 | } |
| 7967 | if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) |
| 7968 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7969 | |
| 7970 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7971 | "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7972 | phba->io_channel_irqs, phba->cfg_fcp_io_channel, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 7973 | phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7974 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7975 | /* Get EQ depth from module parameter, fake the default for now */ |
| 7976 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 7977 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 7978 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7979 | /* Get CQ depth from module parameter, fake the default for now */ |
| 7980 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 7981 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7982 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7983 | } |
| 7984 | |
| 7985 | static int |
| 7986 | lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx) |
| 7987 | { |
| 7988 | struct lpfc_queue *qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7989 | |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 7990 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 7991 | phba->sli4_hba.cq_esize, |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 7992 | LPFC_CQE_EXP_COUNT); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7993 | if (!qdesc) { |
| 7994 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7995 | "0508 Failed allocate fast-path NVME CQ (%d)\n", |
| 7996 | wqidx); |
| 7997 | return 1; |
| 7998 | } |
| 7999 | phba->sli4_hba.nvme_cq[wqidx] = qdesc; |
| 8000 | |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8001 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8002 | LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8003 | if (!qdesc) { |
| 8004 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8005 | "0509 Failed allocate fast-path NVME WQ (%d)\n", |
| 8006 | wqidx); |
| 8007 | return 1; |
| 8008 | } |
| 8009 | phba->sli4_hba.nvme_wq[wqidx] = qdesc; |
| 8010 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8011 | return 0; |
| 8012 | } |
| 8013 | |
| 8014 | static int |
| 8015 | lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx) |
| 8016 | { |
| 8017 | struct lpfc_queue *qdesc; |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8018 | uint32_t wqesize; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8019 | |
| 8020 | /* Create Fast Path FCP CQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8021 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8022 | /* Increase the CQ size when WQEs contain an embedded cdb */ |
| 8023 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8024 | phba->sli4_hba.cq_esize, |
| 8025 | LPFC_CQE_EXP_COUNT); |
| 8026 | |
| 8027 | else |
| 8028 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8029 | phba->sli4_hba.cq_esize, |
| 8030 | phba->sli4_hba.cq_ecount); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8031 | if (!qdesc) { |
| 8032 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8033 | "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx); |
| 8034 | return 1; |
| 8035 | } |
| 8036 | phba->sli4_hba.fcp_cq[wqidx] = qdesc; |
| 8037 | |
| 8038 | /* Create Fast Path FCP WQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8039 | if (phba->enab_exp_wqcq_pages) { |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8040 | /* Increase the WQ size when WQEs contain an embedded cdb */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8041 | wqesize = (phba->fcp_embed_io) ? |
| 8042 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8043 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8044 | wqesize, |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8045 | LPFC_WQE_EXP_COUNT); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8046 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8047 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8048 | phba->sli4_hba.wq_esize, |
| 8049 | phba->sli4_hba.wq_ecount); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8050 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8051 | if (!qdesc) { |
| 8052 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8053 | "0503 Failed allocate fast-path FCP WQ (%d)\n", |
| 8054 | wqidx); |
| 8055 | return 1; |
| 8056 | } |
| 8057 | phba->sli4_hba.fcp_wq[wqidx] = qdesc; |
| 8058 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8059 | return 0; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8060 | } |
| 8061 | |
| 8062 | /** |
| 8063 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 8064 | * @phba: pointer to lpfc hba data structure. |
| 8065 | * |
| 8066 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 8067 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 8068 | * count (queue depth) shall be taken from the module parameter. For now, |
| 8069 | * we just use some constant number as place holder. |
| 8070 | * |
| 8071 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 8072 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8073 | * -ENOMEM - No availble memory |
| 8074 | * -EIO - The mailbox failed to complete successfully. |
| 8075 | **/ |
| 8076 | int |
| 8077 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 8078 | { |
| 8079 | struct lpfc_queue *qdesc; |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 8080 | int idx, io_channel; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8081 | |
| 8082 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8083 | * Create HBA Record arrays. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8084 | * Both NVME and FCP will share that same vectors / EQs |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8085 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8086 | io_channel = phba->io_channel_irqs; |
| 8087 | if (!io_channel) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8088 | return -ERANGE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8089 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8090 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 8091 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 8092 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 8093 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 8094 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 8095 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8096 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8097 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8098 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8099 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8100 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8101 | phba->sli4_hba.hba_eq = kcalloc(io_channel, |
| 8102 | sizeof(struct lpfc_queue *), |
| 8103 | GFP_KERNEL); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8104 | if (!phba->sli4_hba.hba_eq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8105 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8106 | "2576 Failed allocate memory for " |
| 8107 | "fast-path EQ record array\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8108 | goto out_error; |
| 8109 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8110 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8111 | if (phba->cfg_fcp_io_channel) { |
| 8112 | phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel, |
| 8113 | sizeof(struct lpfc_queue *), |
| 8114 | GFP_KERNEL); |
| 8115 | if (!phba->sli4_hba.fcp_cq) { |
| 8116 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8117 | "2577 Failed allocate memory for " |
| 8118 | "fast-path CQ record array\n"); |
| 8119 | goto out_error; |
| 8120 | } |
| 8121 | phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel, |
| 8122 | sizeof(struct lpfc_queue *), |
| 8123 | GFP_KERNEL); |
| 8124 | if (!phba->sli4_hba.fcp_wq) { |
| 8125 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8126 | "2578 Failed allocate memory for " |
| 8127 | "fast-path FCP WQ record array\n"); |
| 8128 | goto out_error; |
| 8129 | } |
| 8130 | /* |
| 8131 | * Since the first EQ can have multiple CQs associated with it, |
| 8132 | * this array is used to quickly see if we have a FCP fast-path |
| 8133 | * CQ match. |
| 8134 | */ |
| 8135 | phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel, |
| 8136 | sizeof(uint16_t), |
| 8137 | GFP_KERNEL); |
| 8138 | if (!phba->sli4_hba.fcp_cq_map) { |
| 8139 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8140 | "2545 Failed allocate memory for " |
| 8141 | "fast-path CQ map\n"); |
| 8142 | goto out_error; |
| 8143 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8144 | } |
| 8145 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8146 | if (phba->cfg_nvme_io_channel) { |
| 8147 | phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel, |
| 8148 | sizeof(struct lpfc_queue *), |
| 8149 | GFP_KERNEL); |
| 8150 | if (!phba->sli4_hba.nvme_cq) { |
| 8151 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8152 | "6077 Failed allocate memory for " |
| 8153 | "fast-path CQ record array\n"); |
| 8154 | goto out_error; |
| 8155 | } |
| 8156 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8157 | phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel, |
| 8158 | sizeof(struct lpfc_queue *), |
| 8159 | GFP_KERNEL); |
| 8160 | if (!phba->sli4_hba.nvme_wq) { |
| 8161 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8162 | "2581 Failed allocate memory for " |
| 8163 | "fast-path NVME WQ record array\n"); |
| 8164 | goto out_error; |
| 8165 | } |
| 8166 | |
| 8167 | /* |
| 8168 | * Since the first EQ can have multiple CQs associated with it, |
| 8169 | * this array is used to quickly see if we have a NVME fast-path |
| 8170 | * CQ match. |
| 8171 | */ |
| 8172 | phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel, |
| 8173 | sizeof(uint16_t), |
| 8174 | GFP_KERNEL); |
| 8175 | if (!phba->sli4_hba.nvme_cq_map) { |
| 8176 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8177 | "6078 Failed allocate memory for " |
| 8178 | "fast-path CQ map\n"); |
| 8179 | goto out_error; |
| 8180 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8181 | |
| 8182 | if (phba->nvmet_support) { |
| 8183 | phba->sli4_hba.nvmet_cqset = kcalloc( |
| 8184 | phba->cfg_nvmet_mrq, |
| 8185 | sizeof(struct lpfc_queue *), |
| 8186 | GFP_KERNEL); |
| 8187 | if (!phba->sli4_hba.nvmet_cqset) { |
| 8188 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8189 | "3121 Fail allocate memory for " |
| 8190 | "fast-path CQ set array\n"); |
| 8191 | goto out_error; |
| 8192 | } |
| 8193 | phba->sli4_hba.nvmet_mrq_hdr = kcalloc( |
| 8194 | phba->cfg_nvmet_mrq, |
| 8195 | sizeof(struct lpfc_queue *), |
| 8196 | GFP_KERNEL); |
| 8197 | if (!phba->sli4_hba.nvmet_mrq_hdr) { |
| 8198 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8199 | "3122 Fail allocate memory for " |
| 8200 | "fast-path RQ set hdr array\n"); |
| 8201 | goto out_error; |
| 8202 | } |
| 8203 | phba->sli4_hba.nvmet_mrq_data = kcalloc( |
| 8204 | phba->cfg_nvmet_mrq, |
| 8205 | sizeof(struct lpfc_queue *), |
| 8206 | GFP_KERNEL); |
| 8207 | if (!phba->sli4_hba.nvmet_mrq_data) { |
| 8208 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8209 | "3124 Fail allocate memory for " |
| 8210 | "fast-path RQ set data array\n"); |
| 8211 | goto out_error; |
| 8212 | } |
| 8213 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8214 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8215 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8216 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8217 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8218 | /* Create HBA Event Queues (EQs) */ |
| 8219 | for (idx = 0; idx < io_channel; idx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8220 | /* Create EQs */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8221 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8222 | phba->sli4_hba.eq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8223 | phba->sli4_hba.eq_ecount); |
| 8224 | if (!qdesc) { |
| 8225 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8226 | "0497 Failed allocate EQ (%d)\n", idx); |
| 8227 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8228 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8229 | phba->sli4_hba.hba_eq[idx] = qdesc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8230 | } |
| 8231 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8232 | /* FCP and NVME io channels are not required to be balanced */ |
| 8233 | |
| 8234 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) |
| 8235 | if (lpfc_alloc_fcp_wq_cq(phba, idx)) |
| 8236 | goto out_error; |
| 8237 | |
| 8238 | for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++) |
| 8239 | if (lpfc_alloc_nvme_wq_cq(phba, idx)) |
| 8240 | goto out_error; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8241 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8242 | if (phba->nvmet_support) { |
| 8243 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
| 8244 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8245 | LPFC_DEFAULT_PAGE_SIZE, |
| 8246 | phba->sli4_hba.cq_esize, |
| 8247 | phba->sli4_hba.cq_ecount); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8248 | if (!qdesc) { |
| 8249 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8250 | "3142 Failed allocate NVME " |
| 8251 | "CQ Set (%d)\n", idx); |
| 8252 | goto out_error; |
| 8253 | } |
| 8254 | phba->sli4_hba.nvmet_cqset[idx] = qdesc; |
| 8255 | } |
| 8256 | } |
| 8257 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8258 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8259 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8260 | */ |
| 8261 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8262 | /* Create slow-path Mailbox Command Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8263 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8264 | phba->sli4_hba.cq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8265 | phba->sli4_hba.cq_ecount); |
| 8266 | if (!qdesc) { |
| 8267 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8268 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8269 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8270 | } |
| 8271 | phba->sli4_hba.mbx_cq = qdesc; |
| 8272 | |
| 8273 | /* Create slow-path ELS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8274 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8275 | phba->sli4_hba.cq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8276 | phba->sli4_hba.cq_ecount); |
| 8277 | if (!qdesc) { |
| 8278 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8279 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8280 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8281 | } |
| 8282 | phba->sli4_hba.els_cq = qdesc; |
| 8283 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8284 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8285 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8286 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8287 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8288 | |
| 8289 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8290 | |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8291 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8292 | phba->sli4_hba.mq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8293 | phba->sli4_hba.mq_ecount); |
| 8294 | if (!qdesc) { |
| 8295 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8296 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8297 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8298 | } |
| 8299 | phba->sli4_hba.mbx_wq = qdesc; |
| 8300 | |
| 8301 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8302 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8303 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8304 | |
| 8305 | /* Create slow-path ELS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8306 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8307 | phba->sli4_hba.wq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8308 | phba->sli4_hba.wq_ecount); |
| 8309 | if (!qdesc) { |
| 8310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8311 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8312 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8313 | } |
| 8314 | phba->sli4_hba.els_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8315 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8316 | |
| 8317 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 8318 | /* Create NVME LS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8319 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8320 | phba->sli4_hba.cq_esize, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8321 | phba->sli4_hba.cq_ecount); |
| 8322 | if (!qdesc) { |
| 8323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8324 | "6079 Failed allocate NVME LS CQ\n"); |
| 8325 | goto out_error; |
| 8326 | } |
| 8327 | phba->sli4_hba.nvmels_cq = qdesc; |
| 8328 | |
| 8329 | /* Create NVME LS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8330 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8331 | phba->sli4_hba.wq_esize, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8332 | phba->sli4_hba.wq_ecount); |
| 8333 | if (!qdesc) { |
| 8334 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8335 | "6080 Failed allocate NVME LS WQ\n"); |
| 8336 | goto out_error; |
| 8337 | } |
| 8338 | phba->sli4_hba.nvmels_wq = qdesc; |
| 8339 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8340 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8341 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8342 | /* |
| 8343 | * Create Receive Queue (RQ) |
| 8344 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8345 | |
| 8346 | /* Create Receive Queue for header */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8347 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8348 | phba->sli4_hba.rq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8349 | phba->sli4_hba.rq_ecount); |
| 8350 | if (!qdesc) { |
| 8351 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8352 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8353 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8354 | } |
| 8355 | phba->sli4_hba.hdr_rq = qdesc; |
| 8356 | |
| 8357 | /* Create Receive Queue for data */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8358 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8359 | phba->sli4_hba.rq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8360 | phba->sli4_hba.rq_ecount); |
| 8361 | if (!qdesc) { |
| 8362 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8363 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8364 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8365 | } |
| 8366 | phba->sli4_hba.dat_rq = qdesc; |
| 8367 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8368 | if (phba->nvmet_support) { |
| 8369 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
| 8370 | /* Create NVMET Receive Queue for header */ |
| 8371 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8372 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8373 | phba->sli4_hba.rq_esize, |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 8374 | LPFC_NVMET_RQE_DEF_COUNT); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8375 | if (!qdesc) { |
| 8376 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8377 | "3146 Failed allocate " |
| 8378 | "receive HRQ\n"); |
| 8379 | goto out_error; |
| 8380 | } |
| 8381 | phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc; |
| 8382 | |
| 8383 | /* Only needed for header of RQ pair */ |
| 8384 | qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb), |
| 8385 | GFP_KERNEL); |
| 8386 | if (qdesc->rqbp == NULL) { |
| 8387 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8388 | "6131 Failed allocate " |
| 8389 | "Header RQBP\n"); |
| 8390 | goto out_error; |
| 8391 | } |
| 8392 | |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 8393 | /* Put list in known state in case driver load fails. */ |
| 8394 | INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list); |
| 8395 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8396 | /* Create NVMET Receive Queue for data */ |
| 8397 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8398 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8399 | phba->sli4_hba.rq_esize, |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 8400 | LPFC_NVMET_RQE_DEF_COUNT); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8401 | if (!qdesc) { |
| 8402 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8403 | "3156 Failed allocate " |
| 8404 | "receive DRQ\n"); |
| 8405 | goto out_error; |
| 8406 | } |
| 8407 | phba->sli4_hba.nvmet_mrq_data[idx] = qdesc; |
| 8408 | } |
| 8409 | } |
| 8410 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8411 | /* Create the Queues needed for Flash Optimized Fabric operations */ |
| 8412 | if (phba->cfg_fof) |
| 8413 | lpfc_fof_queue_create(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8414 | return 0; |
| 8415 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8416 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8417 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8418 | return -ENOMEM; |
| 8419 | } |
| 8420 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8421 | static inline void |
| 8422 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) |
| 8423 | { |
| 8424 | if (*qp != NULL) { |
| 8425 | lpfc_sli4_queue_free(*qp); |
| 8426 | *qp = NULL; |
| 8427 | } |
| 8428 | } |
| 8429 | |
| 8430 | static inline void |
| 8431 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) |
| 8432 | { |
| 8433 | int idx; |
| 8434 | |
| 8435 | if (*qs == NULL) |
| 8436 | return; |
| 8437 | |
| 8438 | for (idx = 0; idx < max; idx++) |
| 8439 | __lpfc_sli4_release_queue(&(*qs)[idx]); |
| 8440 | |
| 8441 | kfree(*qs); |
| 8442 | *qs = NULL; |
| 8443 | } |
| 8444 | |
| 8445 | static inline void |
| 8446 | lpfc_sli4_release_queue_map(uint16_t **qmap) |
| 8447 | { |
| 8448 | if (*qmap != NULL) { |
| 8449 | kfree(*qmap); |
| 8450 | *qmap = NULL; |
| 8451 | } |
| 8452 | } |
| 8453 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8454 | /** |
| 8455 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 8456 | * @phba: pointer to lpfc hba data structure. |
| 8457 | * |
| 8458 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 8459 | * operation. |
| 8460 | * |
| 8461 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8462 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8463 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8464 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8465 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8466 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8467 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 8468 | { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8469 | if (phba->cfg_fof) |
| 8470 | lpfc_fof_queue_destroy(phba); |
| 8471 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8472 | /* Release HBA eqs */ |
| 8473 | lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8474 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8475 | /* Release FCP cqs */ |
| 8476 | lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 8477 | phba->cfg_fcp_io_channel); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8478 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8479 | /* Release FCP wqs */ |
| 8480 | lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 8481 | phba->cfg_fcp_io_channel); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8482 | |
| 8483 | /* Release FCP CQ mapping array */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8484 | lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map); |
| 8485 | |
| 8486 | /* Release NVME cqs */ |
| 8487 | lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq, |
| 8488 | phba->cfg_nvme_io_channel); |
| 8489 | |
| 8490 | /* Release NVME wqs */ |
| 8491 | lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq, |
| 8492 | phba->cfg_nvme_io_channel); |
| 8493 | |
| 8494 | /* Release NVME CQ mapping array */ |
| 8495 | lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8496 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8497 | if (phba->nvmet_support) { |
| 8498 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset, |
| 8499 | phba->cfg_nvmet_mrq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8500 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8501 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr, |
| 8502 | phba->cfg_nvmet_mrq); |
| 8503 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data, |
| 8504 | phba->cfg_nvmet_mrq); |
| 8505 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8506 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8507 | /* Release mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8508 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8509 | |
| 8510 | /* Release ELS work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8511 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); |
| 8512 | |
| 8513 | /* Release ELS work queue */ |
| 8514 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8515 | |
| 8516 | /* Release unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8517 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); |
| 8518 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8519 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8520 | /* Release ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8521 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); |
| 8522 | |
| 8523 | /* Release NVME LS complete queue */ |
| 8524 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8525 | |
| 8526 | /* Release mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8527 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); |
| 8528 | |
| 8529 | /* Everything on this list has been freed */ |
| 8530 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
| 8531 | } |
| 8532 | |
| 8533 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8534 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) |
| 8535 | { |
| 8536 | struct lpfc_rqb *rqbp; |
| 8537 | struct lpfc_dmabuf *h_buf; |
| 8538 | struct rqb_dmabuf *rqb_buffer; |
| 8539 | |
| 8540 | rqbp = rq->rqbp; |
| 8541 | while (!list_empty(&rqbp->rqb_buffer_list)) { |
| 8542 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 8543 | struct lpfc_dmabuf, list); |
| 8544 | |
| 8545 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 8546 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); |
| 8547 | rqbp->buffer_count--; |
| 8548 | } |
| 8549 | return 1; |
| 8550 | } |
| 8551 | |
| 8552 | static int |
| 8553 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 8554 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, |
| 8555 | int qidx, uint32_t qtype) |
| 8556 | { |
| 8557 | struct lpfc_sli_ring *pring; |
| 8558 | int rc; |
| 8559 | |
| 8560 | if (!eq || !cq || !wq) { |
| 8561 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8562 | "6085 Fast-path %s (%d) not allocated\n", |
| 8563 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); |
| 8564 | return -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8565 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8566 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8567 | /* create the Cq first */ |
| 8568 | rc = lpfc_cq_create(phba, cq, eq, |
| 8569 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); |
| 8570 | if (rc) { |
| 8571 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8572 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", |
| 8573 | qidx, (uint32_t)rc); |
| 8574 | return rc; |
| 8575 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8576 | cq->chann = qidx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8577 | |
| 8578 | if (qtype != LPFC_MBOX) { |
| 8579 | /* Setup nvme_cq_map for fast lookup */ |
| 8580 | if (cq_map) |
| 8581 | *cq_map = cq->queue_id; |
| 8582 | |
| 8583 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8584 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", |
| 8585 | qidx, cq->queue_id, qidx, eq->queue_id); |
| 8586 | |
| 8587 | /* create the wq */ |
| 8588 | rc = lpfc_wq_create(phba, wq, cq, qtype); |
| 8589 | if (rc) { |
| 8590 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8591 | "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n", |
| 8592 | qidx, (uint32_t)rc); |
| 8593 | /* no need to tear down cq - caller will do so */ |
| 8594 | return rc; |
| 8595 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8596 | wq->chann = qidx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8597 | |
| 8598 | /* Bind this CQ/WQ to the NVME ring */ |
| 8599 | pring = wq->pring; |
| 8600 | pring->sli.sli4.wqp = (void *)wq; |
| 8601 | cq->pring = pring; |
| 8602 | |
| 8603 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8604 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", |
| 8605 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); |
| 8606 | } else { |
| 8607 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); |
| 8608 | if (rc) { |
| 8609 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8610 | "0539 Failed setup of slow-path MQ: " |
| 8611 | "rc = 0x%x\n", rc); |
| 8612 | /* no need to tear down cq - caller will do so */ |
| 8613 | return rc; |
| 8614 | } |
| 8615 | |
| 8616 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8617 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 8618 | phba->sli4_hba.mbx_wq->queue_id, |
| 8619 | phba->sli4_hba.mbx_cq->queue_id); |
| 8620 | } |
| 8621 | |
| 8622 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8623 | } |
| 8624 | |
| 8625 | /** |
| 8626 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 8627 | * @phba: pointer to lpfc hba data structure. |
| 8628 | * |
| 8629 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 8630 | * operation. |
| 8631 | * |
| 8632 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8633 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8634 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8635 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8636 | **/ |
| 8637 | int |
| 8638 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 8639 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8640 | uint32_t shdr_status, shdr_add_status; |
| 8641 | union lpfc_sli4_cfg_shdr *shdr; |
| 8642 | LPFC_MBOXQ_t *mboxq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8643 | int qidx; |
| 8644 | uint32_t length, io_channel; |
| 8645 | int rc = -ENOMEM; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8646 | |
| 8647 | /* Check for dual-ULP support */ |
| 8648 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8649 | if (!mboxq) { |
| 8650 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8651 | "3249 Unable to allocate memory for " |
| 8652 | "QUERY_FW_CFG mailbox command\n"); |
| 8653 | return -ENOMEM; |
| 8654 | } |
| 8655 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 8656 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8657 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8658 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 8659 | length, LPFC_SLI4_MBX_EMBED); |
| 8660 | |
| 8661 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8662 | |
| 8663 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8664 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8665 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8666 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 8667 | if (shdr_status || shdr_add_status || rc) { |
| 8668 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8669 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 8670 | "x%x add_status x%x, mbx status x%x\n", |
| 8671 | shdr_status, shdr_add_status, rc); |
| 8672 | if (rc != MBX_TIMEOUT) |
| 8673 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8674 | rc = -ENXIO; |
| 8675 | goto out_error; |
| 8676 | } |
| 8677 | |
| 8678 | phba->sli4_hba.fw_func_mode = |
| 8679 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 8680 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 8681 | phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode; |
James Smart | 8b017a3 | 2015-05-21 13:55:18 -0400 | [diff] [blame] | 8682 | phba->sli4_hba.physical_port = |
| 8683 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8684 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8685 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 8686 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 8687 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 8688 | |
| 8689 | if (rc != MBX_TIMEOUT) |
| 8690 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8691 | |
| 8692 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8693 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8694 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8695 | io_channel = phba->io_channel_irqs; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8696 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8697 | /* Set up HBA event queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8698 | if (io_channel && !phba->sli4_hba.hba_eq) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8699 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8700 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8701 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8702 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8703 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8704 | for (qidx = 0; qidx < io_channel; qidx++) { |
| 8705 | if (!phba->sli4_hba.hba_eq[qidx]) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8706 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8707 | "0522 Fast-path EQ (%d) not " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8708 | "allocated\n", qidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8709 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8710 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8711 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8712 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx], |
| 8713 | phba->cfg_fcp_imax); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8714 | if (rc) { |
| 8715 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8716 | "0523 Failed setup of fast-path EQ " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8717 | "(%d), rc = 0x%x\n", qidx, |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 8718 | (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8719 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8720 | } |
| 8721 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8722 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
| 8723 | qidx, phba->sli4_hba.hba_eq[qidx]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8724 | } |
| 8725 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8726 | if (phba->cfg_nvme_io_channel) { |
| 8727 | if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8728 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8729 | "6084 Fast-path NVME %s array not allocated\n", |
| 8730 | (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8731 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8732 | goto out_destroy; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8733 | } |
| 8734 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8735 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) { |
| 8736 | rc = lpfc_create_wq_cq(phba, |
| 8737 | phba->sli4_hba.hba_eq[ |
| 8738 | qidx % io_channel], |
| 8739 | phba->sli4_hba.nvme_cq[qidx], |
| 8740 | phba->sli4_hba.nvme_wq[qidx], |
| 8741 | &phba->sli4_hba.nvme_cq_map[qidx], |
| 8742 | qidx, LPFC_NVME); |
| 8743 | if (rc) { |
| 8744 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8745 | "6123 Failed to setup fastpath " |
| 8746 | "NVME WQ/CQ (%d), rc = 0x%x\n", |
| 8747 | qidx, (uint32_t)rc); |
| 8748 | goto out_destroy; |
| 8749 | } |
| 8750 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8751 | } |
| 8752 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8753 | if (phba->cfg_fcp_io_channel) { |
| 8754 | /* Set up fast-path FCP Response Complete Queue */ |
| 8755 | if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8756 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8757 | "3148 Fast-path FCP %s array not allocated\n", |
| 8758 | phba->sli4_hba.fcp_cq ? "WQ" : "CQ"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8759 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8760 | goto out_destroy; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8761 | } |
| 8762 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8763 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) { |
| 8764 | rc = lpfc_create_wq_cq(phba, |
| 8765 | phba->sli4_hba.hba_eq[ |
| 8766 | qidx % io_channel], |
| 8767 | phba->sli4_hba.fcp_cq[qidx], |
| 8768 | phba->sli4_hba.fcp_wq[qidx], |
| 8769 | &phba->sli4_hba.fcp_cq_map[qidx], |
| 8770 | qidx, LPFC_FCP); |
| 8771 | if (rc) { |
| 8772 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8773 | "0535 Failed to setup fastpath " |
| 8774 | "FCP WQ/CQ (%d), rc = 0x%x\n", |
| 8775 | qidx, (uint32_t)rc); |
| 8776 | goto out_destroy; |
| 8777 | } |
| 8778 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8779 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8780 | |
| 8781 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8782 | * Set up Slow Path Complete Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8783 | */ |
| 8784 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8785 | /* Set up slow-path MBOX CQ/MQ */ |
| 8786 | |
| 8787 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8788 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8789 | "0528 %s not allocated\n", |
| 8790 | phba->sli4_hba.mbx_cq ? |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 8791 | "Mailbox WQ" : "Mailbox CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8792 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8793 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8794 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8795 | |
| 8796 | rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0], |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 8797 | phba->sli4_hba.mbx_cq, |
| 8798 | phba->sli4_hba.mbx_wq, |
| 8799 | NULL, 0, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8800 | if (rc) { |
| 8801 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8802 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
| 8803 | (uint32_t)rc); |
| 8804 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8805 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8806 | if (phba->nvmet_support) { |
| 8807 | if (!phba->sli4_hba.nvmet_cqset) { |
| 8808 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8809 | "3165 Fast-path NVME CQ Set " |
| 8810 | "array not allocated\n"); |
| 8811 | rc = -ENOMEM; |
| 8812 | goto out_destroy; |
| 8813 | } |
| 8814 | if (phba->cfg_nvmet_mrq > 1) { |
| 8815 | rc = lpfc_cq_create_set(phba, |
| 8816 | phba->sli4_hba.nvmet_cqset, |
| 8817 | phba->sli4_hba.hba_eq, |
| 8818 | LPFC_WCQ, LPFC_NVMET); |
| 8819 | if (rc) { |
| 8820 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8821 | "3164 Failed setup of NVME CQ " |
| 8822 | "Set, rc = 0x%x\n", |
| 8823 | (uint32_t)rc); |
| 8824 | goto out_destroy; |
| 8825 | } |
| 8826 | } else { |
| 8827 | /* Set up NVMET Receive Complete Queue */ |
| 8828 | rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0], |
| 8829 | phba->sli4_hba.hba_eq[0], |
| 8830 | LPFC_WCQ, LPFC_NVMET); |
| 8831 | if (rc) { |
| 8832 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8833 | "6089 Failed setup NVMET CQ: " |
| 8834 | "rc = 0x%x\n", (uint32_t)rc); |
| 8835 | goto out_destroy; |
| 8836 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8837 | phba->sli4_hba.nvmet_cqset[0]->chann = 0; |
| 8838 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8839 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8840 | "6090 NVMET CQ setup: cq-id=%d, " |
| 8841 | "parent eq-id=%d\n", |
| 8842 | phba->sli4_hba.nvmet_cqset[0]->queue_id, |
| 8843 | phba->sli4_hba.hba_eq[0]->queue_id); |
| 8844 | } |
| 8845 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8846 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8847 | /* Set up slow-path ELS WQ/CQ */ |
| 8848 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8849 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8850 | "0530 ELS %s not allocated\n", |
| 8851 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8852 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8853 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8854 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8855 | rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0], |
| 8856 | phba->sli4_hba.els_cq, |
| 8857 | phba->sli4_hba.els_wq, |
| 8858 | NULL, 0, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8859 | if (rc) { |
| 8860 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8861 | "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
| 8862 | (uint32_t)rc); |
| 8863 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8864 | } |
| 8865 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8866 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 8867 | phba->sli4_hba.els_wq->queue_id, |
| 8868 | phba->sli4_hba.els_cq->queue_id); |
| 8869 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8870 | if (phba->cfg_nvme_io_channel) { |
| 8871 | /* Set up NVME LS Complete Queue */ |
| 8872 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { |
| 8873 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8874 | "6091 LS %s not allocated\n", |
| 8875 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); |
| 8876 | rc = -ENOMEM; |
| 8877 | goto out_destroy; |
| 8878 | } |
| 8879 | rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0], |
| 8880 | phba->sli4_hba.nvmels_cq, |
| 8881 | phba->sli4_hba.nvmels_wq, |
| 8882 | NULL, 0, LPFC_NVME_LS); |
| 8883 | if (rc) { |
| 8884 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8885 | "0529 Failed setup of NVVME LS WQ/CQ: " |
| 8886 | "rc = 0x%x\n", (uint32_t)rc); |
| 8887 | goto out_destroy; |
| 8888 | } |
| 8889 | |
| 8890 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8891 | "6096 ELS WQ setup: wq-id=%d, " |
| 8892 | "parent cq-id=%d\n", |
| 8893 | phba->sli4_hba.nvmels_wq->queue_id, |
| 8894 | phba->sli4_hba.nvmels_cq->queue_id); |
| 8895 | } |
| 8896 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8897 | /* |
| 8898 | * Create NVMET Receive Queue (RQ) |
| 8899 | */ |
| 8900 | if (phba->nvmet_support) { |
| 8901 | if ((!phba->sli4_hba.nvmet_cqset) || |
| 8902 | (!phba->sli4_hba.nvmet_mrq_hdr) || |
| 8903 | (!phba->sli4_hba.nvmet_mrq_data)) { |
| 8904 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8905 | "6130 MRQ CQ Queues not " |
| 8906 | "allocated\n"); |
| 8907 | rc = -ENOMEM; |
| 8908 | goto out_destroy; |
| 8909 | } |
| 8910 | if (phba->cfg_nvmet_mrq > 1) { |
| 8911 | rc = lpfc_mrq_create(phba, |
| 8912 | phba->sli4_hba.nvmet_mrq_hdr, |
| 8913 | phba->sli4_hba.nvmet_mrq_data, |
| 8914 | phba->sli4_hba.nvmet_cqset, |
| 8915 | LPFC_NVMET); |
| 8916 | if (rc) { |
| 8917 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8918 | "6098 Failed setup of NVMET " |
| 8919 | "MRQ: rc = 0x%x\n", |
| 8920 | (uint32_t)rc); |
| 8921 | goto out_destroy; |
| 8922 | } |
| 8923 | |
| 8924 | } else { |
| 8925 | rc = lpfc_rq_create(phba, |
| 8926 | phba->sli4_hba.nvmet_mrq_hdr[0], |
| 8927 | phba->sli4_hba.nvmet_mrq_data[0], |
| 8928 | phba->sli4_hba.nvmet_cqset[0], |
| 8929 | LPFC_NVMET); |
| 8930 | if (rc) { |
| 8931 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8932 | "6057 Failed setup of NVMET " |
| 8933 | "Receive Queue: rc = 0x%x\n", |
| 8934 | (uint32_t)rc); |
| 8935 | goto out_destroy; |
| 8936 | } |
| 8937 | |
| 8938 | lpfc_printf_log( |
| 8939 | phba, KERN_INFO, LOG_INIT, |
| 8940 | "6099 NVMET RQ setup: hdr-rq-id=%d, " |
| 8941 | "dat-rq-id=%d parent cq-id=%d\n", |
| 8942 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id, |
| 8943 | phba->sli4_hba.nvmet_mrq_data[0]->queue_id, |
| 8944 | phba->sli4_hba.nvmet_cqset[0]->queue_id); |
| 8945 | |
| 8946 | } |
| 8947 | } |
| 8948 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8949 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 8950 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8951 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8952 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8953 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8954 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 8955 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8956 | rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 8957 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8958 | if (rc) { |
| 8959 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8960 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 8961 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8962 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8963 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 8964 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8965 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8966 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 8967 | "parent cq-id=%d\n", |
| 8968 | phba->sli4_hba.hdr_rq->queue_id, |
| 8969 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 8970 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8971 | |
| 8972 | if (phba->cfg_fof) { |
| 8973 | rc = lpfc_fof_queue_setup(phba); |
| 8974 | if (rc) { |
| 8975 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8976 | "0549 Failed setup of FOF Queues: " |
| 8977 | "rc = 0x%x\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8978 | goto out_destroy; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8979 | } |
| 8980 | } |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 8981 | |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 8982 | for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY_EQID_CNT) |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 8983 | lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT, |
| 8984 | phba->cfg_fcp_imax); |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 8985 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8986 | return 0; |
| 8987 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8988 | out_destroy: |
| 8989 | lpfc_sli4_queue_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8990 | out_error: |
| 8991 | return rc; |
| 8992 | } |
| 8993 | |
| 8994 | /** |
| 8995 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 8996 | * @phba: pointer to lpfc hba data structure. |
| 8997 | * |
| 8998 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 8999 | * operation. |
| 9000 | * |
| 9001 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9002 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9003 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9004 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9005 | **/ |
| 9006 | void |
| 9007 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 9008 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9009 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9010 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9011 | /* Unset the queues created for Flash Optimized Fabric operations */ |
| 9012 | if (phba->cfg_fof) |
| 9013 | lpfc_fof_queue_destroy(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9014 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9015 | /* Unset mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9016 | if (phba->sli4_hba.mbx_wq) |
| 9017 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 9018 | |
| 9019 | /* Unset NVME LS work queue */ |
| 9020 | if (phba->sli4_hba.nvmels_wq) |
| 9021 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); |
| 9022 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9023 | /* Unset ELS work queue */ |
Colin Ian King | 019c0d6 | 2017-05-06 23:13:55 +0100 | [diff] [blame] | 9024 | if (phba->sli4_hba.els_wq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9025 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 9026 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9027 | /* Unset unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9028 | if (phba->sli4_hba.hdr_rq) |
| 9029 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, |
| 9030 | phba->sli4_hba.dat_rq); |
| 9031 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9032 | /* Unset FCP work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9033 | if (phba->sli4_hba.fcp_wq) |
| 9034 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) |
| 9035 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]); |
| 9036 | |
| 9037 | /* Unset NVME work queue */ |
| 9038 | if (phba->sli4_hba.nvme_wq) { |
| 9039 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) |
| 9040 | lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9041 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9042 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9043 | /* Unset mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9044 | if (phba->sli4_hba.mbx_cq) |
| 9045 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 9046 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9047 | /* Unset ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9048 | if (phba->sli4_hba.els_cq) |
| 9049 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 9050 | |
| 9051 | /* Unset NVME LS complete queue */ |
| 9052 | if (phba->sli4_hba.nvmels_cq) |
| 9053 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); |
| 9054 | |
| 9055 | /* Unset NVME response complete queue */ |
| 9056 | if (phba->sli4_hba.nvme_cq) |
| 9057 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) |
| 9058 | lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]); |
| 9059 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9060 | if (phba->nvmet_support) { |
| 9061 | /* Unset NVMET MRQ queue */ |
| 9062 | if (phba->sli4_hba.nvmet_mrq_hdr) { |
| 9063 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9064 | lpfc_rq_destroy( |
| 9065 | phba, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9066 | phba->sli4_hba.nvmet_mrq_hdr[qidx], |
| 9067 | phba->sli4_hba.nvmet_mrq_data[qidx]); |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9068 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9069 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9070 | /* Unset NVMET CQ Set complete queue */ |
| 9071 | if (phba->sli4_hba.nvmet_cqset) { |
| 9072 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9073 | lpfc_cq_destroy( |
| 9074 | phba, phba->sli4_hba.nvmet_cqset[qidx]); |
| 9075 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9076 | } |
| 9077 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9078 | /* Unset FCP response complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9079 | if (phba->sli4_hba.fcp_cq) |
| 9080 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) |
| 9081 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]); |
| 9082 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9083 | /* Unset fast-path event queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9084 | if (phba->sli4_hba.hba_eq) |
| 9085 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) |
| 9086 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9087 | } |
| 9088 | |
| 9089 | /** |
| 9090 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 9091 | * @phba: pointer to lpfc hba data structure. |
| 9092 | * |
| 9093 | * This routine is invoked to allocate and set up a pool of completion queue |
| 9094 | * events. The body of the completion queue event is a completion queue entry |
| 9095 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 9096 | * the following HBA completion queue events for the worker thread to process: |
| 9097 | * - Mailbox asynchronous events |
| 9098 | * - Receive queue completion unsolicited events |
| 9099 | * Later, this can be used for all the slow-path events. |
| 9100 | * |
| 9101 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9102 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9103 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9104 | **/ |
| 9105 | static int |
| 9106 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 9107 | { |
| 9108 | struct lpfc_cq_event *cq_event; |
| 9109 | int i; |
| 9110 | |
| 9111 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 9112 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 9113 | if (!cq_event) |
| 9114 | goto out_pool_create_fail; |
| 9115 | list_add_tail(&cq_event->list, |
| 9116 | &phba->sli4_hba.sp_cqe_event_pool); |
| 9117 | } |
| 9118 | return 0; |
| 9119 | |
| 9120 | out_pool_create_fail: |
| 9121 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 9122 | return -ENOMEM; |
| 9123 | } |
| 9124 | |
| 9125 | /** |
| 9126 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 9127 | * @phba: pointer to lpfc hba data structure. |
| 9128 | * |
| 9129 | * This routine is invoked to free the pool of completion queue events at |
| 9130 | * driver unload time. Note that, it is the responsibility of the driver |
| 9131 | * cleanup routine to free all the outstanding completion-queue events |
| 9132 | * allocated from this pool back into the pool before invoking this routine |
| 9133 | * to destroy the pool. |
| 9134 | **/ |
| 9135 | static void |
| 9136 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 9137 | { |
| 9138 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 9139 | |
| 9140 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 9141 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 9142 | list_del(&cq_event->list); |
| 9143 | kfree(cq_event); |
| 9144 | } |
| 9145 | } |
| 9146 | |
| 9147 | /** |
| 9148 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9149 | * @phba: pointer to lpfc hba data structure. |
| 9150 | * |
| 9151 | * This routine is the lock free version of the API invoked to allocate a |
| 9152 | * completion-queue event from the free pool. |
| 9153 | * |
| 9154 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9155 | * NULL otherwise. |
| 9156 | **/ |
| 9157 | struct lpfc_cq_event * |
| 9158 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9159 | { |
| 9160 | struct lpfc_cq_event *cq_event = NULL; |
| 9161 | |
| 9162 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 9163 | struct lpfc_cq_event, list); |
| 9164 | return cq_event; |
| 9165 | } |
| 9166 | |
| 9167 | /** |
| 9168 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9169 | * @phba: pointer to lpfc hba data structure. |
| 9170 | * |
| 9171 | * This routine is the lock version of the API invoked to allocate a |
| 9172 | * completion-queue event from the free pool. |
| 9173 | * |
| 9174 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9175 | * NULL otherwise. |
| 9176 | **/ |
| 9177 | struct lpfc_cq_event * |
| 9178 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9179 | { |
| 9180 | struct lpfc_cq_event *cq_event; |
| 9181 | unsigned long iflags; |
| 9182 | |
| 9183 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9184 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 9185 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9186 | return cq_event; |
| 9187 | } |
| 9188 | |
| 9189 | /** |
| 9190 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 9191 | * @phba: pointer to lpfc hba data structure. |
| 9192 | * @cq_event: pointer to the completion queue event to be freed. |
| 9193 | * |
| 9194 | * This routine is the lock free version of the API invoked to release a |
| 9195 | * completion-queue event back into the free pool. |
| 9196 | **/ |
| 9197 | void |
| 9198 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 9199 | struct lpfc_cq_event *cq_event) |
| 9200 | { |
| 9201 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 9202 | } |
| 9203 | |
| 9204 | /** |
| 9205 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 9206 | * @phba: pointer to lpfc hba data structure. |
| 9207 | * @cq_event: pointer to the completion queue event to be freed. |
| 9208 | * |
| 9209 | * This routine is the lock version of the API invoked to release a |
| 9210 | * completion-queue event back into the free pool. |
| 9211 | **/ |
| 9212 | void |
| 9213 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 9214 | struct lpfc_cq_event *cq_event) |
| 9215 | { |
| 9216 | unsigned long iflags; |
| 9217 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9218 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 9219 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9220 | } |
| 9221 | |
| 9222 | /** |
| 9223 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 9224 | * @phba: pointer to lpfc hba data structure. |
| 9225 | * |
| 9226 | * This routine is to free all the pending completion-queue events to the |
| 9227 | * back into the free pool for device reset. |
| 9228 | **/ |
| 9229 | static void |
| 9230 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 9231 | { |
| 9232 | LIST_HEAD(cqelist); |
| 9233 | struct lpfc_cq_event *cqe; |
| 9234 | unsigned long iflags; |
| 9235 | |
| 9236 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 9237 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9238 | /* Pending FCP XRI abort events */ |
| 9239 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 9240 | &cqelist); |
| 9241 | /* Pending ELS XRI abort events */ |
| 9242 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 9243 | &cqelist); |
| 9244 | /* Pending asynnc events */ |
| 9245 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 9246 | &cqelist); |
| 9247 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9248 | |
| 9249 | while (!list_empty(&cqelist)) { |
| 9250 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 9251 | lpfc_sli4_cq_event_release(phba, cqe); |
| 9252 | } |
| 9253 | } |
| 9254 | |
| 9255 | /** |
| 9256 | * lpfc_pci_function_reset - Reset pci function. |
| 9257 | * @phba: pointer to lpfc hba data structure. |
| 9258 | * |
| 9259 | * This routine is invoked to request a PCI function reset. It will destroys |
| 9260 | * all resources assigned to the PCI function which originates this request. |
| 9261 | * |
| 9262 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9263 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9264 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9265 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9266 | **/ |
| 9267 | int |
| 9268 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 9269 | { |
| 9270 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9271 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9272 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9273 | uint32_t rdy_chk; |
| 9274 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9275 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9276 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 9277 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9278 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9279 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 9280 | switch (if_type) { |
| 9281 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 9282 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 9283 | GFP_KERNEL); |
| 9284 | if (!mboxq) { |
| 9285 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9286 | "0494 Unable to allocate memory for " |
| 9287 | "issuing SLI_FUNCTION_RESET mailbox " |
| 9288 | "command\n"); |
| 9289 | return -ENOMEM; |
| 9290 | } |
| 9291 | |
| 9292 | /* Setup PCI function reset mailbox-ioctl command */ |
| 9293 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9294 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 9295 | LPFC_SLI4_MBX_EMBED); |
| 9296 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9297 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 9298 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 9299 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 9300 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 9301 | &shdr->response); |
| 9302 | if (rc != MBX_TIMEOUT) |
| 9303 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 9304 | if (shdr_status || shdr_add_status || rc) { |
| 9305 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9306 | "0495 SLI_FUNCTION_RESET mailbox " |
| 9307 | "failed with status x%x add_status x%x," |
| 9308 | " mbx status x%x\n", |
| 9309 | shdr_status, shdr_add_status, rc); |
| 9310 | rc = -ENXIO; |
| 9311 | } |
| 9312 | break; |
| 9313 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9314 | wait: |
| 9315 | /* |
| 9316 | * Poll the Port Status Register and wait for RDY for |
| 9317 | * up to 30 seconds. If the port doesn't respond, treat |
| 9318 | * it as an error. |
| 9319 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 9320 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9321 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 9322 | STATUSregaddr, ®_data.word0)) { |
| 9323 | rc = -ENODEV; |
| 9324 | goto out; |
| 9325 | } |
| 9326 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 9327 | break; |
| 9328 | msleep(20); |
| 9329 | } |
| 9330 | |
| 9331 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 9332 | phba->work_status[0] = readl( |
| 9333 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 9334 | phba->work_status[1] = readl( |
| 9335 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 9336 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9337 | "2890 Port not ready, port status reg " |
| 9338 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 9339 | reg_data.word0, |
| 9340 | phba->work_status[0], |
| 9341 | phba->work_status[1]); |
| 9342 | rc = -ENODEV; |
| 9343 | goto out; |
| 9344 | } |
| 9345 | |
| 9346 | if (!port_reset) { |
| 9347 | /* |
| 9348 | * Reset the port now |
| 9349 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9350 | reg_data.word0 = 0; |
| 9351 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 9352 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 9353 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 9354 | LPFC_SLIPORT_INIT_PORT); |
| 9355 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 9356 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 9357 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 9358 | pci_read_config_word(phba->pcidev, |
| 9359 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9360 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9361 | port_reset = 1; |
| 9362 | msleep(20); |
| 9363 | goto wait; |
| 9364 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 9365 | rc = -ENODEV; |
| 9366 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9367 | } |
| 9368 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9369 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9370 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 9371 | default: |
| 9372 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9373 | } |
| 9374 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9375 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9376 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9377 | if (rc) { |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 9378 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9379 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9380 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9381 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 9382 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9383 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9384 | return rc; |
| 9385 | } |
| 9386 | |
| 9387 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9388 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 9389 | * @phba: pointer to lpfc hba data structure. |
| 9390 | * |
| 9391 | * This routine is invoked to set up the PCI device memory space for device |
| 9392 | * with SLI-4 interface spec. |
| 9393 | * |
| 9394 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9395 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9396 | * other values - error |
| 9397 | **/ |
| 9398 | static int |
| 9399 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 9400 | { |
| 9401 | struct pci_dev *pdev; |
| 9402 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
| 9403 | int error = -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9404 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9405 | |
| 9406 | /* Obtain PCI device reference */ |
| 9407 | if (!phba->pcidev) |
| 9408 | return error; |
| 9409 | else |
| 9410 | pdev = phba->pcidev; |
| 9411 | |
| 9412 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 9413 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 9414 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 9415 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 9416 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9417 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 9418 | } |
| 9419 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9420 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9421 | /* |
| 9422 | * The BARs and register set definitions and offset locations are |
| 9423 | * dependent on the if_type. |
| 9424 | */ |
| 9425 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 9426 | &phba->sli4_hba.sli_intf.word0)) { |
| 9427 | return error; |
| 9428 | } |
| 9429 | |
| 9430 | /* There is no SLI3 failback for SLI4 devices. */ |
| 9431 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 9432 | LPFC_SLI_INTF_VALID) { |
| 9433 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9434 | "2894 SLI_INTF reg contents invalid " |
| 9435 | "sli_intf reg 0x%x\n", |
| 9436 | phba->sli4_hba.sli_intf.word0); |
| 9437 | return error; |
| 9438 | } |
| 9439 | |
| 9440 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 9441 | /* |
| 9442 | * Get the bus address of SLI4 device Bar regions and the |
| 9443 | * number of bytes required by each mapping. The mapping of the |
| 9444 | * particular PCI BARs regions is dependent on the type of |
| 9445 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9446 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 9447 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 9448 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 9449 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9450 | |
| 9451 | /* |
| 9452 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 9453 | * addr |
| 9454 | */ |
| 9455 | phba->sli4_hba.conf_regs_memmap_p = |
| 9456 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 9457 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 9458 | dev_printk(KERN_ERR, &pdev->dev, |
| 9459 | "ioremap failed for SLI4 PCI config " |
| 9460 | "registers.\n"); |
| 9461 | goto out; |
| 9462 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 9463 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9464 | /* Set up BAR0 PCI config space register memory map */ |
| 9465 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9466 | } else { |
| 9467 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 9468 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9469 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 9470 | dev_printk(KERN_ERR, &pdev->dev, |
| 9471 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
| 9472 | goto out; |
| 9473 | } |
| 9474 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9475 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9476 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 9477 | dev_printk(KERN_ERR, &pdev->dev, |
| 9478 | "ioremap failed for SLI4 PCI config " |
| 9479 | "registers.\n"); |
| 9480 | goto out; |
| 9481 | } |
| 9482 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9483 | } |
| 9484 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 9485 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 9486 | if (pci_resource_start(pdev, PCI_64BIT_BAR2)) { |
| 9487 | /* |
| 9488 | * Map SLI4 if type 0 HBA Control Register base to a |
| 9489 | * kernel virtual address and setup the registers. |
| 9490 | */ |
| 9491 | phba->pci_bar1_map = pci_resource_start(pdev, |
| 9492 | PCI_64BIT_BAR2); |
| 9493 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 9494 | phba->sli4_hba.ctrl_regs_memmap_p = |
| 9495 | ioremap(phba->pci_bar1_map, |
| 9496 | bar1map_len); |
| 9497 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 9498 | dev_err(&pdev->dev, |
| 9499 | "ioremap failed for SLI4 HBA " |
| 9500 | "control registers.\n"); |
| 9501 | error = -ENOMEM; |
| 9502 | goto out_iounmap_conf; |
| 9503 | } |
| 9504 | phba->pci_bar2_memmap_p = |
| 9505 | phba->sli4_hba.ctrl_regs_memmap_p; |
| 9506 | lpfc_sli4_bar1_register_memmap(phba); |
| 9507 | } else { |
| 9508 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9509 | goto out_iounmap_conf; |
| 9510 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9511 | } |
| 9512 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 9513 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 9514 | if (pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 9515 | /* |
| 9516 | * Map SLI4 if type 0 HBA Doorbell Register base to |
| 9517 | * a kernel virtual address and setup the registers. |
| 9518 | */ |
| 9519 | phba->pci_bar2_map = pci_resource_start(pdev, |
| 9520 | PCI_64BIT_BAR4); |
| 9521 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 9522 | phba->sli4_hba.drbl_regs_memmap_p = |
| 9523 | ioremap(phba->pci_bar2_map, |
| 9524 | bar2map_len); |
| 9525 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 9526 | dev_err(&pdev->dev, |
| 9527 | "ioremap failed for SLI4 HBA" |
| 9528 | " doorbell registers.\n"); |
| 9529 | error = -ENOMEM; |
| 9530 | goto out_iounmap_ctrl; |
| 9531 | } |
| 9532 | phba->pci_bar4_memmap_p = |
| 9533 | phba->sli4_hba.drbl_regs_memmap_p; |
| 9534 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 9535 | if (error) |
| 9536 | goto out_iounmap_all; |
| 9537 | } else { |
| 9538 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9539 | goto out_iounmap_all; |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 9540 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9541 | } |
| 9542 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame^] | 9543 | /* Set up the EQ/CQ register handeling functions now */ |
| 9544 | if (if_type <= LPFC_SLI_INTF_IF_TYPE_2) { |
| 9545 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr; |
| 9546 | phba->sli4_hba.sli4_eq_release = lpfc_sli4_eq_release; |
| 9547 | phba->sli4_hba.sli4_cq_release = lpfc_sli4_cq_release; |
| 9548 | } |
| 9549 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9550 | return 0; |
| 9551 | |
| 9552 | out_iounmap_all: |
| 9553 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 9554 | out_iounmap_ctrl: |
| 9555 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 9556 | out_iounmap_conf: |
| 9557 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 9558 | out: |
| 9559 | return error; |
| 9560 | } |
| 9561 | |
| 9562 | /** |
| 9563 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 9564 | * @phba: pointer to lpfc hba data structure. |
| 9565 | * |
| 9566 | * This routine is invoked to unset the PCI device memory space for device |
| 9567 | * with SLI-4 interface spec. |
| 9568 | **/ |
| 9569 | static void |
| 9570 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 9571 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9572 | uint32_t if_type; |
| 9573 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9574 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9575 | switch (if_type) { |
| 9576 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 9577 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 9578 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 9579 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 9580 | break; |
| 9581 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 9582 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 9583 | break; |
| 9584 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 9585 | default: |
| 9586 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 9587 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 9588 | if_type); |
| 9589 | break; |
| 9590 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9591 | } |
| 9592 | |
| 9593 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9594 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 9595 | * @phba: pointer to lpfc hba data structure. |
| 9596 | * |
| 9597 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9598 | * with SLI-3 interface specs. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9599 | * |
| 9600 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9601 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9602 | * other values - error |
| 9603 | **/ |
| 9604 | static int |
| 9605 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 9606 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9607 | int rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9608 | LPFC_MBOXQ_t *pmb; |
| 9609 | |
| 9610 | /* Set up MSI-X multi-message vectors */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9611 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 9612 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); |
| 9613 | if (rc < 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9614 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9615 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 9616 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9617 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9618 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9619 | /* |
| 9620 | * Assign MSI-X vectors to interrupt handlers |
| 9621 | */ |
| 9622 | |
| 9623 | /* vector-0 is associated to slow-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9624 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9625 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9626 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 9627 | if (rc) { |
| 9628 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 9629 | "0421 MSI-X slow-path request_irq failed " |
| 9630 | "(%d)\n", rc); |
| 9631 | goto msi_fail_out; |
| 9632 | } |
| 9633 | |
| 9634 | /* vector-1 is associated to fast-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9635 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9636 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9637 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 9638 | |
| 9639 | if (rc) { |
| 9640 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 9641 | "0429 MSI-X fast-path request_irq failed " |
| 9642 | "(%d)\n", rc); |
| 9643 | goto irq_fail_out; |
| 9644 | } |
| 9645 | |
| 9646 | /* |
| 9647 | * Configure HBA MSI-X attention conditions to messages |
| 9648 | */ |
| 9649 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9650 | |
| 9651 | if (!pmb) { |
| 9652 | rc = -ENOMEM; |
| 9653 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9654 | "0474 Unable to allocate memory for issuing " |
| 9655 | "MBOX_CONFIG_MSI command\n"); |
| 9656 | goto mem_fail_out; |
| 9657 | } |
| 9658 | rc = lpfc_config_msi(phba, pmb); |
| 9659 | if (rc) |
| 9660 | goto mbx_fail_out; |
| 9661 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 9662 | if (rc != MBX_SUCCESS) { |
| 9663 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 9664 | "0351 Config MSI mailbox command failed, " |
| 9665 | "mbxCmd x%x, mbxStatus x%x\n", |
| 9666 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 9667 | goto mbx_fail_out; |
| 9668 | } |
| 9669 | |
| 9670 | /* Free memory allocated for mailbox command */ |
| 9671 | mempool_free(pmb, phba->mbox_mem_pool); |
| 9672 | return rc; |
| 9673 | |
| 9674 | mbx_fail_out: |
| 9675 | /* Free memory allocated for mailbox command */ |
| 9676 | mempool_free(pmb, phba->mbox_mem_pool); |
| 9677 | |
| 9678 | mem_fail_out: |
| 9679 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9680 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9681 | |
| 9682 | irq_fail_out: |
| 9683 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9684 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9685 | |
| 9686 | msi_fail_out: |
| 9687 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9688 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 9689 | |
| 9690 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9691 | return rc; |
| 9692 | } |
| 9693 | |
| 9694 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9695 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 9696 | * @phba: pointer to lpfc hba data structure. |
| 9697 | * |
| 9698 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 9699 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 9700 | * enable the MSI vector. The device driver is responsible for calling the |
| 9701 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 9702 | * is done in this function. |
| 9703 | * |
| 9704 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9705 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9706 | * other values - error |
| 9707 | */ |
| 9708 | static int |
| 9709 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 9710 | { |
| 9711 | int rc; |
| 9712 | |
| 9713 | rc = pci_enable_msi(phba->pcidev); |
| 9714 | if (!rc) |
| 9715 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9716 | "0462 PCI enable MSI mode success.\n"); |
| 9717 | else { |
| 9718 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9719 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 9720 | return rc; |
| 9721 | } |
| 9722 | |
| 9723 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9724 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9725 | if (rc) { |
| 9726 | pci_disable_msi(phba->pcidev); |
| 9727 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 9728 | "0478 MSI request_irq failed (%d)\n", rc); |
| 9729 | } |
| 9730 | return rc; |
| 9731 | } |
| 9732 | |
| 9733 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9734 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 9735 | * @phba: pointer to lpfc hba data structure. |
| 9736 | * |
| 9737 | * This routine is invoked to enable device interrupt and associate driver's |
| 9738 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 9739 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 9740 | * will try to fallback from the configured interrupt mode to an interrupt |
| 9741 | * mode which is supported by the platform, kernel, and device in the order |
| 9742 | * of: |
| 9743 | * MSI-X -> MSI -> IRQ. |
| 9744 | * |
| 9745 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9746 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9747 | * other values - error |
| 9748 | **/ |
| 9749 | static uint32_t |
| 9750 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 9751 | { |
| 9752 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 9753 | int retval; |
| 9754 | |
| 9755 | if (cfg_mode == 2) { |
| 9756 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 9757 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 9758 | if (!retval) { |
| 9759 | /* Now, try to enable MSI-X interrupt mode */ |
| 9760 | retval = lpfc_sli_enable_msix(phba); |
| 9761 | if (!retval) { |
| 9762 | /* Indicate initialization to MSI-X mode */ |
| 9763 | phba->intr_type = MSIX; |
| 9764 | intr_mode = 2; |
| 9765 | } |
| 9766 | } |
| 9767 | } |
| 9768 | |
| 9769 | /* Fallback to MSI if MSI-X initialization failed */ |
| 9770 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 9771 | retval = lpfc_sli_enable_msi(phba); |
| 9772 | if (!retval) { |
| 9773 | /* Indicate initialization to MSI mode */ |
| 9774 | phba->intr_type = MSI; |
| 9775 | intr_mode = 1; |
| 9776 | } |
| 9777 | } |
| 9778 | |
| 9779 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 9780 | if (phba->intr_type == NONE) { |
| 9781 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 9782 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 9783 | if (!retval) { |
| 9784 | /* Indicate initialization to INTx mode */ |
| 9785 | phba->intr_type = INTx; |
| 9786 | intr_mode = 0; |
| 9787 | } |
| 9788 | } |
| 9789 | return intr_mode; |
| 9790 | } |
| 9791 | |
| 9792 | /** |
| 9793 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 9794 | * @phba: pointer to lpfc hba data structure. |
| 9795 | * |
| 9796 | * This routine is invoked to disable device interrupt and disassociate the |
| 9797 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 9798 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 9799 | * release the interrupt vector(s) for the message signaled interrupt. |
| 9800 | **/ |
| 9801 | static void |
| 9802 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 9803 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9804 | int nr_irqs, i; |
| 9805 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9806 | if (phba->intr_type == MSIX) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9807 | nr_irqs = LPFC_MSIX_VECTORS; |
| 9808 | else |
| 9809 | nr_irqs = 1; |
| 9810 | |
| 9811 | for (i = 0; i < nr_irqs; i++) |
| 9812 | free_irq(pci_irq_vector(phba->pcidev, i), phba); |
| 9813 | pci_free_irq_vectors(phba->pcidev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9814 | |
| 9815 | /* Reset interrupt management states */ |
| 9816 | phba->intr_type = NONE; |
| 9817 | phba->sli.slistat.sli_intr = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9818 | } |
| 9819 | |
| 9820 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9821 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9822 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9823 | * @vectors: number of msix vectors allocated. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9824 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9825 | * The routine will figure out the CPU affinity assignment for every |
| 9826 | * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated |
| 9827 | * with a pointer to the CPU mask that defines ALL the CPUs this vector |
| 9828 | * can be associated with. If the vector can be unquely associated with |
| 9829 | * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu. |
| 9830 | * In addition, the CPU to IO channel mapping will be calculated |
| 9831 | * and the phba->sli4_hba.cpu_map array will reflect this. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9832 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9833 | static void |
| 9834 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9835 | { |
| 9836 | struct lpfc_vector_map_info *cpup; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9837 | int index = 0; |
| 9838 | int vec = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9839 | int cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9840 | #ifdef CONFIG_X86 |
| 9841 | struct cpuinfo_x86 *cpuinfo; |
| 9842 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9843 | |
| 9844 | /* Init cpu_map array */ |
| 9845 | memset(phba->sli4_hba.cpu_map, 0xff, |
| 9846 | (sizeof(struct lpfc_vector_map_info) * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9847 | phba->sli4_hba.num_present_cpu)); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9848 | |
| 9849 | /* Update CPU map with physical id and core id of each CPU */ |
| 9850 | cpup = phba->sli4_hba.cpu_map; |
| 9851 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 9852 | #ifdef CONFIG_X86 |
| 9853 | cpuinfo = &cpu_data(cpu); |
| 9854 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 9855 | cpup->core_id = cpuinfo->cpu_core_id; |
| 9856 | #else |
| 9857 | /* No distinction between CPUs for other platforms */ |
| 9858 | cpup->phys_id = 0; |
| 9859 | cpup->core_id = 0; |
| 9860 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9861 | cpup->channel_id = index; /* For now round robin */ |
| 9862 | cpup->irq = pci_irq_vector(phba->pcidev, vec); |
| 9863 | vec++; |
| 9864 | if (vec >= vectors) |
| 9865 | vec = 0; |
| 9866 | index++; |
| 9867 | if (index >= phba->cfg_fcp_io_channel) |
| 9868 | index = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9869 | cpup++; |
| 9870 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9871 | } |
| 9872 | |
| 9873 | |
| 9874 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9875 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 9876 | * @phba: pointer to lpfc hba data structure. |
| 9877 | * |
| 9878 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9879 | * with SLI-4 interface spec. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9880 | * |
| 9881 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9882 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9883 | * other values - error |
| 9884 | **/ |
| 9885 | static int |
| 9886 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 9887 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9888 | int vectors, rc, index; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 9889 | char *name; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9890 | |
| 9891 | /* Set up MSI-X multi-message vectors */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9892 | vectors = phba->io_channel_irqs; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9893 | if (phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9894 | vectors++; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9895 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 9896 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 9897 | (phba->nvmet_support) ? 1 : 2, |
| 9898 | vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY); |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 9899 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9900 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9901 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 9902 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9903 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 9904 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 9905 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9906 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9907 | for (index = 0; index < vectors; index++) { |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 9908 | name = phba->sli4_hba.hba_eq_hdl[index].handler_name; |
| 9909 | memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ); |
| 9910 | snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 9911 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9912 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9913 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 9914 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
| 9915 | atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9916 | if (phba->cfg_fof && (index == (vectors - 1))) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9917 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9918 | &lpfc_sli4_fof_intr_handler, 0, |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 9919 | name, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9920 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9921 | else |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9922 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9923 | &lpfc_sli4_hba_intr_handler, 0, |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 9924 | name, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9925 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9926 | if (rc) { |
| 9927 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 9928 | "0486 MSI-X fast-path (%d) " |
| 9929 | "request_irq failed (%d)\n", index, rc); |
| 9930 | goto cfg_fail_out; |
| 9931 | } |
| 9932 | } |
| 9933 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9934 | if (phba->cfg_fof) |
| 9935 | vectors--; |
| 9936 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9937 | if (vectors != phba->io_channel_irqs) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 9938 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9939 | "3238 Reducing IO channels to match number of " |
| 9940 | "MSI-X vectors, requested %d got %d\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9941 | phba->io_channel_irqs, vectors); |
| 9942 | if (phba->cfg_fcp_io_channel > vectors) |
| 9943 | phba->cfg_fcp_io_channel = vectors; |
| 9944 | if (phba->cfg_nvme_io_channel > vectors) |
| 9945 | phba->cfg_nvme_io_channel = vectors; |
| 9946 | if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel) |
| 9947 | phba->io_channel_irqs = phba->cfg_fcp_io_channel; |
| 9948 | else |
| 9949 | phba->io_channel_irqs = phba->cfg_nvme_io_channel; |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 9950 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9951 | lpfc_cpu_affinity_check(phba, vectors); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9952 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9953 | return rc; |
| 9954 | |
| 9955 | cfg_fail_out: |
| 9956 | /* free the irq already requested */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9957 | for (--index; index >= 0; index--) |
| 9958 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 9959 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9960 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9961 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9962 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 9963 | |
| 9964 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9965 | return rc; |
| 9966 | } |
| 9967 | |
| 9968 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9969 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 9970 | * @phba: pointer to lpfc hba data structure. |
| 9971 | * |
| 9972 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 9973 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 9974 | * to enable the MSI vector. The device driver is responsible for calling |
| 9975 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 9976 | * which is done in this function. |
| 9977 | * |
| 9978 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9979 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9980 | * other values - error |
| 9981 | **/ |
| 9982 | static int |
| 9983 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 9984 | { |
| 9985 | int rc, index; |
| 9986 | |
| 9987 | rc = pci_enable_msi(phba->pcidev); |
| 9988 | if (!rc) |
| 9989 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9990 | "0487 PCI enable MSI mode success.\n"); |
| 9991 | else { |
| 9992 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9993 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 9994 | return rc; |
| 9995 | } |
| 9996 | |
| 9997 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9998 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9999 | if (rc) { |
| 10000 | pci_disable_msi(phba->pcidev); |
| 10001 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10002 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10003 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10004 | } |
| 10005 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10006 | for (index = 0; index < phba->io_channel_irqs; index++) { |
| 10007 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 10008 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10009 | } |
| 10010 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10011 | if (phba->cfg_fof) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10012 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 10013 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10014 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10015 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10016 | } |
| 10017 | |
| 10018 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10019 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 10020 | * @phba: pointer to lpfc hba data structure. |
| 10021 | * |
| 10022 | * This routine is invoked to enable device interrupt and associate driver's |
| 10023 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 10024 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 10025 | * the driver will try to fallback from the configured interrupt mode to an |
| 10026 | * interrupt mode which is supported by the platform, kernel, and device in |
| 10027 | * the order of: |
| 10028 | * MSI-X -> MSI -> IRQ. |
| 10029 | * |
| 10030 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10031 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10032 | * other values - error |
| 10033 | **/ |
| 10034 | static uint32_t |
| 10035 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 10036 | { |
| 10037 | uint32_t intr_mode = LPFC_INTR_ERROR; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10038 | int retval, idx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10039 | |
| 10040 | if (cfg_mode == 2) { |
| 10041 | /* Preparation before conf_msi mbox cmd */ |
| 10042 | retval = 0; |
| 10043 | if (!retval) { |
| 10044 | /* Now, try to enable MSI-X interrupt mode */ |
| 10045 | retval = lpfc_sli4_enable_msix(phba); |
| 10046 | if (!retval) { |
| 10047 | /* Indicate initialization to MSI-X mode */ |
| 10048 | phba->intr_type = MSIX; |
| 10049 | intr_mode = 2; |
| 10050 | } |
| 10051 | } |
| 10052 | } |
| 10053 | |
| 10054 | /* Fallback to MSI if MSI-X initialization failed */ |
| 10055 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 10056 | retval = lpfc_sli4_enable_msi(phba); |
| 10057 | if (!retval) { |
| 10058 | /* Indicate initialization to MSI mode */ |
| 10059 | phba->intr_type = MSI; |
| 10060 | intr_mode = 1; |
| 10061 | } |
| 10062 | } |
| 10063 | |
| 10064 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 10065 | if (phba->intr_type == NONE) { |
| 10066 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 10067 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 10068 | if (!retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10069 | struct lpfc_hba_eq_hdl *eqhdl; |
| 10070 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10071 | /* Indicate initialization to INTx mode */ |
| 10072 | phba->intr_type = INTx; |
| 10073 | intr_mode = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10074 | |
| 10075 | for (idx = 0; idx < phba->io_channel_irqs; idx++) { |
| 10076 | eqhdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
| 10077 | eqhdl->idx = idx; |
| 10078 | eqhdl->phba = phba; |
| 10079 | atomic_set(&eqhdl->hba_eq_in_use, 1); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10080 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10081 | if (phba->cfg_fof) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10082 | eqhdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
| 10083 | eqhdl->idx = idx; |
| 10084 | eqhdl->phba = phba; |
| 10085 | atomic_set(&eqhdl->hba_eq_in_use, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10086 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10087 | } |
| 10088 | } |
| 10089 | return intr_mode; |
| 10090 | } |
| 10091 | |
| 10092 | /** |
| 10093 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 10094 | * @phba: pointer to lpfc hba data structure. |
| 10095 | * |
| 10096 | * This routine is invoked to disable device interrupt and disassociate |
| 10097 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 10098 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 10099 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 10100 | **/ |
| 10101 | static void |
| 10102 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 10103 | { |
| 10104 | /* Disable the currently initialized interrupt mode */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10105 | if (phba->intr_type == MSIX) { |
| 10106 | int index; |
| 10107 | |
| 10108 | /* Free up MSI-X multi-message vectors */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10109 | for (index = 0; index < phba->io_channel_irqs; index++) |
| 10110 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 10111 | &phba->sli4_hba.hba_eq_hdl[index]); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10112 | |
| 10113 | if (phba->cfg_fof) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10114 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 10115 | &phba->sli4_hba.hba_eq_hdl[index]); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10116 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10117 | free_irq(phba->pcidev->irq, phba); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10118 | } |
| 10119 | |
| 10120 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10121 | |
| 10122 | /* Reset interrupt management states */ |
| 10123 | phba->intr_type = NONE; |
| 10124 | phba->sli.slistat.sli_intr = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10125 | } |
| 10126 | |
| 10127 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10128 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 10129 | * @phba: pointer to lpfc hba data structure. |
| 10130 | * |
| 10131 | * This routine is invoked to unset the HBA device initialization steps to |
| 10132 | * a device with SLI-3 interface spec. |
| 10133 | **/ |
| 10134 | static void |
| 10135 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 10136 | { |
| 10137 | struct lpfc_vport *vport = phba->pport; |
| 10138 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 10139 | |
| 10140 | spin_lock_irq(shost->host_lock); |
| 10141 | vport->load_flag |= FC_UNLOADING; |
| 10142 | spin_unlock_irq(shost->host_lock); |
| 10143 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 10144 | kfree(phba->vpi_bmask); |
| 10145 | kfree(phba->vpi_ids); |
| 10146 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10147 | lpfc_stop_hba_timers(phba); |
| 10148 | |
| 10149 | phba->pport->work_port_events = 0; |
| 10150 | |
| 10151 | lpfc_sli_hba_down(phba); |
| 10152 | |
| 10153 | lpfc_sli_brdrestart(phba); |
| 10154 | |
| 10155 | lpfc_sli_disable_intr(phba); |
| 10156 | |
| 10157 | return; |
| 10158 | } |
| 10159 | |
| 10160 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10161 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 10162 | * @phba: Pointer to HBA context object. |
| 10163 | * |
| 10164 | * This function is called in the SLI4 code path to wait for completion |
| 10165 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 10166 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 10167 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 10168 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 10169 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 10170 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 10171 | * the rest of the driver unload resource release. |
| 10172 | **/ |
| 10173 | static void |
| 10174 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 10175 | { |
| 10176 | int wait_time = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10177 | int nvme_xri_cmpl = 1; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 10178 | int nvmet_xri_cmpl = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10179 | int fcp_xri_cmpl = 1; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10180 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 10181 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 10182 | /* Driver just aborted IOs during the hba_unset process. Pause |
| 10183 | * here to give the HBA time to complete the IO and get entries |
| 10184 | * into the abts lists. |
| 10185 | */ |
| 10186 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5); |
| 10187 | |
| 10188 | /* Wait for NVME pending IO to flush back to transport. */ |
| 10189 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 10190 | lpfc_nvme_wait_for_io_drain(phba); |
| 10191 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10192 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) |
| 10193 | fcp_xri_cmpl = |
| 10194 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 10195 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10196 | nvme_xri_cmpl = |
| 10197 | list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 10198 | nvmet_xri_cmpl = |
| 10199 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 10200 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10201 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 10202 | while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl || |
| 10203 | !nvmet_xri_cmpl) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10204 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10205 | if (!nvme_xri_cmpl) |
| 10206 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10207 | "6100 NVME XRI exchange busy " |
| 10208 | "wait time: %d seconds.\n", |
| 10209 | wait_time/1000); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10210 | if (!fcp_xri_cmpl) |
| 10211 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10212 | "2877 FCP XRI exchange busy " |
| 10213 | "wait time: %d seconds.\n", |
| 10214 | wait_time/1000); |
| 10215 | if (!els_xri_cmpl) |
| 10216 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10217 | "2878 ELS XRI exchange busy " |
| 10218 | "wait time: %d seconds.\n", |
| 10219 | wait_time/1000); |
| 10220 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 10221 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 10222 | } else { |
| 10223 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 10224 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 10225 | } |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 10226 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10227 | nvme_xri_cmpl = list_empty( |
| 10228 | &phba->sli4_hba.lpfc_abts_nvme_buf_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 10229 | nvmet_xri_cmpl = list_empty( |
| 10230 | &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 10231 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10232 | |
| 10233 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) |
| 10234 | fcp_xri_cmpl = list_empty( |
| 10235 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 10236 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10237 | els_xri_cmpl = |
| 10238 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 10239 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10240 | } |
| 10241 | } |
| 10242 | |
| 10243 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10244 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 10245 | * @phba: Pointer to HBA context object. |
| 10246 | * |
| 10247 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 10248 | * function. The caller is not required to hold any lock. This routine |
| 10249 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 10250 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 10251 | * free any pending commands. |
| 10252 | **/ |
| 10253 | static void |
| 10254 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 10255 | { |
| 10256 | int wait_cnt = 0; |
| 10257 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10258 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10259 | |
| 10260 | lpfc_stop_hba_timers(phba); |
| 10261 | phba->sli4_hba.intr_enable = 0; |
| 10262 | |
| 10263 | /* |
| 10264 | * Gracefully wait out the potential current outstanding asynchronous |
| 10265 | * mailbox command. |
| 10266 | */ |
| 10267 | |
| 10268 | /* First, block any pending async mailbox command from posted */ |
| 10269 | spin_lock_irq(&phba->hbalock); |
| 10270 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 10271 | spin_unlock_irq(&phba->hbalock); |
| 10272 | /* Now, trying to wait it out if we can */ |
| 10273 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 10274 | msleep(10); |
| 10275 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 10276 | break; |
| 10277 | } |
| 10278 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 10279 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 10280 | spin_lock_irq(&phba->hbalock); |
| 10281 | mboxq = phba->sli.mbox_active; |
| 10282 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10283 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 10284 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10285 | phba->sli.mbox_active = NULL; |
| 10286 | spin_unlock_irq(&phba->hbalock); |
| 10287 | } |
| 10288 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10289 | /* Abort all iocbs associated with the hba */ |
| 10290 | lpfc_sli_hba_iocb_abort(phba); |
| 10291 | |
| 10292 | /* Wait for completion of device XRI exchange busy */ |
| 10293 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 10294 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10295 | /* Disable PCI subsystem interrupt */ |
| 10296 | lpfc_sli4_disable_intr(phba); |
| 10297 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10298 | /* Disable SR-IOV if enabled */ |
| 10299 | if (phba->cfg_sriov_nr_virtfn) |
| 10300 | pci_disable_sriov(pdev); |
| 10301 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10302 | /* Stop kthread signal shall trigger work_done one more time */ |
| 10303 | kthread_stop(phba->worker_thread); |
| 10304 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 10305 | /* Unset the queues shared with the hardware then release all |
| 10306 | * allocated resources. |
| 10307 | */ |
| 10308 | lpfc_sli4_queue_unset(phba); |
| 10309 | lpfc_sli4_queue_destroy(phba); |
| 10310 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 10311 | /* Reset SLI4 HBA FCoE function */ |
| 10312 | lpfc_pci_function_reset(phba); |
| 10313 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10314 | /* Stop the SLI4 device port */ |
| 10315 | phba->pport->work_port_events = 0; |
| 10316 | } |
| 10317 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10318 | /** |
| 10319 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 10320 | * @phba: Pointer to HBA context object. |
| 10321 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 10322 | * |
| 10323 | * This function is called in the SLI4 code path to read the port's |
| 10324 | * sli4 capabilities. |
| 10325 | * |
| 10326 | * This function may be be called from any context that can block-wait |
| 10327 | * for the completion. The expectation is that this routine is called |
| 10328 | * typically from probe_one or from the online routine. |
| 10329 | **/ |
| 10330 | int |
| 10331 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 10332 | { |
| 10333 | int rc; |
| 10334 | struct lpfc_mqe *mqe; |
| 10335 | struct lpfc_pc_sli4_params *sli4_params; |
| 10336 | uint32_t mbox_tmo; |
| 10337 | |
| 10338 | rc = 0; |
| 10339 | mqe = &mboxq->u.mqe; |
| 10340 | |
| 10341 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10342 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10343 | if (!phba->sli4_hba.intr_enable) |
| 10344 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10345 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10346 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10347 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 10348 | } |
| 10349 | |
| 10350 | if (unlikely(rc)) |
| 10351 | return 1; |
| 10352 | |
| 10353 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 10354 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 10355 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 10356 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 10357 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 10358 | &mqe->un.sli4_params); |
| 10359 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 10360 | &mqe->un.sli4_params); |
| 10361 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 10362 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 10363 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 10364 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 10365 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 10366 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 10367 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 10368 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 10369 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 10370 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 10371 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 10372 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 10373 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 10374 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 10375 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 10376 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 10377 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 10378 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 10379 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 10380 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 10381 | sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 10382 | |
| 10383 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 10384 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 10385 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 10386 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10387 | return rc; |
| 10388 | } |
| 10389 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10390 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10391 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 10392 | * @phba: Pointer to HBA context object. |
| 10393 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 10394 | * |
| 10395 | * This function is called in the SLI4 code path to read the port's |
| 10396 | * sli4 capabilities. |
| 10397 | * |
| 10398 | * This function may be be called from any context that can block-wait |
| 10399 | * for the completion. The expectation is that this routine is called |
| 10400 | * typically from probe_one or from the online routine. |
| 10401 | **/ |
| 10402 | int |
| 10403 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 10404 | { |
| 10405 | int rc; |
| 10406 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 10407 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10408 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10409 | int length; |
| 10410 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 10411 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10412 | /* |
| 10413 | * By default, the driver assumes the SLI4 port requires RPI |
| 10414 | * header postings. The SLI4_PARAM response will correct this |
| 10415 | * assumption. |
| 10416 | */ |
| 10417 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 10418 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10419 | /* Read the port's SLI4 Config Parameters */ |
| 10420 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 10421 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 10422 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10423 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 10424 | length, LPFC_SLI4_MBX_EMBED); |
| 10425 | if (!phba->sli4_hba.intr_enable) |
| 10426 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10427 | else { |
| 10428 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 10429 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 10430 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10431 | if (unlikely(rc)) |
| 10432 | return rc; |
| 10433 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 10434 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 10435 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 10436 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 10437 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 10438 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 10439 | mbx_sli4_parameters); |
| 10440 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 10441 | mbx_sli4_parameters); |
| 10442 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 10443 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 10444 | else |
| 10445 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 10446 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 10447 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10448 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10449 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 10450 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 10451 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 10452 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 10453 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10454 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 10455 | mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10456 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10457 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 10458 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10459 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 10460 | phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10461 | phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
| 10462 | bf_get(cfg_xib, mbx_sli4_parameters)); |
| 10463 | |
| 10464 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) || |
| 10465 | !phba->nvme_support) { |
| 10466 | phba->nvme_support = 0; |
| 10467 | phba->nvmet_support = 0; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 10468 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10469 | phba->cfg_nvme_io_channel = 0; |
| 10470 | phba->io_channel_irqs = phba->cfg_fcp_io_channel; |
| 10471 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, |
| 10472 | "6101 Disabling NVME support: " |
| 10473 | "Not supported by firmware: %d %d\n", |
| 10474 | bf_get(cfg_nvme, mbx_sli4_parameters), |
| 10475 | bf_get(cfg_xib, mbx_sli4_parameters)); |
| 10476 | |
| 10477 | /* If firmware doesn't support NVME, just use SCSI support */ |
| 10478 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 10479 | return -ENODEV; |
| 10480 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; |
| 10481 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 10482 | |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 10483 | /* |
| 10484 | * To support Suppress Response feature we must satisfy 3 conditions. |
| 10485 | * lpfc_suppress_rsp module parameter must be set (default). |
| 10486 | * In SLI4-Parameters Descriptor: |
| 10487 | * Extended Inline Buffers (XIB) must be supported. |
| 10488 | * Suppress Response IU Not Supported (SRIUNS) must NOT be supported |
| 10489 | * (double negative). |
| 10490 | */ |
| 10491 | if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) && |
| 10492 | !(bf_get(cfg_nosr, mbx_sli4_parameters))) |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 10493 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 10494 | else |
| 10495 | phba->cfg_suppress_rsp = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 10496 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 10497 | if (bf_get(cfg_eqdr, mbx_sli4_parameters)) |
| 10498 | phba->sli.sli_flag |= LPFC_SLI_USE_EQDR; |
| 10499 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 10500 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 10501 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 10502 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 10503 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10504 | /* |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10505 | * Check whether the adapter supports an embedded copy of the |
| 10506 | * FCP CMD IU within the WQE for FCP_Ixxx commands. In order |
| 10507 | * to use this option, 128-byte WQEs must be used. |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10508 | */ |
| 10509 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 10510 | phba->fcp_embed_io = 1; |
| 10511 | else |
| 10512 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 10513 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10514 | if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) && |
| 10515 | (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) && |
| 10516 | (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT)) |
| 10517 | phba->enab_exp_wqcq_pages = 1; |
| 10518 | else |
| 10519 | phba->enab_exp_wqcq_pages = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 10520 | /* |
| 10521 | * Check if the SLI port supports MDS Diagnostics |
| 10522 | */ |
| 10523 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 10524 | phba->mds_diags_support = 1; |
| 10525 | else |
| 10526 | phba->mds_diags_support = 0; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10527 | return 0; |
| 10528 | } |
| 10529 | |
| 10530 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10531 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 10532 | * @pdev: pointer to PCI device |
| 10533 | * @pid: pointer to PCI device identifier |
| 10534 | * |
| 10535 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 10536 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 10537 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 10538 | * information of the device and driver to see if the driver state that it can |
| 10539 | * support this kind of device. If the match is successful, the driver core |
| 10540 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 10541 | * does all the initialization that it needs to do to handle the HBA properly. |
| 10542 | * |
| 10543 | * Return code |
| 10544 | * 0 - driver can claim the device |
| 10545 | * negative value - driver can not claim the device |
| 10546 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10547 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10548 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10549 | { |
| 10550 | struct lpfc_hba *phba; |
| 10551 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10552 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10553 | int error; |
| 10554 | uint32_t cfg_mode, intr_mode; |
| 10555 | |
| 10556 | /* Allocate memory for HBA structure */ |
| 10557 | phba = lpfc_hba_alloc(pdev); |
| 10558 | if (!phba) |
| 10559 | return -ENOMEM; |
| 10560 | |
| 10561 | /* Perform generic PCI device enabling operation */ |
| 10562 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10563 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10564 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10565 | |
| 10566 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 10567 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 10568 | if (error) |
| 10569 | goto out_disable_pci_dev; |
| 10570 | |
| 10571 | /* Set up SLI-3 specific device PCI memory space */ |
| 10572 | error = lpfc_sli_pci_mem_setup(phba); |
| 10573 | if (error) { |
| 10574 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10575 | "1402 Failed to set up pci memory space.\n"); |
| 10576 | goto out_disable_pci_dev; |
| 10577 | } |
| 10578 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10579 | /* Set up SLI-3 specific device driver resources */ |
| 10580 | error = lpfc_sli_driver_resource_setup(phba); |
| 10581 | if (error) { |
| 10582 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10583 | "1404 Failed to set up driver resource.\n"); |
| 10584 | goto out_unset_pci_mem_s3; |
| 10585 | } |
| 10586 | |
| 10587 | /* Initialize and populate the iocb list per host */ |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 10588 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10589 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 10590 | if (error) { |
| 10591 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10592 | "1405 Failed to initialize iocb list.\n"); |
| 10593 | goto out_unset_driver_resource_s3; |
| 10594 | } |
| 10595 | |
| 10596 | /* Set up common device driver resources */ |
| 10597 | error = lpfc_setup_driver_resource_phase2(phba); |
| 10598 | if (error) { |
| 10599 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10600 | "1406 Failed to set up driver resource.\n"); |
| 10601 | goto out_free_iocb_list; |
| 10602 | } |
| 10603 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10604 | /* Get the default values for Model Name and Description */ |
| 10605 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 10606 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10607 | /* Create SCSI host to the physical port */ |
| 10608 | error = lpfc_create_shost(phba); |
| 10609 | if (error) { |
| 10610 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10611 | "1407 Failed to create scsi host.\n"); |
| 10612 | goto out_unset_driver_resource; |
| 10613 | } |
| 10614 | |
| 10615 | /* Configure sysfs attributes */ |
| 10616 | vport = phba->pport; |
| 10617 | error = lpfc_alloc_sysfs_attr(vport); |
| 10618 | if (error) { |
| 10619 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10620 | "1476 Failed to allocate sysfs attr\n"); |
| 10621 | goto out_destroy_shost; |
| 10622 | } |
| 10623 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10624 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10625 | /* Now, trying to enable interrupt and bring up the device */ |
| 10626 | cfg_mode = phba->cfg_use_msi; |
| 10627 | while (true) { |
| 10628 | /* Put device to a known state before enabling interrupt */ |
| 10629 | lpfc_stop_port(phba); |
| 10630 | /* Configure and enable interrupt */ |
| 10631 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 10632 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10633 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10634 | "0431 Failed to enable interrupt.\n"); |
| 10635 | error = -ENODEV; |
| 10636 | goto out_free_sysfs_attr; |
| 10637 | } |
| 10638 | /* SLI-3 HBA setup */ |
| 10639 | if (lpfc_sli_hba_setup(phba)) { |
| 10640 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10641 | "1477 Failed to set up hba\n"); |
| 10642 | error = -ENODEV; |
| 10643 | goto out_remove_device; |
| 10644 | } |
| 10645 | |
| 10646 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 10647 | msleep(50); |
| 10648 | /* Check active interrupts on message signaled interrupts */ |
| 10649 | if (intr_mode == 0 || |
| 10650 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 10651 | /* Log the current active interrupt mode */ |
| 10652 | phba->intr_mode = intr_mode; |
| 10653 | lpfc_log_intr_mode(phba, intr_mode); |
| 10654 | break; |
| 10655 | } else { |
| 10656 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10657 | "0447 Configure interrupt mode (%d) " |
| 10658 | "failed active interrupt test.\n", |
| 10659 | intr_mode); |
| 10660 | /* Disable the current interrupt mode */ |
| 10661 | lpfc_sli_disable_intr(phba); |
| 10662 | /* Try next level of interrupt mode */ |
| 10663 | cfg_mode = --intr_mode; |
| 10664 | } |
| 10665 | } |
| 10666 | |
| 10667 | /* Perform post initialization setup */ |
| 10668 | lpfc_post_init_setup(phba); |
| 10669 | |
| 10670 | /* Check if there are static vports to be created. */ |
| 10671 | lpfc_create_static_vport(phba); |
| 10672 | |
| 10673 | return 0; |
| 10674 | |
| 10675 | out_remove_device: |
| 10676 | lpfc_unset_hba(phba); |
| 10677 | out_free_sysfs_attr: |
| 10678 | lpfc_free_sysfs_attr(vport); |
| 10679 | out_destroy_shost: |
| 10680 | lpfc_destroy_shost(phba); |
| 10681 | out_unset_driver_resource: |
| 10682 | lpfc_unset_driver_resource_phase2(phba); |
| 10683 | out_free_iocb_list: |
| 10684 | lpfc_free_iocb_list(phba); |
| 10685 | out_unset_driver_resource_s3: |
| 10686 | lpfc_sli_driver_resource_unset(phba); |
| 10687 | out_unset_pci_mem_s3: |
| 10688 | lpfc_sli_pci_mem_unset(phba); |
| 10689 | out_disable_pci_dev: |
| 10690 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10691 | if (shost) |
| 10692 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10693 | out_free_phba: |
| 10694 | lpfc_hba_free(phba); |
| 10695 | return error; |
| 10696 | } |
| 10697 | |
| 10698 | /** |
| 10699 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10700 | * @pdev: pointer to PCI device |
| 10701 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10702 | * This routine is to be called to disattach a device with SLI-3 interface |
| 10703 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 10704 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 10705 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10706 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10707 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10708 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10709 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10710 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10711 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 10712 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10713 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 10714 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 10715 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 10716 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10717 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 10718 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10719 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10720 | lpfc_free_sysfs_attr(vport); |
| 10721 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 10722 | /* Release all the vports against this physical port */ |
| 10723 | vports = lpfc_create_vport_work_array(phba); |
| 10724 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10725 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 10726 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 10727 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 10728 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10729 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 10730 | lpfc_destroy_vport_work_array(phba, vports); |
| 10731 | |
| 10732 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10733 | fc_remove_host(shost); |
| 10734 | scsi_remove_host(shost); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 10735 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 10736 | lpfc_cleanup(vport); |
| 10737 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10738 | /* |
| 10739 | * Bring down the SLI Layer. This step disable all interrupts, |
| 10740 | * clears the rings, discards all mailbox commands, and resets |
| 10741 | * the HBA. |
| 10742 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10743 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 10744 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10745 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10746 | /* Stop kthread signal shall trigger work_done one more time */ |
| 10747 | kthread_stop(phba->worker_thread); |
| 10748 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10749 | lpfc_sli_brdrestart(phba); |
| 10750 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 10751 | kfree(phba->vpi_bmask); |
| 10752 | kfree(phba->vpi_ids); |
| 10753 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10754 | lpfc_stop_hba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10755 | spin_lock_irq(&phba->hbalock); |
| 10756 | list_del_init(&vport->listentry); |
| 10757 | spin_unlock_irq(&phba->hbalock); |
| 10758 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10759 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10760 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10761 | /* Disable SR-IOV if enabled */ |
| 10762 | if (phba->cfg_sriov_nr_virtfn) |
| 10763 | pci_disable_sriov(pdev); |
| 10764 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10765 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10766 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10767 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10768 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10769 | |
| 10770 | /* |
| 10771 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 10772 | * corresponding pools here. |
| 10773 | */ |
| 10774 | lpfc_scsi_free(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10775 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10776 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10777 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 10778 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10779 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10780 | /* Free resources associated with SLI2 interface */ |
| 10781 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10782 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10783 | |
| 10784 | /* unmap adapter SLIM and Control Registers */ |
| 10785 | iounmap(phba->ctrl_regs_memmap_p); |
| 10786 | iounmap(phba->slim_memmap_p); |
| 10787 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10788 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10789 | |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 10790 | pci_release_mem_regions(pdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10791 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10792 | } |
| 10793 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10794 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10795 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10796 | * @pdev: pointer to PCI device |
| 10797 | * @msg: power management message |
| 10798 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10799 | * This routine is to be called from the kernel's PCI subsystem to support |
| 10800 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 10801 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 10802 | * worker thread for the device, turning off device's interrupt and DMA, |
| 10803 | * and bring the device offline. Note that as the driver implements the |
| 10804 | * minimum PM requirements to a power-aware driver's PM support for the |
| 10805 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 10806 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 10807 | * fully reinitialize its device during resume() method call, the driver will |
| 10808 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 10809 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10810 | * |
| 10811 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10812 | * 0 - driver suspended the device |
| 10813 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10814 | **/ |
| 10815 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10816 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10817 | { |
| 10818 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10819 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 10820 | |
| 10821 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10822 | "0473 PCI device Power Management suspend.\n"); |
| 10823 | |
| 10824 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10825 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10826 | lpfc_offline(phba); |
| 10827 | kthread_stop(phba->worker_thread); |
| 10828 | |
| 10829 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10830 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10831 | |
| 10832 | /* Save device state to PCI config space */ |
| 10833 | pci_save_state(pdev); |
| 10834 | pci_set_power_state(pdev, PCI_D3hot); |
| 10835 | |
| 10836 | return 0; |
| 10837 | } |
| 10838 | |
| 10839 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10840 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10841 | * @pdev: pointer to PCI device |
| 10842 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10843 | * This routine is to be called from the kernel's PCI subsystem to support |
| 10844 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 10845 | * invokes this method, it restores the device's PCI config space state and |
| 10846 | * fully reinitializes the device and brings it online. Note that as the |
| 10847 | * driver implements the minimum PM requirements to a power-aware driver's |
| 10848 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 10849 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 10850 | * driver will fully reinitialize its device during resume() method call, |
| 10851 | * the device will be set to PCI_D0 directly in PCI config space before |
| 10852 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10853 | * |
| 10854 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10855 | * 0 - driver suspended the device |
| 10856 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10857 | **/ |
| 10858 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10859 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10860 | { |
| 10861 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10862 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10863 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10864 | int error; |
| 10865 | |
| 10866 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10867 | "0452 PCI device Power Management resume.\n"); |
| 10868 | |
| 10869 | /* Restore device state from PCI config space */ |
| 10870 | pci_set_power_state(pdev, PCI_D0); |
| 10871 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10872 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10873 | /* |
| 10874 | * As the new kernel behavior of pci_restore_state() API call clears |
| 10875 | * device saved_state flag, need to save the restored state again. |
| 10876 | */ |
| 10877 | pci_save_state(pdev); |
| 10878 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10879 | if (pdev->is_busmaster) |
| 10880 | pci_set_master(pdev); |
| 10881 | |
| 10882 | /* Startup the kernel thread for this host adapter. */ |
| 10883 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 10884 | "lpfc_worker_%d", phba->brd_no); |
| 10885 | if (IS_ERR(phba->worker_thread)) { |
| 10886 | error = PTR_ERR(phba->worker_thread); |
| 10887 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10888 | "0434 PM resume failed to start worker " |
| 10889 | "thread: error=x%x.\n", error); |
| 10890 | return error; |
| 10891 | } |
| 10892 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10893 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10894 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10895 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10896 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10897 | "0430 PM resume Failed to enable interrupt\n"); |
| 10898 | return -EIO; |
| 10899 | } else |
| 10900 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10901 | |
| 10902 | /* Restart HBA and bring it online */ |
| 10903 | lpfc_sli_brdrestart(phba); |
| 10904 | lpfc_online(phba); |
| 10905 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10906 | /* Log the current active interrupt mode */ |
| 10907 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 10908 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 10909 | return 0; |
| 10910 | } |
| 10911 | |
| 10912 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10913 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 10914 | * @phba: pointer to lpfc hba data structure. |
| 10915 | * |
| 10916 | * This routine is called to prepare the SLI3 device for PCI slot recover. It |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10917 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10918 | **/ |
| 10919 | static void |
| 10920 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 10921 | { |
| 10922 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10923 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10924 | |
| 10925 | /* |
| 10926 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 10927 | * and let the SCSI mid-layer to retry them to recover. |
| 10928 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 10929 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10930 | } |
| 10931 | |
| 10932 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10933 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 10934 | * @phba: pointer to lpfc hba data structure. |
| 10935 | * |
| 10936 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 10937 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 10938 | * pending I/Os. |
| 10939 | **/ |
| 10940 | static void |
| 10941 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 10942 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10943 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10944 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10945 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10946 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 10947 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10948 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10949 | /* Block all SCSI devices' I/Os on the host */ |
| 10950 | lpfc_scsi_dev_block(phba); |
| 10951 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 10952 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 10953 | lpfc_sli_flush_fcp_rings(phba); |
| 10954 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10955 | /* stop all timers */ |
| 10956 | lpfc_stop_hba_timers(phba); |
| 10957 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10958 | /* Disable interrupt and pci device */ |
| 10959 | lpfc_sli_disable_intr(phba); |
| 10960 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10961 | } |
| 10962 | |
| 10963 | /** |
| 10964 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 10965 | * @phba: pointer to lpfc hba data structure. |
| 10966 | * |
| 10967 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 10968 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 10969 | * pending I/Os. |
| 10970 | **/ |
| 10971 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10972 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10973 | { |
| 10974 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 10975 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 10976 | /* Block all SCSI devices' I/Os on the host */ |
| 10977 | lpfc_scsi_dev_block(phba); |
| 10978 | |
| 10979 | /* stop all timers */ |
| 10980 | lpfc_stop_hba_timers(phba); |
| 10981 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 10982 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 10983 | lpfc_sli_flush_fcp_rings(phba); |
| 10984 | } |
| 10985 | |
| 10986 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10987 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10988 | * @pdev: pointer to PCI device. |
| 10989 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10990 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10991 | * This routine is called from the PCI subsystem for I/O error handling to |
| 10992 | * device with SLI-3 interface spec. This function is called by the PCI |
| 10993 | * subsystem after a PCI bus error affecting this device has been detected. |
| 10994 | * When this function is invoked, it will need to stop all the I/Os and |
| 10995 | * interrupt(s) to the device. Once that is done, it will return |
| 10996 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 10997 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10998 | * |
| 10999 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11000 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11001 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 11002 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11003 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11004 | static pci_ers_result_t |
| 11005 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11006 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11007 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11008 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11009 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11010 | switch (state) { |
| 11011 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 11012 | /* Non-fatal error, prepare for recovery */ |
| 11013 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11014 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 11015 | case pci_channel_io_frozen: |
| 11016 | /* Fatal error, prepare for slot reset */ |
| 11017 | lpfc_sli_prep_dev_for_reset(phba); |
| 11018 | return PCI_ERS_RESULT_NEED_RESET; |
| 11019 | case pci_channel_io_perm_failure: |
| 11020 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11021 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11022 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11023 | default: |
| 11024 | /* Unknown state, prepare and request slot reset */ |
| 11025 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11026 | "0472 Unknown PCI error state: x%x\n", state); |
| 11027 | lpfc_sli_prep_dev_for_reset(phba); |
| 11028 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 11029 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11030 | } |
| 11031 | |
| 11032 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11033 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11034 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11035 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11036 | * This routine is called from the PCI subsystem for error handling to |
| 11037 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 11038 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 11039 | * During the PCI subsystem error recovery, after driver returns |
| 11040 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 11041 | * recovery and then call this routine before calling the .resume method |
| 11042 | * to recover the device. This function will initialize the HBA device, |
| 11043 | * enable the interrupt, but it will just put the HBA to offline state |
| 11044 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11045 | * |
| 11046 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11047 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 11048 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11049 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11050 | static pci_ers_result_t |
| 11051 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11052 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11053 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11054 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11055 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11056 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11057 | |
| 11058 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 11059 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11060 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 11061 | "PCI device after reset.\n"); |
| 11062 | return PCI_ERS_RESULT_DISCONNECT; |
| 11063 | } |
| 11064 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 11065 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 11066 | |
| 11067 | /* |
| 11068 | * As the new kernel behavior of pci_restore_state() API call clears |
| 11069 | * device saved_state flag, need to save the restored state again. |
| 11070 | */ |
| 11071 | pci_save_state(pdev); |
| 11072 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 11073 | if (pdev->is_busmaster) |
| 11074 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11075 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11076 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11077 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11078 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11079 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11080 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11081 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11082 | if (intr_mode == LPFC_INTR_ERROR) { |
| 11083 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11084 | "0427 Cannot re-enable interrupt after " |
| 11085 | "slot reset.\n"); |
| 11086 | return PCI_ERS_RESULT_DISCONNECT; |
| 11087 | } else |
| 11088 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11089 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11090 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11091 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11092 | lpfc_offline(phba); |
| 11093 | lpfc_sli_brdrestart(phba); |
| 11094 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11095 | /* Log the current active interrupt mode */ |
| 11096 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 11097 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11098 | return PCI_ERS_RESULT_RECOVERED; |
| 11099 | } |
| 11100 | |
| 11101 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11102 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11103 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11104 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11105 | * This routine is called from the PCI subsystem for error handling to device |
| 11106 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 11107 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 11108 | * error recovery. After this call, traffic can start to flow from this device |
| 11109 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11110 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11111 | static void |
| 11112 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11113 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11114 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11115 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11116 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 11117 | /* Bring device online, it will be no-op for non-fatal error resume */ |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 11118 | lpfc_online(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11119 | |
| 11120 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 11121 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 11122 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11123 | } |
| 11124 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11125 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11126 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 11127 | * @phba: pointer to lpfc hba data structure. |
| 11128 | * |
| 11129 | * returns the number of ELS/CT IOCBs to reserve |
| 11130 | **/ |
| 11131 | int |
| 11132 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 11133 | { |
| 11134 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 11135 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 11136 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11137 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11138 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 11139 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11140 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 11141 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11142 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 11143 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11144 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 11145 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11146 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 11147 | else if (max_xri <= 2048) |
| 11148 | return 200; |
| 11149 | else |
| 11150 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 11151 | } else |
| 11152 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11153 | } |
| 11154 | |
| 11155 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11156 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve |
| 11157 | * @phba: pointer to lpfc hba data structure. |
| 11158 | * |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11159 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11160 | **/ |
| 11161 | int |
| 11162 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) |
| 11163 | { |
| 11164 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); |
| 11165 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11166 | if (phba->nvmet_support) |
| 11167 | max_xri += LPFC_NVMET_BUF_POST; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11168 | return max_xri; |
| 11169 | } |
| 11170 | |
| 11171 | |
| 11172 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11173 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11174 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11175 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11176 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11177 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11178 | static void |
| 11179 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11180 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11181 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 11182 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11183 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11184 | struct list_head dma_buffer_list; |
| 11185 | int i, rc = 0; |
| 11186 | struct lpfc_dmabuf *dmabuf, *next; |
| 11187 | uint32_t offset = 0, temp_offset = 0; |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 11188 | uint32_t magic_number, ftype, fid, fsize; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11189 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 11190 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11191 | if (!fw) { |
| 11192 | rc = -ENXIO; |
| 11193 | goto out; |
| 11194 | } |
| 11195 | image = (struct lpfc_grp_hdr *)fw->data; |
| 11196 | |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 11197 | magic_number = be32_to_cpu(image->magic_number); |
| 11198 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); |
| 11199 | fid = bf_get_be32(lpfc_grp_hdr_id, image), |
| 11200 | fsize = be32_to_cpu(image->size); |
| 11201 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11202 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 11203 | if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 && |
| 11204 | magic_number != LPFC_GROUP_OJECT_MAGIC_G6) || |
| 11205 | ftype != LPFC_FILE_TYPE_GROUP || fsize != fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11206 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11207 | "3022 Invalid FW image found. " |
Arnd Bergmann | efe583c | 2016-10-17 14:35:46 +0200 | [diff] [blame] | 11208 | "Magic:%x Type:%x ID:%x Size %d %zd\n", |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 11209 | magic_number, ftype, fid, fsize, fw->size); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11210 | rc = -EINVAL; |
| 11211 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11212 | } |
| 11213 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 11214 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11215 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11216 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11217 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 11218 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11219 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 11220 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 11221 | GFP_KERNEL); |
| 11222 | if (!dmabuf) { |
| 11223 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11224 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11225 | } |
| 11226 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 11227 | SLI4_PAGE_SIZE, |
| 11228 | &dmabuf->phys, |
| 11229 | GFP_KERNEL); |
| 11230 | if (!dmabuf->virt) { |
| 11231 | kfree(dmabuf); |
| 11232 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11233 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11234 | } |
| 11235 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 11236 | } |
| 11237 | while (offset < fw->size) { |
| 11238 | temp_offset = offset; |
| 11239 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11240 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11241 | memcpy(dmabuf->virt, |
| 11242 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11243 | fw->size - temp_offset); |
| 11244 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11245 | break; |
| 11246 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11247 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 11248 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 11249 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11250 | } |
| 11251 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 11252 | (fw->size - offset), &offset); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11253 | if (rc) |
| 11254 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11255 | } |
| 11256 | rc = offset; |
| 11257 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11258 | |
| 11259 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11260 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 11261 | list_del(&dmabuf->list); |
| 11262 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 11263 | dmabuf->virt, dmabuf->phys); |
| 11264 | kfree(dmabuf); |
| 11265 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11266 | release_firmware(fw); |
| 11267 | out: |
| 11268 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 11269 | "3024 Firmware update done: %d.\n", rc); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11270 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11271 | } |
| 11272 | |
| 11273 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 11274 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 11275 | * @phba: pointer to lpfc hba data structure. |
| 11276 | * |
| 11277 | * This routine is called to perform Linux generic firmware upgrade on device |
| 11278 | * that supports such feature. |
| 11279 | **/ |
| 11280 | int |
| 11281 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 11282 | { |
| 11283 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 11284 | int ret; |
| 11285 | const struct firmware *fw; |
| 11286 | |
| 11287 | /* Only supported on SLI4 interface type 2 for now */ |
| 11288 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 11289 | LPFC_SLI_INTF_IF_TYPE_2) |
| 11290 | return -EPERM; |
| 11291 | |
| 11292 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 11293 | |
| 11294 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 11295 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 11296 | file_name, &phba->pcidev->dev, |
| 11297 | GFP_KERNEL, (void *)phba, |
| 11298 | lpfc_write_firmware); |
| 11299 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 11300 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 11301 | if (!ret) |
| 11302 | lpfc_write_firmware(fw, (void *)phba); |
| 11303 | } else { |
| 11304 | ret = -EINVAL; |
| 11305 | } |
| 11306 | |
| 11307 | return ret; |
| 11308 | } |
| 11309 | |
| 11310 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11311 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 11312 | * @pdev: pointer to PCI device |
| 11313 | * @pid: pointer to PCI device identifier |
| 11314 | * |
| 11315 | * This routine is called from the kernel's PCI subsystem to device with |
| 11316 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 11317 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 11318 | * information of the device and driver to see if the driver state that it |
| 11319 | * can support this kind of device. If the match is successful, the driver |
| 11320 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 11321 | * it does all the initialization that it needs to do to handle the HBA |
| 11322 | * properly. |
| 11323 | * |
| 11324 | * Return code |
| 11325 | * 0 - driver can claim the device |
| 11326 | * negative value - driver can not claim the device |
| 11327 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11328 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11329 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 11330 | { |
| 11331 | struct lpfc_hba *phba; |
| 11332 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11333 | struct Scsi_Host *shost = NULL; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 11334 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11335 | uint32_t cfg_mode, intr_mode; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11336 | |
| 11337 | /* Allocate memory for HBA structure */ |
| 11338 | phba = lpfc_hba_alloc(pdev); |
| 11339 | if (!phba) |
| 11340 | return -ENOMEM; |
| 11341 | |
| 11342 | /* Perform generic PCI device enabling operation */ |
| 11343 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11344 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11345 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11346 | |
| 11347 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 11348 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 11349 | if (error) |
| 11350 | goto out_disable_pci_dev; |
| 11351 | |
| 11352 | /* Set up SLI-4 specific device PCI memory space */ |
| 11353 | error = lpfc_sli4_pci_mem_setup(phba); |
| 11354 | if (error) { |
| 11355 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11356 | "1410 Failed to set up pci memory space.\n"); |
| 11357 | goto out_disable_pci_dev; |
| 11358 | } |
| 11359 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11360 | /* Set up SLI-4 Specific device driver resources */ |
| 11361 | error = lpfc_sli4_driver_resource_setup(phba); |
| 11362 | if (error) { |
| 11363 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11364 | "1412 Failed to set up driver resource.\n"); |
| 11365 | goto out_unset_pci_mem_s4; |
| 11366 | } |
| 11367 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 11368 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 11369 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 11370 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11371 | /* Set up common device driver resources */ |
| 11372 | error = lpfc_setup_driver_resource_phase2(phba); |
| 11373 | if (error) { |
| 11374 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11375 | "1414 Failed to set up driver resource.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 11376 | goto out_unset_driver_resource_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11377 | } |
| 11378 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11379 | /* Get the default values for Model Name and Description */ |
| 11380 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 11381 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11382 | /* Create SCSI host to the physical port */ |
| 11383 | error = lpfc_create_shost(phba); |
| 11384 | if (error) { |
| 11385 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11386 | "1415 Failed to create scsi host.\n"); |
| 11387 | goto out_unset_driver_resource; |
| 11388 | } |
| 11389 | |
| 11390 | /* Configure sysfs attributes */ |
| 11391 | vport = phba->pport; |
| 11392 | error = lpfc_alloc_sysfs_attr(vport); |
| 11393 | if (error) { |
| 11394 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11395 | "1416 Failed to allocate sysfs attr\n"); |
| 11396 | goto out_destroy_shost; |
| 11397 | } |
| 11398 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11399 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11400 | /* Now, trying to enable interrupt and bring up the device */ |
| 11401 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11402 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 11403 | /* Put device to a known state before enabling interrupt */ |
| 11404 | lpfc_stop_port(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11405 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 11406 | /* Configure and enable interrupt */ |
| 11407 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 11408 | if (intr_mode == LPFC_INTR_ERROR) { |
| 11409 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11410 | "0426 Failed to enable interrupt.\n"); |
| 11411 | error = -ENODEV; |
| 11412 | goto out_free_sysfs_attr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11413 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 11414 | /* Default to single EQ for non-MSI-X */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11415 | if (phba->intr_type != MSIX) { |
| 11416 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) |
| 11417 | phba->cfg_fcp_io_channel = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11418 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11419 | phba->cfg_nvme_io_channel = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11420 | if (phba->nvmet_support) |
| 11421 | phba->cfg_nvmet_mrq = 1; |
| 11422 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11423 | phba->io_channel_irqs = 1; |
| 11424 | } |
| 11425 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 11426 | /* Set up SLI-4 HBA */ |
| 11427 | if (lpfc_sli4_hba_setup(phba)) { |
| 11428 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11429 | "1421 Failed to set up hba\n"); |
| 11430 | error = -ENODEV; |
| 11431 | goto out_disable_intr; |
| 11432 | } |
| 11433 | |
| 11434 | /* Log the current active interrupt mode */ |
| 11435 | phba->intr_mode = intr_mode; |
| 11436 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11437 | |
| 11438 | /* Perform post initialization setup */ |
| 11439 | lpfc_post_init_setup(phba); |
| 11440 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11441 | /* NVME support in FW earlier in the driver load corrects the |
| 11442 | * FC4 type making a check for nvme_support unnecessary. |
| 11443 | */ |
| 11444 | if ((phba->nvmet_support == 0) && |
| 11445 | (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) { |
| 11446 | /* Create NVME binding with nvme_fc_transport. This |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11447 | * ensures the vport is initialized. If the localport |
| 11448 | * create fails, it should not unload the driver to |
| 11449 | * support field issues. |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11450 | */ |
| 11451 | error = lpfc_nvme_create_localport(vport); |
| 11452 | if (error) { |
| 11453 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11454 | "6004 NVME registration failed, " |
| 11455 | "error x%x\n", |
| 11456 | error); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11457 | } |
| 11458 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11459 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 11460 | /* check for firmware upgrade or downgrade */ |
| 11461 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 11462 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11463 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 11464 | /* Check if there are static vports to be created. */ |
| 11465 | lpfc_create_static_vport(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11466 | return 0; |
| 11467 | |
| 11468 | out_disable_intr: |
| 11469 | lpfc_sli4_disable_intr(phba); |
| 11470 | out_free_sysfs_attr: |
| 11471 | lpfc_free_sysfs_attr(vport); |
| 11472 | out_destroy_shost: |
| 11473 | lpfc_destroy_shost(phba); |
| 11474 | out_unset_driver_resource: |
| 11475 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11476 | out_unset_driver_resource_s4: |
| 11477 | lpfc_sli4_driver_resource_unset(phba); |
| 11478 | out_unset_pci_mem_s4: |
| 11479 | lpfc_sli4_pci_mem_unset(phba); |
| 11480 | out_disable_pci_dev: |
| 11481 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11482 | if (shost) |
| 11483 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11484 | out_free_phba: |
| 11485 | lpfc_hba_free(phba); |
| 11486 | return error; |
| 11487 | } |
| 11488 | |
| 11489 | /** |
| 11490 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 11491 | * @pdev: pointer to PCI device |
| 11492 | * |
| 11493 | * This routine is called from the kernel's PCI subsystem to device with |
| 11494 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 11495 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 11496 | * device to be removed from the PCI subsystem properly. |
| 11497 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11498 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11499 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 11500 | { |
| 11501 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11502 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 11503 | struct lpfc_vport **vports; |
| 11504 | struct lpfc_hba *phba = vport->phba; |
| 11505 | int i; |
| 11506 | |
| 11507 | /* Mark the device unloading flag */ |
| 11508 | spin_lock_irq(&phba->hbalock); |
| 11509 | vport->load_flag |= FC_UNLOADING; |
| 11510 | spin_unlock_irq(&phba->hbalock); |
| 11511 | |
| 11512 | /* Free the HBA sysfs attributes */ |
| 11513 | lpfc_free_sysfs_attr(vport); |
| 11514 | |
| 11515 | /* Release all the vports against this physical port */ |
| 11516 | vports = lpfc_create_vport_work_array(phba); |
| 11517 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 11518 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 11519 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 11520 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11521 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 11522 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11523 | lpfc_destroy_vport_work_array(phba, vports); |
| 11524 | |
| 11525 | /* Remove FC host and then SCSI host with the physical port */ |
| 11526 | fc_remove_host(shost); |
| 11527 | scsi_remove_host(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11528 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11529 | /* Perform ndlp cleanup on the physical port. The nvme and nvmet |
| 11530 | * localports are destroyed after to cleanup all transport memory. |
| 11531 | */ |
| 11532 | lpfc_cleanup(vport); |
| 11533 | lpfc_nvmet_destroy_targetport(phba); |
| 11534 | lpfc_nvme_destroy_localport(vport); |
| 11535 | |
James Smart | 281d619 | 2018-01-30 15:58:47 -0800 | [diff] [blame] | 11536 | /* |
| 11537 | * Bring down the SLI Layer. This step disables all interrupts, |
| 11538 | * clears the rings, discards all mailbox commands, and resets |
| 11539 | * the HBA FCoE function. |
| 11540 | */ |
| 11541 | lpfc_debugfs_terminate(vport); |
| 11542 | lpfc_sli4_hba_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11543 | |
Dick Kennedy | 1901762 | 2017-09-29 17:34:27 -0700 | [diff] [blame] | 11544 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11545 | spin_lock_irq(&phba->hbalock); |
| 11546 | list_del_init(&vport->listentry); |
| 11547 | spin_unlock_irq(&phba->hbalock); |
| 11548 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 11549 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11550 | * buffers are released to their corresponding pools here. |
| 11551 | */ |
| 11552 | lpfc_scsi_free(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11553 | lpfc_nvme_free(phba); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11554 | lpfc_free_iocb_list(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11555 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11556 | lpfc_sli4_driver_resource_unset(phba); |
| 11557 | |
| 11558 | /* Unmap adapter Control and Doorbell registers */ |
| 11559 | lpfc_sli4_pci_mem_unset(phba); |
| 11560 | |
| 11561 | /* Release PCI resources and disable device's PCI function */ |
| 11562 | scsi_host_put(shost); |
| 11563 | lpfc_disable_pci_dev(phba); |
| 11564 | |
| 11565 | /* Finally, free the driver's device data structure */ |
| 11566 | lpfc_hba_free(phba); |
| 11567 | |
| 11568 | return; |
| 11569 | } |
| 11570 | |
| 11571 | /** |
| 11572 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 11573 | * @pdev: pointer to PCI device |
| 11574 | * @msg: power management message |
| 11575 | * |
| 11576 | * This routine is called from the kernel's PCI subsystem to support system |
| 11577 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 11578 | * this method, it quiesces the device by stopping the driver's worker |
| 11579 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 11580 | * the device offline. Note that as the driver implements the minimum PM |
| 11581 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 11582 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 11583 | * method call will be treated as SUSPEND and the driver will fully |
| 11584 | * reinitialize its device during resume() method call, the driver will set |
| 11585 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 11586 | * according to the @msg provided by the PM. |
| 11587 | * |
| 11588 | * Return code |
| 11589 | * 0 - driver suspended the device |
| 11590 | * Error otherwise |
| 11591 | **/ |
| 11592 | static int |
| 11593 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 11594 | { |
| 11595 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11596 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11597 | |
| 11598 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11599 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11600 | |
| 11601 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11602 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11603 | lpfc_offline(phba); |
| 11604 | kthread_stop(phba->worker_thread); |
| 11605 | |
| 11606 | /* Disable interrupt from device */ |
| 11607 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11608 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11609 | |
| 11610 | /* Save device state to PCI config space */ |
| 11611 | pci_save_state(pdev); |
| 11612 | pci_set_power_state(pdev, PCI_D3hot); |
| 11613 | |
| 11614 | return 0; |
| 11615 | } |
| 11616 | |
| 11617 | /** |
| 11618 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 11619 | * @pdev: pointer to PCI device |
| 11620 | * |
| 11621 | * This routine is called from the kernel's PCI subsystem to support system |
| 11622 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 11623 | * this method, it restores the device's PCI config space state and fully |
| 11624 | * reinitializes the device and brings it online. Note that as the driver |
| 11625 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 11626 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 11627 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 11628 | * will fully reinitialize its device during resume() method call, the device |
| 11629 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 11630 | * state. |
| 11631 | * |
| 11632 | * Return code |
| 11633 | * 0 - driver suspended the device |
| 11634 | * Error otherwise |
| 11635 | **/ |
| 11636 | static int |
| 11637 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 11638 | { |
| 11639 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11640 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11641 | uint32_t intr_mode; |
| 11642 | int error; |
| 11643 | |
| 11644 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11645 | "0292 PCI device Power Management resume.\n"); |
| 11646 | |
| 11647 | /* Restore device state from PCI config space */ |
| 11648 | pci_set_power_state(pdev, PCI_D0); |
| 11649 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 11650 | |
| 11651 | /* |
| 11652 | * As the new kernel behavior of pci_restore_state() API call clears |
| 11653 | * device saved_state flag, need to save the restored state again. |
| 11654 | */ |
| 11655 | pci_save_state(pdev); |
| 11656 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11657 | if (pdev->is_busmaster) |
| 11658 | pci_set_master(pdev); |
| 11659 | |
| 11660 | /* Startup the kernel thread for this host adapter. */ |
| 11661 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 11662 | "lpfc_worker_%d", phba->brd_no); |
| 11663 | if (IS_ERR(phba->worker_thread)) { |
| 11664 | error = PTR_ERR(phba->worker_thread); |
| 11665 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11666 | "0293 PM resume failed to start worker " |
| 11667 | "thread: error=x%x.\n", error); |
| 11668 | return error; |
| 11669 | } |
| 11670 | |
| 11671 | /* Configure and enable interrupt */ |
| 11672 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 11673 | if (intr_mode == LPFC_INTR_ERROR) { |
| 11674 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11675 | "0294 PM resume Failed to enable interrupt\n"); |
| 11676 | return -EIO; |
| 11677 | } else |
| 11678 | phba->intr_mode = intr_mode; |
| 11679 | |
| 11680 | /* Restart HBA and bring it online */ |
| 11681 | lpfc_sli_brdrestart(phba); |
| 11682 | lpfc_online(phba); |
| 11683 | |
| 11684 | /* Log the current active interrupt mode */ |
| 11685 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 11686 | |
| 11687 | return 0; |
| 11688 | } |
| 11689 | |
| 11690 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11691 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 11692 | * @phba: pointer to lpfc hba data structure. |
| 11693 | * |
| 11694 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 11695 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 11696 | **/ |
| 11697 | static void |
| 11698 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 11699 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11700 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11701 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 11702 | /* |
| 11703 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 11704 | * and let the SCSI mid-layer to retry them to recover. |
| 11705 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11706 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11707 | } |
| 11708 | |
| 11709 | /** |
| 11710 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 11711 | * @phba: pointer to lpfc hba data structure. |
| 11712 | * |
| 11713 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 11714 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 11715 | * pending I/Os. |
| 11716 | **/ |
| 11717 | static void |
| 11718 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 11719 | { |
| 11720 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11721 | "2826 PCI channel disable preparing for reset\n"); |
| 11722 | |
| 11723 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11724 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11725 | |
| 11726 | /* Block all SCSI devices' I/Os on the host */ |
| 11727 | lpfc_scsi_dev_block(phba); |
| 11728 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 11729 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 11730 | lpfc_sli_flush_fcp_rings(phba); |
| 11731 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11732 | /* Flush the outstanding NVME IOs if fc4 type enabled. */ |
| 11733 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11734 | lpfc_sli_flush_nvme_rings(phba); |
| 11735 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11736 | /* stop all timers */ |
| 11737 | lpfc_stop_hba_timers(phba); |
| 11738 | |
| 11739 | /* Disable interrupt and pci device */ |
| 11740 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11741 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11742 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11743 | } |
| 11744 | |
| 11745 | /** |
| 11746 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 11747 | * @phba: pointer to lpfc hba data structure. |
| 11748 | * |
| 11749 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 11750 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 11751 | * pending I/Os. |
| 11752 | **/ |
| 11753 | static void |
| 11754 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 11755 | { |
| 11756 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11757 | "2827 PCI channel permanent disable for failure\n"); |
| 11758 | |
| 11759 | /* Block all SCSI devices' I/Os on the host */ |
| 11760 | lpfc_scsi_dev_block(phba); |
| 11761 | |
| 11762 | /* stop all timers */ |
| 11763 | lpfc_stop_hba_timers(phba); |
| 11764 | |
| 11765 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 11766 | lpfc_sli_flush_fcp_rings(phba); |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11767 | |
| 11768 | /* Flush the outstanding NVME IOs if fc4 type enabled. */ |
| 11769 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11770 | lpfc_sli_flush_nvme_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11771 | } |
| 11772 | |
| 11773 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11774 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 11775 | * @pdev: pointer to PCI device. |
| 11776 | * @state: the current PCI connection state. |
| 11777 | * |
| 11778 | * This routine is called from the PCI subsystem for error handling to device |
| 11779 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 11780 | * after a PCI bus error affecting this device has been detected. When this |
| 11781 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 11782 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 11783 | * for the PCI subsystem to perform proper recovery as desired. |
| 11784 | * |
| 11785 | * Return codes |
| 11786 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 11787 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 11788 | **/ |
| 11789 | static pci_ers_result_t |
| 11790 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 11791 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11792 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11793 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11794 | |
| 11795 | switch (state) { |
| 11796 | case pci_channel_io_normal: |
| 11797 | /* Non-fatal error, prepare for recovery */ |
| 11798 | lpfc_sli4_prep_dev_for_recover(phba); |
| 11799 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 11800 | case pci_channel_io_frozen: |
| 11801 | /* Fatal error, prepare for slot reset */ |
| 11802 | lpfc_sli4_prep_dev_for_reset(phba); |
| 11803 | return PCI_ERS_RESULT_NEED_RESET; |
| 11804 | case pci_channel_io_perm_failure: |
| 11805 | /* Permanent failure, prepare for device down */ |
| 11806 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 11807 | return PCI_ERS_RESULT_DISCONNECT; |
| 11808 | default: |
| 11809 | /* Unknown state, prepare and request slot reset */ |
| 11810 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11811 | "2825 Unknown PCI error state: x%x\n", state); |
| 11812 | lpfc_sli4_prep_dev_for_reset(phba); |
| 11813 | return PCI_ERS_RESULT_NEED_RESET; |
| 11814 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11815 | } |
| 11816 | |
| 11817 | /** |
| 11818 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 11819 | * @pdev: pointer to PCI device. |
| 11820 | * |
| 11821 | * This routine is called from the PCI subsystem for error handling to device |
| 11822 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 11823 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 11824 | * PCI subsystem error recovery, after the driver returns |
| 11825 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 11826 | * recovery and then call this routine before calling the .resume method to |
| 11827 | * recover the device. This function will initialize the HBA device, enable |
| 11828 | * the interrupt, but it will just put the HBA to offline state without |
| 11829 | * passing any I/O traffic. |
| 11830 | * |
| 11831 | * Return codes |
| 11832 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 11833 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 11834 | */ |
| 11835 | static pci_ers_result_t |
| 11836 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 11837 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11838 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11839 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11840 | struct lpfc_sli *psli = &phba->sli; |
| 11841 | uint32_t intr_mode; |
| 11842 | |
| 11843 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 11844 | if (pci_enable_device_mem(pdev)) { |
| 11845 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 11846 | "PCI device after reset.\n"); |
| 11847 | return PCI_ERS_RESULT_DISCONNECT; |
| 11848 | } |
| 11849 | |
| 11850 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 11851 | |
| 11852 | /* |
| 11853 | * As the new kernel behavior of pci_restore_state() API call clears |
| 11854 | * device saved_state flag, need to save the restored state again. |
| 11855 | */ |
| 11856 | pci_save_state(pdev); |
| 11857 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11858 | if (pdev->is_busmaster) |
| 11859 | pci_set_master(pdev); |
| 11860 | |
| 11861 | spin_lock_irq(&phba->hbalock); |
| 11862 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 11863 | spin_unlock_irq(&phba->hbalock); |
| 11864 | |
| 11865 | /* Configure and enable interrupt */ |
| 11866 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 11867 | if (intr_mode == LPFC_INTR_ERROR) { |
| 11868 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11869 | "2824 Cannot re-enable interrupt after " |
| 11870 | "slot reset.\n"); |
| 11871 | return PCI_ERS_RESULT_DISCONNECT; |
| 11872 | } else |
| 11873 | phba->intr_mode = intr_mode; |
| 11874 | |
| 11875 | /* Log the current active interrupt mode */ |
| 11876 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 11877 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11878 | return PCI_ERS_RESULT_RECOVERED; |
| 11879 | } |
| 11880 | |
| 11881 | /** |
| 11882 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 11883 | * @pdev: pointer to PCI device |
| 11884 | * |
| 11885 | * This routine is called from the PCI subsystem for error handling to device |
| 11886 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 11887 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 11888 | * error recovery. After this call, traffic can start to flow from this device |
| 11889 | * again. |
| 11890 | **/ |
| 11891 | static void |
| 11892 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 11893 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11894 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11895 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11896 | |
| 11897 | /* |
| 11898 | * In case of slot reset, as function reset is performed through |
| 11899 | * mailbox command which needs DMA to be enabled, this operation |
| 11900 | * has to be moved to the io resume phase. Taking device offline |
| 11901 | * will perform the necessary cleanup. |
| 11902 | */ |
| 11903 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 11904 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11905 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11906 | lpfc_offline(phba); |
| 11907 | lpfc_sli_brdrestart(phba); |
| 11908 | /* Bring the device back online */ |
| 11909 | lpfc_online(phba); |
| 11910 | } |
| 11911 | |
| 11912 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 11913 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 11914 | pci_cleanup_aer_uncorrect_error_status(pdev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11915 | } |
| 11916 | |
| 11917 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11918 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 11919 | * @pdev: pointer to PCI device |
| 11920 | * @pid: pointer to PCI device identifier |
| 11921 | * |
| 11922 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 11923 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 11924 | * at PCI device-specific information of the device and driver to see if the |
| 11925 | * driver state that it can support this kind of device. If the match is |
| 11926 | * successful, the driver core invokes this routine. This routine dispatches |
| 11927 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 11928 | * do all the initialization that it needs to do to handle the HBA device |
| 11929 | * properly. |
| 11930 | * |
| 11931 | * Return code |
| 11932 | * 0 - driver can claim the device |
| 11933 | * negative value - driver can not claim the device |
| 11934 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11935 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11936 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 11937 | { |
| 11938 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 11939 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11940 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11941 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11942 | return -ENODEV; |
| 11943 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 11944 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 11945 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11946 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 11947 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11948 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 11949 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11950 | return rc; |
| 11951 | } |
| 11952 | |
| 11953 | /** |
| 11954 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 11955 | * @pdev: pointer to PCI device |
| 11956 | * |
| 11957 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 11958 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 11959 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 11960 | * remove routine, which will perform all the necessary cleanup for the |
| 11961 | * device to be removed from the PCI subsystem properly. |
| 11962 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11963 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11964 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 11965 | { |
| 11966 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11967 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11968 | |
| 11969 | switch (phba->pci_dev_grp) { |
| 11970 | case LPFC_PCI_DEV_LP: |
| 11971 | lpfc_pci_remove_one_s3(pdev); |
| 11972 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11973 | case LPFC_PCI_DEV_OC: |
| 11974 | lpfc_pci_remove_one_s4(pdev); |
| 11975 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11976 | default: |
| 11977 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11978 | "1424 Invalid PCI device group: 0x%x\n", |
| 11979 | phba->pci_dev_grp); |
| 11980 | break; |
| 11981 | } |
| 11982 | return; |
| 11983 | } |
| 11984 | |
| 11985 | /** |
| 11986 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 11987 | * @pdev: pointer to PCI device |
| 11988 | * @msg: power management message |
| 11989 | * |
| 11990 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 11991 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 11992 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 11993 | * suspend the device. |
| 11994 | * |
| 11995 | * Return code |
| 11996 | * 0 - driver suspended the device |
| 11997 | * Error otherwise |
| 11998 | **/ |
| 11999 | static int |
| 12000 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 12001 | { |
| 12002 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12003 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12004 | int rc = -ENODEV; |
| 12005 | |
| 12006 | switch (phba->pci_dev_grp) { |
| 12007 | case LPFC_PCI_DEV_LP: |
| 12008 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 12009 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12010 | case LPFC_PCI_DEV_OC: |
| 12011 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 12012 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12013 | default: |
| 12014 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12015 | "1425 Invalid PCI device group: 0x%x\n", |
| 12016 | phba->pci_dev_grp); |
| 12017 | break; |
| 12018 | } |
| 12019 | return rc; |
| 12020 | } |
| 12021 | |
| 12022 | /** |
| 12023 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 12024 | * @pdev: pointer to PCI device |
| 12025 | * |
| 12026 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 12027 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 12028 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 12029 | * resume the device. |
| 12030 | * |
| 12031 | * Return code |
| 12032 | * 0 - driver suspended the device |
| 12033 | * Error otherwise |
| 12034 | **/ |
| 12035 | static int |
| 12036 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 12037 | { |
| 12038 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12039 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12040 | int rc = -ENODEV; |
| 12041 | |
| 12042 | switch (phba->pci_dev_grp) { |
| 12043 | case LPFC_PCI_DEV_LP: |
| 12044 | rc = lpfc_pci_resume_one_s3(pdev); |
| 12045 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12046 | case LPFC_PCI_DEV_OC: |
| 12047 | rc = lpfc_pci_resume_one_s4(pdev); |
| 12048 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12049 | default: |
| 12050 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12051 | "1426 Invalid PCI device group: 0x%x\n", |
| 12052 | phba->pci_dev_grp); |
| 12053 | break; |
| 12054 | } |
| 12055 | return rc; |
| 12056 | } |
| 12057 | |
| 12058 | /** |
| 12059 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 12060 | * @pdev: pointer to PCI device. |
| 12061 | * @state: the current PCI connection state. |
| 12062 | * |
| 12063 | * This routine is registered to the PCI subsystem for error handling. This |
| 12064 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 12065 | * this device has been detected. When this routine is invoked, it dispatches |
| 12066 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 12067 | * routine, which will perform the proper error detected operation. |
| 12068 | * |
| 12069 | * Return codes |
| 12070 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12071 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 12072 | **/ |
| 12073 | static pci_ers_result_t |
| 12074 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 12075 | { |
| 12076 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12077 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12078 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 12079 | |
| 12080 | switch (phba->pci_dev_grp) { |
| 12081 | case LPFC_PCI_DEV_LP: |
| 12082 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 12083 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12084 | case LPFC_PCI_DEV_OC: |
| 12085 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 12086 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12087 | default: |
| 12088 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12089 | "1427 Invalid PCI device group: 0x%x\n", |
| 12090 | phba->pci_dev_grp); |
| 12091 | break; |
| 12092 | } |
| 12093 | return rc; |
| 12094 | } |
| 12095 | |
| 12096 | /** |
| 12097 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 12098 | * @pdev: pointer to PCI device. |
| 12099 | * |
| 12100 | * This routine is registered to the PCI subsystem for error handling. This |
| 12101 | * function is called after PCI bus has been reset to restart the PCI card |
| 12102 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 12103 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 12104 | * routine, which will perform the proper device reset. |
| 12105 | * |
| 12106 | * Return codes |
| 12107 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 12108 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 12109 | **/ |
| 12110 | static pci_ers_result_t |
| 12111 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 12112 | { |
| 12113 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12114 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12115 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 12116 | |
| 12117 | switch (phba->pci_dev_grp) { |
| 12118 | case LPFC_PCI_DEV_LP: |
| 12119 | rc = lpfc_io_slot_reset_s3(pdev); |
| 12120 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12121 | case LPFC_PCI_DEV_OC: |
| 12122 | rc = lpfc_io_slot_reset_s4(pdev); |
| 12123 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12124 | default: |
| 12125 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12126 | "1428 Invalid PCI device group: 0x%x\n", |
| 12127 | phba->pci_dev_grp); |
| 12128 | break; |
| 12129 | } |
| 12130 | return rc; |
| 12131 | } |
| 12132 | |
| 12133 | /** |
| 12134 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 12135 | * @pdev: pointer to PCI device |
| 12136 | * |
| 12137 | * This routine is registered to the PCI subsystem for error handling. It |
| 12138 | * is called when kernel error recovery tells the lpfc driver that it is |
| 12139 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 12140 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 12141 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 12142 | **/ |
| 12143 | static void |
| 12144 | lpfc_io_resume(struct pci_dev *pdev) |
| 12145 | { |
| 12146 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12147 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12148 | |
| 12149 | switch (phba->pci_dev_grp) { |
| 12150 | case LPFC_PCI_DEV_LP: |
| 12151 | lpfc_io_resume_s3(pdev); |
| 12152 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12153 | case LPFC_PCI_DEV_OC: |
| 12154 | lpfc_io_resume_s4(pdev); |
| 12155 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12156 | default: |
| 12157 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12158 | "1429 Invalid PCI device group: 0x%x\n", |
| 12159 | phba->pci_dev_grp); |
| 12160 | break; |
| 12161 | } |
| 12162 | return; |
| 12163 | } |
| 12164 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12165 | /** |
| 12166 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 12167 | * @phba: pointer to lpfc hba data structure. |
| 12168 | * |
| 12169 | * This routine checks to see if OAS is supported for this adapter. If |
| 12170 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 12171 | * the enable oas flag is cleared and the pool created for OAS device data |
| 12172 | * is destroyed. |
| 12173 | * |
| 12174 | **/ |
| 12175 | void |
| 12176 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 12177 | { |
| 12178 | |
| 12179 | if (!phba->cfg_EnableXLane) |
| 12180 | return; |
| 12181 | |
| 12182 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 12183 | phba->cfg_fof = 1; |
| 12184 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 12185 | phba->cfg_fof = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12186 | if (phba->device_data_mem_pool) |
| 12187 | mempool_destroy(phba->device_data_mem_pool); |
| 12188 | phba->device_data_mem_pool = NULL; |
| 12189 | } |
| 12190 | |
| 12191 | return; |
| 12192 | } |
| 12193 | |
| 12194 | /** |
| 12195 | * lpfc_fof_queue_setup - Set up all the fof queues |
| 12196 | * @phba: pointer to lpfc hba data structure. |
| 12197 | * |
| 12198 | * This routine is invoked to set up all the fof queues for the FC HBA |
| 12199 | * operation. |
| 12200 | * |
| 12201 | * Return codes |
| 12202 | * 0 - successful |
| 12203 | * -ENOMEM - No available memory |
| 12204 | **/ |
| 12205 | int |
| 12206 | lpfc_fof_queue_setup(struct lpfc_hba *phba) |
| 12207 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12208 | struct lpfc_sli_ring *pring; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12209 | int rc; |
| 12210 | |
| 12211 | rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX); |
| 12212 | if (rc) |
| 12213 | return -ENOMEM; |
| 12214 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 12215 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12216 | |
| 12217 | rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq, |
| 12218 | phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP); |
| 12219 | if (rc) |
| 12220 | goto out_oas_cq; |
| 12221 | |
| 12222 | rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq, |
| 12223 | phba->sli4_hba.oas_cq, LPFC_FCP); |
| 12224 | if (rc) |
| 12225 | goto out_oas_wq; |
| 12226 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12227 | /* Bind this CQ/WQ to the NVME ring */ |
| 12228 | pring = phba->sli4_hba.oas_wq->pring; |
| 12229 | pring->sli.sli4.wqp = |
| 12230 | (void *)phba->sli4_hba.oas_wq; |
| 12231 | phba->sli4_hba.oas_cq->pring = pring; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12232 | } |
| 12233 | |
| 12234 | return 0; |
| 12235 | |
| 12236 | out_oas_wq: |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 12237 | lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12238 | out_oas_cq: |
| 12239 | lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq); |
| 12240 | return rc; |
| 12241 | |
| 12242 | } |
| 12243 | |
| 12244 | /** |
| 12245 | * lpfc_fof_queue_create - Create all the fof queues |
| 12246 | * @phba: pointer to lpfc hba data structure. |
| 12247 | * |
| 12248 | * This routine is invoked to allocate all the fof queues for the FC HBA |
| 12249 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 12250 | * count (queue depth) shall be taken from the module parameter. For now, |
| 12251 | * we just use some constant number as place holder. |
| 12252 | * |
| 12253 | * Return codes |
| 12254 | * 0 - successful |
| 12255 | * -ENOMEM - No availble memory |
| 12256 | * -EIO - The mailbox failed to complete successfully. |
| 12257 | **/ |
| 12258 | int |
| 12259 | lpfc_fof_queue_create(struct lpfc_hba *phba) |
| 12260 | { |
| 12261 | struct lpfc_queue *qdesc; |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12262 | uint32_t wqesize; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12263 | |
| 12264 | /* Create FOF EQ */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 12265 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 12266 | phba->sli4_hba.eq_esize, |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12267 | phba->sli4_hba.eq_ecount); |
| 12268 | if (!qdesc) |
| 12269 | goto out_error; |
| 12270 | |
| 12271 | phba->sli4_hba.fof_eq = qdesc; |
| 12272 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 12273 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12274 | |
| 12275 | /* Create OAS CQ */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12276 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 12277 | qdesc = lpfc_sli4_queue_alloc(phba, |
| 12278 | LPFC_EXPANDED_PAGE_SIZE, |
| 12279 | phba->sli4_hba.cq_esize, |
| 12280 | LPFC_CQE_EXP_COUNT); |
| 12281 | else |
| 12282 | qdesc = lpfc_sli4_queue_alloc(phba, |
| 12283 | LPFC_DEFAULT_PAGE_SIZE, |
| 12284 | phba->sli4_hba.cq_esize, |
| 12285 | phba->sli4_hba.cq_ecount); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12286 | if (!qdesc) |
| 12287 | goto out_error; |
| 12288 | |
| 12289 | phba->sli4_hba.oas_cq = qdesc; |
| 12290 | |
| 12291 | /* Create OAS WQ */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12292 | if (phba->enab_exp_wqcq_pages) { |
| 12293 | wqesize = (phba->fcp_embed_io) ? |
| 12294 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 12295 | qdesc = lpfc_sli4_queue_alloc(phba, |
| 12296 | LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12297 | wqesize, |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 12298 | LPFC_WQE_EXP_COUNT); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12299 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 12300 | qdesc = lpfc_sli4_queue_alloc(phba, |
| 12301 | LPFC_DEFAULT_PAGE_SIZE, |
| 12302 | phba->sli4_hba.wq_esize, |
| 12303 | phba->sli4_hba.wq_ecount); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12304 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12305 | if (!qdesc) |
| 12306 | goto out_error; |
| 12307 | |
| 12308 | phba->sli4_hba.oas_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12309 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12310 | |
| 12311 | } |
| 12312 | return 0; |
| 12313 | |
| 12314 | out_error: |
| 12315 | lpfc_fof_queue_destroy(phba); |
| 12316 | return -ENOMEM; |
| 12317 | } |
| 12318 | |
| 12319 | /** |
| 12320 | * lpfc_fof_queue_destroy - Destroy all the fof queues |
| 12321 | * @phba: pointer to lpfc hba data structure. |
| 12322 | * |
| 12323 | * This routine is invoked to release all the SLI4 queues with the FC HBA |
| 12324 | * operation. |
| 12325 | * |
| 12326 | * Return codes |
| 12327 | * 0 - successful |
| 12328 | **/ |
| 12329 | int |
| 12330 | lpfc_fof_queue_destroy(struct lpfc_hba *phba) |
| 12331 | { |
| 12332 | /* Release FOF Event queue */ |
| 12333 | if (phba->sli4_hba.fof_eq != NULL) { |
| 12334 | lpfc_sli4_queue_free(phba->sli4_hba.fof_eq); |
| 12335 | phba->sli4_hba.fof_eq = NULL; |
| 12336 | } |
| 12337 | |
| 12338 | /* Release OAS Completion queue */ |
| 12339 | if (phba->sli4_hba.oas_cq != NULL) { |
| 12340 | lpfc_sli4_queue_free(phba->sli4_hba.oas_cq); |
| 12341 | phba->sli4_hba.oas_cq = NULL; |
| 12342 | } |
| 12343 | |
| 12344 | /* Release OAS Work queue */ |
| 12345 | if (phba->sli4_hba.oas_wq != NULL) { |
| 12346 | lpfc_sli4_queue_free(phba->sli4_hba.oas_wq); |
| 12347 | phba->sli4_hba.oas_wq = NULL; |
| 12348 | } |
| 12349 | return 0; |
| 12350 | } |
| 12351 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12352 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 12353 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 12354 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12355 | .error_detected = lpfc_io_error_detected, |
| 12356 | .slot_reset = lpfc_io_slot_reset, |
| 12357 | .resume = lpfc_io_resume, |
| 12358 | }; |
| 12359 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12360 | static struct pci_driver lpfc_driver = { |
| 12361 | .name = LPFC_DRIVER_NAME, |
| 12362 | .id_table = lpfc_id_table, |
| 12363 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12364 | .remove = lpfc_pci_remove_one, |
Anton Blanchard | 85e8a23 | 2017-02-13 08:49:20 +1100 | [diff] [blame] | 12365 | .shutdown = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12366 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12367 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12368 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12369 | }; |
| 12370 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 12371 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 12372 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 12373 | }; |
| 12374 | |
| 12375 | static struct miscdevice lpfc_mgmt_dev = { |
| 12376 | .minor = MISC_DYNAMIC_MINOR, |
| 12377 | .name = "lpfcmgmt", |
| 12378 | .fops = &lpfc_mgmt_fop, |
| 12379 | }; |
| 12380 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12381 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12382 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12383 | * |
| 12384 | * This routine is to be invoked when the lpfc module is loaded into the |
| 12385 | * kernel. The special kernel macro module_init() is used to indicate the |
| 12386 | * role of this routine to the kernel as lpfc module entry point. |
| 12387 | * |
| 12388 | * Return codes |
| 12389 | * 0 - successful |
| 12390 | * -ENOMEM - FC attach transport failed |
| 12391 | * all others - failed |
| 12392 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12393 | static int __init |
| 12394 | lpfc_init(void) |
| 12395 | { |
| 12396 | int error = 0; |
| 12397 | |
| 12398 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12399 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12400 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 12401 | error = misc_register(&lpfc_mgmt_dev); |
| 12402 | if (error) |
| 12403 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 12404 | "misc_register returned with status %d", error); |
| 12405 | |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 12406 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 12407 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12408 | lpfc_transport_template = |
| 12409 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 12410 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12411 | return -ENOMEM; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 12412 | lpfc_vport_transport_template = |
| 12413 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 12414 | if (lpfc_vport_transport_template == NULL) { |
| 12415 | fc_release_transport(lpfc_transport_template); |
| 12416 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 12417 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12418 | |
| 12419 | /* Initialize in case vector mapping is needed */ |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 12420 | lpfc_used_cpu = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 12421 | lpfc_present_cpu = num_present_cpus(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12422 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12423 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12424 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12425 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 12426 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12427 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12428 | |
| 12429 | return error; |
| 12430 | } |
| 12431 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12432 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12433 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12434 | * |
| 12435 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 12436 | * The special kernel macro module_exit() is used to indicate the role of |
| 12437 | * this routine to the kernel as lpfc module exit point. |
| 12438 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12439 | static void __exit |
| 12440 | lpfc_exit(void) |
| 12441 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 12442 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12443 | pci_unregister_driver(&lpfc_driver); |
| 12444 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 12445 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 12446 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12447 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 12448 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 12449 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 12450 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 12451 | } |
| 12452 | |
| 12453 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12454 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 12455 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 12456 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 12457 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 12458 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 12459 | kfree(lpfc_used_cpu); |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 12460 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12461 | } |
| 12462 | |
| 12463 | module_init(lpfc_init); |
| 12464 | module_exit(lpfc_exit); |
| 12465 | MODULE_LICENSE("GPL"); |
| 12466 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 12467 | MODULE_AUTHOR("Broadcom"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12468 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |