| 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 | 3e21d1c | 2018-05-04 20:37:59 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. 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) && |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 734 | !(phba->lmt & LMT_32Gb)) || |
| 735 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) && |
| 736 | !(phba->lmt & LMT_64Gb))) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 737 | /* Reset link speed to auto */ |
| 738 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
| 739 | "1302 Invalid speed for this board:%d " |
| 740 | "Reset link speed to auto.\n", |
| 741 | phba->cfg_link_speed); |
| 742 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 743 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 744 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 745 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 746 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 747 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 748 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 749 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 750 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 751 | "0498 Adapter failed to init, mbxCmd x%x " |
| 752 | "INIT_LINK, mbxStatus x%x\n", |
| 753 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 754 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 755 | /* Clear all interrupt enable conditions */ |
| 756 | writel(0, phba->HCregaddr); |
| 757 | readl(phba->HCregaddr); /* flush */ |
| 758 | /* Clear all pending interrupts */ |
| 759 | writel(0xffffffff, phba->HAregaddr); |
| 760 | readl(phba->HAregaddr); /* flush */ |
| 761 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 762 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 763 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 764 | mempool_free(pmb, phba->mbox_mem_pool); |
| 765 | return -EIO; |
| 766 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 767 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 768 | if (flag == MBX_POLL) |
| 769 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 770 | |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 776 | * @phba: pointer to lpfc hba data structure. |
| 777 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 778 | * |
| 779 | * This routine will issue the DOWN_LINK mailbox command call. |
| 780 | * It is available to other drivers through the lpfc_hba data |
| 781 | * structure for use to stop the link. |
| 782 | * |
| 783 | * Return code |
| 784 | * 0 - success |
| 785 | * Any other value - error |
| 786 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 787 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 788 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 789 | { |
| 790 | LPFC_MBOXQ_t *pmb; |
| 791 | int rc; |
| 792 | |
| 793 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 794 | if (!pmb) { |
| 795 | phba->link_state = LPFC_HBA_ERROR; |
| 796 | return -ENOMEM; |
| 797 | } |
| 798 | |
| 799 | lpfc_printf_log(phba, |
| 800 | KERN_ERR, LOG_INIT, |
| 801 | "0491 Adapter Link is disabled.\n"); |
| 802 | lpfc_down_link(phba, pmb); |
| 803 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 804 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 805 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
| 806 | lpfc_printf_log(phba, |
| 807 | KERN_ERR, LOG_INIT, |
| 808 | "2522 Adapter failed to issue DOWN_LINK" |
| 809 | " mbox command rc 0x%x\n", rc); |
| 810 | |
| 811 | mempool_free(pmb, phba->mbox_mem_pool); |
| 812 | return -EIO; |
| 813 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 814 | if (flag == MBX_POLL) |
| 815 | mempool_free(pmb, phba->mbox_mem_pool); |
| 816 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 821 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 822 | * @phba: pointer to lpfc HBA data structure. |
| 823 | * |
| 824 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 825 | * bringing down the SLI Layer. |
| 826 | * |
| 827 | * Return codes |
| 828 | * 0 - success. |
| 829 | * Any other value - error. |
| 830 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 831 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 832 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 833 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 834 | struct lpfc_vport **vports; |
| 835 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 836 | |
| 837 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 838 | /* Disable interrupts */ |
| 839 | writel(0, phba->HCregaddr); |
| 840 | readl(phba->HCregaddr); /* flush */ |
| 841 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 842 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 843 | if (phba->pport->load_flag & FC_UNLOADING) |
| 844 | lpfc_cleanup_discovery_resources(phba->pport); |
| 845 | else { |
| 846 | vports = lpfc_create_vport_work_array(phba); |
| 847 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 848 | for (i = 0; i <= phba->max_vports && |
| 849 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 850 | lpfc_cleanup_discovery_resources(vports[i]); |
| 851 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 852 | } |
| 853 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 854 | } |
| 855 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 856 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 857 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 858 | * rspiocb which got deferred |
| 859 | * |
| 860 | * @phba: pointer to lpfc HBA data structure. |
| 861 | * |
| 862 | * This routine will cleanup completed slow path events after HBA is reset |
| 863 | * when bringing down the SLI Layer. |
| 864 | * |
| 865 | * |
| 866 | * Return codes |
| 867 | * void. |
| 868 | **/ |
| 869 | static void |
| 870 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 871 | { |
| 872 | struct lpfc_iocbq *rspiocbq; |
| 873 | struct hbq_dmabuf *dmabuf; |
| 874 | struct lpfc_cq_event *cq_event; |
| 875 | |
| 876 | spin_lock_irq(&phba->hbalock); |
| 877 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 878 | spin_unlock_irq(&phba->hbalock); |
| 879 | |
| 880 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 881 | /* Get the response iocb from the head of work queue */ |
| 882 | spin_lock_irq(&phba->hbalock); |
| 883 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 884 | cq_event, struct lpfc_cq_event, list); |
| 885 | spin_unlock_irq(&phba->hbalock); |
| 886 | |
| 887 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 888 | case CQE_CODE_COMPL_WQE: |
| 889 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 890 | cq_event); |
| 891 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 892 | break; |
| 893 | case CQE_CODE_RECEIVE: |
| 894 | case CQE_CODE_RECEIVE_V1: |
| 895 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 896 | cq_event); |
| 897 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 903 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 904 | * @phba: pointer to lpfc HBA data structure. |
| 905 | * |
| 906 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 907 | * when bringing down the SLI Layer. |
| 908 | * |
| 909 | * |
| 910 | * Return codes |
| 911 | * void. |
| 912 | **/ |
| 913 | static void |
| 914 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 915 | { |
| 916 | struct lpfc_sli *psli = &phba->sli; |
| 917 | struct lpfc_sli_ring *pring; |
| 918 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 919 | LIST_HEAD(buflist); |
| 920 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 921 | |
| 922 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 923 | lpfc_sli_hbqbuf_free_all(phba); |
| 924 | else { |
| 925 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 926 | pring = &psli->sli3_ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 927 | spin_lock_irq(&phba->hbalock); |
| 928 | list_splice_init(&pring->postbufq, &buflist); |
| 929 | spin_unlock_irq(&phba->hbalock); |
| 930 | |
| 931 | count = 0; |
| 932 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 933 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 934 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 935 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 936 | kfree(mp); |
| 937 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 938 | |
| 939 | spin_lock_irq(&phba->hbalock); |
| 940 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 941 | spin_unlock_irq(&phba->hbalock); |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | /** |
| 946 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 947 | * @phba: pointer to lpfc HBA data structure. |
| 948 | * |
| 949 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 950 | * down the SLI Layer. |
| 951 | * |
| 952 | * Return codes |
| 953 | * void |
| 954 | **/ |
| 955 | static void |
| 956 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 957 | { |
| 958 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 959 | struct lpfc_queue *qp = NULL; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 960 | struct lpfc_sli_ring *pring; |
| 961 | LIST_HEAD(completions); |
| 962 | int i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 963 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 964 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 965 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 966 | for (i = 0; i < psli->num_rings; i++) { |
| 967 | pring = &psli->sli3_ring[i]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 968 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 969 | /* At this point in time the HBA is either reset or DOA |
| 970 | * Nothing should be on txcmplq as it will |
| 971 | * NEVER complete. |
| 972 | */ |
| 973 | list_splice_init(&pring->txcmplq, &completions); |
| 974 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 975 | spin_unlock_irq(&phba->hbalock); |
| 976 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 977 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 978 | } |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 979 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 980 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 981 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
| 982 | return; |
| 983 | } |
| 984 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 985 | pring = qp->pring; |
| 986 | if (!pring) |
| 987 | continue; |
| 988 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 989 | list_for_each_entry_safe(piocb, next_iocb, |
| 990 | &pring->txcmplq, list) |
| 991 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 992 | list_splice_init(&pring->txcmplq, &completions); |
| 993 | pring->txcmplq_cnt = 0; |
| 994 | spin_unlock_irq(&pring->ring_lock); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 995 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 996 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 997 | /* Cancel all the IOCBs from the completions list */ |
| 998 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 999 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1003 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1004 | int i; |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1005 | * @phba: pointer to lpfc HBA data structure. |
| 1006 | * |
| 1007 | * This routine will do uninitialization after the HBA is reset when bring |
| 1008 | * down the SLI Layer. |
| 1009 | * |
| 1010 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1011 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1012 | * Any other value - error. |
| 1013 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1014 | static int |
| 1015 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1016 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1017 | lpfc_hba_free_post_buf(phba); |
| 1018 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1019 | return 0; |
| 1020 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 1021 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1022 | /** |
| 1023 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 1024 | * @phba: pointer to lpfc HBA data structure. |
| 1025 | * |
| 1026 | * This routine will do uninitialization after the HBA is reset when bring |
| 1027 | * down the SLI Layer. |
| 1028 | * |
| 1029 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1030 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1031 | * Any other value - error. |
| 1032 | **/ |
| 1033 | static int |
| 1034 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 1035 | { |
| 1036 | struct lpfc_scsi_buf *psb, *psb_next; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1037 | struct lpfc_nvmet_rcv_ctx *ctxp, *ctxp_next; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1038 | LIST_HEAD(aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1039 | LIST_HEAD(nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1040 | LIST_HEAD(nvmet_aborts); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1041 | unsigned long iflag = 0; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1042 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1043 | int cnt; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1044 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1045 | |
| 1046 | lpfc_sli_hbqbuf_free_all(phba); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1047 | lpfc_hba_clean_txcmplq(phba); |
| 1048 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1049 | /* At this point in time the HBA is either reset or DOA. Either |
| 1050 | * 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] | 1051 | * 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] | 1052 | * driver is unloading or reposted if the driver is restarting |
| 1053 | * the port. |
| 1054 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1055 | spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1056 | /* scsl_buf_list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1057 | /* sgl_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1058 | * list. |
| 1059 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1060 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1061 | list_for_each_entry(sglq_entry, |
| 1062 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1063 | sglq_entry->state = SGL_FREED; |
| 1064 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1065 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1066 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1067 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1068 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1069 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1070 | /* abts_scsi_buf_list_lock required because worker thread uses this |
| 1071 | * list. |
| 1072 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1073 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 1074 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 1075 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, |
| 1076 | &aborts); |
| 1077 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 1078 | } |
| 1079 | |
| 1080 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 1081 | spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); |
| 1082 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list, |
| 1083 | &nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1084 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list, |
| 1085 | &nvmet_aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1086 | spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); |
| 1087 | } |
| 1088 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1089 | spin_unlock_irq(&phba->hbalock); |
| 1090 | |
| 1091 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
| 1092 | psb->pCmd = NULL; |
| 1093 | psb->status = IOSTAT_SUCCESS; |
| 1094 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 1095 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
| 1096 | list_splice(&aborts, &phba->lpfc_scsi_buf_list_put); |
| 1097 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1098 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1099 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1100 | cnt = 0; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1101 | list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) { |
| 1102 | psb->pCmd = NULL; |
| 1103 | psb->status = IOSTAT_SUCCESS; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1104 | cnt++; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1105 | } |
| 1106 | spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1107 | phba->put_nvme_bufs += cnt; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1108 | list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put); |
| 1109 | spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag); |
| 1110 | |
| 1111 | list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) { |
| 1112 | ctxp->flag &= ~(LPFC_NVMET_XBUSY | LPFC_NVMET_ABORT_OP); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 1113 | lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1114 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1115 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1116 | |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1117 | lpfc_sli4_free_sp_events(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1118 | return 0; |
| 1119 | } |
| 1120 | |
| 1121 | /** |
| 1122 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1123 | * @phba: pointer to lpfc HBA data structure. |
| 1124 | * |
| 1125 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1126 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1127 | * |
| 1128 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1129 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1130 | * Any other value - error. |
| 1131 | **/ |
| 1132 | int |
| 1133 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1134 | { |
| 1135 | return (*phba->lpfc_hba_down_post)(phba); |
| 1136 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1137 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1138 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1139 | * lpfc_hb_timeout - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1140 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1141 | * |
| 1142 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1143 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1144 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1145 | * event will be used by the worker thread to invoke the actual timeout |
| 1146 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1147 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1148 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1149 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1150 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1151 | lpfc_hb_timeout(struct timer_list *t) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1152 | { |
| 1153 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1154 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1155 | unsigned long iflag; |
| 1156 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1157 | phba = from_timer(phba, t, hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1158 | |
| 1159 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1160 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1161 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1162 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1163 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1164 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1165 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1166 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1167 | if (!tmo_posted) |
| 1168 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1169 | return; |
| 1170 | } |
| 1171 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1172 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1173 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
| 1174 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 1175 | * |
| 1176 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1177 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1178 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1179 | * event will be used by the worker thread to invoke the actual timeout |
| 1180 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1181 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1182 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1183 | **/ |
| 1184 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1185 | lpfc_rrq_timeout(struct timer_list *t) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1186 | { |
| 1187 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1188 | unsigned long iflag; |
| 1189 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1190 | phba = from_timer(phba, t, rrq_tmr); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1191 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1192 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1193 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1194 | else |
| 1195 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1196 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1197 | |
| 1198 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1199 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1203 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1204 | * @phba: pointer to lpfc hba data structure. |
| 1205 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1206 | * |
| 1207 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1208 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1209 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1210 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1211 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1212 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1213 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1214 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1215 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1216 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1217 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1218 | static void |
| 1219 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1220 | { |
| 1221 | unsigned long drvr_flag; |
| 1222 | |
| 1223 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1224 | phba->hb_outstanding = 0; |
| 1225 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1226 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1227 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1228 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1229 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1230 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1231 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1232 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1233 | jiffies + |
| 1234 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1235 | return; |
| 1236 | } |
| 1237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1238 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1239 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1240 | * @phba: pointer to lpfc hba data structure. |
| 1241 | * |
| 1242 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1243 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1244 | * handler performs any periodic operations needed for the device. If such |
| 1245 | * periodic event has already been attended to either in the interrupt handler |
| 1246 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1247 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1248 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1249 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1250 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1251 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1252 | * to offline. |
| 1253 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1254 | void |
| 1255 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1256 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1257 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1258 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1259 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1260 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1261 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1262 | LIST_HEAD(completions); |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 1263 | struct lpfc_queue *qp; |
| 1264 | unsigned long time_elapsed; |
| 1265 | uint32_t tick_cqe, max_cqe, val; |
| 1266 | uint64_t tot, data1, data2, data3; |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 1267 | struct lpfc_nvmet_tgtport *tgtp; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 1268 | struct lpfc_register reg_data; |
James Smart | 66a210f | 2018-04-09 14:24:23 -0700 | [diff] [blame] | 1269 | struct nvme_fc_local_port *localport; |
| 1270 | struct lpfc_nvme_lport *lport; |
| 1271 | struct lpfc_nvme_ctrl_stat *cstat; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 1272 | void __iomem *eqdreg = phba->sli4_hba.u.if_type2.EQDregaddr; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1273 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1274 | vports = lpfc_create_vport_work_array(phba); |
| 1275 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1276 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1277 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1278 | lpfc_fdmi_num_disc_check(vports[i]); |
| 1279 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1280 | lpfc_destroy_vport_work_array(phba, vports); |
| 1281 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1282 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1283 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1284 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1285 | return; |
| 1286 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 1287 | if (phba->cfg_auto_imax) { |
| 1288 | if (!phba->last_eqdelay_time) { |
| 1289 | phba->last_eqdelay_time = jiffies; |
| 1290 | goto skip_eqdelay; |
| 1291 | } |
| 1292 | time_elapsed = jiffies - phba->last_eqdelay_time; |
| 1293 | phba->last_eqdelay_time = jiffies; |
| 1294 | |
| 1295 | tot = 0xffff; |
| 1296 | /* Check outstanding IO count */ |
| 1297 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 1298 | if (phba->nvmet_support) { |
Dick Kennedy | 66d7ce9 | 2017-08-23 16:55:42 -0700 | [diff] [blame] | 1299 | tgtp = phba->targetport->private; |
| 1300 | /* Calculate outstanding IOs */ |
| 1301 | tot = atomic_read(&tgtp->rcv_fcp_cmd_drop); |
| 1302 | tot += atomic_read(&tgtp->xmt_fcp_release); |
| 1303 | tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot; |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 1304 | } else { |
James Smart | 66a210f | 2018-04-09 14:24:23 -0700 | [diff] [blame] | 1305 | localport = phba->pport->localport; |
| 1306 | if (!localport || !localport->private) |
| 1307 | goto skip_eqdelay; |
| 1308 | lport = (struct lpfc_nvme_lport *) |
| 1309 | localport->private; |
| 1310 | tot = 0; |
| 1311 | for (i = 0; |
| 1312 | i < phba->cfg_nvme_io_channel; i++) { |
| 1313 | cstat = &lport->cstat[i]; |
| 1314 | data1 = atomic_read( |
| 1315 | &cstat->fc4NvmeInputRequests); |
| 1316 | data2 = atomic_read( |
| 1317 | &cstat->fc4NvmeOutputRequests); |
| 1318 | data3 = atomic_read( |
| 1319 | &cstat->fc4NvmeControlRequests); |
| 1320 | tot += (data1 + data2 + data3); |
| 1321 | tot -= atomic_read( |
| 1322 | &cstat->fc4NvmeIoCmpls); |
| 1323 | } |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | /* Interrupts per sec per EQ */ |
| 1328 | val = phba->cfg_fcp_imax / phba->io_channel_irqs; |
| 1329 | tick_cqe = val / CONFIG_HZ; /* Per tick per EQ */ |
| 1330 | |
| 1331 | /* Assume 1 CQE/ISR, calc max CQEs allowed for time duration */ |
| 1332 | max_cqe = time_elapsed * tick_cqe; |
| 1333 | |
| 1334 | for (i = 0; i < phba->io_channel_irqs; i++) { |
| 1335 | /* Fast-path EQ */ |
| 1336 | qp = phba->sli4_hba.hba_eq[i]; |
| 1337 | if (!qp) |
| 1338 | continue; |
| 1339 | |
| 1340 | /* Use no EQ delay if we don't have many outstanding |
| 1341 | * IOs, or if we are only processing 1 CQE/ISR or less. |
| 1342 | * Otherwise, assume we can process up to lpfc_fcp_imax |
| 1343 | * interrupts per HBA. |
| 1344 | */ |
| 1345 | if (tot < LPFC_NODELAY_MAX_IO || |
| 1346 | qp->EQ_cqe_cnt <= max_cqe) |
| 1347 | val = 0; |
| 1348 | else |
| 1349 | val = phba->cfg_fcp_imax; |
| 1350 | |
| 1351 | if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) { |
| 1352 | /* Use EQ Delay Register method */ |
| 1353 | |
| 1354 | /* Convert for EQ Delay register */ |
| 1355 | if (val) { |
| 1356 | /* First, interrupts per sec per EQ */ |
| 1357 | val = phba->cfg_fcp_imax / |
| 1358 | phba->io_channel_irqs; |
| 1359 | |
| 1360 | /* us delay between each interrupt */ |
| 1361 | val = LPFC_SEC_TO_USEC / val; |
| 1362 | } |
| 1363 | if (val != qp->q_mode) { |
| 1364 | reg_data.word0 = 0; |
| 1365 | bf_set(lpfc_sliport_eqdelay_id, |
| 1366 | ®_data, qp->queue_id); |
| 1367 | bf_set(lpfc_sliport_eqdelay_delay, |
| 1368 | ®_data, val); |
| 1369 | writel(reg_data.word0, eqdreg); |
| 1370 | } |
| 1371 | } else { |
| 1372 | /* Use mbox command method */ |
| 1373 | if (val != qp->q_mode) |
| 1374 | lpfc_modify_hba_eq_delay(phba, i, |
| 1375 | 1, val); |
| 1376 | } |
| 1377 | |
| 1378 | /* |
| 1379 | * val is cfg_fcp_imax or 0 for mbox delay or us delay |
| 1380 | * between interrupts for EQDR. |
| 1381 | */ |
| 1382 | qp->q_mode = val; |
| 1383 | qp->EQ_cqe_cnt = 0; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | skip_eqdelay: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1388 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1389 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1390 | if (time_after(phba->last_completion_time + |
| 1391 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1392 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1393 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1394 | if (!phba->hb_outstanding) |
| 1395 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1396 | jiffies + |
| 1397 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1398 | else |
| 1399 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1400 | jiffies + |
| 1401 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1402 | return; |
| 1403 | } |
| 1404 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1405 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1406 | if (phba->elsbuf_cnt && |
| 1407 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1408 | spin_lock_irq(&phba->hbalock); |
| 1409 | list_splice_init(&phba->elsbuf, &completions); |
| 1410 | phba->elsbuf_cnt = 0; |
| 1411 | phba->elsbuf_prev_cnt = 0; |
| 1412 | spin_unlock_irq(&phba->hbalock); |
| 1413 | |
| 1414 | while (!list_empty(&completions)) { |
| 1415 | list_remove_head(&completions, buf_ptr, |
| 1416 | struct lpfc_dmabuf, list); |
| 1417 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1418 | kfree(buf_ptr); |
| 1419 | } |
| 1420 | } |
| 1421 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1422 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1423 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1424 | if (phba->cfg_enable_hba_heartbeat) { |
| 1425 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1426 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1427 | (list_empty(&psli->mboxq))) { |
| 1428 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1429 | GFP_KERNEL); |
| 1430 | if (!pmboxq) { |
| 1431 | mod_timer(&phba->hb_tmofunc, |
| 1432 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1433 | msecs_to_jiffies(1000 * |
| 1434 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1435 | return; |
| 1436 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1437 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1438 | lpfc_heart_beat(phba, pmboxq); |
| 1439 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1440 | pmboxq->vport = phba->pport; |
| 1441 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1442 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1443 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1444 | if (retval != MBX_BUSY && |
| 1445 | retval != MBX_SUCCESS) { |
| 1446 | mempool_free(pmboxq, |
| 1447 | phba->mbox_mem_pool); |
| 1448 | mod_timer(&phba->hb_tmofunc, |
| 1449 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1450 | msecs_to_jiffies(1000 * |
| 1451 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1452 | return; |
| 1453 | } |
| 1454 | phba->skipped_hb = 0; |
| 1455 | phba->hb_outstanding = 1; |
| 1456 | } else if (time_before_eq(phba->last_completion_time, |
| 1457 | phba->skipped_hb)) { |
| 1458 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1459 | "2857 Last completion time not " |
| 1460 | " updated in %d ms\n", |
| 1461 | jiffies_to_msecs(jiffies |
| 1462 | - phba->last_completion_time)); |
| 1463 | } else |
| 1464 | phba->skipped_hb = jiffies; |
| 1465 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1466 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1467 | jiffies + |
| 1468 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1469 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1470 | } else { |
| 1471 | /* |
| 1472 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1473 | * we need to give the hb mailbox cmd a chance to |
| 1474 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1475 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1476 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1477 | "0459 Adapter heartbeat still out" |
| 1478 | "standing:last compl time was %d ms.\n", |
| 1479 | jiffies_to_msecs(jiffies |
| 1480 | - phba->last_completion_time)); |
| 1481 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1482 | jiffies + |
| 1483 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1484 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1485 | } else { |
| 1486 | mod_timer(&phba->hb_tmofunc, |
| 1487 | jiffies + |
| 1488 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1489 | } |
| 1490 | } |
| 1491 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1492 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1493 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1494 | * @phba: pointer to lpfc hba data structure. |
| 1495 | * |
| 1496 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1497 | * other than Port Error 6 has been detected. |
| 1498 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1499 | static void |
| 1500 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1501 | { |
| 1502 | struct lpfc_sli *psli = &phba->sli; |
| 1503 | |
| 1504 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1505 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1506 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1507 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1508 | |
| 1509 | lpfc_offline(phba); |
| 1510 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1511 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1512 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1513 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1514 | lpfc_hba_down_post(phba); |
| 1515 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1516 | lpfc_unblock_mgmt_io(phba); |
| 1517 | phba->link_state = LPFC_HBA_ERROR; |
| 1518 | return; |
| 1519 | } |
| 1520 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1521 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1522 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1523 | * @phba: pointer to lpfc hba data structure. |
| 1524 | * |
| 1525 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1526 | * other than Port Error 6 has been detected. |
| 1527 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1528 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1529 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1530 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1531 | spin_lock_irq(&phba->hbalock); |
| 1532 | phba->link_state = LPFC_HBA_ERROR; |
| 1533 | spin_unlock_irq(&phba->hbalock); |
| 1534 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1535 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1536 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1537 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1538 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1542 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1543 | * @phba: pointer to lpfc hba data structure. |
| 1544 | * |
| 1545 | * This routine is invoked to handle the deferred HBA hardware error |
| 1546 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1547 | * and another ER bit in the host status register. The driver will |
| 1548 | * wait until the ER1 bit clears before handling the error condition. |
| 1549 | **/ |
| 1550 | static void |
| 1551 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1552 | { |
| 1553 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1554 | struct lpfc_sli *psli = &phba->sli; |
| 1555 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1556 | /* If the pci channel is offline, ignore possible errors, |
| 1557 | * since we cannot communicate with the pci card anyway. |
| 1558 | */ |
| 1559 | if (pci_channel_offline(phba->pcidev)) { |
| 1560 | spin_lock_irq(&phba->hbalock); |
| 1561 | phba->hba_flag &= ~DEFER_ERATT; |
| 1562 | spin_unlock_irq(&phba->hbalock); |
| 1563 | return; |
| 1564 | } |
| 1565 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1566 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1567 | "0479 Deferred Adapter Hardware Error " |
| 1568 | "Data: x%x x%x x%x\n", |
| 1569 | phba->work_hs, |
| 1570 | phba->work_status[0], phba->work_status[1]); |
| 1571 | |
| 1572 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1573 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1574 | spin_unlock_irq(&phba->hbalock); |
| 1575 | |
| 1576 | |
| 1577 | /* |
| 1578 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1579 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1580 | * SCSI layer retry it after re-establishing link. |
| 1581 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1582 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1583 | |
| 1584 | /* |
| 1585 | * There was a firmware error. Take the hba offline and then |
| 1586 | * attempt to restart it. |
| 1587 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1588 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1589 | lpfc_offline(phba); |
| 1590 | |
| 1591 | /* Wait for the ER1 bit to clear.*/ |
| 1592 | while (phba->work_hs & HS_FFER1) { |
| 1593 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1594 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1595 | phba->work_hs = UNPLUG_ERR ; |
| 1596 | break; |
| 1597 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1598 | /* If driver is unloading let the worker thread continue */ |
| 1599 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1600 | phba->work_hs = 0; |
| 1601 | break; |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | /* |
| 1606 | * This is to ptrotect against a race condition in which |
| 1607 | * first write to the host attention register clear the |
| 1608 | * host status register. |
| 1609 | */ |
| 1610 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1611 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1612 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1613 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1614 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1615 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1616 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1617 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1618 | } |
| 1619 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1620 | static void |
| 1621 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1622 | { |
| 1623 | struct lpfc_board_event_header board_event; |
| 1624 | struct Scsi_Host *shost; |
| 1625 | |
| 1626 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1627 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1628 | shost = lpfc_shost_from_vport(phba->pport); |
| 1629 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1630 | sizeof(board_event), |
| 1631 | (char *) &board_event, |
| 1632 | LPFC_NL_VENDOR_ID); |
| 1633 | } |
| 1634 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1635 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1636 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1637 | * @phba: pointer to lpfc hba data structure. |
| 1638 | * |
| 1639 | * This routine is invoked to handle the following HBA hardware error |
| 1640 | * conditions: |
| 1641 | * 1 - HBA error attention interrupt |
| 1642 | * 2 - DMA ring index out of range |
| 1643 | * 3 - Mailbox command came back as unknown |
| 1644 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1645 | static void |
| 1646 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1647 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1648 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1649 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1650 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1651 | unsigned long temperature; |
| 1652 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1653 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1654 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1655 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1656 | * since we cannot communicate with the pci card anyway. |
| 1657 | */ |
| 1658 | if (pci_channel_offline(phba->pcidev)) { |
| 1659 | spin_lock_irq(&phba->hbalock); |
| 1660 | phba->hba_flag &= ~DEFER_ERATT; |
| 1661 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1662 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1663 | } |
| 1664 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1665 | /* If resets are disabled then leave the HBA alone and return */ |
| 1666 | if (!phba->cfg_enable_hba_reset) |
| 1667 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1668 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1669 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1670 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1671 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1672 | if (phba->hba_flag & DEFER_ERATT) |
| 1673 | lpfc_handle_deferred_eratt(phba); |
| 1674 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1675 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1676 | if (phba->work_hs & HS_FFER6) |
| 1677 | /* Re-establishing Link */ |
| 1678 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1679 | "1301 Re-establishing Link " |
| 1680 | "Data: x%x x%x x%x\n", |
| 1681 | phba->work_hs, phba->work_status[0], |
| 1682 | phba->work_status[1]); |
| 1683 | if (phba->work_hs & HS_FFER8) |
| 1684 | /* Device Zeroization */ |
| 1685 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1686 | "2861 Host Authentication device " |
| 1687 | "zeroization Data:x%x x%x x%x\n", |
| 1688 | phba->work_hs, phba->work_status[0], |
| 1689 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1690 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1691 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1692 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1693 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1694 | |
| 1695 | /* |
| 1696 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1697 | * That could cause the I/Os dropped by the firmware. |
| 1698 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1699 | * retry it after re-establishing link. |
| 1700 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1701 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1702 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1703 | /* |
| 1704 | * There was a firmware error. Take the hba offline and then |
| 1705 | * attempt to restart it. |
| 1706 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1707 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1708 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1709 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1710 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1711 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1712 | return; |
| 1713 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1714 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1715 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1716 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1717 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1718 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1719 | temp_event_data.data = (uint32_t)temperature; |
| 1720 | |
| 1721 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1722 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1723 | "(%ld), taking this port offline " |
| 1724 | "Data: x%x x%x x%x\n", |
| 1725 | temperature, phba->work_hs, |
| 1726 | phba->work_status[0], phba->work_status[1]); |
| 1727 | |
| 1728 | shost = lpfc_shost_from_vport(phba->pport); |
| 1729 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1730 | sizeof(temp_event_data), |
| 1731 | (char *) &temp_event_data, |
| 1732 | SCSI_NL_VID_TYPE_PCI |
| 1733 | | PCI_VENDOR_ID_EMULEX); |
| 1734 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1735 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1736 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1737 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1738 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1739 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1740 | } else { |
| 1741 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1742 | * failure is a value other than FFER6. Do not call the offline |
| 1743 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1744 | */ |
| 1745 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1746 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1747 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1748 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1749 | phba->work_status[0], phba->work_status[1]); |
| 1750 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1751 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1752 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1753 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1754 | sizeof(event_data), (char *) &event_data, |
| 1755 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1756 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1757 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1758 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1759 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1760 | } |
| 1761 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1762 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1763 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1764 | * @phba: pointer to lpfc hba data structure. |
| 1765 | * @mbx_action: flag for mailbox shutdown action. |
| 1766 | * |
| 1767 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1768 | * response to port status register polling attention. It waits for port |
| 1769 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1770 | * During this process, interrupt vectors are freed and later requested |
| 1771 | * for handling possible port resource change. |
| 1772 | **/ |
| 1773 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1774 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1775 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1776 | { |
| 1777 | int rc; |
| 1778 | uint32_t intr_mode; |
| 1779 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1780 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >= |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1781 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1782 | /* |
| 1783 | * On error status condition, driver need to wait for port |
| 1784 | * ready before performing reset. |
| 1785 | */ |
| 1786 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1787 | if (rc) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1788 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1789 | } |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1790 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1791 | /* need reset: attempt for port recovery */ |
| 1792 | if (en_rn_msg) |
| 1793 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1794 | "2887 Reset Needed: Attempting Port " |
| 1795 | "Recovery...\n"); |
| 1796 | lpfc_offline_prep(phba, mbx_action); |
| 1797 | lpfc_offline(phba); |
| 1798 | /* release interrupt for possible resource change */ |
| 1799 | lpfc_sli4_disable_intr(phba); |
| 1800 | lpfc_sli_brdrestart(phba); |
| 1801 | /* request and enable interrupt */ |
| 1802 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1803 | if (intr_mode == LPFC_INTR_ERROR) { |
| 1804 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1805 | "3175 Failed to enable interrupt\n"); |
| 1806 | return -EIO; |
| 1807 | } |
| 1808 | phba->intr_mode = intr_mode; |
| 1809 | rc = lpfc_online(phba); |
| 1810 | if (rc == 0) |
| 1811 | lpfc_unblock_mgmt_io(phba); |
| 1812 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1813 | return rc; |
| 1814 | } |
| 1815 | |
| 1816 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1817 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1818 | * @phba: pointer to lpfc hba data structure. |
| 1819 | * |
| 1820 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1821 | * conditions. |
| 1822 | **/ |
| 1823 | static void |
| 1824 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1825 | { |
| 1826 | struct lpfc_vport *vport = phba->pport; |
| 1827 | uint32_t event_data; |
| 1828 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1829 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1830 | struct lpfc_register portstat_reg = {0}; |
| 1831 | uint32_t reg_err1, reg_err2; |
| 1832 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1833 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1834 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1835 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1836 | struct lpfc_register portsmphr_reg; |
| 1837 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1838 | |
| 1839 | /* If the pci channel is offline, ignore possible errors, since |
| 1840 | * we cannot communicate with the pci card anyway. |
| 1841 | */ |
| 1842 | if (pci_channel_offline(phba->pcidev)) |
| 1843 | return; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1844 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1845 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1846 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1847 | switch (if_type) { |
| 1848 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1849 | pci_rd_rc1 = lpfc_readl( |
| 1850 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1851 | &uerrlo_reg); |
| 1852 | pci_rd_rc2 = lpfc_readl( |
| 1853 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1854 | &uemasklo_reg); |
| 1855 | /* consider PCI bus read error as pci_channel_offline */ |
| 1856 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1857 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1858 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1859 | lpfc_sli4_offline_eratt(phba); |
| 1860 | return; |
| 1861 | } |
| 1862 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1863 | "7623 Checking UE recoverable"); |
| 1864 | |
| 1865 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1866 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1867 | &portsmphr_reg.word0)) |
| 1868 | continue; |
| 1869 | |
| 1870 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1871 | &portsmphr_reg); |
| 1872 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1873 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1874 | break; |
| 1875 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1876 | msleep(1000); |
| 1877 | } |
| 1878 | |
| 1879 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1880 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1881 | smphr_port_status, i); |
| 1882 | |
| 1883 | /* Recoverable UE, reset the HBA device */ |
| 1884 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1885 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1886 | for (i = 0; i < 20; i++) { |
| 1887 | msleep(1000); |
| 1888 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1889 | &portsmphr_reg.word0) && |
| 1890 | (LPFC_POST_STAGE_PORT_READY == |
| 1891 | bf_get(lpfc_port_smphr_port_status, |
| 1892 | &portsmphr_reg))) { |
| 1893 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 1894 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 1895 | if (rc == 0) |
| 1896 | return; |
| 1897 | lpfc_printf_log(phba, |
| 1898 | KERN_ERR, LOG_INIT, |
| 1899 | "4215 Failed to recover UE"); |
| 1900 | break; |
| 1901 | } |
| 1902 | } |
| 1903 | } |
| 1904 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1905 | "7624 Firmware not ready: Failing UE recovery," |
| 1906 | " waited %dSec", i); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1907 | lpfc_sli4_offline_eratt(phba); |
| 1908 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1909 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1910 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1911 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1912 | pci_rd_rc1 = lpfc_readl( |
| 1913 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1914 | &portstat_reg.word0); |
| 1915 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1916 | if (pci_rd_rc1 == -EIO) { |
| 1917 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1918 | "3151 PCI bus read access failure: x%x\n", |
| 1919 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1920 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1921 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1922 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1923 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1924 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1926 | "2889 Port Overtemperature event, " |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1927 | "taking port offline Data: x%x x%x\n", |
| 1928 | reg_err1, reg_err2); |
| 1929 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 1930 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1931 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1932 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1933 | temp_event_data.data = 0xFFFFFFFF; |
| 1934 | |
| 1935 | shost = lpfc_shost_from_vport(phba->pport); |
| 1936 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1937 | sizeof(temp_event_data), |
| 1938 | (char *)&temp_event_data, |
| 1939 | SCSI_NL_VID_TYPE_PCI |
| 1940 | | PCI_VENDOR_ID_EMULEX); |
| 1941 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1942 | spin_lock_irq(&phba->hbalock); |
| 1943 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1944 | spin_unlock_irq(&phba->hbalock); |
| 1945 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1946 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1947 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1948 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1949 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1950 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1951 | "3143 Port Down: Firmware Update " |
| 1952 | "Detected\n"); |
| 1953 | en_rn_msg = false; |
| 1954 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1955 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1956 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1957 | "3144 Port Down: Debug Dump\n"); |
| 1958 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1959 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
| 1960 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1961 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1962 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1963 | /* If resets are disabled then leave the HBA alone and return */ |
| 1964 | if (!phba->cfg_enable_hba_reset) |
| 1965 | return; |
| 1966 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1967 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1968 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 1969 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1970 | if (rc == 0) { |
| 1971 | /* don't report event on forced debug dump */ |
| 1972 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 1973 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 1974 | return; |
| 1975 | else |
| 1976 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1977 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1978 | /* fall through for not able to recover */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1979 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1980 | "3152 Unrecoverable error, bring the port " |
| 1981 | "offline\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1982 | lpfc_sli4_offline_eratt(phba); |
| 1983 | break; |
| 1984 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 1985 | default: |
| 1986 | break; |
| 1987 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1988 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1989 | "3123 Report dump event to upper layer\n"); |
| 1990 | /* Send an internal error event to mgmt application */ |
| 1991 | lpfc_board_errevt_to_mgmt(phba); |
| 1992 | |
| 1993 | event_data = FC_REG_DUMP_EVENT; |
| 1994 | shost = lpfc_shost_from_vport(vport); |
| 1995 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1996 | sizeof(event_data), (char *) &event_data, |
| 1997 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | /** |
| 2001 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 2002 | * @phba: pointer to lpfc HBA data structure. |
| 2003 | * |
| 2004 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 2005 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 2006 | * |
| 2007 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2008 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2009 | * Any other value - error. |
| 2010 | **/ |
| 2011 | void |
| 2012 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 2013 | { |
| 2014 | (*phba->lpfc_handle_eratt)(phba); |
| 2015 | } |
| 2016 | |
| 2017 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2018 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2019 | * @phba: pointer to lpfc hba data structure. |
| 2020 | * |
| 2021 | * 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] | 2022 | * attention link event. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2023 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2024 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2025 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2026 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2027 | struct lpfc_vport *vport = phba->pport; |
| 2028 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2029 | LPFC_MBOXQ_t *pmb; |
| 2030 | volatile uint32_t control; |
| 2031 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2032 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2033 | |
| 2034 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2035 | if (!pmb) { |
| 2036 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2037 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2038 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2039 | |
| 2040 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2041 | if (!mp) { |
| 2042 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2043 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2044 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2045 | |
| 2046 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2047 | if (!mp->virt) { |
| 2048 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2049 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2050 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2051 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 2052 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2053 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2054 | |
| 2055 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2056 | lpfc_read_topology(phba, pmb, mp); |
| 2057 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2058 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2059 | /* Block ELS IOCBs until we have processed this mbox command */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2060 | phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2061 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2062 | if (rc == MBX_NOT_FINISHED) { |
| 2063 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2064 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2065 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2066 | |
| 2067 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2068 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2069 | writel(HA_LATT, phba->HAregaddr); |
| 2070 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2071 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2072 | |
| 2073 | return; |
| 2074 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2075 | lpfc_handle_latt_free_mbuf: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2076 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2077 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2078 | lpfc_handle_latt_free_mp: |
| 2079 | kfree(mp); |
| 2080 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2081 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2082 | lpfc_handle_latt_err_exit: |
| 2083 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2084 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2085 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 2086 | control = readl(phba->HCregaddr); |
| 2087 | control |= HC_LAINT_ENA; |
| 2088 | writel(control, phba->HCregaddr); |
| 2089 | readl(phba->HCregaddr); /* flush */ |
| 2090 | |
| 2091 | /* Clear Link Attention in HA REG */ |
| 2092 | writel(HA_LATT, phba->HAregaddr); |
| 2093 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2094 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2096 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2097 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2098 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 2099 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2100 | |
| 2101 | return; |
| 2102 | } |
| 2103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2105 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2106 | * @phba: pointer to lpfc hba data structure. |
| 2107 | * @vpd: pointer to the vital product data. |
| 2108 | * @len: length of the vital product data in bytes. |
| 2109 | * |
| 2110 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 2111 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 2112 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 2113 | * |
| 2114 | * Return codes |
| 2115 | * 0 - pointer to the VPD passed in is NULL |
| 2116 | * 1 - success |
| 2117 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2118 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2119 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | { |
| 2121 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 2122 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2123 | int i, j; |
| 2124 | int finished = 0; |
| 2125 | int index = 0; |
| 2126 | |
| 2127 | if (!vpd) |
| 2128 | return 0; |
| 2129 | |
| 2130 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2131 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2132 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 2134 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2135 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2136 | switch (vpd[index]) { |
| 2137 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2138 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | index += 1; |
| 2140 | lenlo = vpd[index]; |
| 2141 | index += 1; |
| 2142 | lenhi = vpd[index]; |
| 2143 | index += 1; |
| 2144 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 2145 | index += i; |
| 2146 | break; |
| 2147 | case 0x90: |
| 2148 | index += 1; |
| 2149 | lenlo = vpd[index]; |
| 2150 | index += 1; |
| 2151 | lenhi = vpd[index]; |
| 2152 | index += 1; |
| 2153 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2154 | if (Length > len - index) |
| 2155 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2156 | while (Length > 0) { |
| 2157 | /* Look for Serial Number */ |
| 2158 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 2159 | index += 2; |
| 2160 | i = vpd[index]; |
| 2161 | index += 1; |
| 2162 | j = 0; |
| 2163 | Length -= (3+i); |
| 2164 | while(i--) { |
| 2165 | phba->SerialNumber[j++] = vpd[index++]; |
| 2166 | if (j == 31) |
| 2167 | break; |
| 2168 | } |
| 2169 | phba->SerialNumber[j] = 0; |
| 2170 | continue; |
| 2171 | } |
| 2172 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 2173 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 2174 | index += 2; |
| 2175 | i = vpd[index]; |
| 2176 | index += 1; |
| 2177 | j = 0; |
| 2178 | Length -= (3+i); |
| 2179 | while(i--) { |
| 2180 | phba->ModelDesc[j++] = vpd[index++]; |
| 2181 | if (j == 255) |
| 2182 | break; |
| 2183 | } |
| 2184 | phba->ModelDesc[j] = 0; |
| 2185 | continue; |
| 2186 | } |
| 2187 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 2188 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 2189 | index += 2; |
| 2190 | i = vpd[index]; |
| 2191 | index += 1; |
| 2192 | j = 0; |
| 2193 | Length -= (3+i); |
| 2194 | while(i--) { |
| 2195 | phba->ModelName[j++] = vpd[index++]; |
| 2196 | if (j == 79) |
| 2197 | break; |
| 2198 | } |
| 2199 | phba->ModelName[j] = 0; |
| 2200 | continue; |
| 2201 | } |
| 2202 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2203 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2204 | index += 2; |
| 2205 | i = vpd[index]; |
| 2206 | index += 1; |
| 2207 | j = 0; |
| 2208 | Length -= (3+i); |
| 2209 | while(i--) { |
| 2210 | phba->ProgramType[j++] = vpd[index++]; |
| 2211 | if (j == 255) |
| 2212 | break; |
| 2213 | } |
| 2214 | phba->ProgramType[j] = 0; |
| 2215 | continue; |
| 2216 | } |
| 2217 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2218 | phba->vpd_flag |= VPD_PORT; |
| 2219 | index += 2; |
| 2220 | i = vpd[index]; |
| 2221 | index += 1; |
| 2222 | j = 0; |
| 2223 | Length -= (3+i); |
| 2224 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2225 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2226 | (phba->sli4_hba.pport_name_sta == |
| 2227 | LPFC_SLI4_PPNAME_GET)) { |
| 2228 | j++; |
| 2229 | index++; |
| 2230 | } else |
| 2231 | phba->Port[j++] = vpd[index++]; |
| 2232 | if (j == 19) |
| 2233 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2234 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2235 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 2236 | (phba->sli4_hba.pport_name_sta == |
| 2237 | LPFC_SLI4_PPNAME_NON)) |
| 2238 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2239 | continue; |
| 2240 | } |
| 2241 | else { |
| 2242 | index += 2; |
| 2243 | i = vpd[index]; |
| 2244 | index += 1; |
| 2245 | index += i; |
| 2246 | Length -= (3 + i); |
| 2247 | } |
| 2248 | } |
| 2249 | finished = 0; |
| 2250 | break; |
| 2251 | case 0x78: |
| 2252 | finished = 1; |
| 2253 | break; |
| 2254 | default: |
| 2255 | index ++; |
| 2256 | break; |
| 2257 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2258 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2259 | |
| 2260 | return(1); |
| 2261 | } |
| 2262 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2263 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2264 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2265 | * @phba: pointer to lpfc hba data structure. |
| 2266 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2267 | * @descp: pointer to the data structure to hold the derived description. |
| 2268 | * |
| 2269 | * This routine retrieves HBA's description based on its registered PCI device |
| 2270 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2271 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2272 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2273 | * function returns, the @mdp will be filled with the model name. |
| 2274 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2275 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2276 | 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] | 2277 | { |
| 2278 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2279 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2280 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2281 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2282 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2283 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2284 | char *name; |
| 2285 | char *bus; |
| 2286 | char *function; |
| 2287 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2288 | |
| 2289 | if (mdp && mdp[0] != '\0' |
| 2290 | && descp && descp[0] != '\0') |
| 2291 | return; |
| 2292 | |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 2293 | if (phba->lmt & LMT_64Gb) |
| 2294 | max_speed = 64; |
| 2295 | else if (phba->lmt & LMT_32Gb) |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2296 | max_speed = 32; |
| 2297 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2298 | max_speed = 16; |
| 2299 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2300 | max_speed = 10; |
| 2301 | else if (phba->lmt & LMT_8Gb) |
| 2302 | max_speed = 8; |
| 2303 | else if (phba->lmt & LMT_4Gb) |
| 2304 | max_speed = 4; |
| 2305 | else if (phba->lmt & LMT_2Gb) |
| 2306 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2307 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2308 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2309 | else |
| 2310 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2311 | |
| 2312 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2313 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2314 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2315 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2316 | m = (typeof(m)){"LP6000", "PCI", |
| 2317 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2318 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2319 | case PCI_DEVICE_ID_SUPERFLY: |
| 2320 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2321 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2322 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2323 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2324 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | break; |
| 2326 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2327 | m = (typeof(m)){"LP8000", "PCI", |
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_CENTAUR: |
| 2331 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2332 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2333 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2334 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2335 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2336 | break; |
| 2337 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2338 | m = (typeof(m)){"LP952", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2339 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2340 | break; |
| 2341 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2342 | m = (typeof(m)){"LP9802", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2343 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2344 | break; |
| 2345 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2346 | m = (typeof(m)){"LP10000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2347 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2348 | break; |
| 2349 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2350 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2351 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | break; |
| 2353 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2354 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2355 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2356 | break; |
| 2357 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2358 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2359 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2360 | break; |
| 2361 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2362 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2363 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2364 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2365 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2366 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2367 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2368 | break; |
| 2369 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2370 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2371 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2372 | break; |
| 2373 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2374 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2375 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2376 | break; |
| 2377 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2378 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2379 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2380 | break; |
| 2381 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2382 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2383 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2384 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2385 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2386 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2387 | break; |
| 2388 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2389 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2390 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2391 | break; |
| 2392 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2393 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2394 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2395 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2396 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2397 | break; |
| 2398 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2399 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2400 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2401 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2403 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2404 | break; |
| 2405 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2406 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | break; |
| 2408 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2409 | m = (typeof(m)){"LP101", "PCI-X", |
| 2410 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2411 | break; |
| 2412 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2413 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2414 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2415 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2416 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2417 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2418 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2419 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2420 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2421 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2422 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2423 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2424 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2425 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2426 | break; |
| 2427 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2428 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2429 | break; |
| 2430 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2431 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2432 | break; |
| 2433 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2434 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2435 | break; |
| 2436 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2437 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2438 | break; |
| 2439 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2440 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2441 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2442 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2443 | m = (typeof(m)){"LP21000", "PCIe", |
| 2444 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2445 | GE = 1; |
| 2446 | break; |
| 2447 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2448 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2449 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2450 | break; |
| 2451 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2452 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2453 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2454 | break; |
| 2455 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2456 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2457 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2458 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2459 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2460 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2461 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2462 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2463 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2464 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2465 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2466 | break; |
| 2467 | case PCI_DEVICE_ID_FALCON: |
| 2468 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2469 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2470 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2471 | case PCI_DEVICE_ID_BALIUS: |
| 2472 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2473 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2474 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2475 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2476 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2477 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2478 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2479 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2480 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2481 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2482 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2483 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2484 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2485 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2486 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2487 | oneConnect = 1; |
| 2488 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2489 | "Obsolete, Unsupported FCoE"}; |
| 2490 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2491 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2492 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2493 | break; |
James Smart | c238b9b | 2018-02-22 08:18:44 -0800 | [diff] [blame] | 2494 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 2495 | m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"}; |
| 2496 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2497 | case PCI_DEVICE_ID_SKYHAWK: |
| 2498 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2499 | oneConnect = 1; |
| 2500 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2501 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2502 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2503 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2504 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2505 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2506 | |
| 2507 | if (mdp && mdp[0] == '\0') |
| 2508 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2509 | /* |
| 2510 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2511 | * and we put the port number on the end |
| 2512 | */ |
| 2513 | if (descp && descp[0] == '\0') { |
| 2514 | if (oneConnect) |
| 2515 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2516 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2517 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2518 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2519 | else if (max_speed == 0) |
| 2520 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2521 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2522 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2523 | else |
| 2524 | snprintf(descp, 255, |
| 2525 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2526 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2527 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2528 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2529 | } |
| 2530 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2531 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2532 | * 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] | 2533 | * @phba: pointer to lpfc hba data structure. |
| 2534 | * @pring: pointer to a IOCB ring. |
| 2535 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2536 | * |
| 2537 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2538 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2539 | * |
| 2540 | * Return codes |
| 2541 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2542 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2543 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2544 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2545 | { |
| 2546 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2547 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2548 | struct lpfc_dmabuf *mp1, *mp2; |
| 2549 | |
| 2550 | cnt += pring->missbufcnt; |
| 2551 | |
| 2552 | /* While there are buffers to post */ |
| 2553 | while (cnt > 0) { |
| 2554 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2555 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2556 | if (iocb == NULL) { |
| 2557 | pring->missbufcnt = cnt; |
| 2558 | return cnt; |
| 2559 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2560 | icmd = &iocb->iocb; |
| 2561 | |
| 2562 | /* 2 buffers can be posted per command */ |
| 2563 | /* Allocate buffer to post */ |
| 2564 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2565 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2566 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2567 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2568 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2569 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2570 | pring->missbufcnt = cnt; |
| 2571 | return cnt; |
| 2572 | } |
| 2573 | |
| 2574 | INIT_LIST_HEAD(&mp1->list); |
| 2575 | /* Allocate buffer to post */ |
| 2576 | if (cnt > 1) { |
| 2577 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2578 | if (mp2) |
| 2579 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2580 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2581 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2582 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2583 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2584 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2585 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2586 | pring->missbufcnt = cnt; |
| 2587 | return cnt; |
| 2588 | } |
| 2589 | |
| 2590 | INIT_LIST_HEAD(&mp2->list); |
| 2591 | } else { |
| 2592 | mp2 = NULL; |
| 2593 | } |
| 2594 | |
| 2595 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2596 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2597 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2598 | icmd->ulpBdeCount = 1; |
| 2599 | cnt--; |
| 2600 | if (mp2) { |
| 2601 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2602 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2603 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2604 | cnt--; |
| 2605 | icmd->ulpBdeCount = 2; |
| 2606 | } |
| 2607 | |
| 2608 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2609 | icmd->ulpLe = 1; |
| 2610 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2611 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2612 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2613 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2614 | kfree(mp1); |
| 2615 | cnt++; |
| 2616 | if (mp2) { |
| 2617 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2618 | kfree(mp2); |
| 2619 | cnt++; |
| 2620 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2621 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2622 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2623 | return cnt; |
| 2624 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2626 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2627 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2628 | } |
| 2629 | pring->missbufcnt = 0; |
| 2630 | return 0; |
| 2631 | } |
| 2632 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2633 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2634 | * 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] | 2635 | * @phba: pointer to lpfc hba data structure. |
| 2636 | * |
| 2637 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2638 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2639 | * set to 64 IOCBs. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2640 | * |
| 2641 | * Return codes |
| 2642 | * 0 - success (currently always success) |
| 2643 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2644 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2645 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2646 | { |
| 2647 | struct lpfc_sli *psli = &phba->sli; |
| 2648 | |
| 2649 | /* Ring 0, ELS / CT buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2650 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | /* Ring 2 - FCP no buffers needed */ |
| 2652 | |
| 2653 | return 0; |
| 2654 | } |
| 2655 | |
| 2656 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2657 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2658 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2659 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2660 | * @HashResultPointer: pointer to an array as hash table. |
| 2661 | * |
| 2662 | * This routine sets up the initial values to the array of hash table entries |
| 2663 | * for the LC HBAs. |
| 2664 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2665 | static void |
| 2666 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2667 | { |
| 2668 | HashResultPointer[0] = 0x67452301; |
| 2669 | HashResultPointer[1] = 0xEFCDAB89; |
| 2670 | HashResultPointer[2] = 0x98BADCFE; |
| 2671 | HashResultPointer[3] = 0x10325476; |
| 2672 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2673 | } |
| 2674 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2675 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2676 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2677 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2678 | * @HashWorkingPointer: pointer to an working hash table. |
| 2679 | * |
| 2680 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2681 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2682 | * The results are putting back to the initial hash table, returned through |
| 2683 | * the @HashResultPointer as the result hash table. |
| 2684 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2685 | static void |
| 2686 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2687 | { |
| 2688 | int t; |
| 2689 | uint32_t TEMP; |
| 2690 | uint32_t A, B, C, D, E; |
| 2691 | t = 16; |
| 2692 | do { |
| 2693 | HashWorkingPointer[t] = |
| 2694 | S(1, |
| 2695 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2696 | 8] ^ |
| 2697 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2698 | } while (++t <= 79); |
| 2699 | t = 0; |
| 2700 | A = HashResultPointer[0]; |
| 2701 | B = HashResultPointer[1]; |
| 2702 | C = HashResultPointer[2]; |
| 2703 | D = HashResultPointer[3]; |
| 2704 | E = HashResultPointer[4]; |
| 2705 | |
| 2706 | do { |
| 2707 | if (t < 20) { |
| 2708 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2709 | } else if (t < 40) { |
| 2710 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2711 | } else if (t < 60) { |
| 2712 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2713 | } else { |
| 2714 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2715 | } |
| 2716 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2717 | E = D; |
| 2718 | D = C; |
| 2719 | C = S(30, B); |
| 2720 | B = A; |
| 2721 | A = TEMP; |
| 2722 | } while (++t <= 79); |
| 2723 | |
| 2724 | HashResultPointer[0] += A; |
| 2725 | HashResultPointer[1] += B; |
| 2726 | HashResultPointer[2] += C; |
| 2727 | HashResultPointer[3] += D; |
| 2728 | HashResultPointer[4] += E; |
| 2729 | |
| 2730 | } |
| 2731 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2732 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2733 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2734 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2735 | * @HashWorking: pointer to the entry of the working hash array. |
| 2736 | * |
| 2737 | * This routine calculates the working hash array referred by @HashWorking |
| 2738 | * from the challenge random numbers associated with the host, referred by |
| 2739 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2740 | * array and returned by reference through @HashWorking. |
| 2741 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | static void |
| 2743 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2744 | { |
| 2745 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2746 | } |
| 2747 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2748 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2749 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2750 | * @phba: pointer to lpfc hba data structure. |
| 2751 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2752 | * |
| 2753 | * This routine performs the special handling for LC HBA initialization. |
| 2754 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2755 | void |
| 2756 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2757 | { |
| 2758 | int t; |
| 2759 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2760 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2761 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2762 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2763 | if (!HashWorking) |
| 2764 | return; |
| 2765 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2766 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2767 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2768 | |
| 2769 | for (t = 0; t < 7; t++) |
| 2770 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2771 | |
| 2772 | lpfc_sha_init(hbainit); |
| 2773 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2774 | kfree(HashWorking); |
| 2775 | } |
| 2776 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2777 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2778 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2779 | * @vport: pointer to a virtual N_Port data structure. |
| 2780 | * |
| 2781 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2782 | * It invokes the discovery state machine to perform necessary state |
| 2783 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2784 | * the physical port is treated as @vport 0. |
| 2785 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2786 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2787 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2788 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2789 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2790 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2791 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2792 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2793 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2794 | lpfc_port_link_failure(vport); |
| 2795 | |
| 2796 | 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] | 2797 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 2798 | ndlp = lpfc_enable_node(vport, ndlp, |
| 2799 | NLP_STE_UNUSED_NODE); |
| 2800 | if (!ndlp) |
| 2801 | continue; |
| 2802 | spin_lock_irq(&phba->ndlp_lock); |
| 2803 | NLP_SET_FREE_REQ(ndlp); |
| 2804 | spin_unlock_irq(&phba->ndlp_lock); |
| 2805 | /* Trigger the release of the ndlp memory */ |
| 2806 | lpfc_nlp_put(ndlp); |
| 2807 | continue; |
| 2808 | } |
| 2809 | spin_lock_irq(&phba->ndlp_lock); |
| 2810 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 2811 | /* The ndlp should not be in memory free mode already */ |
| 2812 | spin_unlock_irq(&phba->ndlp_lock); |
| 2813 | continue; |
| 2814 | } else |
| 2815 | /* Indicate request for freeing ndlp memory */ |
| 2816 | NLP_SET_FREE_REQ(ndlp); |
| 2817 | spin_unlock_irq(&phba->ndlp_lock); |
| 2818 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2819 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2820 | ndlp->nlp_DID == Fabric_DID) { |
| 2821 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2822 | lpfc_nlp_put(ndlp); |
| 2823 | continue; |
| 2824 | } |
| 2825 | |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2826 | /* take care of nodes in unused state before the state |
| 2827 | * machine taking action. |
| 2828 | */ |
| 2829 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
| 2830 | lpfc_nlp_put(ndlp); |
| 2831 | continue; |
| 2832 | } |
| 2833 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2834 | if (ndlp->nlp_type & NLP_FABRIC) |
| 2835 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2836 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2837 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2838 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2839 | NLP_EVT_DEVICE_RM); |
| 2840 | } |
| 2841 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2842 | /* At this point, ALL ndlp's should be gone |
| 2843 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2844 | * Lets wait for this to happen, if needed. |
| 2845 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2846 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2847 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2848 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2849 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2850 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2851 | &vport->fc_nodes, nlp_listp) { |
| 2852 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 2853 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2854 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2855 | "usgmap:x%x refcnt:%d\n", |
| 2856 | ndlp->nlp_DID, (void *)ndlp, |
| 2857 | ndlp->nlp_usg_map, |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 2858 | kref_read(&ndlp->kref)); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2859 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2860 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2861 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2862 | |
| 2863 | /* Wait for any activity on ndlps to settle */ |
| 2864 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2865 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2866 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2867 | } |
| 2868 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2869 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2870 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2871 | * @vport: pointer to a virtual N_Port data structure. |
| 2872 | * |
| 2873 | * This routine stops all the timers associated with a @vport. This function |
| 2874 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2875 | * port is treated as @vport 0. |
| 2876 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2877 | void |
| 2878 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2879 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2880 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2881 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2882 | lpfc_can_disctmo(vport); |
| 2883 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2884 | } |
| 2885 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2886 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2887 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2888 | * @phba: pointer to lpfc hba data structure. |
| 2889 | * |
| 2890 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2891 | * caller of this routine should already hold the host lock. |
| 2892 | **/ |
| 2893 | void |
| 2894 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2895 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2896 | /* Clear pending FCF rediscovery wait flag */ |
| 2897 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2898 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2899 | /* Now, try to stop the timer */ |
| 2900 | del_timer(&phba->fcf.redisc_wait); |
| 2901 | } |
| 2902 | |
| 2903 | /** |
| 2904 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2905 | * @phba: pointer to lpfc hba data structure. |
| 2906 | * |
| 2907 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2908 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2909 | * lock held before proceeding with disabling the timer and clearing the |
| 2910 | * wait timer pendig flag. |
| 2911 | **/ |
| 2912 | void |
| 2913 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2914 | { |
| 2915 | spin_lock_irq(&phba->hbalock); |
| 2916 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2917 | /* FCF rediscovery timer already fired or stopped */ |
| 2918 | spin_unlock_irq(&phba->hbalock); |
| 2919 | return; |
| 2920 | } |
| 2921 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2922 | /* Clear failover in progress flags */ |
| 2923 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2924 | spin_unlock_irq(&phba->hbalock); |
| 2925 | } |
| 2926 | |
| 2927 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2928 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2929 | * @phba: pointer to lpfc hba data structure. |
| 2930 | * |
| 2931 | * This routine stops all the timers associated with a HBA. This function is |
| 2932 | * invoked before either putting a HBA offline or unloading the driver. |
| 2933 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2934 | void |
| 2935 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2936 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2937 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2938 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2939 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2940 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2941 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2942 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2943 | del_timer_sync(&phba->rrq_tmr); |
| 2944 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2945 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2946 | phba->hb_outstanding = 0; |
| 2947 | |
| 2948 | switch (phba->pci_dev_grp) { |
| 2949 | case LPFC_PCI_DEV_LP: |
| 2950 | /* Stop any LightPulse device specific driver timers */ |
| 2951 | del_timer_sync(&phba->fcp_poll_timer); |
| 2952 | break; |
| 2953 | case LPFC_PCI_DEV_OC: |
| 2954 | /* Stop any OneConnect device sepcific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2955 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2956 | break; |
| 2957 | default: |
| 2958 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2959 | "0297 Invalid device group (x%x)\n", |
| 2960 | phba->pci_dev_grp); |
| 2961 | break; |
| 2962 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2963 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2964 | } |
| 2965 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2966 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2967 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2968 | * @phba: pointer to lpfc hba data structure. |
| 2969 | * |
| 2970 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 2971 | * management interface is marked as blocked, all the user space access to |
| 2972 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 2973 | * all be blocked. The HBA is set to block the management interface when the |
| 2974 | * driver prepares the HBA interface for online or offline. |
| 2975 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2976 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2977 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2978 | { |
| 2979 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2980 | uint8_t actcmd = MBX_HEARTBEAT; |
| 2981 | unsigned long timeout; |
| 2982 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2983 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 2984 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2985 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 2986 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 2987 | return; |
| 2988 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 2989 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2990 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 2991 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2992 | /* Determine how long we might wait for the active mailbox |
| 2993 | * command to be gracefully completed by firmware. |
| 2994 | */ |
| 2995 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 2996 | phba->sli.mbox_active) * 1000) + jiffies; |
| 2997 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 2998 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 2999 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3000 | /* Wait for the outstnading mailbox command to complete */ |
| 3001 | while (phba->sli.mbox_active) { |
| 3002 | /* Check active mailbox complete status every 2ms */ |
| 3003 | msleep(2); |
| 3004 | if (time_after(jiffies, timeout)) { |
| 3005 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3006 | "2813 Mgmt IO is Blocked %x " |
| 3007 | "- mbox cmd %x still active\n", |
| 3008 | phba->sli.sli_flag, actcmd); |
| 3009 | break; |
| 3010 | } |
| 3011 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3012 | } |
| 3013 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3014 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3015 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 3016 | * @phba: pointer to lpfc hba data structure. |
| 3017 | * |
| 3018 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 3019 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 3020 | * is to fixup the temporary rpi assignments. |
| 3021 | **/ |
| 3022 | void |
| 3023 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 3024 | { |
| 3025 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3026 | struct lpfc_vport **vports; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3027 | int i, rpi; |
| 3028 | unsigned long flags; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3029 | |
| 3030 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 3031 | return; |
| 3032 | |
| 3033 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3034 | if (vports == NULL) |
| 3035 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3036 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3037 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3038 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3039 | continue; |
| 3040 | |
| 3041 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3042 | &vports[i]->fc_nodes, |
| 3043 | nlp_listp) { |
| 3044 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3045 | continue; |
| 3046 | rpi = lpfc_sli4_alloc_rpi(phba); |
| 3047 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
| 3048 | spin_lock_irqsave(&phba->ndlp_lock, flags); |
| 3049 | NLP_CLR_NODE_ACT(ndlp); |
| 3050 | spin_unlock_irqrestore(&phba->ndlp_lock, flags); |
| 3051 | continue; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3052 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3053 | ndlp->nlp_rpi = rpi; |
| 3054 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, |
| 3055 | "0009 rpi:%x DID:%x " |
| 3056 | "flg:%x map:%x %p\n", ndlp->nlp_rpi, |
| 3057 | ndlp->nlp_DID, ndlp->nlp_flag, |
| 3058 | ndlp->nlp_usg_map, ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3059 | } |
| 3060 | } |
| 3061 | lpfc_destroy_vport_work_array(phba, vports); |
| 3062 | } |
| 3063 | |
| 3064 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3065 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3066 | * @phba: pointer to lpfc hba data structure. |
| 3067 | * |
| 3068 | * This routine initializes the HBA and brings a HBA online. During this |
| 3069 | * process, the management interface is blocked to prevent user space access |
| 3070 | * to the HBA interfering with the driver initialization. |
| 3071 | * |
| 3072 | * Return codes |
| 3073 | * 0 - successful |
| 3074 | * 1 - failed |
| 3075 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3076 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3077 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3078 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3079 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3080 | struct lpfc_vport **vports; |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3081 | int i, error = 0; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3082 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3083 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3084 | if (!phba) |
| 3085 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3086 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3087 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3088 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3089 | return 0; |
| 3090 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3091 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3092 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3093 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3094 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3095 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3096 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3097 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 3098 | lpfc_unblock_mgmt_io(phba); |
| 3099 | return 1; |
| 3100 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3101 | spin_lock_irq(&phba->hbalock); |
| 3102 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 3103 | vpis_cleared = true; |
| 3104 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3105 | |
| 3106 | /* Reestablish the local initiator port. |
| 3107 | * The offline process destroyed the previous lport. |
| 3108 | */ |
| 3109 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
| 3110 | !phba->nvmet_support) { |
| 3111 | error = lpfc_nvme_create_localport(phba->pport); |
| 3112 | if (error) |
| 3113 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3114 | "6132 NVME restore reg failed " |
| 3115 | "on nvmei error x%x\n", error); |
| 3116 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3117 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3118 | lpfc_sli_queue_init(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3119 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 3120 | lpfc_unblock_mgmt_io(phba); |
| 3121 | return 1; |
| 3122 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3123 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3124 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3125 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3126 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3127 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3128 | struct Scsi_Host *shost; |
| 3129 | shost = lpfc_shost_from_vport(vports[i]); |
| 3130 | spin_lock_irq(shost->host_lock); |
| 3131 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 3132 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3133 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3134 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3135 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3136 | if ((vpis_cleared) && |
| 3137 | (vports[i]->port_type != |
| 3138 | LPFC_PHYSICAL_PORT)) |
| 3139 | vports[i]->vpi = 0; |
| 3140 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3141 | spin_unlock_irq(shost->host_lock); |
| 3142 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3143 | } |
| 3144 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3145 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3146 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3147 | return 0; |
| 3148 | } |
| 3149 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3150 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3151 | * 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] | 3152 | * @phba: pointer to lpfc hba data structure. |
| 3153 | * |
| 3154 | * This routine marks a HBA's management interface as not blocked. Once the |
| 3155 | * HBA's management interface is marked as not blocked, all the user space |
| 3156 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 3157 | * interface will be allowed. The HBA is set to block the management interface |
| 3158 | * when the driver prepares the HBA interface for online or offline and then |
| 3159 | * set to unblock the management interface afterwards. |
| 3160 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3161 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3162 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 3163 | { |
| 3164 | unsigned long iflag; |
| 3165 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3166 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3167 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 3168 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3169 | } |
| 3170 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3171 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3172 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3173 | * @phba: pointer to lpfc hba data structure. |
| 3174 | * |
| 3175 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 3176 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 3177 | * queue to make it ready to be brought offline. |
| 3178 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3179 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3180 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3181 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3182 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3183 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3184 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3185 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3186 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3187 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3188 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3189 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3190 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3191 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | |
| 3193 | lpfc_linkdown(phba); |
| 3194 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3195 | /* Issue an unreg_login to all nodes on all vports */ |
| 3196 | vports = lpfc_create_vport_work_array(phba); |
| 3197 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3198 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3199 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3200 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3201 | shost = lpfc_shost_from_vport(vports[i]); |
| 3202 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3203 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3204 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 3205 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3206 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3207 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3208 | shost = lpfc_shost_from_vport(vports[i]); |
| 3209 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3210 | &vports[i]->fc_nodes, |
| 3211 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3212 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 3213 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3214 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 3215 | continue; |
| 3216 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3217 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3218 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 3219 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3220 | NULL, NLP_EVT_DEVICE_RM); |
| 3221 | } |
| 3222 | spin_lock_irq(shost->host_lock); |
| 3223 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3224 | spin_unlock_irq(shost->host_lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3225 | /* |
| 3226 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3227 | * RPI. Get a new RPI when the adapter port |
| 3228 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3229 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3230 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3231 | lpfc_printf_vlog(ndlp->vport, |
| 3232 | KERN_INFO, LOG_NODE, |
| 3233 | "0011 lpfc_offline: " |
| 3234 | "ndlp:x%p did %x " |
| 3235 | "usgmap:x%x rpi:%x\n", |
| 3236 | ndlp, ndlp->nlp_DID, |
| 3237 | ndlp->nlp_usg_map, |
| 3238 | ndlp->nlp_rpi); |
| 3239 | |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3240 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3241 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3242 | lpfc_unreg_rpi(vports[i], ndlp); |
| 3243 | } |
| 3244 | } |
| 3245 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3246 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3247 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3248 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 3249 | |
| 3250 | if (phba->wq) |
| 3251 | flush_workqueue(phba->wq); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3252 | } |
| 3253 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3254 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3255 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3256 | * @phba: pointer to lpfc hba data structure. |
| 3257 | * |
| 3258 | * This routine actually brings a HBA offline. It stops all the timers |
| 3259 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3260 | * marks the HBA as in offline state for the upper layer protocol. |
| 3261 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3262 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3263 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3264 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3265 | struct Scsi_Host *shost; |
| 3266 | struct lpfc_vport **vports; |
| 3267 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3268 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3269 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3270 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3271 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3272 | /* stop port and all timers associated with this hba */ |
| 3273 | lpfc_stop_port(phba); |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 3274 | |
| 3275 | /* Tear down the local and target port registrations. The |
| 3276 | * nvme transports need to cleanup. |
| 3277 | */ |
| 3278 | lpfc_nvmet_destroy_targetport(phba); |
| 3279 | lpfc_nvme_destroy_localport(phba->pport); |
| 3280 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3281 | vports = lpfc_create_vport_work_array(phba); |
| 3282 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3283 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3284 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3285 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3286 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3287 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3288 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3289 | now. */ |
| 3290 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3291 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3292 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3293 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3294 | vports = lpfc_create_vport_work_array(phba); |
| 3295 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3296 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3297 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3298 | spin_lock_irq(shost->host_lock); |
| 3299 | vports[i]->work_port_events = 0; |
| 3300 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3301 | spin_unlock_irq(shost->host_lock); |
| 3302 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3303 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3304 | } |
| 3305 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3306 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3307 | * 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] | 3308 | * @phba: pointer to lpfc hba data structure. |
| 3309 | * |
| 3310 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3311 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3312 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3313 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3314 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3315 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3316 | { |
| 3317 | struct lpfc_scsi_buf *sb, *sb_next; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3318 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3319 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3320 | return; |
| 3321 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3322 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3323 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3324 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3325 | |
| 3326 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3327 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3328 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3329 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3330 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3331 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3332 | kfree(sb); |
| 3333 | phba->total_scsi_bufs--; |
| 3334 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3335 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3336 | |
| 3337 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3338 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3339 | list) { |
| 3340 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3341 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3342 | sb->dma_handle); |
| 3343 | kfree(sb); |
| 3344 | phba->total_scsi_bufs--; |
| 3345 | } |
| 3346 | spin_unlock(&phba->scsi_buf_list_get_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3347 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3348 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3349 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3350 | * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists |
| 3351 | * @phba: pointer to lpfc hba data structure. |
| 3352 | * |
| 3353 | * This routine is to free all the NVME buffers and IOCBs from the driver |
| 3354 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3355 | * the internal resources before the device is removed from the system. |
| 3356 | **/ |
| 3357 | static void |
| 3358 | lpfc_nvme_free(struct lpfc_hba *phba) |
| 3359 | { |
| 3360 | struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3361 | |
| 3362 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) |
| 3363 | return; |
| 3364 | |
| 3365 | spin_lock_irq(&phba->hbalock); |
| 3366 | |
| 3367 | /* Release all the lpfc_nvme_bufs maintained by this host. */ |
| 3368 | spin_lock(&phba->nvme_buf_list_put_lock); |
| 3369 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3370 | &phba->lpfc_nvme_buf_list_put, list) { |
| 3371 | list_del(&lpfc_ncmd->list); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3372 | phba->put_nvme_bufs--; |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3373 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3374 | lpfc_ncmd->dma_handle); |
| 3375 | kfree(lpfc_ncmd); |
| 3376 | phba->total_nvme_bufs--; |
| 3377 | } |
| 3378 | spin_unlock(&phba->nvme_buf_list_put_lock); |
| 3379 | |
| 3380 | spin_lock(&phba->nvme_buf_list_get_lock); |
| 3381 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3382 | &phba->lpfc_nvme_buf_list_get, list) { |
| 3383 | list_del(&lpfc_ncmd->list); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3384 | phba->get_nvme_bufs--; |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3385 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3386 | lpfc_ncmd->dma_handle); |
| 3387 | kfree(lpfc_ncmd); |
| 3388 | phba->total_nvme_bufs--; |
| 3389 | } |
| 3390 | spin_unlock(&phba->nvme_buf_list_get_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3391 | spin_unlock_irq(&phba->hbalock); |
| 3392 | } |
| 3393 | /** |
| 3394 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3395 | * @phba: pointer to lpfc hba data structure. |
| 3396 | * |
| 3397 | * This routine first calculates the sizes of the current els and allocated |
| 3398 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3399 | * XRIs assigned due to port function reset. During port initialization, the |
| 3400 | * current els and allocated scsi sgl lists are 0s. |
| 3401 | * |
| 3402 | * Return codes |
| 3403 | * 0 - successful (for now, it always returns 0) |
| 3404 | **/ |
| 3405 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3406 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3407 | { |
| 3408 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3409 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3410 | LIST_HEAD(els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3411 | int rc; |
| 3412 | |
| 3413 | /* |
| 3414 | * update on pci function's els xri-sgl list |
| 3415 | */ |
| 3416 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3417 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3418 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3419 | /* els xri-sgl expanded */ |
| 3420 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3421 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3422 | "3157 ELS xri-sgl count increased from " |
| 3423 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3424 | els_xri_cnt); |
| 3425 | /* allocate the additional els sgls */ |
| 3426 | for (i = 0; i < xri_cnt; i++) { |
| 3427 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3428 | GFP_KERNEL); |
| 3429 | if (sglq_entry == NULL) { |
| 3430 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3431 | "2562 Failure to allocate an " |
| 3432 | "ELS sgl entry:%d\n", i); |
| 3433 | rc = -ENOMEM; |
| 3434 | goto out_free_mem; |
| 3435 | } |
| 3436 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3437 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3438 | &sglq_entry->phys); |
| 3439 | if (sglq_entry->virt == NULL) { |
| 3440 | kfree(sglq_entry); |
| 3441 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3442 | "2563 Failure to allocate an " |
| 3443 | "ELS mbuf:%d\n", i); |
| 3444 | rc = -ENOMEM; |
| 3445 | goto out_free_mem; |
| 3446 | } |
| 3447 | sglq_entry->sgl = sglq_entry->virt; |
| 3448 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3449 | sglq_entry->state = SGL_FREED; |
| 3450 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3451 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3452 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3453 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3454 | list_splice_init(&els_sgl_list, |
| 3455 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3456 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3457 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3458 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3459 | /* els xri-sgl shrinked */ |
| 3460 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3461 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3462 | "3158 ELS xri-sgl count decreased from " |
| 3463 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3464 | els_xri_cnt); |
| 3465 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3466 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3467 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, |
| 3468 | &els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3469 | /* release extra els sgls from list */ |
| 3470 | for (i = 0; i < xri_cnt; i++) { |
| 3471 | list_remove_head(&els_sgl_list, |
| 3472 | sglq_entry, struct lpfc_sglq, list); |
| 3473 | if (sglq_entry) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3474 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3475 | sglq_entry->phys); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3476 | kfree(sglq_entry); |
| 3477 | } |
| 3478 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3479 | list_splice_init(&els_sgl_list, |
| 3480 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3481 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3482 | spin_unlock_irq(&phba->hbalock); |
| 3483 | } else |
| 3484 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3485 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3486 | els_xri_cnt); |
| 3487 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3488 | |
| 3489 | /* update xris to els sgls on the list */ |
| 3490 | sglq_entry = NULL; |
| 3491 | sglq_entry_next = NULL; |
| 3492 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3493 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3494 | lxri = lpfc_sli4_next_xritag(phba); |
| 3495 | if (lxri == NO_XRI) { |
| 3496 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3497 | "2400 Failed to allocate xri for " |
| 3498 | "ELS sgl\n"); |
| 3499 | rc = -ENOMEM; |
| 3500 | goto out_free_mem; |
| 3501 | } |
| 3502 | sglq_entry->sli4_lxritag = lxri; |
| 3503 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3504 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3505 | return 0; |
| 3506 | |
| 3507 | out_free_mem: |
| 3508 | lpfc_free_els_sgl_list(phba); |
| 3509 | return rc; |
| 3510 | } |
| 3511 | |
| 3512 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3513 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping |
| 3514 | * @phba: pointer to lpfc hba data structure. |
| 3515 | * |
| 3516 | * This routine first calculates the sizes of the current els and allocated |
| 3517 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3518 | * XRIs assigned due to port function reset. During port initialization, the |
| 3519 | * current els and allocated scsi sgl lists are 0s. |
| 3520 | * |
| 3521 | * Return codes |
| 3522 | * 0 - successful (for now, it always returns 0) |
| 3523 | **/ |
| 3524 | int |
| 3525 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) |
| 3526 | { |
| 3527 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3528 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3529 | uint16_t nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3530 | LIST_HEAD(nvmet_sgl_list); |
| 3531 | int rc; |
| 3532 | |
| 3533 | /* |
| 3534 | * update on pci function's nvmet xri-sgl list |
| 3535 | */ |
| 3536 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 3537 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3538 | /* For NVMET, ALL remaining XRIs are dedicated for IO processing */ |
| 3539 | 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] | 3540 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { |
| 3541 | /* els xri-sgl expanded */ |
| 3542 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; |
| 3543 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3544 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", |
| 3545 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); |
| 3546 | /* allocate the additional nvmet sgls */ |
| 3547 | for (i = 0; i < xri_cnt; i++) { |
| 3548 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3549 | GFP_KERNEL); |
| 3550 | if (sglq_entry == NULL) { |
| 3551 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3552 | "6303 Failure to allocate an " |
| 3553 | "NVMET sgl entry:%d\n", i); |
| 3554 | rc = -ENOMEM; |
| 3555 | goto out_free_mem; |
| 3556 | } |
| 3557 | sglq_entry->buff_type = NVMET_BUFF_TYPE; |
| 3558 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, |
| 3559 | &sglq_entry->phys); |
| 3560 | if (sglq_entry->virt == NULL) { |
| 3561 | kfree(sglq_entry); |
| 3562 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3563 | "6304 Failure to allocate an " |
| 3564 | "NVMET buf:%d\n", i); |
| 3565 | rc = -ENOMEM; |
| 3566 | goto out_free_mem; |
| 3567 | } |
| 3568 | sglq_entry->sgl = sglq_entry->virt; |
| 3569 | memset(sglq_entry->sgl, 0, |
| 3570 | phba->cfg_sg_dma_buf_size); |
| 3571 | sglq_entry->state = SGL_FREED; |
| 3572 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); |
| 3573 | } |
| 3574 | spin_lock_irq(&phba->hbalock); |
| 3575 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3576 | list_splice_init(&nvmet_sgl_list, |
| 3577 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3578 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3579 | spin_unlock_irq(&phba->hbalock); |
| 3580 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { |
| 3581 | /* nvmet xri-sgl shrunk */ |
| 3582 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; |
| 3583 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3584 | "6305 NVMET xri-sgl count decreased from " |
| 3585 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, |
| 3586 | nvmet_xri_cnt); |
| 3587 | spin_lock_irq(&phba->hbalock); |
| 3588 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3589 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 3590 | &nvmet_sgl_list); |
| 3591 | /* release extra nvmet sgls from list */ |
| 3592 | for (i = 0; i < xri_cnt; i++) { |
| 3593 | list_remove_head(&nvmet_sgl_list, |
| 3594 | sglq_entry, struct lpfc_sglq, list); |
| 3595 | if (sglq_entry) { |
| 3596 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, |
| 3597 | sglq_entry->phys); |
| 3598 | kfree(sglq_entry); |
| 3599 | } |
| 3600 | } |
| 3601 | list_splice_init(&nvmet_sgl_list, |
| 3602 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3603 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3604 | spin_unlock_irq(&phba->hbalock); |
| 3605 | } else |
| 3606 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3607 | "6306 NVMET xri-sgl count unchanged: %d\n", |
| 3608 | nvmet_xri_cnt); |
| 3609 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; |
| 3610 | |
| 3611 | /* update xris to nvmet sgls on the list */ |
| 3612 | sglq_entry = NULL; |
| 3613 | sglq_entry_next = NULL; |
| 3614 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3615 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { |
| 3616 | lxri = lpfc_sli4_next_xritag(phba); |
| 3617 | if (lxri == NO_XRI) { |
| 3618 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3619 | "6307 Failed to allocate xri for " |
| 3620 | "NVMET sgl\n"); |
| 3621 | rc = -ENOMEM; |
| 3622 | goto out_free_mem; |
| 3623 | } |
| 3624 | sglq_entry->sli4_lxritag = lxri; |
| 3625 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3626 | } |
| 3627 | return 0; |
| 3628 | |
| 3629 | out_free_mem: |
| 3630 | lpfc_free_nvmet_sgl_list(phba); |
| 3631 | return rc; |
| 3632 | } |
| 3633 | |
| 3634 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3635 | * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping |
| 3636 | * @phba: pointer to lpfc hba data structure. |
| 3637 | * |
| 3638 | * This routine first calculates the sizes of the current els and allocated |
| 3639 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3640 | * XRIs assigned due to port function reset. During port initialization, the |
| 3641 | * current els and allocated scsi sgl lists are 0s. |
| 3642 | * |
| 3643 | * Return codes |
| 3644 | * 0 - successful (for now, it always returns 0) |
| 3645 | **/ |
| 3646 | int |
| 3647 | lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba) |
| 3648 | { |
| 3649 | struct lpfc_scsi_buf *psb, *psb_next; |
| 3650 | uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt; |
| 3651 | LIST_HEAD(scsi_sgl_list); |
| 3652 | int rc; |
| 3653 | |
| 3654 | /* |
| 3655 | * update on pci function's els xri-sgl list |
| 3656 | */ |
| 3657 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 3658 | phba->total_scsi_bufs = 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3659 | |
| 3660 | /* |
| 3661 | * update on pci function's allocated scsi xri-sgl list |
| 3662 | */ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3663 | /* maximum number of xris available for scsi buffers */ |
| 3664 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - |
| 3665 | els_xri_cnt; |
| 3666 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3667 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3668 | return 0; |
| 3669 | |
| 3670 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3671 | phba->sli4_hba.scsi_xri_max = /* Split them up */ |
| 3672 | (phba->sli4_hba.scsi_xri_max * |
| 3673 | phba->cfg_xri_split) / 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3674 | |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3675 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3676 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3677 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list); |
| 3678 | list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3679 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3680 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3681 | |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 3682 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3683 | "6060 Current allocated SCSI xri-sgl count:%d, " |
| 3684 | "maximum SCSI xri count:%d (split:%d)\n", |
| 3685 | phba->sli4_hba.scsi_xri_cnt, |
| 3686 | phba->sli4_hba.scsi_xri_max, phba->cfg_xri_split); |
| 3687 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3688 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { |
| 3689 | /* max scsi xri shrinked below the allocated scsi buffers */ |
| 3690 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - |
| 3691 | phba->sli4_hba.scsi_xri_max; |
| 3692 | /* release the extra allocated scsi buffers */ |
| 3693 | for (i = 0; i < scsi_xri_cnt; i++) { |
| 3694 | list_remove_head(&scsi_sgl_list, psb, |
| 3695 | struct lpfc_scsi_buf, list); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 3696 | if (psb) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3697 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 3698 | psb->data, psb->dma_handle); |
| 3699 | kfree(psb); |
| 3700 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3701 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3702 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3703 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3704 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3705 | } |
| 3706 | |
| 3707 | /* update xris associated to remaining allocated scsi buffers */ |
| 3708 | psb = NULL; |
| 3709 | psb_next = NULL; |
| 3710 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { |
| 3711 | lxri = lpfc_sli4_next_xritag(phba); |
| 3712 | if (lxri == NO_XRI) { |
| 3713 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3714 | "2560 Failed to allocate xri for " |
| 3715 | "scsi buffer\n"); |
| 3716 | rc = -ENOMEM; |
| 3717 | goto out_free_mem; |
| 3718 | } |
| 3719 | psb->cur_iocbq.sli4_lxritag = lxri; |
| 3720 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3721 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3722 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3723 | spin_lock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3724 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get); |
| 3725 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 164cecd | 2013-09-06 12:22:38 -0400 | [diff] [blame] | 3726 | spin_unlock(&phba->scsi_buf_list_put_lock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3727 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3728 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3729 | |
| 3730 | out_free_mem: |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3731 | lpfc_scsi_free(phba); |
| 3732 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3733 | } |
| 3734 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3735 | static uint64_t |
| 3736 | lpfc_get_wwpn(struct lpfc_hba *phba) |
| 3737 | { |
| 3738 | uint64_t wwn; |
| 3739 | int rc; |
| 3740 | LPFC_MBOXQ_t *mboxq; |
| 3741 | MAILBOX_t *mb; |
| 3742 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3743 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 3744 | GFP_KERNEL); |
| 3745 | if (!mboxq) |
| 3746 | return (uint64_t)-1; |
| 3747 | |
| 3748 | /* First get WWN of HBA instance */ |
| 3749 | lpfc_read_nv(phba, mboxq); |
| 3750 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 3751 | if (rc != MBX_SUCCESS) { |
| 3752 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3753 | "6019 Mailbox failed , mbxCmd x%x " |
| 3754 | "READ_NV, mbxStatus x%x\n", |
| 3755 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 3756 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 3757 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 3758 | return (uint64_t) -1; |
| 3759 | } |
| 3760 | mb = &mboxq->u.mb; |
| 3761 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t)); |
| 3762 | /* wwn is WWPN of HBA instance */ |
| 3763 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 3764 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 3765 | return be64_to_cpu(wwn); |
| 3766 | else |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 3767 | return rol64(wwn, 32); |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3768 | } |
| 3769 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3770 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3771 | * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping |
| 3772 | * @phba: pointer to lpfc hba data structure. |
| 3773 | * |
| 3774 | * This routine first calculates the sizes of the current els and allocated |
| 3775 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3776 | * XRIs assigned due to port function reset. During port initialization, the |
| 3777 | * current els and allocated scsi sgl lists are 0s. |
| 3778 | * |
| 3779 | * Return codes |
| 3780 | * 0 - successful (for now, it always returns 0) |
| 3781 | **/ |
| 3782 | int |
| 3783 | lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba) |
| 3784 | { |
| 3785 | struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; |
| 3786 | uint16_t i, lxri, els_xri_cnt; |
| 3787 | uint16_t nvme_xri_cnt, nvme_xri_max; |
| 3788 | LIST_HEAD(nvme_sgl_list); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3789 | int rc, cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3790 | |
| 3791 | phba->total_nvme_bufs = 0; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3792 | phba->get_nvme_bufs = 0; |
| 3793 | phba->put_nvme_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3794 | |
| 3795 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) |
| 3796 | return 0; |
| 3797 | /* |
| 3798 | * update on pci function's allocated nvme xri-sgl list |
| 3799 | */ |
| 3800 | |
| 3801 | /* maximum number of xris available for nvme buffers */ |
| 3802 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
| 3803 | nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 3804 | phba->sli4_hba.nvme_xri_max = nvme_xri_max; |
| 3805 | phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max; |
| 3806 | |
| 3807 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3808 | "6074 Current allocated NVME xri-sgl count:%d, " |
| 3809 | "maximum NVME xri count:%d\n", |
| 3810 | phba->sli4_hba.nvme_xri_cnt, |
| 3811 | phba->sli4_hba.nvme_xri_max); |
| 3812 | |
| 3813 | spin_lock_irq(&phba->nvme_buf_list_get_lock); |
| 3814 | spin_lock(&phba->nvme_buf_list_put_lock); |
| 3815 | list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list); |
| 3816 | list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3817 | cnt = phba->get_nvme_bufs + phba->put_nvme_bufs; |
| 3818 | phba->get_nvme_bufs = 0; |
| 3819 | phba->put_nvme_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3820 | spin_unlock(&phba->nvme_buf_list_put_lock); |
| 3821 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); |
| 3822 | |
| 3823 | if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) { |
| 3824 | /* max nvme xri shrunk below the allocated nvme buffers */ |
| 3825 | spin_lock_irq(&phba->nvme_buf_list_get_lock); |
| 3826 | nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt - |
| 3827 | phba->sli4_hba.nvme_xri_max; |
| 3828 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); |
| 3829 | /* release the extra allocated nvme buffers */ |
| 3830 | for (i = 0; i < nvme_xri_cnt; i++) { |
| 3831 | list_remove_head(&nvme_sgl_list, lpfc_ncmd, |
| 3832 | struct lpfc_nvme_buf, list); |
| 3833 | if (lpfc_ncmd) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3834 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3835 | lpfc_ncmd->data, |
| 3836 | lpfc_ncmd->dma_handle); |
| 3837 | kfree(lpfc_ncmd); |
| 3838 | } |
| 3839 | } |
| 3840 | spin_lock_irq(&phba->nvme_buf_list_get_lock); |
| 3841 | phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt; |
| 3842 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); |
| 3843 | } |
| 3844 | |
| 3845 | /* update xris associated to remaining allocated nvme buffers */ |
| 3846 | lpfc_ncmd = NULL; |
| 3847 | lpfc_ncmd_next = NULL; |
| 3848 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3849 | &nvme_sgl_list, list) { |
| 3850 | lxri = lpfc_sli4_next_xritag(phba); |
| 3851 | if (lxri == NO_XRI) { |
| 3852 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3853 | "6075 Failed to allocate xri for " |
| 3854 | "nvme buffer\n"); |
| 3855 | rc = -ENOMEM; |
| 3856 | goto out_free_mem; |
| 3857 | } |
| 3858 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; |
| 3859 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3860 | } |
| 3861 | spin_lock_irq(&phba->nvme_buf_list_get_lock); |
| 3862 | spin_lock(&phba->nvme_buf_list_put_lock); |
| 3863 | list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 3864 | phba->get_nvme_bufs = cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3865 | INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put); |
| 3866 | spin_unlock(&phba->nvme_buf_list_put_lock); |
| 3867 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); |
| 3868 | return 0; |
| 3869 | |
| 3870 | out_free_mem: |
| 3871 | lpfc_nvme_free(phba); |
| 3872 | return rc; |
| 3873 | } |
| 3874 | |
| 3875 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3876 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3877 | * @phba: pointer to lpfc hba data structure. |
| 3878 | * @instance: a unique integer ID to this FC port. |
| 3879 | * @dev: pointer to the device data structure. |
| 3880 | * |
| 3881 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 3882 | * can be created on top of either a physical port or a virtual port provided |
| 3883 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 3884 | * and associates the FC port created before adding the shost into the SCSI |
| 3885 | * layer. |
| 3886 | * |
| 3887 | * Return codes |
| 3888 | * @vport - pointer to the virtual N_Port data structure. |
| 3889 | * NULL - port create failed. |
| 3890 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3891 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3892 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3893 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3894 | struct lpfc_vport *vport; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3895 | struct Scsi_Host *shost = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3896 | int error = 0; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3897 | int i; |
| 3898 | uint64_t wwn; |
| 3899 | bool use_no_reset_hba = false; |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 3900 | int rc; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3901 | |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 3902 | if (lpfc_no_hba_reset_cnt) { |
| 3903 | if (phba->sli_rev < LPFC_SLI_REV4 && |
| 3904 | dev == &phba->pcidev->dev) { |
| 3905 | /* Reset the port first */ |
| 3906 | lpfc_sli_brdrestart(phba); |
| 3907 | rc = lpfc_sli_chipset_init(phba); |
| 3908 | if (rc) |
| 3909 | return NULL; |
| 3910 | } |
| 3911 | wwn = lpfc_get_wwpn(phba); |
| 3912 | } |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3913 | |
| 3914 | for (i = 0; i < lpfc_no_hba_reset_cnt; i++) { |
| 3915 | if (wwn == lpfc_no_hba_reset[i]) { |
| 3916 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 3917 | "6020 Setting use_no_reset port=%llx\n", |
| 3918 | wwn); |
| 3919 | use_no_reset_hba = true; |
| 3920 | break; |
| 3921 | } |
| 3922 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3923 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3924 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 3925 | if (dev != &phba->pcidev->dev) { |
| 3926 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 3927 | sizeof(struct lpfc_vport)); |
| 3928 | } else { |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3929 | if (!use_no_reset_hba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3930 | shost = scsi_host_alloc(&lpfc_template, |
| 3931 | sizeof(struct lpfc_vport)); |
| 3932 | else |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 3933 | shost = scsi_host_alloc(&lpfc_template_no_hr, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3934 | sizeof(struct lpfc_vport)); |
| 3935 | } |
| 3936 | } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 3937 | shost = scsi_host_alloc(&lpfc_template_nvme, |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 3938 | sizeof(struct lpfc_vport)); |
| 3939 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3940 | if (!shost) |
| 3941 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3942 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3943 | vport = (struct lpfc_vport *) shost->hostdata; |
| 3944 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3945 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3946 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 3947 | vport->fc_rscn_flush = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3948 | lpfc_get_vport_cfgparam(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3949 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3950 | shost->unique_id = instance; |
| 3951 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3952 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3953 | shost->this_id = -1; |
| 3954 | shost->max_cmd_len = 16; |
James Smart | 8b0dff1 | 2015-05-22 10:42:38 -0400 | [diff] [blame] | 3955 | shost->nr_hw_queues = phba->cfg_fcp_io_channel; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3956 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 3957 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 3958 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3959 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 3960 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 3961 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3962 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3963 | * Set initial can_queue value since 0 is no longer supported and |
| 3964 | * scsi_add_host will fail. This will be adjusted later based on the |
| 3965 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3966 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3967 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 3968 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3969 | shost->transportt = lpfc_vport_transport_template; |
| 3970 | vport->port_type = LPFC_NPIV_PORT; |
| 3971 | } else { |
| 3972 | shost->transportt = lpfc_transport_template; |
| 3973 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 3974 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3975 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3976 | /* Initialize all internally managed lists. */ |
| 3977 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3978 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3979 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3980 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3981 | timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3982 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3983 | timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3984 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 3985 | timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 3986 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 3987 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3988 | if (error) |
| 3989 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3990 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3991 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3992 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3993 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3994 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 3995 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3996 | out_put_shost: |
| 3997 | scsi_host_put(shost); |
| 3998 | out: |
| 3999 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4000 | } |
| 4001 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4002 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4003 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4004 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 4005 | * |
| 4006 | * This routine destroys a FC port from the upper layer protocol. All the |
| 4007 | * resources associated with the port are released. |
| 4008 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4009 | void |
| 4010 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4011 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4012 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4013 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4014 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4015 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4016 | fc_remove_host(shost); |
| 4017 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4018 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4019 | spin_lock_irq(&phba->hbalock); |
| 4020 | list_del_init(&vport->listentry); |
| 4021 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4022 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4023 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4024 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4025 | } |
| 4026 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4027 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4028 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4029 | * |
| 4030 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 4031 | * uses the kernel idr facility to perform the task. |
| 4032 | * |
| 4033 | * Return codes: |
| 4034 | * instance - a unique integer ID allocated as the new instance. |
| 4035 | * -1 - lpfc get instance failed. |
| 4036 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4037 | int |
| 4038 | lpfc_get_instance(void) |
| 4039 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4040 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4041 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4042 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 4043 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4044 | } |
| 4045 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4046 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4047 | * 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] | 4048 | * @shost: pointer to SCSI host data structure. |
| 4049 | * @time: elapsed time of the scan in jiffies. |
| 4050 | * |
| 4051 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 4052 | * whether the scan host is finished. |
| 4053 | * |
| 4054 | * Note: there is no scan_start function as adapter initialization will have |
| 4055 | * asynchronously kicked off the link initialization. |
| 4056 | * |
| 4057 | * Return codes |
| 4058 | * 0 - SCSI host scan is not over yet. |
| 4059 | * 1 - SCSI host scan is over. |
| 4060 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4061 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 4062 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4063 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4064 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4065 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4066 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4067 | spin_lock_irq(shost->host_lock); |
| 4068 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4069 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4070 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4071 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4072 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4073 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4074 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4075 | "0461 Scanning longer than 30 " |
| 4076 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4077 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4078 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4079 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4080 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 4081 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4082 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4083 | "0465 Link down longer than 15 " |
| 4084 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4085 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4086 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4087 | } |
| 4088 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4089 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4090 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4091 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4092 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4093 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4094 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4095 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4096 | goto finished; |
| 4097 | |
| 4098 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4099 | |
| 4100 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4101 | spin_unlock_irq(shost->host_lock); |
| 4102 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4103 | } |
| 4104 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4105 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4106 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4107 | * @shost: pointer to SCSI host data structure. |
| 4108 | * |
| 4109 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 4110 | * SCSI host can be either on top of a physical port or a virtual port. |
| 4111 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4112 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 4113 | { |
| 4114 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4115 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4116 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4117 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4118 | */ |
| 4119 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4120 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 4121 | 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] | 4122 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 4123 | |
| 4124 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4125 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4126 | fc_host_supported_fc4s(shost)[2] = 1; |
| 4127 | fc_host_supported_fc4s(shost)[7] = 1; |
| 4128 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4129 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 4130 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4131 | |
| 4132 | fc_host_supported_speeds(shost) = 0; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 4133 | if (phba->lmt & LMT_64Gb) |
| 4134 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4135 | if (phba->lmt & LMT_32Gb) |
| 4136 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 4137 | if (phba->lmt & LMT_16Gb) |
| 4138 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4139 | if (phba->lmt & LMT_10Gb) |
| 4140 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 4141 | if (phba->lmt & LMT_8Gb) |
| 4142 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4143 | if (phba->lmt & LMT_4Gb) |
| 4144 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 4145 | if (phba->lmt & LMT_2Gb) |
| 4146 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 4147 | if (phba->lmt & LMT_1Gb) |
| 4148 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 4149 | |
| 4150 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4151 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 4152 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4153 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 4154 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 4155 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4156 | /* This value is also unchanging */ |
| 4157 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4158 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4159 | fc_host_active_fc4s(shost)[2] = 1; |
| 4160 | fc_host_active_fc4s(shost)[7] = 1; |
| 4161 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4162 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4163 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4164 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4165 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4166 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4167 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4168 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4169 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4170 | * @phba: pointer to lpfc hba data structure. |
| 4171 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4172 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 4173 | * from generating interrupts and stops the device driver's timers for the |
| 4174 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4175 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4176 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4177 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4178 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4179 | /* Clear all interrupt enable conditions */ |
| 4180 | writel(0, phba->HCregaddr); |
| 4181 | readl(phba->HCregaddr); /* flush */ |
| 4182 | /* Clear all pending interrupts */ |
| 4183 | writel(0xffffffff, phba->HAregaddr); |
| 4184 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4185 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4186 | /* Reset some HBA SLI setup states */ |
| 4187 | lpfc_stop_hba_timers(phba); |
| 4188 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4189 | } |
| 4190 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4191 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4192 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4193 | * @phba: pointer to lpfc hba data structure. |
| 4194 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4195 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 4196 | * from generating interrupts and stops the device driver's timers for the |
| 4197 | * device. |
| 4198 | **/ |
| 4199 | static void |
| 4200 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 4201 | { |
| 4202 | /* Reset some HBA SLI4 setup states */ |
| 4203 | lpfc_stop_hba_timers(phba); |
| 4204 | phba->pport->work_port_events = 0; |
| 4205 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | /** |
| 4209 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 4210 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4211 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4212 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 4213 | * the API jump table function pointer from the lpfc_hba struct. |
| 4214 | **/ |
| 4215 | void |
| 4216 | lpfc_stop_port(struct lpfc_hba *phba) |
| 4217 | { |
| 4218 | phba->lpfc_stop_port(phba); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 4219 | |
| 4220 | if (phba->wq) |
| 4221 | flush_workqueue(phba->wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4225 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 4226 | * @phba: Pointer to hba for which this call is being executed. |
| 4227 | * |
| 4228 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 4229 | **/ |
| 4230 | void |
| 4231 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 4232 | { |
| 4233 | unsigned long fcf_redisc_wait_tmo = |
| 4234 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 4235 | /* Start fcf rediscovery wait period timer */ |
| 4236 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 4237 | spin_lock_irq(&phba->hbalock); |
| 4238 | /* Allow action to new fcf asynchronous event */ |
| 4239 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 4240 | /* Mark the FCF rediscovery pending state */ |
| 4241 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 4242 | spin_unlock_irq(&phba->hbalock); |
| 4243 | } |
| 4244 | |
| 4245 | /** |
| 4246 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
| 4247 | * @ptr: Map to lpfc_hba data structure pointer. |
| 4248 | * |
| 4249 | * This routine is invoked when waiting for FCF table rediscover has been |
| 4250 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 4251 | * wait period, a new FCF event shall be added to the FCOE async event |
| 4252 | * list, and then worker thread shall be waked up for processing from the |
| 4253 | * worker thread context. |
| 4254 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 4255 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4256 | lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4257 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4258 | struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4259 | |
| 4260 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 4261 | spin_lock_irq(&phba->hbalock); |
| 4262 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 4263 | spin_unlock_irq(&phba->hbalock); |
| 4264 | return; |
| 4265 | } |
| 4266 | /* Clear FCF rediscovery timer pending flag */ |
| 4267 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 4268 | /* FCF rediscovery event to worker thread */ |
| 4269 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 4270 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4271 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4272 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4273 | /* wake up worker thread */ |
| 4274 | lpfc_worker_wake_up(phba); |
| 4275 | } |
| 4276 | |
| 4277 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4278 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 4279 | * @phba: pointer to lpfc hba data structure. |
| 4280 | * @acqe_link: pointer to the async link completion queue entry. |
| 4281 | * |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4282 | * This routine is to parse the SLI4 link-attention link fault code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4283 | **/ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4284 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4285 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 4286 | struct lpfc_acqe_link *acqe_link) |
| 4287 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4288 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 4289 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 4290 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 4291 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4292 | case LPFC_ASYNC_LINK_FAULT_LR_LRR: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4293 | break; |
| 4294 | default: |
| 4295 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4296 | "0398 Unknown link fault code: x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4297 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4298 | break; |
| 4299 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | /** |
| 4303 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 4304 | * @phba: pointer to lpfc hba data structure. |
| 4305 | * @acqe_link: pointer to the async link completion queue entry. |
| 4306 | * |
| 4307 | * This routine is to parse the SLI4 link attention type and translate it |
| 4308 | * into the base driver's link attention type coding. |
| 4309 | * |
| 4310 | * Return: Link attention type in terms of base driver's coding. |
| 4311 | **/ |
| 4312 | static uint8_t |
| 4313 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 4314 | struct lpfc_acqe_link *acqe_link) |
| 4315 | { |
| 4316 | uint8_t att_type; |
| 4317 | |
| 4318 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 4319 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 4320 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4321 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4322 | break; |
| 4323 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 4324 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4325 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4326 | break; |
| 4327 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4328 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4329 | break; |
| 4330 | default: |
| 4331 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 4332 | "0399 Invalid link attention type: x%x\n", |
| 4333 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4334 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4335 | break; |
| 4336 | } |
| 4337 | return att_type; |
| 4338 | } |
| 4339 | |
| 4340 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4341 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 4342 | * @phba: pointer to lpfc hba data structure. |
| 4343 | * |
| 4344 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 4345 | * |
| 4346 | * Return: link speed in terms of Mbps. |
| 4347 | **/ |
| 4348 | uint32_t |
| 4349 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 4350 | { |
| 4351 | uint32_t link_speed; |
| 4352 | |
| 4353 | if (!lpfc_is_link_up(phba)) |
| 4354 | return 0; |
| 4355 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4356 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 4357 | switch (phba->fc_linkspeed) { |
| 4358 | case LPFC_LINK_SPEED_1GHZ: |
| 4359 | link_speed = 1000; |
| 4360 | break; |
| 4361 | case LPFC_LINK_SPEED_2GHZ: |
| 4362 | link_speed = 2000; |
| 4363 | break; |
| 4364 | case LPFC_LINK_SPEED_4GHZ: |
| 4365 | link_speed = 4000; |
| 4366 | break; |
| 4367 | case LPFC_LINK_SPEED_8GHZ: |
| 4368 | link_speed = 8000; |
| 4369 | break; |
| 4370 | case LPFC_LINK_SPEED_10GHZ: |
| 4371 | link_speed = 10000; |
| 4372 | break; |
| 4373 | case LPFC_LINK_SPEED_16GHZ: |
| 4374 | link_speed = 16000; |
| 4375 | break; |
| 4376 | default: |
| 4377 | link_speed = 0; |
| 4378 | } |
| 4379 | } else { |
| 4380 | if (phba->sli4_hba.link_state.logical_speed) |
| 4381 | link_speed = |
| 4382 | phba->sli4_hba.link_state.logical_speed; |
| 4383 | else |
| 4384 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4385 | } |
| 4386 | return link_speed; |
| 4387 | } |
| 4388 | |
| 4389 | /** |
| 4390 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 4391 | * @phba: pointer to lpfc hba data structure. |
| 4392 | * @evt_code: asynchronous event code. |
| 4393 | * @speed_code: asynchronous event link speed code. |
| 4394 | * |
| 4395 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4396 | * value of Mbps for the link speed. |
| 4397 | * |
| 4398 | * Return: link speed in terms of Mbps. |
| 4399 | **/ |
| 4400 | static uint32_t |
| 4401 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 4402 | uint8_t speed_code) |
| 4403 | { |
| 4404 | uint32_t port_speed; |
| 4405 | |
| 4406 | switch (evt_code) { |
| 4407 | case LPFC_TRAILER_CODE_LINK: |
| 4408 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4409 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4410 | port_speed = 0; |
| 4411 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4412 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4413 | port_speed = 10; |
| 4414 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4415 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4416 | port_speed = 100; |
| 4417 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4418 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4419 | port_speed = 1000; |
| 4420 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4421 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4422 | port_speed = 10000; |
| 4423 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4424 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 4425 | port_speed = 20000; |
| 4426 | break; |
| 4427 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 4428 | port_speed = 25000; |
| 4429 | break; |
| 4430 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 4431 | port_speed = 40000; |
| 4432 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4433 | default: |
| 4434 | port_speed = 0; |
| 4435 | } |
| 4436 | break; |
| 4437 | case LPFC_TRAILER_CODE_FC: |
| 4438 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4439 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4440 | port_speed = 0; |
| 4441 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4442 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4443 | port_speed = 1000; |
| 4444 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4445 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4446 | port_speed = 2000; |
| 4447 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4448 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4449 | port_speed = 4000; |
| 4450 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4451 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4452 | port_speed = 8000; |
| 4453 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4454 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4455 | port_speed = 10000; |
| 4456 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4457 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4458 | port_speed = 16000; |
| 4459 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4460 | case LPFC_FC_LA_SPEED_32G: |
| 4461 | port_speed = 32000; |
| 4462 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 4463 | case LPFC_FC_LA_SPEED_64G: |
| 4464 | port_speed = 64000; |
| 4465 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4466 | default: |
| 4467 | port_speed = 0; |
| 4468 | } |
| 4469 | break; |
| 4470 | default: |
| 4471 | port_speed = 0; |
| 4472 | } |
| 4473 | return port_speed; |
| 4474 | } |
| 4475 | |
| 4476 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4477 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4478 | * @phba: pointer to lpfc hba data structure. |
| 4479 | * @acqe_link: pointer to the async link completion queue entry. |
| 4480 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4481 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4482 | **/ |
| 4483 | static void |
| 4484 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 4485 | struct lpfc_acqe_link *acqe_link) |
| 4486 | { |
| 4487 | struct lpfc_dmabuf *mp; |
| 4488 | LPFC_MBOXQ_t *pmb; |
| 4489 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4490 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4491 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4492 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4493 | |
| 4494 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4495 | 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] | 4496 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 4497 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4498 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4499 | if (!pmb) { |
| 4500 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4501 | "0395 The mboxq allocation failed\n"); |
| 4502 | return; |
| 4503 | } |
| 4504 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4505 | if (!mp) { |
| 4506 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4507 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 4508 | goto out_free_pmb; |
| 4509 | } |
| 4510 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4511 | if (!mp->virt) { |
| 4512 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4513 | "0397 The mbuf allocation failed\n"); |
| 4514 | goto out_free_dmabuf; |
| 4515 | } |
| 4516 | |
| 4517 | /* Cleanup any outstanding ELS commands */ |
| 4518 | lpfc_els_flush_all_cmd(phba); |
| 4519 | |
| 4520 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4521 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4522 | |
| 4523 | /* Update link event statistics */ |
| 4524 | phba->sli.slistat.link_event++; |
| 4525 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4526 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 4527 | lpfc_read_topology(phba, pmb, mp); |
| 4528 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4529 | pmb->vport = phba->pport; |
| 4530 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4531 | /* Keep the link status for extra SLI4 state machine reference */ |
| 4532 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4533 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 4534 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4535 | phba->sli4_hba.link_state.duplex = |
| 4536 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 4537 | phba->sli4_hba.link_state.status = |
| 4538 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4539 | phba->sli4_hba.link_state.type = |
| 4540 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 4541 | phba->sli4_hba.link_state.number = |
| 4542 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4543 | phba->sli4_hba.link_state.fault = |
| 4544 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 4545 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4546 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 4547 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4548 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 4549 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 4550 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 4551 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4552 | phba->sli4_hba.link_state.speed, |
| 4553 | phba->sli4_hba.link_state.topology, |
| 4554 | phba->sli4_hba.link_state.status, |
| 4555 | phba->sli4_hba.link_state.type, |
| 4556 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4557 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4558 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4559 | /* |
| 4560 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 4561 | * topology info. Note: Optional for non FC-AL ports. |
| 4562 | */ |
| 4563 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 4564 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4565 | if (rc == MBX_NOT_FINISHED) |
| 4566 | goto out_free_dmabuf; |
| 4567 | return; |
| 4568 | } |
| 4569 | /* |
| 4570 | * For FCoE Mode: fill in all the topology information we need and call |
| 4571 | * the READ_TOPOLOGY completion routine to continue without actually |
| 4572 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 4573 | */ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4574 | /* Initialize completion status */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4575 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4576 | mb->mbxStatus = MBX_SUCCESS; |
| 4577 | |
| 4578 | /* Parse port fault information field */ |
| 4579 | lpfc_sli4_parse_latt_fault(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4580 | |
| 4581 | /* Parse and translate link attention fields */ |
| 4582 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 4583 | la->eventTag = acqe_link->event_tag; |
| 4584 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 4585 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4586 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4587 | |
| 4588 | /* Fake the the following irrelvant fields */ |
| 4589 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 4590 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 4591 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 4592 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 4593 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 4594 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4595 | |
| 4596 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4597 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4598 | |
| 4599 | return; |
| 4600 | |
| 4601 | out_free_dmabuf: |
| 4602 | kfree(mp); |
| 4603 | out_free_pmb: |
| 4604 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4605 | } |
| 4606 | |
| 4607 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4608 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 4609 | * @phba: pointer to lpfc hba data structure. |
| 4610 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 4611 | * |
| 4612 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 4613 | * that the event was received and then issue a read_topology mailbox command so |
| 4614 | * that the rest of the driver will treat it the same as SLI3. |
| 4615 | **/ |
| 4616 | static void |
| 4617 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 4618 | { |
| 4619 | struct lpfc_dmabuf *mp; |
| 4620 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4621 | MAILBOX_t *mb; |
| 4622 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4623 | int rc; |
| 4624 | |
| 4625 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 4626 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
| 4627 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4628 | "2895 Non FC link Event detected.(%d)\n", |
| 4629 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 4630 | return; |
| 4631 | } |
| 4632 | /* Keep the link status for extra SLI4 state machine reference */ |
| 4633 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4634 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 4635 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4636 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 4637 | phba->sli4_hba.link_state.topology = |
| 4638 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 4639 | phba->sli4_hba.link_state.status = |
| 4640 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 4641 | phba->sli4_hba.link_state.type = |
| 4642 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 4643 | phba->sli4_hba.link_state.number = |
| 4644 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 4645 | phba->sli4_hba.link_state.fault = |
| 4646 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
| 4647 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4648 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4649 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4650 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 4651 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 4652 | "%dMbps Fault:%d\n", |
| 4653 | phba->sli4_hba.link_state.speed, |
| 4654 | phba->sli4_hba.link_state.topology, |
| 4655 | phba->sli4_hba.link_state.status, |
| 4656 | phba->sli4_hba.link_state.type, |
| 4657 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4658 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4659 | phba->sli4_hba.link_state.fault); |
| 4660 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4661 | if (!pmb) { |
| 4662 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4663 | "2897 The mboxq allocation failed\n"); |
| 4664 | return; |
| 4665 | } |
| 4666 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4667 | if (!mp) { |
| 4668 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4669 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 4670 | goto out_free_pmb; |
| 4671 | } |
| 4672 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4673 | if (!mp->virt) { |
| 4674 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4675 | "2899 The mbuf allocation failed\n"); |
| 4676 | goto out_free_dmabuf; |
| 4677 | } |
| 4678 | |
| 4679 | /* Cleanup any outstanding ELS commands */ |
| 4680 | lpfc_els_flush_all_cmd(phba); |
| 4681 | |
| 4682 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4683 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4684 | |
| 4685 | /* Update link event statistics */ |
| 4686 | phba->sli.slistat.link_event++; |
| 4687 | |
| 4688 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 4689 | lpfc_read_topology(phba, pmb, mp); |
| 4690 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 4691 | pmb->vport = phba->pport; |
| 4692 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4693 | 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] | 4694 | phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK); |
| 4695 | |
| 4696 | switch (phba->sli4_hba.link_state.status) { |
| 4697 | case LPFC_FC_LA_TYPE_MDS_LINK_DOWN: |
| 4698 | phba->link_flag |= LS_MDS_LINK_DOWN; |
| 4699 | break; |
| 4700 | case LPFC_FC_LA_TYPE_MDS_LOOPBACK: |
| 4701 | phba->link_flag |= LS_MDS_LOOPBACK; |
| 4702 | break; |
| 4703 | default: |
| 4704 | break; |
| 4705 | } |
| 4706 | |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4707 | /* Initialize completion status */ |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4708 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4709 | mb->mbxStatus = MBX_SUCCESS; |
| 4710 | |
| 4711 | /* Parse port fault information field */ |
| 4712 | lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4713 | |
| 4714 | /* Parse and translate link attention fields */ |
| 4715 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 4716 | la->eventTag = acqe_fc->event_tag; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4717 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 4718 | if (phba->sli4_hba.link_state.status == |
| 4719 | LPFC_FC_LA_TYPE_UNEXP_WWPN) { |
| 4720 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 4721 | LPFC_FC_LA_TYPE_UNEXP_WWPN); |
| 4722 | } else { |
| 4723 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 4724 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 4725 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 4726 | /* Invoke the mailbox command callback function */ |
| 4727 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 4728 | |
| 4729 | return; |
| 4730 | } |
| 4731 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4732 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 4733 | if (rc == MBX_NOT_FINISHED) |
| 4734 | goto out_free_dmabuf; |
| 4735 | return; |
| 4736 | |
| 4737 | out_free_dmabuf: |
| 4738 | kfree(mp); |
| 4739 | out_free_pmb: |
| 4740 | mempool_free(pmb, phba->mbox_mem_pool); |
| 4741 | } |
| 4742 | |
| 4743 | /** |
| 4744 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 4745 | * @phba: pointer to lpfc hba data structure. |
| 4746 | * @acqe_fc: pointer to the async SLI completion queue entry. |
| 4747 | * |
| 4748 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 4749 | **/ |
| 4750 | static void |
| 4751 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 4752 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4753 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 4754 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4755 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4756 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4757 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4758 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4759 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4760 | struct Scsi_Host *shost; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4761 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4762 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 4763 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4764 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4765 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" |
| 4766 | "x%08x SLI Event Type:%d\n", |
| 4767 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 4768 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4769 | |
| 4770 | port_name = phba->Port[0]; |
| 4771 | if (port_name == 0x00) |
| 4772 | port_name = '?'; /* get port name is empty */ |
| 4773 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4774 | switch (evt_type) { |
| 4775 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 4776 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 4777 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 4778 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 4779 | |
| 4780 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 4781 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 4782 | acqe_sli->event_data1, port_name); |
| 4783 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 4784 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4785 | shost = lpfc_shost_from_vport(phba->pport); |
| 4786 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4787 | sizeof(temp_event_data), |
| 4788 | (char *)&temp_event_data, |
| 4789 | SCSI_NL_VID_TYPE_PCI |
| 4790 | | PCI_VENDOR_ID_EMULEX); |
| 4791 | break; |
| 4792 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 4793 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 4794 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 4795 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 4796 | |
| 4797 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4798 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 4799 | acqe_sli->event_data1, port_name); |
| 4800 | |
| 4801 | shost = lpfc_shost_from_vport(phba->pport); |
| 4802 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 4803 | sizeof(temp_event_data), |
| 4804 | (char *)&temp_event_data, |
| 4805 | SCSI_NL_VID_TYPE_PCI |
| 4806 | | PCI_VENDOR_ID_EMULEX); |
| 4807 | break; |
| 4808 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 4809 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4810 | &acqe_sli->event_data1; |
| 4811 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4812 | /* fetch the status for this port */ |
| 4813 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 4814 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4815 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 4816 | &misconfigured->theEvent); |
| 4817 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4818 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4819 | break; |
| 4820 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4821 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 4822 | &misconfigured->theEvent); |
| 4823 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4824 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4825 | break; |
| 4826 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4827 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 4828 | &misconfigured->theEvent); |
| 4829 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4830 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4831 | break; |
| 4832 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4833 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 4834 | &misconfigured->theEvent); |
| 4835 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4836 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4837 | break; |
| 4838 | default: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4839 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 4840 | "3296 " |
| 4841 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 4842 | "event: Invalid link %d", |
| 4843 | phba->sli4_hba.lnk_info.lnk_no); |
| 4844 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4845 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4846 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4847 | /* Skip if optic state unchanged */ |
| 4848 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 4849 | return; |
| 4850 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4851 | switch (status) { |
| 4852 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4853 | sprintf(message, "Physical Link is functional"); |
| 4854 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4855 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 4856 | sprintf(message, "Optics faulted/incorrectly " |
| 4857 | "installed/not installed - Reseat optics, " |
| 4858 | "if issue not resolved, replace."); |
| 4859 | break; |
| 4860 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 4861 | sprintf(message, |
| 4862 | "Optics of two types installed - Remove one " |
| 4863 | "optic or install matching pair of optics."); |
| 4864 | break; |
| 4865 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 4866 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 4867 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4868 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4869 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 4870 | sprintf(message, "Unqualified optics - Replace with " |
| 4871 | "Avago optics for Warranty and Technical " |
| 4872 | "Support - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4873 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4874 | break; |
| 4875 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 4876 | sprintf(message, "Uncertified optics - Replace with " |
| 4877 | "Avago-certified optics to enable link " |
| 4878 | "operation - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4879 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4880 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4881 | default: |
| 4882 | /* firmware is reporting a status we don't know about */ |
| 4883 | sprintf(message, "Unknown event status x%02x", status); |
| 4884 | break; |
| 4885 | } |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4886 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4887 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 4888 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4889 | break; |
| 4890 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 4891 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4892 | "3192 Remote DPort Test Initiated - " |
| 4893 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 4894 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4895 | break; |
| 4896 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 4897 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4898 | "3193 Async SLI event - Event Data1:x%08x Event Data2:" |
| 4899 | "x%08x SLI Event Type:%d\n", |
| 4900 | acqe_sli->event_data1, acqe_sli->event_data2, |
| 4901 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 4902 | break; |
| 4903 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4907 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 4908 | * @vport: pointer to vport data structure. |
| 4909 | * |
| 4910 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 4911 | * response to a CVL event. |
| 4912 | * |
| 4913 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 4914 | * return NULL. |
| 4915 | **/ |
| 4916 | static struct lpfc_nodelist * |
| 4917 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 4918 | { |
| 4919 | struct lpfc_nodelist *ndlp; |
| 4920 | struct Scsi_Host *shost; |
| 4921 | struct lpfc_hba *phba; |
| 4922 | |
| 4923 | if (!vport) |
| 4924 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4925 | phba = vport->phba; |
| 4926 | if (!phba) |
| 4927 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 4928 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 4929 | if (!ndlp) { |
| 4930 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 4931 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 4932 | if (!ndlp) |
| 4933 | return 0; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 4934 | /* Set the node type */ |
| 4935 | ndlp->nlp_type |= NLP_FABRIC; |
| 4936 | /* Put ndlp onto node list */ |
| 4937 | lpfc_enqueue_node(vport, ndlp); |
| 4938 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 4939 | /* re-setup ndlp without removing from node list */ |
| 4940 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); |
| 4941 | if (!ndlp) |
| 4942 | return 0; |
| 4943 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4944 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 4945 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4946 | return NULL; |
| 4947 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 4948 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 4949 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 4950 | return NULL; |
| 4951 | shost = lpfc_shost_from_vport(vport); |
| 4952 | if (!shost) |
| 4953 | return NULL; |
| 4954 | lpfc_linkdown_port(vport); |
| 4955 | lpfc_cleanup_pending_mbox(vport); |
| 4956 | spin_lock_irq(shost->host_lock); |
| 4957 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 4958 | spin_unlock_irq(shost->host_lock); |
| 4959 | |
| 4960 | return ndlp; |
| 4961 | } |
| 4962 | |
| 4963 | /** |
| 4964 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
| 4965 | * @vport: pointer to lpfc hba data structure. |
| 4966 | * |
| 4967 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 4968 | * response to a FCF dead event. |
| 4969 | **/ |
| 4970 | static void |
| 4971 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 4972 | { |
| 4973 | struct lpfc_vport **vports; |
| 4974 | int i; |
| 4975 | |
| 4976 | vports = lpfc_create_vport_work_array(phba); |
| 4977 | if (vports) |
| 4978 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 4979 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 4980 | lpfc_destroy_vport_work_array(phba, vports); |
| 4981 | } |
| 4982 | |
| 4983 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4984 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4985 | * @phba: pointer to lpfc hba data structure. |
| 4986 | * @acqe_link: pointer to the async fcoe completion queue entry. |
| 4987 | * |
| 4988 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 4989 | **/ |
| 4990 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4991 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4992 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4993 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4994 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4995 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 4996 | struct lpfc_vport *vport; |
| 4997 | struct lpfc_nodelist *ndlp; |
| 4998 | struct Scsi_Host *shost; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 4999 | int active_vlink_present; |
| 5000 | struct lpfc_vport **vports; |
| 5001 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5002 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5003 | phba->fc_eventTag = acqe_fip->event_tag; |
| 5004 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5005 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5006 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 5007 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 5008 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5009 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5010 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5011 | "2546 New FCF event, evt_tag:x%x, " |
| 5012 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5013 | acqe_fip->event_tag, |
| 5014 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5015 | else |
| 5016 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 5017 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5018 | "2788 FCF param modified event, " |
| 5019 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5020 | acqe_fip->event_tag, |
| 5021 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5022 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5023 | /* |
| 5024 | * During period of FCF discovery, read the FCF |
| 5025 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5026 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5027 | */ |
| 5028 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5029 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5030 | "2779 Read FCF (x%x) for updating " |
| 5031 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5032 | acqe_fip->index); |
| 5033 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5034 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5035 | |
| 5036 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5037 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5038 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5039 | spin_unlock_irq(&phba->hbalock); |
| 5040 | break; |
| 5041 | } |
| 5042 | /* If fast FCF failover rescan event is pending, do nothing */ |
| 5043 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
| 5044 | spin_unlock_irq(&phba->hbalock); |
| 5045 | break; |
| 5046 | } |
| 5047 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5048 | /* If the FCF has been in discovered state, do nothing. */ |
| 5049 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5050 | spin_unlock_irq(&phba->hbalock); |
| 5051 | break; |
| 5052 | } |
| 5053 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5054 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5055 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 5056 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5057 | "2770 Start FCF table scan per async FCF " |
| 5058 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5059 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5060 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 5061 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5062 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5063 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5064 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5065 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5066 | break; |
| 5067 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5068 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5069 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 5070 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5071 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 5072 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5073 | break; |
| 5074 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5075 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5076 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5077 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5078 | "2549 FCF (x%x) disconnected from network, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5079 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5080 | /* |
| 5081 | * If we are in the middle of FCF failover process, clear |
| 5082 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5083 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5084 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame] | 5085 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 5086 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5087 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5088 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5089 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5090 | break; |
| 5091 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5092 | spin_unlock_irq(&phba->hbalock); |
| 5093 | |
| 5094 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5095 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5096 | break; |
| 5097 | |
| 5098 | /* |
| 5099 | * Otherwise, request the port to rediscover the entire FCF |
| 5100 | * table for a fast recovery from case that the current FCF |
| 5101 | * is no longer valid as we are not in the middle of FCF |
| 5102 | * failover process already. |
| 5103 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5104 | spin_lock_irq(&phba->hbalock); |
| 5105 | /* Mark the fast failover process in progress */ |
| 5106 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 5107 | spin_unlock_irq(&phba->hbalock); |
| 5108 | |
| 5109 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 5110 | "2771 Start FCF fast failover process due to " |
| 5111 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 5112 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 5113 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 5114 | if (rc) { |
| 5115 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5116 | LOG_DISCOVERY, |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5117 | "2772 Issue FCF rediscover mailbox " |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5118 | "command failed, fail through to FCF " |
| 5119 | "dead event\n"); |
| 5120 | spin_lock_irq(&phba->hbalock); |
| 5121 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 5122 | spin_unlock_irq(&phba->hbalock); |
| 5123 | /* |
| 5124 | * Last resort will fail over by treating this |
| 5125 | * as a link down to FCF registration. |
| 5126 | */ |
| 5127 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 5128 | } else { |
| 5129 | /* Reset FCF roundrobin bmask for new discovery */ |
| 5130 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 5131 | /* |
| 5132 | * Handling fast FCF failover to a DEAD FCF event is |
| 5133 | * considered equalivant to receiving CVL to all vports. |
| 5134 | */ |
| 5135 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 5136 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5137 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5138 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5139 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5140 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5141 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5142 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5143 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5144 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5145 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5146 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5147 | if (!ndlp) |
| 5148 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5149 | active_vlink_present = 0; |
| 5150 | |
| 5151 | vports = lpfc_create_vport_work_array(phba); |
| 5152 | if (vports) { |
| 5153 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5154 | i++) { |
| 5155 | if ((!(vports[i]->fc_flag & |
| 5156 | FC_VPORT_CVL_RCVD)) && |
| 5157 | (vports[i]->port_state > LPFC_FDISC)) { |
| 5158 | active_vlink_present = 1; |
| 5159 | break; |
| 5160 | } |
| 5161 | } |
| 5162 | lpfc_destroy_vport_work_array(phba, vports); |
| 5163 | } |
| 5164 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 5165 | /* |
| 5166 | * Don't re-instantiate if vport is marked for deletion. |
| 5167 | * If we are here first then vport_delete is going to wait |
| 5168 | * for discovery to complete. |
| 5169 | */ |
| 5170 | if (!(vport->load_flag & FC_UNLOADING) && |
| 5171 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5172 | /* |
| 5173 | * If there are other active VLinks present, |
| 5174 | * re-instantiate the Vlink using FDISC. |
| 5175 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 5176 | mod_timer(&ndlp->nlp_delayfunc, |
| 5177 | jiffies + msecs_to_jiffies(1000)); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5178 | shost = lpfc_shost_from_vport(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5179 | spin_lock_irq(shost->host_lock); |
| 5180 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
| 5181 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5182 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 5183 | vport->port_state = LPFC_FDISC; |
| 5184 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5185 | /* |
| 5186 | * Otherwise, we request port to rediscover |
| 5187 | * the entire FCF table for a fast recovery |
| 5188 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5189 | * is no longer valid if we are not already |
| 5190 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5191 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5192 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5193 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5194 | spin_unlock_irq(&phba->hbalock); |
| 5195 | break; |
| 5196 | } |
| 5197 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5198 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5199 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5200 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5201 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5202 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5203 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5204 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5205 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5206 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
| 5207 | LOG_DISCOVERY, |
| 5208 | "2774 Issue FCF rediscover " |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5209 | "mailbox command failed, " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5210 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5211 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5212 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5213 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5214 | /* |
| 5215 | * Last resort will be re-try on the |
| 5216 | * the current registered FCF entry. |
| 5217 | */ |
| 5218 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5219 | } else |
| 5220 | /* |
| 5221 | * Reset FCF roundrobin bmask for new |
| 5222 | * discovery. |
| 5223 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 5224 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5225 | } |
| 5226 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5227 | default: |
| 5228 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5229 | "0288 Unknown FCoE event type 0x%x event tag " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5230 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5231 | break; |
| 5232 | } |
| 5233 | } |
| 5234 | |
| 5235 | /** |
| 5236 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 5237 | * @phba: pointer to lpfc hba data structure. |
| 5238 | * @acqe_link: pointer to the async dcbx completion queue entry. |
| 5239 | * |
| 5240 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 5241 | **/ |
| 5242 | static void |
| 5243 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 5244 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 5245 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5246 | phba->fc_eventTag = acqe_dcbx->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5247 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5248 | "0290 The SLI4 DCBX asynchronous event is not " |
| 5249 | "handled yet\n"); |
| 5250 | } |
| 5251 | |
| 5252 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5253 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 5254 | * @phba: pointer to lpfc hba data structure. |
| 5255 | * @acqe_link: pointer to the async grp5 completion queue entry. |
| 5256 | * |
| 5257 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 5258 | * is an asynchronous notified of a logical link speed change. The Port |
| 5259 | * reports the logical link speed in units of 10Mbps. |
| 5260 | **/ |
| 5261 | static void |
| 5262 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 5263 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 5264 | { |
| 5265 | uint16_t prev_ll_spd; |
| 5266 | |
| 5267 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 5268 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 5269 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 5270 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5271 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5272 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5273 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5274 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 5275 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5279 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 5280 | * @phba: pointer to lpfc hba data structure. |
| 5281 | * |
| 5282 | * This routine is invoked by the worker thread to process all the pending |
| 5283 | * SLI4 asynchronous events. |
| 5284 | **/ |
| 5285 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 5286 | { |
| 5287 | struct lpfc_cq_event *cq_event; |
| 5288 | |
| 5289 | /* First, declare the async event has been handled */ |
| 5290 | spin_lock_irq(&phba->hbalock); |
| 5291 | phba->hba_flag &= ~ASYNC_EVENT; |
| 5292 | spin_unlock_irq(&phba->hbalock); |
| 5293 | /* Now, handle all the async events */ |
| 5294 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
| 5295 | /* Get the first event from the head of the event queue */ |
| 5296 | spin_lock_irq(&phba->hbalock); |
| 5297 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 5298 | cq_event, struct lpfc_cq_event, list); |
| 5299 | spin_unlock_irq(&phba->hbalock); |
| 5300 | /* Process the asynchronous event */ |
| 5301 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 5302 | case LPFC_TRAILER_CODE_LINK: |
| 5303 | lpfc_sli4_async_link_evt(phba, |
| 5304 | &cq_event->cqe.acqe_link); |
| 5305 | break; |
| 5306 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5307 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5308 | break; |
| 5309 | case LPFC_TRAILER_CODE_DCBX: |
| 5310 | lpfc_sli4_async_dcbx_evt(phba, |
| 5311 | &cq_event->cqe.acqe_dcbx); |
| 5312 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5313 | case LPFC_TRAILER_CODE_GRP5: |
| 5314 | lpfc_sli4_async_grp5_evt(phba, |
| 5315 | &cq_event->cqe.acqe_grp5); |
| 5316 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5317 | case LPFC_TRAILER_CODE_FC: |
| 5318 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 5319 | break; |
| 5320 | case LPFC_TRAILER_CODE_SLI: |
| 5321 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 5322 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5323 | default: |
| 5324 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 5325 | "1804 Invalid asynchrous event code: " |
| 5326 | "x%x\n", bf_get(lpfc_trailer_code, |
| 5327 | &cq_event->cqe.mcqe_cmpl)); |
| 5328 | break; |
| 5329 | } |
| 5330 | /* Free the completion event processed to the free pool */ |
| 5331 | lpfc_sli4_cq_event_release(phba, cq_event); |
| 5332 | } |
| 5333 | } |
| 5334 | |
| 5335 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5336 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 5337 | * @phba: pointer to lpfc hba data structure. |
| 5338 | * |
| 5339 | * This routine is invoked by the worker thread to process FCF table |
| 5340 | * rediscovery pending completion event. |
| 5341 | **/ |
| 5342 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 5343 | { |
| 5344 | int rc; |
| 5345 | |
| 5346 | spin_lock_irq(&phba->hbalock); |
| 5347 | /* Clear FCF rediscovery timeout event */ |
| 5348 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 5349 | /* Clear driver fast failover FCF record flag */ |
| 5350 | phba->fcf.failover_rec.flag = 0; |
| 5351 | /* Set state for FCF fast failover */ |
| 5352 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 5353 | spin_unlock_irq(&phba->hbalock); |
| 5354 | |
| 5355 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5356 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5357 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5358 | 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] | 5359 | if (rc) |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5360 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
| 5361 | "2747 Issue FCF scan read FCF mailbox " |
| 5362 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5366 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 5367 | * @phba: pointer to lpfc hba data structure. |
| 5368 | * @dev_grp: The HBA PCI-Device group number. |
| 5369 | * |
| 5370 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 5371 | * API jump table entries. |
| 5372 | * |
| 5373 | * Return: 0 if success, otherwise -ENODEV |
| 5374 | **/ |
| 5375 | int |
| 5376 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5377 | { |
| 5378 | int rc; |
| 5379 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5380 | /* Set up lpfc PCI-device group */ |
| 5381 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5382 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5383 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 5384 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 5385 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5386 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5387 | /* Set up device INIT API function jump table */ |
| 5388 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 5389 | if (rc) |
| 5390 | return -ENODEV; |
| 5391 | /* Set up SCSI API function jump table */ |
| 5392 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 5393 | if (rc) |
| 5394 | return -ENODEV; |
| 5395 | /* Set up SLI API function jump table */ |
| 5396 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 5397 | if (rc) |
| 5398 | return -ENODEV; |
| 5399 | /* Set up MBOX API function jump table */ |
| 5400 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 5401 | if (rc) |
| 5402 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5403 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5404 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5405 | } |
| 5406 | |
| 5407 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 5408 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5409 | * @phba: pointer to lpfc hba data structure. |
| 5410 | * @intr_mode: active interrupt mode adopted. |
| 5411 | * |
| 5412 | * This routine it invoked to log the currently used active interrupt mode |
| 5413 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5414 | **/ |
| 5415 | 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] | 5416 | { |
| 5417 | switch (intr_mode) { |
| 5418 | case 0: |
| 5419 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5420 | "0470 Enable INTx interrupt mode.\n"); |
| 5421 | break; |
| 5422 | case 1: |
| 5423 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5424 | "0481 Enabled MSI interrupt mode.\n"); |
| 5425 | break; |
| 5426 | case 2: |
| 5427 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 5428 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 5429 | break; |
| 5430 | default: |
| 5431 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5432 | "0482 Illegal interrupt mode.\n"); |
| 5433 | break; |
| 5434 | } |
| 5435 | return; |
| 5436 | } |
| 5437 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5438 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5439 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5440 | * @phba: pointer to lpfc hba data structure. |
| 5441 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5442 | * This routine is invoked to enable the PCI device that is common to all |
| 5443 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5444 | * |
| 5445 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5446 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5447 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5448 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5449 | static int |
| 5450 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
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 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5453 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5454 | /* Obtain PCI device reference */ |
| 5455 | if (!phba->pcidev) |
| 5456 | goto out_error; |
| 5457 | else |
| 5458 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5459 | /* Enable PCI device */ |
| 5460 | if (pci_enable_device_mem(pdev)) |
| 5461 | goto out_error; |
| 5462 | /* Request PCI resource for the device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 5463 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5464 | goto out_disable_device; |
| 5465 | /* Set up device as PCI master and save state for EEH */ |
| 5466 | pci_set_master(pdev); |
| 5467 | pci_try_set_mwi(pdev); |
| 5468 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5469 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5470 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 5471 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 5472 | pdev->needs_freset = 1; |
| 5473 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5474 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5475 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5476 | out_disable_device: |
| 5477 | pci_disable_device(pdev); |
| 5478 | out_error: |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 5479 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 5480 | "1401 Failed to enable pci device\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5481 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5485 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5486 | * @phba: pointer to lpfc hba data structure. |
| 5487 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5488 | * This routine is invoked to disable the PCI device that is common to all |
| 5489 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5490 | **/ |
| 5491 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5492 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5493 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5494 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5495 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5496 | /* Obtain PCI device reference */ |
| 5497 | if (!phba->pcidev) |
| 5498 | return; |
| 5499 | else |
| 5500 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5501 | /* Release PCI resource and disable PCI device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 5502 | pci_release_mem_regions(pdev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5503 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 5504 | |
| 5505 | return; |
| 5506 | } |
| 5507 | |
| 5508 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5509 | * lpfc_reset_hba - Reset a hba |
| 5510 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5511 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5512 | * This routine is invoked to reset a hba device. It brings the HBA |
| 5513 | * offline, performs a board restart, and then brings the board back |
| 5514 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 5515 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 5516 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5517 | void |
| 5518 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5519 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5520 | /* If resets are disabled then set error state and return. */ |
| 5521 | if (!phba->cfg_enable_hba_reset) { |
| 5522 | phba->link_state = LPFC_HBA_ERROR; |
| 5523 | return; |
| 5524 | } |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 5525 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 5526 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
| 5527 | else |
| 5528 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5529 | lpfc_offline(phba); |
| 5530 | lpfc_sli_brdrestart(phba); |
| 5531 | lpfc_online(phba); |
| 5532 | lpfc_unblock_mgmt_io(phba); |
| 5533 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5534 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5535 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 5536 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 5537 | * @phba: pointer to lpfc hba data structure. |
| 5538 | * |
| 5539 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 5540 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 5541 | * enable the number of virtual functions to the physical function. As |
| 5542 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 5543 | * API call does not considered as an error condition for most of the device. |
| 5544 | **/ |
| 5545 | uint16_t |
| 5546 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 5547 | { |
| 5548 | struct pci_dev *pdev = phba->pcidev; |
| 5549 | uint16_t nr_virtfn; |
| 5550 | int pos; |
| 5551 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 5552 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 5553 | if (pos == 0) |
| 5554 | return 0; |
| 5555 | |
| 5556 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 5557 | return nr_virtfn; |
| 5558 | } |
| 5559 | |
| 5560 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5561 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 5562 | * @phba: pointer to lpfc hba data structure. |
| 5563 | * @nr_vfn: number of virtual functions to be enabled. |
| 5564 | * |
| 5565 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 5566 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 5567 | * enable the number of virtual functions to the physical function. As |
| 5568 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 5569 | * API call does not considered as an error condition for most of the device. |
| 5570 | **/ |
| 5571 | int |
| 5572 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 5573 | { |
| 5574 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 5575 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5576 | int rc; |
| 5577 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 5578 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 5579 | if (nr_vfn > max_nr_vfn) { |
| 5580 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 5581 | "3057 Requested vfs (%d) greater than " |
| 5582 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 5583 | return -EINVAL; |
| 5584 | } |
| 5585 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5586 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 5587 | if (rc) { |
| 5588 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5589 | "2806 Failed to enable sriov on this device " |
| 5590 | "with vfn number nr_vf:%d, rc:%d\n", |
| 5591 | nr_vfn, rc); |
| 5592 | } else |
| 5593 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5594 | "2807 Successful enable sriov on this device " |
| 5595 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 5596 | return rc; |
| 5597 | } |
| 5598 | |
| 5599 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5600 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5601 | * @phba: pointer to lpfc hba data structure. |
| 5602 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5603 | * This routine is invoked to set up the driver internal resources before the |
| 5604 | * device specific resource setup to support the HBA device it attached to. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5605 | * |
| 5606 | * Return codes |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5607 | * 0 - successful |
| 5608 | * other values - error |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5609 | **/ |
| 5610 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5611 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5612 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5613 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5614 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5615 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5616 | * Driver resources common to all SLI revisions |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5617 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5618 | atomic_set(&phba->fast_event_count, 0); |
| 5619 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 5620 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5621 | /* Initialize ndlp management spinlock */ |
| 5622 | spin_lock_init(&phba->ndlp_lock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5623 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5624 | INIT_LIST_HEAD(&phba->port_list); |
| 5625 | INIT_LIST_HEAD(&phba->work_list); |
| 5626 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| 5627 | |
| 5628 | /* Initialize the wait queue head for the kernel thread */ |
| 5629 | init_waitqueue_head(&phba->work_waitq); |
| 5630 | |
| 5631 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 5632 | "1403 Protocols supported %s %s %s\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5633 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
| 5634 | "SCSI" : " "), |
| 5635 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 5636 | "NVME" : " "), |
| 5637 | (phba->nvmet_support ? "NVMET" : " ")); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5638 | |
| 5639 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 5640 | /* Initialize the scsi buffer list used by driver for scsi IO */ |
| 5641 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 5642 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 5643 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 5644 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
| 5645 | } |
| 5646 | |
| 5647 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 5648 | (phba->nvmet_support == 0)) { |
| 5649 | /* Initialize the NVME buffer list used by driver for NVME IO */ |
| 5650 | spin_lock_init(&phba->nvme_buf_list_get_lock); |
| 5651 | INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 5652 | phba->get_nvme_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5653 | spin_lock_init(&phba->nvme_buf_list_put_lock); |
| 5654 | INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put); |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 5655 | phba->put_nvme_bufs = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | /* Initialize the fabric iocb list */ |
| 5659 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 5660 | |
| 5661 | /* Initialize list to save ELS buffers */ |
| 5662 | INIT_LIST_HEAD(&phba->elsbuf); |
| 5663 | |
| 5664 | /* Initialize FCF connection rec list */ |
| 5665 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| 5666 | |
| 5667 | /* Initialize OAS configuration list */ |
| 5668 | spin_lock_init(&phba->devicelock); |
| 5669 | INIT_LIST_HEAD(&phba->luns); |
| 5670 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5671 | /* MBOX heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5672 | timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5673 | /* Fabric block timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5674 | timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5675 | /* EA polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5676 | timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5677 | /* Heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5678 | timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5679 | |
| 5680 | return 0; |
| 5681 | } |
| 5682 | |
| 5683 | /** |
| 5684 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev |
| 5685 | * @phba: pointer to lpfc hba data structure. |
| 5686 | * |
| 5687 | * This routine is invoked to set up the driver internal resources specific to |
| 5688 | * support the SLI-3 HBA device it attached to. |
| 5689 | * |
| 5690 | * Return codes |
| 5691 | * 0 - successful |
| 5692 | * other values - error |
| 5693 | **/ |
| 5694 | static int |
| 5695 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 5696 | { |
| 5697 | int rc; |
| 5698 | |
| 5699 | /* |
| 5700 | * Initialize timers used by driver |
| 5701 | */ |
| 5702 | |
| 5703 | /* FCP polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5704 | timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5705 | |
| 5706 | /* Host attention work mask setup */ |
| 5707 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 5708 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 5709 | |
| 5710 | /* Get all the module params for configuring this host */ |
| 5711 | lpfc_get_cfgparam(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5712 | /* Set up phase-1 common device driver resources */ |
| 5713 | |
| 5714 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 5715 | if (rc) |
| 5716 | return -ENODEV; |
| 5717 | |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 5718 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 5719 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 5720 | /* check for menlo minimum sg count */ |
| 5721 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 5722 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 5723 | } |
| 5724 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5725 | if (!phba->sli.sli3_ring) |
| 5726 | phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING * |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5727 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5728 | if (!phba->sli.sli3_ring) |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5729 | return -ENOMEM; |
| 5730 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5731 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5732 | * 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] | 5733 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5734 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5735 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5736 | /* Initialize the host templates the configured values. */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5737 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 5738 | lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5739 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5740 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5741 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 5742 | if (phba->cfg_enable_bg) { |
| 5743 | /* |
| 5744 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 5745 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 5746 | * over how many protection data segments the SCSI Layer |
| 5747 | * will hand us (ie: there could be one for every block |
| 5748 | * in the IO), we just allocate enough BDEs to accomidate |
| 5749 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 5750 | * minimize the risk of running out. |
| 5751 | */ |
| 5752 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5753 | sizeof(struct fcp_rsp) + |
| 5754 | (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64)); |
| 5755 | |
| 5756 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 5757 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 5758 | |
| 5759 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 5760 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 5761 | } else { |
| 5762 | /* |
| 5763 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 5764 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 5765 | * cfg_sg_seg_cnt data segments. |
| 5766 | */ |
| 5767 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 5768 | sizeof(struct fcp_rsp) + |
| 5769 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
| 5770 | |
| 5771 | /* Total BDEs in BPL for scsi_sg_list */ |
| 5772 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 5773 | } |
| 5774 | |
| 5775 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5776 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
| 5777 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5778 | phba->cfg_total_seg_cnt); |
| 5779 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5780 | phba->max_vpi = LPFC_MAX_VPI; |
| 5781 | /* This will be set to correct value after config_port mbox */ |
| 5782 | phba->max_vports = 0; |
| 5783 | |
| 5784 | /* |
| 5785 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 5786 | */ |
| 5787 | lpfc_sli_setup(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5788 | lpfc_sli_queue_init(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5789 | |
| 5790 | /* Allocate device driver memory */ |
| 5791 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 5792 | return -ENOMEM; |
| 5793 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 5794 | /* |
| 5795 | * Enable sr-iov virtual functions if supported and configured |
| 5796 | * through the module parameter. |
| 5797 | */ |
| 5798 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 5799 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 5800 | phba->cfg_sriov_nr_virtfn); |
| 5801 | if (rc) { |
| 5802 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 5803 | "2808 Requested number of SR-IOV " |
| 5804 | "virtual functions (%d) is not " |
| 5805 | "supported\n", |
| 5806 | phba->cfg_sriov_nr_virtfn); |
| 5807 | phba->cfg_sriov_nr_virtfn = 0; |
| 5808 | } |
| 5809 | } |
| 5810 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 5811 | return 0; |
| 5812 | } |
| 5813 | |
| 5814 | /** |
| 5815 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 5816 | * @phba: pointer to lpfc hba data structure. |
| 5817 | * |
| 5818 | * This routine is invoked to unset the driver internal resources set up |
| 5819 | * specific for supporting the SLI-3 HBA device it attached to. |
| 5820 | **/ |
| 5821 | static void |
| 5822 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 5823 | { |
| 5824 | /* Free device driver memory allocated */ |
| 5825 | lpfc_mem_free_all(phba); |
| 5826 | |
| 5827 | return; |
| 5828 | } |
| 5829 | |
| 5830 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5831 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 5832 | * @phba: pointer to lpfc hba data structure. |
| 5833 | * |
| 5834 | * This routine is invoked to set up the driver internal resources specific to |
| 5835 | * support the SLI-4 HBA device it attached to. |
| 5836 | * |
| 5837 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 5838 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5839 | * other values - error |
| 5840 | **/ |
| 5841 | static int |
| 5842 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 5843 | { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5844 | LPFC_MBOXQ_t *mboxq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 5845 | MAILBOX_t *mb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5846 | int rc, i, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5847 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 5848 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5849 | int longs; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 5850 | int fof_vectors = 0; |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5851 | int extra; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 5852 | uint64_t wwn; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5853 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5854 | phba->sli4_hba.num_online_cpu = num_online_cpus(); |
| 5855 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
| 5856 | phba->sli4_hba.curr_disp_cpu = 0; |
| 5857 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 5858 | /* Get all the module params for configuring this host */ |
| 5859 | lpfc_get_cfgparam(phba); |
| 5860 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5861 | /* Set up phase-1 common device driver resources */ |
| 5862 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 5863 | if (rc) |
| 5864 | return -ENODEV; |
| 5865 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5866 | /* Before proceed, wait for POST done and device ready */ |
| 5867 | rc = lpfc_sli4_post_status_check(phba); |
| 5868 | if (rc) |
| 5869 | return -ENODEV; |
| 5870 | |
| 5871 | /* |
| 5872 | * Initialize timers used by driver |
| 5873 | */ |
| 5874 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5875 | timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5876 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5877 | /* FCF rediscover timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 5878 | 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] | 5879 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5880 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 5881 | * Control structure for handling external multi-buffer mailbox |
| 5882 | * command pass-through. |
| 5883 | */ |
| 5884 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 5885 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 5886 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 5887 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5888 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 5889 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5890 | /* This will be set to correct value after the read_config mbox */ |
| 5891 | phba->max_vports = 0; |
| 5892 | |
| 5893 | /* Program the default value of vlan_id and fc_map */ |
| 5894 | phba->valid_vlan = 0; |
| 5895 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 5896 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 5897 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 5898 | |
| 5899 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5900 | * 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] | 5901 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
| 5902 | * The WQ create will allocate the ring. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 5903 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5904 | |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5905 | /* |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5906 | * 1 for cmd, 1 for rsp, NVME adds an extra one |
| 5907 | * for boundary conditions in its max_sgl_segment template. |
| 5908 | */ |
| 5909 | extra = 2; |
| 5910 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 5911 | extra++; |
| 5912 | |
| 5913 | /* |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5914 | * It doesn't matter what family our adapter is in, we are |
| 5915 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 5916 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 5917 | */ |
| 5918 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5919 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - extra) |
| 5920 | phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - extra; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 5921 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5922 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5923 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
| 5924 | * used to create the sg_dma_buf_pool must be calculated. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 5925 | */ |
James Smart | f44ac12 | 2018-03-05 12:04:08 -0800 | [diff] [blame] | 5926 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5927 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5928 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
| 5929 | * the FCP rsp, and a SGE. Sice we have no control |
| 5930 | * over how many protection segments the SCSI Layer |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5931 | * will hand us (ie: there could be one for every block |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5932 | * in the IO), just allocate enough SGEs to accomidate |
| 5933 | * our max amount and we need to limit lpfc_sg_seg_cnt |
| 5934 | * to minimize the risk of running out. |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5935 | */ |
| 5936 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5937 | sizeof(struct fcp_rsp) + max_buf_size; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5938 | |
| 5939 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 5940 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 5941 | |
| 5942 | 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] | 5943 | phba->cfg_sg_seg_cnt = |
| 5944 | LPFC_MAX_SG_SLI4_SEG_CNT_DIF; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5945 | } else { |
| 5946 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5947 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5948 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 5949 | * cfg_sg_seg_cnt data segments. |
| 5950 | */ |
| 5951 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5952 | sizeof(struct fcp_rsp) + |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5953 | ((phba->cfg_sg_seg_cnt + extra) * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5954 | sizeof(struct sli4_sge)); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5955 | |
| 5956 | /* Total SGEs for scsi_sg_list */ |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5957 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5958 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5959 | /* |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 5960 | * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5961 | * need to post 1 page for the SGL. |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5962 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 5963 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 5964 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5965 | /* Initialize the host templates with the updated values. */ |
| 5966 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
| 5967 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 5968 | lpfc_template_no_hr.sg_tablesize = phba->cfg_sg_seg_cnt; |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 5969 | |
| 5970 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 5971 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 5972 | else |
| 5973 | phba->cfg_sg_dma_buf_size = |
| 5974 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 5975 | |
| 5976 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 5977 | "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n", |
| 5978 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 5979 | phba->cfg_total_seg_cnt); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5980 | |
| 5981 | /* Initialize buffer queue management fields */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5982 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5983 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 5984 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 5985 | |
| 5986 | /* |
| 5987 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 5988 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5989 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 5990 | /* Initialize the Abort scsi buffer list used by driver */ |
| 5991 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); |
| 5992 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 5993 | } |
| 5994 | |
| 5995 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 5996 | /* Initialize the Abort nvme buffer list used by driver */ |
| 5997 | spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock); |
| 5998 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 5999 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6000 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6001 | } |
| 6002 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6003 | /* This abort list used by worker thread */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6004 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6005 | spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6006 | |
| 6007 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6008 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6009 | */ |
| 6010 | |
| 6011 | /* Driver internel slow-path CQ Event pool */ |
| 6012 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 6013 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6014 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6015 | /* Asynchronous event CQ Event work queue list */ |
| 6016 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
| 6017 | /* Fast-path XRI aborted CQ Event work queue list */ |
| 6018 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); |
| 6019 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 6020 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 6021 | /* Receive queue CQ Event work queue list */ |
| 6022 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 6023 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6024 | /* Initialize extent block lists. */ |
| 6025 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 6026 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 6027 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 6028 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 6029 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6030 | /* Initialize mboxq lists. If the early init routines fail |
| 6031 | * these lists need to be correctly initialized. |
| 6032 | */ |
| 6033 | INIT_LIST_HEAD(&phba->sli.mboxq); |
| 6034 | INIT_LIST_HEAD(&phba->sli.mboxq_cmpl); |
| 6035 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6036 | /* initialize optic_state to 0xFF */ |
| 6037 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 6038 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6039 | /* Allocate device driver memory */ |
| 6040 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 6041 | if (rc) |
| 6042 | return -ENOMEM; |
| 6043 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6044 | /* IF Type 2 ports get initialized now. */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 6045 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >= |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6046 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 6047 | rc = lpfc_pci_function_reset(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6048 | if (unlikely(rc)) { |
| 6049 | rc = -ENODEV; |
| 6050 | goto out_free_mem; |
| 6051 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6052 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6053 | } |
| 6054 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6055 | /* Create the bootstrap mailbox command */ |
| 6056 | rc = lpfc_create_bootstrap_mbox(phba); |
| 6057 | if (unlikely(rc)) |
| 6058 | goto out_free_mem; |
| 6059 | |
| 6060 | /* Set up the host's endian order with the device. */ |
| 6061 | rc = lpfc_setup_endian_order(phba); |
| 6062 | if (unlikely(rc)) |
| 6063 | goto out_free_bsmbx; |
| 6064 | |
| 6065 | /* Set up the hba's configuration parameters. */ |
| 6066 | rc = lpfc_sli4_read_config(phba); |
| 6067 | if (unlikely(rc)) |
| 6068 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6069 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 6070 | if (unlikely(rc)) |
| 6071 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6072 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6073 | /* IF Type 0 ports get initialized now. */ |
| 6074 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6075 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6076 | rc = lpfc_pci_function_reset(phba); |
| 6077 | if (unlikely(rc)) |
| 6078 | goto out_free_bsmbx; |
| 6079 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6080 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6081 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6082 | GFP_KERNEL); |
| 6083 | if (!mboxq) { |
| 6084 | rc = -ENOMEM; |
| 6085 | goto out_free_bsmbx; |
| 6086 | } |
| 6087 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6088 | /* Check for NVMET being configured */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6089 | phba->nvmet_support = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6090 | if (lpfc_enable_nvmet_cnt) { |
| 6091 | |
| 6092 | /* First get WWN of HBA instance */ |
| 6093 | lpfc_read_nv(phba, mboxq); |
| 6094 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6095 | if (rc != MBX_SUCCESS) { |
| 6096 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 6097 | "6016 Mailbox failed , mbxCmd x%x " |
| 6098 | "READ_NV, mbxStatus x%x\n", |
| 6099 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 6100 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6101 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6102 | rc = -EIO; |
| 6103 | goto out_free_bsmbx; |
| 6104 | } |
| 6105 | mb = &mboxq->u.mb; |
| 6106 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, |
| 6107 | sizeof(uint64_t)); |
| 6108 | wwn = cpu_to_be64(wwn); |
| 6109 | phba->sli4_hba.wwnn.u.name = wwn; |
| 6110 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, |
| 6111 | sizeof(uint64_t)); |
| 6112 | /* wwn is WWPN of HBA instance */ |
| 6113 | wwn = cpu_to_be64(wwn); |
| 6114 | phba->sli4_hba.wwpn.u.name = wwn; |
| 6115 | |
| 6116 | /* Check to see if it matches any module parameter */ |
| 6117 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { |
| 6118 | if (wwn == lpfc_enable_nvmet[i]) { |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6119 | #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6120 | if (lpfc_nvmet_mem_alloc(phba)) |
| 6121 | break; |
| 6122 | |
| 6123 | phba->nvmet_support = 1; /* a match */ |
| 6124 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6125 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6126 | "6017 NVME Target %016llx\n", |
| 6127 | wwn); |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6128 | #else |
| 6129 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6130 | "6021 Can't enable NVME Target." |
| 6131 | " NVME_TARGET_FC infrastructure" |
| 6132 | " is not in kernel\n"); |
| 6133 | #endif |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6134 | break; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6135 | } |
| 6136 | } |
| 6137 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6138 | |
| 6139 | lpfc_nvme_mod_param_dep(phba); |
| 6140 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6141 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6142 | lpfc_supported_pages(mboxq); |
| 6143 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6144 | if (!rc) { |
| 6145 | mqe = &mboxq->u.mqe; |
| 6146 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 6147 | LPFC_MAX_SUPPORTED_PAGES); |
| 6148 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 6149 | switch (pn_page[i]) { |
| 6150 | case LPFC_SLI4_PARAMETERS: |
| 6151 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 6152 | break; |
| 6153 | default: |
| 6154 | break; |
| 6155 | } |
| 6156 | } |
| 6157 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 6158 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 6159 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 6160 | if (rc) { |
| 6161 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6162 | rc = -EIO; |
| 6163 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6164 | } |
| 6165 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6166 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6167 | /* |
| 6168 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6169 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 6170 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6171 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6172 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 6173 | if (rc) { |
| 6174 | if (phba->sli4_hba.extents_in_use && |
| 6175 | phba->sli4_hba.rpi_hdrs_in_use) { |
| 6176 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6177 | "2999 Unsupported SLI4 Parameters " |
| 6178 | "Extents and RPI headers enabled.\n"); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6179 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6180 | mempool_free(mboxq, phba->mbox_mem_pool); |
Stefano Brivio | 5c75606 | 2017-09-06 11:02:56 +0200 | [diff] [blame] | 6181 | rc = -EIO; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6182 | goto out_free_bsmbx; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6183 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6184 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6185 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6186 | |
| 6187 | /* Verify OAS is supported */ |
| 6188 | lpfc_sli4_oas_verify(phba); |
| 6189 | if (phba->cfg_fof) |
| 6190 | fof_vectors = 1; |
| 6191 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6192 | /* Verify all the SLI4 queues */ |
| 6193 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6194 | if (rc) |
| 6195 | goto out_free_bsmbx; |
| 6196 | |
| 6197 | /* Create driver internal CQE event pool */ |
| 6198 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 6199 | if (rc) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6200 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6201 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6202 | /* Initialize sgl lists per host */ |
| 6203 | lpfc_init_sgl_list(phba); |
| 6204 | |
| 6205 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6206 | rc = lpfc_init_active_sgl_array(phba); |
| 6207 | if (rc) { |
| 6208 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6209 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6210 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6211 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6212 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 6213 | if (rc) { |
| 6214 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6215 | "1432 Failed to initialize rpi headers.\n"); |
| 6216 | goto out_free_active_sgl; |
| 6217 | } |
| 6218 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6219 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6220 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
| 6221 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), |
| 6222 | GFP_KERNEL); |
| 6223 | if (!phba->fcf.fcf_rr_bmask) { |
| 6224 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6225 | "2759 Failed allocate memory for FCF round " |
| 6226 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6227 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6228 | goto out_remove_rpi_hdrs; |
| 6229 | } |
| 6230 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6231 | phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs, |
| 6232 | sizeof(struct lpfc_hba_eq_hdl), |
| 6233 | GFP_KERNEL); |
| 6234 | if (!phba->sli4_hba.hba_eq_hdl) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6235 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6236 | "2572 Failed allocate memory for " |
| 6237 | "fast-path per-EQ handle array\n"); |
| 6238 | rc = -ENOMEM; |
| 6239 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6240 | } |
| 6241 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6242 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu, |
| 6243 | sizeof(struct lpfc_vector_map_info), |
| 6244 | GFP_KERNEL); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6245 | if (!phba->sli4_hba.cpu_map) { |
| 6246 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6247 | "3327 Failed allocate memory for msi-x " |
| 6248 | "interrupt vector mapping\n"); |
| 6249 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6250 | goto out_free_hba_eq_hdl; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6251 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6252 | if (lpfc_used_cpu == NULL) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6253 | lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t), |
| 6254 | GFP_KERNEL); |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6255 | if (!lpfc_used_cpu) { |
| 6256 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6257 | "3335 Failed allocate memory for msi-x " |
| 6258 | "interrupt vector mapping\n"); |
| 6259 | kfree(phba->sli4_hba.cpu_map); |
| 6260 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6261 | goto out_free_hba_eq_hdl; |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 6262 | } |
| 6263 | for (i = 0; i < lpfc_present_cpu; i++) |
| 6264 | lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY; |
| 6265 | } |
| 6266 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6267 | /* |
| 6268 | * Enable sr-iov virtual functions if supported and configured |
| 6269 | * through the module parameter. |
| 6270 | */ |
| 6271 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6272 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6273 | phba->cfg_sriov_nr_virtfn); |
| 6274 | if (rc) { |
| 6275 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6276 | "3020 Requested number of SR-IOV " |
| 6277 | "virtual functions (%d) is not " |
| 6278 | "supported\n", |
| 6279 | phba->cfg_sriov_nr_virtfn); |
| 6280 | phba->cfg_sriov_nr_virtfn = 0; |
| 6281 | } |
| 6282 | } |
| 6283 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 6284 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6285 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6286 | out_free_hba_eq_hdl: |
| 6287 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6288 | out_free_fcf_rr_bmask: |
| 6289 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6290 | out_remove_rpi_hdrs: |
| 6291 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 6292 | out_free_active_sgl: |
| 6293 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6294 | out_destroy_cq_event_pool: |
| 6295 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6296 | out_free_bsmbx: |
| 6297 | lpfc_destroy_bootstrap_mbox(phba); |
| 6298 | out_free_mem: |
| 6299 | lpfc_mem_free(phba); |
| 6300 | return rc; |
| 6301 | } |
| 6302 | |
| 6303 | /** |
| 6304 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 6305 | * @phba: pointer to lpfc hba data structure. |
| 6306 | * |
| 6307 | * This routine is invoked to unset the driver internal resources set up |
| 6308 | * specific for supporting the SLI-4 HBA device it attached to. |
| 6309 | **/ |
| 6310 | static void |
| 6311 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 6312 | { |
| 6313 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 6314 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6315 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 6316 | kfree(phba->sli4_hba.cpu_map); |
| 6317 | phba->sli4_hba.num_present_cpu = 0; |
| 6318 | phba->sli4_hba.num_online_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 6319 | phba->sli4_hba.curr_disp_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6320 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6321 | /* Free memory allocated for fast-path work queue handles */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6322 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6323 | |
| 6324 | /* Free the allocated rpi headers. */ |
| 6325 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 6326 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6327 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6328 | /* Free eligible FCF index bmask */ |
| 6329 | kfree(phba->fcf.fcf_rr_bmask); |
| 6330 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6331 | /* Free the ELS sgl list */ |
| 6332 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6333 | lpfc_free_els_sgl_list(phba); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6334 | lpfc_free_nvmet_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6335 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6336 | /* Free the completion queue EQ event pool */ |
| 6337 | lpfc_sli4_cq_event_release_all(phba); |
| 6338 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 6339 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6340 | /* Release resource identifiers. */ |
| 6341 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 6342 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6343 | /* Free the bsmbx region. */ |
| 6344 | lpfc_destroy_bootstrap_mbox(phba); |
| 6345 | |
| 6346 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 6347 | lpfc_mem_free_all(phba); |
| 6348 | |
| 6349 | /* Free the current connect table */ |
| 6350 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6351 | &phba->fcf_conn_rec_list, list) { |
| 6352 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6353 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6354 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6355 | |
| 6356 | return; |
| 6357 | } |
| 6358 | |
| 6359 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 6360 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6361 | * @phba: The hba struct for which this call is being executed. |
| 6362 | * @dev_grp: The HBA PCI-Device group number. |
| 6363 | * |
| 6364 | * This routine sets up the device INIT interface API function jump table |
| 6365 | * in @phba struct. |
| 6366 | * |
| 6367 | * Returns: 0 - success, -ENODEV - failure. |
| 6368 | **/ |
| 6369 | int |
| 6370 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 6371 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 6372 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 6373 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 6374 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6375 | switch (dev_grp) { |
| 6376 | case LPFC_PCI_DEV_LP: |
| 6377 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 6378 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 6379 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 6380 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6381 | case LPFC_PCI_DEV_OC: |
| 6382 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 6383 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 6384 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 6385 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6386 | default: |
| 6387 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 6388 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 6389 | dev_grp); |
| 6390 | return -ENODEV; |
| 6391 | break; |
| 6392 | } |
| 6393 | return 0; |
| 6394 | } |
| 6395 | |
| 6396 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6397 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 6398 | * @phba: pointer to lpfc hba data structure. |
| 6399 | * |
| 6400 | * This routine is invoked to set up the driver internal resources after the |
| 6401 | * device specific resource setup to support the HBA device it attached to. |
| 6402 | * |
| 6403 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6404 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6405 | * other values - error |
| 6406 | **/ |
| 6407 | static int |
| 6408 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 6409 | { |
| 6410 | int error; |
| 6411 | |
| 6412 | /* Startup the kernel thread for this host adapter. */ |
| 6413 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 6414 | "lpfc_worker_%d", phba->brd_no); |
| 6415 | if (IS_ERR(phba->worker_thread)) { |
| 6416 | error = PTR_ERR(phba->worker_thread); |
| 6417 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 6418 | } |
| 6419 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 6420 | /* The lpfc_wq workqueue for deferred irq use, is only used for SLI4 */ |
| 6421 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6422 | phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); |
| 6423 | else |
| 6424 | phba->wq = NULL; |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 6425 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6426 | return 0; |
| 6427 | } |
| 6428 | |
| 6429 | /** |
| 6430 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 6431 | * @phba: pointer to lpfc hba data structure. |
| 6432 | * |
| 6433 | * This routine is invoked to unset the driver internal resources set up after |
| 6434 | * the device specific resource setup for supporting the HBA device it |
| 6435 | * attached to. |
| 6436 | **/ |
| 6437 | static void |
| 6438 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 6439 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 6440 | if (phba->wq) { |
| 6441 | flush_workqueue(phba->wq); |
| 6442 | destroy_workqueue(phba->wq); |
| 6443 | phba->wq = NULL; |
| 6444 | } |
| 6445 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6446 | /* Stop kernel worker thread */ |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 6447 | if (phba->worker_thread) |
| 6448 | kthread_stop(phba->worker_thread); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6449 | } |
| 6450 | |
| 6451 | /** |
| 6452 | * lpfc_free_iocb_list - Free iocb list. |
| 6453 | * @phba: pointer to lpfc hba data structure. |
| 6454 | * |
| 6455 | * This routine is invoked to free the driver's IOCB list and memory. |
| 6456 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6457 | void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6458 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 6459 | { |
| 6460 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 6461 | |
| 6462 | spin_lock_irq(&phba->hbalock); |
| 6463 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 6464 | &phba->lpfc_iocb_list, list) { |
| 6465 | list_del(&iocbq_entry->list); |
| 6466 | kfree(iocbq_entry); |
| 6467 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 6468 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6469 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6470 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6471 | return; |
| 6472 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6473 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6474 | /** |
| 6475 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 6476 | * @phba: pointer to lpfc hba data structure. |
| 6477 | * |
| 6478 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 6479 | * list and set up the IOCB tag array accordingly. |
| 6480 | * |
| 6481 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6482 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6483 | * other values - error |
| 6484 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 6485 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6486 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 6487 | { |
| 6488 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 6489 | uint16_t iotag; |
| 6490 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6491 | |
| 6492 | /* Initialize and populate the iocb list per host. */ |
| 6493 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6494 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 6495 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6496 | if (iocbq_entry == NULL) { |
| 6497 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 6498 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 6499 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6500 | goto out_free_iocbq; |
| 6501 | } |
| 6502 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 6503 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 6504 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6505 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 6506 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6507 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 6508 | goto out_free_iocbq; |
| 6509 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6510 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6511 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6512 | |
| 6513 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6514 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 6515 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6516 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6517 | } |
| 6518 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6519 | return 0; |
| 6520 | |
| 6521 | out_free_iocbq: |
| 6522 | lpfc_free_iocb_list(phba); |
| 6523 | |
| 6524 | return -ENOMEM; |
| 6525 | } |
| 6526 | |
| 6527 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6528 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6529 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6530 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6531 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6532 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6533 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6534 | void |
| 6535 | 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] | 6536 | { |
| 6537 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6538 | |
| 6539 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 6540 | list_del(&sglq_entry->list); |
| 6541 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 6542 | kfree(sglq_entry); |
| 6543 | } |
| 6544 | } |
| 6545 | |
| 6546 | /** |
| 6547 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 6548 | * @phba: pointer to lpfc hba data structure. |
| 6549 | * |
| 6550 | * This routine is invoked to free the driver's els sgl list and memory. |
| 6551 | **/ |
| 6552 | static void |
| 6553 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 6554 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6555 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6556 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6557 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6558 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6559 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6560 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); |
| 6561 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6562 | spin_unlock_irq(&phba->hbalock); |
| 6563 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6564 | /* Now free the sgl list */ |
| 6565 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6566 | } |
| 6567 | |
| 6568 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6569 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. |
| 6570 | * @phba: pointer to lpfc hba data structure. |
| 6571 | * |
| 6572 | * This routine is invoked to free the driver's nvmet sgl list and memory. |
| 6573 | **/ |
| 6574 | static void |
| 6575 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) |
| 6576 | { |
| 6577 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 6578 | LIST_HEAD(sglq_list); |
| 6579 | |
| 6580 | /* Retrieve all nvmet sgls from driver list */ |
| 6581 | spin_lock_irq(&phba->hbalock); |
| 6582 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 6583 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); |
| 6584 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 6585 | spin_unlock_irq(&phba->hbalock); |
| 6586 | |
| 6587 | /* Now free the sgl list */ |
| 6588 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { |
| 6589 | list_del(&sglq_entry->list); |
| 6590 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 6591 | kfree(sglq_entry); |
| 6592 | } |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 6593 | |
| 6594 | /* Update the nvmet_xri_cnt to reflect no current sgls. |
| 6595 | * The next initialization cycle sets the count and allocates |
| 6596 | * the sgls over again. |
| 6597 | */ |
| 6598 | phba->sli4_hba.nvmet_xri_cnt = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6599 | } |
| 6600 | |
| 6601 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6602 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 6603 | * @phba: pointer to lpfc hba data structure. |
| 6604 | * |
| 6605 | * This routine is invoked to allocate the driver's active sgl memory. |
| 6606 | * This array will hold the sglq_entry's for active IOs. |
| 6607 | **/ |
| 6608 | static int |
| 6609 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 6610 | { |
| 6611 | int size; |
| 6612 | size = sizeof(struct lpfc_sglq *); |
| 6613 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 6614 | |
| 6615 | phba->sli4_hba.lpfc_sglq_active_list = |
| 6616 | kzalloc(size, GFP_KERNEL); |
| 6617 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 6618 | return -ENOMEM; |
| 6619 | return 0; |
| 6620 | } |
| 6621 | |
| 6622 | /** |
| 6623 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 6624 | * @phba: pointer to lpfc hba data structure. |
| 6625 | * |
| 6626 | * This routine is invoked to walk through the array of active sglq entries |
| 6627 | * and free all of the resources. |
| 6628 | * This is just a place holder for now. |
| 6629 | **/ |
| 6630 | static void |
| 6631 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 6632 | { |
| 6633 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 6634 | } |
| 6635 | |
| 6636 | /** |
| 6637 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 6638 | * @phba: pointer to lpfc hba data structure. |
| 6639 | * |
| 6640 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 6641 | * list and set up the sgl xritag tag array accordingly. |
| 6642 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6643 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6644 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6645 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 6646 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6647 | /* Initialize and populate the sglq list per host/VF. */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6648 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6649 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6650 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 6651 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6652 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6653 | /* els xri-sgl book keeping */ |
| 6654 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6655 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6656 | /* scsi xri-buffer book keeping */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6657 | phba->sli4_hba.scsi_xri_cnt = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6658 | |
| 6659 | /* nvme xri-buffer book keeping */ |
| 6660 | phba->sli4_hba.nvme_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6661 | } |
| 6662 | |
| 6663 | /** |
| 6664 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 6665 | * @phba: pointer to lpfc hba data structure. |
| 6666 | * |
| 6667 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6668 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6669 | * 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] | 6670 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 6671 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6672 | * |
| 6673 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6674 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 6675 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6676 | **/ |
| 6677 | int |
| 6678 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 6679 | { |
| 6680 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6681 | struct lpfc_rpi_hdr *rpi_hdr; |
| 6682 | |
| 6683 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 6684 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6685 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6686 | if (phba->sli4_hba.extents_in_use) |
| 6687 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6688 | |
| 6689 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 6690 | if (!rpi_hdr) { |
| 6691 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, |
| 6692 | "0391 Error during rpi post operation\n"); |
| 6693 | lpfc_sli4_remove_rpis(phba); |
| 6694 | rc = -ENODEV; |
| 6695 | } |
| 6696 | |
| 6697 | return rc; |
| 6698 | } |
| 6699 | |
| 6700 | /** |
| 6701 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 6702 | * @phba: pointer to lpfc hba data structure. |
| 6703 | * |
| 6704 | * This routine is invoked to allocate a single 4KB memory region to |
| 6705 | * support rpis and stores them in the phba. This single region |
| 6706 | * provides support for up to 64 rpis. The region is used globally |
| 6707 | * by the device. |
| 6708 | * |
| 6709 | * Returns: |
| 6710 | * A valid rpi hdr on success. |
| 6711 | * A NULL pointer on any failure. |
| 6712 | **/ |
| 6713 | struct lpfc_rpi_hdr * |
| 6714 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 6715 | { |
| 6716 | uint16_t rpi_limit, curr_rpi_range; |
| 6717 | struct lpfc_dmabuf *dmabuf; |
| 6718 | struct lpfc_rpi_hdr *rpi_hdr; |
| 6719 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6720 | /* |
| 6721 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 6722 | * required. Set the expected maximum count and let the actual value |
| 6723 | * get set when extents are fully allocated. |
| 6724 | */ |
| 6725 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6726 | return NULL; |
| 6727 | if (phba->sli4_hba.extents_in_use) |
| 6728 | return NULL; |
| 6729 | |
| 6730 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 6731 | rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6732 | |
| 6733 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6734 | /* |
| 6735 | * Establish the starting RPI in this header block. The starting |
| 6736 | * rpi is normalized to a zero base because the physical rpi is |
| 6737 | * port based. |
| 6738 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 6739 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6740 | spin_unlock_irq(&phba->hbalock); |
| 6741 | |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 6742 | /* Reached full RPI range */ |
| 6743 | if (curr_rpi_range == rpi_limit) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6744 | return NULL; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 6745 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6746 | /* |
| 6747 | * First allocate the protocol header region for the port. The |
| 6748 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 6749 | */ |
| 6750 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6751 | if (!dmabuf) |
| 6752 | return NULL; |
| 6753 | |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 6754 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
| 6755 | LPFC_HDR_TEMPLATE_SIZE, |
| 6756 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6757 | if (!dmabuf->virt) { |
| 6758 | rpi_hdr = NULL; |
| 6759 | goto err_free_dmabuf; |
| 6760 | } |
| 6761 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6762 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 6763 | rpi_hdr = NULL; |
| 6764 | goto err_free_coherent; |
| 6765 | } |
| 6766 | |
| 6767 | /* Save the rpi header data for cleanup later. */ |
| 6768 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 6769 | if (!rpi_hdr) |
| 6770 | goto err_free_coherent; |
| 6771 | |
| 6772 | rpi_hdr->dmabuf = dmabuf; |
| 6773 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 6774 | rpi_hdr->page_count = 1; |
| 6775 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6776 | |
| 6777 | /* The rpi_hdr stores the logical index only. */ |
| 6778 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 6779 | 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] | 6780 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 6781 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6782 | spin_unlock_irq(&phba->hbalock); |
| 6783 | return rpi_hdr; |
| 6784 | |
| 6785 | err_free_coherent: |
| 6786 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 6787 | dmabuf->virt, dmabuf->phys); |
| 6788 | err_free_dmabuf: |
| 6789 | kfree(dmabuf); |
| 6790 | return NULL; |
| 6791 | } |
| 6792 | |
| 6793 | /** |
| 6794 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 6795 | * @phba: pointer to lpfc hba data structure. |
| 6796 | * |
| 6797 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6798 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 6799 | * presumes the caller has released all rpis consumed by fabric or port |
| 6800 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6801 | **/ |
| 6802 | void |
| 6803 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 6804 | { |
| 6805 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 6806 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6807 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 6808 | goto exit; |
| 6809 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6810 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 6811 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 6812 | list_del(&rpi_hdr->list); |
| 6813 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 6814 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 6815 | kfree(rpi_hdr->dmabuf); |
| 6816 | kfree(rpi_hdr); |
| 6817 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6818 | exit: |
| 6819 | /* There are no rpis available to the port now. */ |
| 6820 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6821 | } |
| 6822 | |
| 6823 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6824 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 6825 | * @pdev: pointer to pci device data structure. |
| 6826 | * |
| 6827 | * This routine is invoked to allocate the driver hba data structure for an |
| 6828 | * HBA device. If the allocation is successful, the phba reference to the |
| 6829 | * PCI device data structure is set. |
| 6830 | * |
| 6831 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6832 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6833 | * NULL - error |
| 6834 | **/ |
| 6835 | static struct lpfc_hba * |
| 6836 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 6837 | { |
| 6838 | struct lpfc_hba *phba; |
| 6839 | |
| 6840 | /* Allocate memory for HBA structure */ |
| 6841 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 6842 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 6843 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6844 | return NULL; |
| 6845 | } |
| 6846 | |
| 6847 | /* Set reference to PCI device in HBA structure */ |
| 6848 | phba->pcidev = pdev; |
| 6849 | |
| 6850 | /* Assign an unused board number */ |
| 6851 | phba->brd_no = lpfc_get_instance(); |
| 6852 | if (phba->brd_no < 0) { |
| 6853 | kfree(phba); |
| 6854 | return NULL; |
| 6855 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6856 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6857 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 6858 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 6859 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 6860 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6861 | return phba; |
| 6862 | } |
| 6863 | |
| 6864 | /** |
| 6865 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 6866 | * @phba: pointer to lpfc hba data structure. |
| 6867 | * |
| 6868 | * This routine is invoked to free the driver hba data structure with an |
| 6869 | * HBA device. |
| 6870 | **/ |
| 6871 | static void |
| 6872 | lpfc_hba_free(struct lpfc_hba *phba) |
| 6873 | { |
| 6874 | /* Release the driver assigned board number */ |
| 6875 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 6876 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6877 | /* Free memory allocated with sli3 rings */ |
| 6878 | kfree(phba->sli.sli3_ring); |
| 6879 | phba->sli.sli3_ring = NULL; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6880 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6881 | kfree(phba); |
| 6882 | return; |
| 6883 | } |
| 6884 | |
| 6885 | /** |
| 6886 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 6887 | * @phba: pointer to lpfc hba data structure. |
| 6888 | * |
| 6889 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 6890 | * host with it. |
| 6891 | * |
| 6892 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6893 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6894 | * other values - error |
| 6895 | **/ |
| 6896 | static int |
| 6897 | lpfc_create_shost(struct lpfc_hba *phba) |
| 6898 | { |
| 6899 | struct lpfc_vport *vport; |
| 6900 | struct Scsi_Host *shost; |
| 6901 | |
| 6902 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6903 | phba->fc_edtov = FF_DEF_EDTOV; |
| 6904 | phba->fc_ratov = FF_DEF_RATOV; |
| 6905 | phba->fc_altov = FF_DEF_ALTOV; |
| 6906 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 6907 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 6908 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 2cee780 | 2017-06-01 21:07:02 -0700 | [diff] [blame] | 6909 | atomic_set(&phba->fc4ScsiInputRequests, 0); |
| 6910 | atomic_set(&phba->fc4ScsiOutputRequests, 0); |
| 6911 | atomic_set(&phba->fc4ScsiControlRequests, 0); |
| 6912 | atomic_set(&phba->fc4ScsiIoCmpls, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 6913 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6914 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6915 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6916 | |
| 6917 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6918 | phba->pport = vport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 6919 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6920 | if (phba->nvmet_support) { |
| 6921 | /* Only 1 vport (pport) will support NVME target */ |
| 6922 | if (phba->txrdy_payload_pool == NULL) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 6923 | phba->txrdy_payload_pool = dma_pool_create( |
| 6924 | "txrdy_pool", &phba->pcidev->dev, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6925 | TXRDY_PAYLOAD_LEN, 16, 0); |
| 6926 | if (phba->txrdy_payload_pool) { |
| 6927 | phba->targetport = NULL; |
| 6928 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; |
| 6929 | lpfc_printf_log(phba, KERN_INFO, |
| 6930 | LOG_INIT | LOG_NVME_DISC, |
| 6931 | "6076 NVME Target Found\n"); |
| 6932 | } |
| 6933 | } |
| 6934 | } |
| 6935 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 6936 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6937 | /* Put reference to SCSI host to driver's device private data */ |
| 6938 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 6939 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6940 | /* |
| 6941 | * At this point we are fully registered with PSA. In addition, |
| 6942 | * any initial discovery should be completed. |
| 6943 | */ |
| 6944 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 6945 | if (phba->cfg_enable_SmartSAN || |
| 6946 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6947 | |
| 6948 | /* Setup appropriate attribute masks */ |
| 6949 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 6950 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 6951 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 6952 | else |
| 6953 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 6954 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6955 | return 0; |
| 6956 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6957 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6958 | /** |
| 6959 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 6960 | * @phba: pointer to lpfc hba data structure. |
| 6961 | * |
| 6962 | * This routine is invoked to destroy HBA physical port and the associated |
| 6963 | * SCSI host. |
| 6964 | **/ |
| 6965 | static void |
| 6966 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 6967 | { |
| 6968 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 6969 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6970 | /* Destroy physical port that associated with the SCSI host */ |
| 6971 | destroy_port(vport); |
| 6972 | |
| 6973 | return; |
| 6974 | } |
| 6975 | |
| 6976 | /** |
| 6977 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 6978 | * @phba: pointer to lpfc hba data structure. |
| 6979 | * @shost: the shost to be used to detect Block guard settings. |
| 6980 | * |
| 6981 | * This routine sets up the local Block guard protocol settings for @shost. |
| 6982 | * This routine also allocates memory for debugging bg buffers. |
| 6983 | **/ |
| 6984 | static void |
| 6985 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 6986 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6987 | uint32_t old_mask; |
| 6988 | uint32_t old_guard; |
| 6989 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6990 | int pagecnt = 10; |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 6991 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6992 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6993 | "1478 Registering BlockGuard with the " |
| 6994 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6995 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 6996 | old_mask = phba->cfg_prot_mask; |
| 6997 | old_guard = phba->cfg_prot_guard; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 6998 | |
| 6999 | /* Only allow supported values */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7000 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7001 | SHOST_DIX_TYPE0_PROTECTION | |
| 7002 | SHOST_DIX_TYPE1_PROTECTION); |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7003 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
| 7004 | SHOST_DIX_GUARD_CRC); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7005 | |
| 7006 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7007 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 7008 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7009 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7010 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
| 7011 | if ((old_mask != phba->cfg_prot_mask) || |
| 7012 | (old_guard != phba->cfg_prot_guard)) |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7013 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7014 | "1475 Registering BlockGuard with the " |
| 7015 | "SCSI layer: mask %d guard %d\n", |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7016 | phba->cfg_prot_mask, |
| 7017 | phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7018 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7019 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
| 7020 | scsi_host_set_guard(shost, phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7021 | } else |
| 7022 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7023 | "1479 Not Registering BlockGuard with the SCSI " |
| 7024 | "layer, Bad protection parameters: %d %d\n", |
| 7025 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7026 | } |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7027 | |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7028 | if (!_dump_buf_data) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7029 | while (pagecnt) { |
| 7030 | spin_lock_init(&_dump_buf_lock); |
| 7031 | _dump_buf_data = |
| 7032 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 7033 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7034 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7035 | "9043 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7036 | "_dump_buf_data at 0x%p\n", |
| 7037 | (1 << pagecnt), _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7038 | _dump_buf_data_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7039 | memset(_dump_buf_data, 0, |
| 7040 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7041 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7042 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7043 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7044 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7045 | if (!_dump_buf_data_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7046 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7047 | "9044 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7048 | "memory for hexdump\n"); |
| 7049 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7050 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7051 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7052 | "\n", _dump_buf_data); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7053 | if (!_dump_buf_dif) { |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7054 | while (pagecnt) { |
| 7055 | _dump_buf_dif = |
| 7056 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); |
| 7057 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7058 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7059 | "9046 BLKGRD: allocated %d pages for " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7060 | "_dump_buf_dif at 0x%p\n", |
| 7061 | (1 << pagecnt), _dump_buf_dif); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7062 | _dump_buf_dif_order = pagecnt; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7063 | memset(_dump_buf_dif, 0, |
| 7064 | ((1 << PAGE_SHIFT) << pagecnt)); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7065 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7066 | } else |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7067 | --pagecnt; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7068 | } |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 7069 | if (!_dump_buf_dif_order) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7070 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7071 | "9047 BLKGRD: ERROR unable to allocate " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7072 | "memory for hexdump\n"); |
| 7073 | } else |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 7074 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
| 7075 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7076 | _dump_buf_dif); |
| 7077 | } |
| 7078 | |
| 7079 | /** |
| 7080 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 7081 | * @phba: pointer to lpfc hba data structure. |
| 7082 | * |
| 7083 | * This routine is invoked to perform all the necessary post initialization |
| 7084 | * setup for the device. |
| 7085 | **/ |
| 7086 | static void |
| 7087 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 7088 | { |
| 7089 | struct Scsi_Host *shost; |
| 7090 | struct lpfc_adapter_event_header adapter_event; |
| 7091 | |
| 7092 | /* Get the default values for Model Name and Description */ |
| 7093 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 7094 | |
| 7095 | /* |
| 7096 | * hba setup may have changed the hba_queue_depth so we need to |
| 7097 | * adjust the value of can_queue. |
| 7098 | */ |
| 7099 | shost = pci_get_drvdata(phba->pcidev); |
| 7100 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 7101 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 7102 | lpfc_setup_bg(phba, shost); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7103 | |
| 7104 | lpfc_host_attrib_init(shost); |
| 7105 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7106 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 7107 | spin_lock_irq(shost->host_lock); |
| 7108 | lpfc_poll_start_timer(phba); |
| 7109 | spin_unlock_irq(shost->host_lock); |
| 7110 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 7111 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7112 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7113 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7114 | /* Send board arrival event to upper layer */ |
| 7115 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 7116 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 7117 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7118 | sizeof(adapter_event), |
| 7119 | (char *) &adapter_event, |
| 7120 | LPFC_NL_VENDOR_ID); |
| 7121 | return; |
| 7122 | } |
| 7123 | |
| 7124 | /** |
| 7125 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 7126 | * @phba: pointer to lpfc hba data structure. |
| 7127 | * |
| 7128 | * This routine is invoked to set up the PCI device memory space for device |
| 7129 | * with SLI-3 interface spec. |
| 7130 | * |
| 7131 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7132 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7133 | * other values - error |
| 7134 | **/ |
| 7135 | static int |
| 7136 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 7137 | { |
| 7138 | struct pci_dev *pdev; |
| 7139 | unsigned long bar0map_len, bar2map_len; |
| 7140 | int i, hbq_count; |
| 7141 | void *ptr; |
| 7142 | int error = -ENODEV; |
| 7143 | |
| 7144 | /* Obtain PCI device reference */ |
| 7145 | if (!phba->pcidev) |
| 7146 | return error; |
| 7147 | else |
| 7148 | pdev = phba->pcidev; |
| 7149 | |
| 7150 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7151 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 7152 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 7153 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 7154 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7155 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 7156 | } |
| 7157 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7158 | |
| 7159 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 7160 | * required by each mapping. |
| 7161 | */ |
| 7162 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7163 | bar0map_len = pci_resource_len(pdev, 0); |
| 7164 | |
| 7165 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 7166 | bar2map_len = pci_resource_len(pdev, 2); |
| 7167 | |
| 7168 | /* Map HBA SLIM to a kernel virtual address. */ |
| 7169 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 7170 | if (!phba->slim_memmap_p) { |
| 7171 | dev_printk(KERN_ERR, &pdev->dev, |
| 7172 | "ioremap failed for SLIM memory.\n"); |
| 7173 | goto out; |
| 7174 | } |
| 7175 | |
| 7176 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 7177 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 7178 | if (!phba->ctrl_regs_memmap_p) { |
| 7179 | dev_printk(KERN_ERR, &pdev->dev, |
| 7180 | "ioremap failed for HBA control registers.\n"); |
| 7181 | goto out_iounmap_slim; |
| 7182 | } |
| 7183 | |
| 7184 | /* Allocate memory for SLI-2 structures */ |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 7185 | phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7186 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7187 | if (!phba->slim2p.virt) |
| 7188 | goto out_iounmap; |
| 7189 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7190 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7191 | phba->mbox_ext = (phba->slim2p.virt + |
| 7192 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7193 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 7194 | phba->IOCBs = (phba->slim2p.virt + |
| 7195 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 7196 | |
| 7197 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 7198 | lpfc_sli_hbq_size(), |
| 7199 | &phba->hbqslimp.phys, |
| 7200 | GFP_KERNEL); |
| 7201 | if (!phba->hbqslimp.virt) |
| 7202 | goto out_free_slim; |
| 7203 | |
| 7204 | hbq_count = lpfc_sli_hbq_count(); |
| 7205 | ptr = phba->hbqslimp.virt; |
| 7206 | for (i = 0; i < hbq_count; ++i) { |
| 7207 | phba->hbqs[i].hbq_virt = ptr; |
| 7208 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 7209 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 7210 | sizeof(struct lpfc_hbq_entry)); |
| 7211 | } |
| 7212 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 7213 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 7214 | |
| 7215 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 7216 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7217 | phba->MBslimaddr = phba->slim_memmap_p; |
| 7218 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 7219 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 7220 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 7221 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7222 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7223 | return 0; |
| 7224 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7225 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7226 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7227 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7228 | out_iounmap: |
| 7229 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7230 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7231 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7232 | out: |
| 7233 | return error; |
| 7234 | } |
| 7235 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7236 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7237 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 7238 | * @phba: pointer to lpfc hba data structure. |
| 7239 | * |
| 7240 | * This routine is invoked to unset the PCI device memory space for device |
| 7241 | * with SLI-3 interface spec. |
| 7242 | **/ |
| 7243 | static void |
| 7244 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 7245 | { |
| 7246 | struct pci_dev *pdev; |
| 7247 | |
| 7248 | /* Obtain PCI device reference */ |
| 7249 | if (!phba->pcidev) |
| 7250 | return; |
| 7251 | else |
| 7252 | pdev = phba->pcidev; |
| 7253 | |
| 7254 | /* Free coherent DMA memory allocated */ |
| 7255 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 7256 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 7257 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7258 | phba->slim2p.virt, phba->slim2p.phys); |
| 7259 | |
| 7260 | /* I/O memory unmap */ |
| 7261 | iounmap(phba->ctrl_regs_memmap_p); |
| 7262 | iounmap(phba->slim_memmap_p); |
| 7263 | |
| 7264 | return; |
| 7265 | } |
| 7266 | |
| 7267 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7268 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 7269 | * @phba: pointer to lpfc hba data structure. |
| 7270 | * |
| 7271 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 7272 | * done and check status. |
| 7273 | * |
| 7274 | * Return 0 if successful, otherwise -ENODEV. |
| 7275 | **/ |
| 7276 | int |
| 7277 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 7278 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7279 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 7280 | struct lpfc_register reg_data; |
| 7281 | int i, port_error = 0; |
| 7282 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7283 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7284 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 7285 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7286 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7287 | return -ENODEV; |
| 7288 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7289 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 7290 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7291 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 7292 | &portsmphr_reg.word0) || |
| 7293 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7294 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7295 | port_error = -ENODEV; |
| 7296 | break; |
| 7297 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7298 | if (LPFC_POST_STAGE_PORT_READY == |
| 7299 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7300 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7301 | msleep(10); |
| 7302 | } |
| 7303 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7304 | /* |
| 7305 | * If there was a port error during POST, then don't proceed with |
| 7306 | * other register reads as the data may not be valid. Just exit. |
| 7307 | */ |
| 7308 | if (port_error) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7309 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7310 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 7311 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 7312 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 7313 | portsmphr_reg.word0, |
| 7314 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 7315 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 7316 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 7317 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 7318 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 7319 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 7320 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 7321 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 7322 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7323 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7324 | "2534 Device Info: SLIFamily=0x%x, " |
| 7325 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 7326 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7327 | bf_get(lpfc_sli_intf_sli_family, |
| 7328 | &phba->sli4_hba.sli_intf), |
| 7329 | bf_get(lpfc_sli_intf_slirev, |
| 7330 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7331 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7332 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7333 | bf_get(lpfc_sli_intf_sli_hint1, |
| 7334 | &phba->sli4_hba.sli_intf), |
| 7335 | bf_get(lpfc_sli_intf_sli_hint2, |
| 7336 | &phba->sli4_hba.sli_intf), |
| 7337 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7338 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7339 | /* |
| 7340 | * Check for other Port errors during the initialization |
| 7341 | * process. Fail the load if the port did not come up |
| 7342 | * correctly. |
| 7343 | */ |
| 7344 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 7345 | &phba->sli4_hba.sli_intf); |
| 7346 | switch (if_type) { |
| 7347 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7348 | phba->sli4_hba.ue_mask_lo = |
| 7349 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 7350 | phba->sli4_hba.ue_mask_hi = |
| 7351 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 7352 | uerrlo_reg.word0 = |
| 7353 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 7354 | uerrhi_reg.word0 = |
| 7355 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 7356 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 7357 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
| 7358 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7359 | "1422 Unrecoverable Error " |
| 7360 | "Detected during POST " |
| 7361 | "uerr_lo_reg=0x%x, " |
| 7362 | "uerr_hi_reg=0x%x, " |
| 7363 | "ue_mask_lo_reg=0x%x, " |
| 7364 | "ue_mask_hi_reg=0x%x\n", |
| 7365 | uerrlo_reg.word0, |
| 7366 | uerrhi_reg.word0, |
| 7367 | phba->sli4_hba.ue_mask_lo, |
| 7368 | phba->sli4_hba.ue_mask_hi); |
| 7369 | port_error = -ENODEV; |
| 7370 | } |
| 7371 | break; |
| 7372 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7373 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7374 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7375 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 7376 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7377 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 7378 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7379 | phba->work_status[0] = |
| 7380 | readl(phba->sli4_hba.u.if_type2. |
| 7381 | ERR1regaddr); |
| 7382 | phba->work_status[1] = |
| 7383 | readl(phba->sli4_hba.u.if_type2. |
| 7384 | ERR2regaddr); |
| 7385 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 7386 | "2888 Unrecoverable port error " |
| 7387 | "following POST: port status reg " |
| 7388 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7389 | "error 1=0x%x, error 2=0x%x\n", |
| 7390 | reg_data.word0, |
| 7391 | portsmphr_reg.word0, |
| 7392 | phba->work_status[0], |
| 7393 | phba->work_status[1]); |
| 7394 | port_error = -ENODEV; |
| 7395 | } |
| 7396 | break; |
| 7397 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7398 | default: |
| 7399 | break; |
| 7400 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7401 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7402 | return port_error; |
| 7403 | } |
| 7404 | |
| 7405 | /** |
| 7406 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 7407 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7408 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7409 | * |
| 7410 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 7411 | * memory map. |
| 7412 | **/ |
| 7413 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7414 | 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] | 7415 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7416 | switch (if_type) { |
| 7417 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7418 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 7419 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 7420 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 7421 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 7422 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 7423 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 7424 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 7425 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 7426 | phba->sli4_hba.SLIINTFregaddr = |
| 7427 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 7428 | break; |
| 7429 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 7430 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 7431 | phba->sli4_hba.conf_regs_memmap_p + |
| 7432 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7433 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7434 | phba->sli4_hba.conf_regs_memmap_p + |
| 7435 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7436 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7437 | phba->sli4_hba.conf_regs_memmap_p + |
| 7438 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7439 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7440 | phba->sli4_hba.conf_regs_memmap_p + |
| 7441 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7442 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7443 | phba->sli4_hba.conf_regs_memmap_p + |
| 7444 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7445 | phba->sli4_hba.SLIINTFregaddr = |
| 7446 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 7447 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7448 | phba->sli4_hba.conf_regs_memmap_p + |
| 7449 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7450 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7451 | phba->sli4_hba.conf_regs_memmap_p + |
| 7452 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7453 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7454 | phba->sli4_hba.conf_regs_memmap_p + |
| 7455 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 7456 | phba->sli4_hba.CQDBregaddr = |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7457 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 7458 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7459 | phba->sli4_hba.MQDBregaddr = |
| 7460 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 7461 | phba->sli4_hba.BMBXregaddr = |
| 7462 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 7463 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7464 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 7465 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 7466 | phba->sli4_hba.conf_regs_memmap_p + |
| 7467 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
| 7468 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
| 7469 | phba->sli4_hba.conf_regs_memmap_p + |
| 7470 | LPFC_CTL_PORT_ER1_OFFSET; |
| 7471 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
| 7472 | phba->sli4_hba.conf_regs_memmap_p + |
| 7473 | LPFC_CTL_PORT_ER2_OFFSET; |
| 7474 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
| 7475 | phba->sli4_hba.conf_regs_memmap_p + |
| 7476 | LPFC_CTL_PORT_CTL_OFFSET; |
| 7477 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
| 7478 | phba->sli4_hba.conf_regs_memmap_p + |
| 7479 | LPFC_CTL_PORT_STA_OFFSET; |
| 7480 | phba->sli4_hba.PSMPHRregaddr = |
| 7481 | phba->sli4_hba.conf_regs_memmap_p + |
| 7482 | LPFC_CTL_PORT_SEM_OFFSET; |
| 7483 | phba->sli4_hba.BMBXregaddr = |
| 7484 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 7485 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7486 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7487 | default: |
| 7488 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 7489 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 7490 | if_type); |
| 7491 | break; |
| 7492 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7493 | } |
| 7494 | |
| 7495 | /** |
| 7496 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 7497 | * @phba: pointer to lpfc hba data structure. |
| 7498 | * |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7499 | * This routine is invoked to set up SLI4 BAR1 register memory map. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7500 | **/ |
| 7501 | static void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7502 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba, uint32_t if_type) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7503 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7504 | switch (if_type) { |
| 7505 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7506 | phba->sli4_hba.PSMPHRregaddr = |
| 7507 | phba->sli4_hba.ctrl_regs_memmap_p + |
| 7508 | LPFC_SLIPORT_IF0_SMPHR; |
| 7509 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 7510 | LPFC_HST_ISR0; |
| 7511 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 7512 | LPFC_HST_IMR0; |
| 7513 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 7514 | LPFC_HST_ISCR0; |
| 7515 | break; |
| 7516 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 7517 | phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 7518 | LPFC_IF6_RQ_DOORBELL; |
| 7519 | phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 7520 | LPFC_IF6_WQ_DOORBELL; |
| 7521 | phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 7522 | LPFC_IF6_CQ_DOORBELL; |
| 7523 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 7524 | LPFC_IF6_EQ_DOORBELL; |
| 7525 | phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 7526 | LPFC_IF6_MQ_DOORBELL; |
| 7527 | break; |
| 7528 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 7529 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 7530 | default: |
| 7531 | dev_err(&phba->pcidev->dev, |
| 7532 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 7533 | if_type); |
| 7534 | break; |
| 7535 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7536 | } |
| 7537 | |
| 7538 | /** |
| 7539 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 7540 | * @phba: pointer to lpfc hba data structure. |
| 7541 | * @vf: virtual function number |
| 7542 | * |
| 7543 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 7544 | * based on the given viftual function number, @vf. |
| 7545 | * |
| 7546 | * Return 0 if successful, otherwise -ENODEV. |
| 7547 | **/ |
| 7548 | static int |
| 7549 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 7550 | { |
| 7551 | if (vf > LPFC_VIR_FUNC_MAX) |
| 7552 | return -ENODEV; |
| 7553 | |
| 7554 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7555 | vf * LPFC_VFR_PAGE_SIZE + |
| 7556 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7557 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 7558 | vf * LPFC_VFR_PAGE_SIZE + |
| 7559 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 7560 | phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 7561 | vf * LPFC_VFR_PAGE_SIZE + |
| 7562 | LPFC_EQCQ_DOORBELL); |
| 7563 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7564 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 7565 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 7566 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 7567 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 7568 | return 0; |
| 7569 | } |
| 7570 | |
| 7571 | /** |
| 7572 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 7573 | * @phba: pointer to lpfc hba data structure. |
| 7574 | * |
| 7575 | * This routine is invoked to create the bootstrap mailbox |
| 7576 | * region consistent with the SLI-4 interface spec. This |
| 7577 | * routine allocates all memory necessary to communicate |
| 7578 | * mailbox commands to the port and sets up all alignment |
| 7579 | * needs. No locks are expected to be held when calling |
| 7580 | * this routine. |
| 7581 | * |
| 7582 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7583 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7584 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7585 | **/ |
| 7586 | static int |
| 7587 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 7588 | { |
| 7589 | uint32_t bmbx_size; |
| 7590 | struct lpfc_dmabuf *dmabuf; |
| 7591 | struct dma_address *dma_address; |
| 7592 | uint32_t pa_addr; |
| 7593 | uint64_t phys_addr; |
| 7594 | |
| 7595 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 7596 | if (!dmabuf) |
| 7597 | return -ENOMEM; |
| 7598 | |
| 7599 | /* |
| 7600 | * The bootstrap mailbox region is comprised of 2 parts |
| 7601 | * plus an alignment restriction of 16 bytes. |
| 7602 | */ |
| 7603 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Joe Perches | 1aee383 | 2014-09-03 12:56:12 -0400 | [diff] [blame] | 7604 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 7605 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7606 | if (!dmabuf->virt) { |
| 7607 | kfree(dmabuf); |
| 7608 | return -ENOMEM; |
| 7609 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7610 | |
| 7611 | /* |
| 7612 | * Initialize the bootstrap mailbox pointers now so that the register |
| 7613 | * operations are simple later. The mailbox dma address is required |
| 7614 | * to be 16-byte aligned. Also align the virtual memory as each |
| 7615 | * maibox is copied into the bmbx mailbox region before issuing the |
| 7616 | * command to the port. |
| 7617 | */ |
| 7618 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 7619 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 7620 | |
| 7621 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 7622 | LPFC_ALIGN_16_BYTE); |
| 7623 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 7624 | LPFC_ALIGN_16_BYTE); |
| 7625 | |
| 7626 | /* |
| 7627 | * Set the high and low physical addresses now. The SLI4 alignment |
| 7628 | * requirement is 16 bytes and the mailbox is posted to the port |
| 7629 | * as two 30-bit addresses. The other data is a bit marking whether |
| 7630 | * the 30-bit address is the high or low address. |
| 7631 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 7632 | * clean on 32 bit machines. |
| 7633 | */ |
| 7634 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 7635 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 7636 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 7637 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 7638 | LPFC_BMBX_BIT1_ADDR_HI); |
| 7639 | |
| 7640 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 7641 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 7642 | LPFC_BMBX_BIT1_ADDR_LO); |
| 7643 | return 0; |
| 7644 | } |
| 7645 | |
| 7646 | /** |
| 7647 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 7648 | * @phba: pointer to lpfc hba data structure. |
| 7649 | * |
| 7650 | * This routine is invoked to teardown the bootstrap mailbox |
| 7651 | * region and release all host resources. This routine requires |
| 7652 | * the caller to ensure all mailbox commands recovered, no |
| 7653 | * additional mailbox comands are sent, and interrupts are disabled |
| 7654 | * before calling this routine. |
| 7655 | * |
| 7656 | **/ |
| 7657 | static void |
| 7658 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 7659 | { |
| 7660 | dma_free_coherent(&phba->pcidev->dev, |
| 7661 | phba->sli4_hba.bmbx.bmbx_size, |
| 7662 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 7663 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 7664 | |
| 7665 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 7666 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 7667 | } |
| 7668 | |
| 7669 | /** |
| 7670 | * lpfc_sli4_read_config - Get the config parameters. |
| 7671 | * @phba: pointer to lpfc hba data structure. |
| 7672 | * |
| 7673 | * This routine is invoked to read the configuration parameters from the HBA. |
| 7674 | * The configuration parameters are used to set the base and maximum values |
| 7675 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 7676 | * allocation for the port. |
| 7677 | * |
| 7678 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7679 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7680 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7681 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7682 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7683 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7684 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 7685 | { |
| 7686 | LPFC_MBOXQ_t *pmb; |
| 7687 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7688 | union lpfc_sli4_cfg_shdr *shdr; |
| 7689 | uint32_t shdr_status, shdr_add_status; |
| 7690 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 7691 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7692 | char *pdesc_0; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 7693 | uint16_t forced_link_speed; |
| 7694 | uint32_t if_type; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7695 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7696 | |
| 7697 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 7698 | if (!pmb) { |
| 7699 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7700 | "2011 Unable to allocate memory for issuing " |
| 7701 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 7702 | return -ENOMEM; |
| 7703 | } |
| 7704 | |
| 7705 | lpfc_read_config(phba, pmb); |
| 7706 | |
| 7707 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 7708 | if (rc != MBX_SUCCESS) { |
| 7709 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7710 | "2012 Mailbox failed , mbxCmd x%x " |
| 7711 | "READ_CONFIG, mbxStatus x%x\n", |
| 7712 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 7713 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
| 7714 | rc = -EIO; |
| 7715 | } else { |
| 7716 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7717 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 7718 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 7719 | phba->sli4_hba.lnk_info.lnk_tp = |
| 7720 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 7721 | phba->sli4_hba.lnk_info.lnk_no = |
| 7722 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 7723 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 7724 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 7725 | phba->sli4_hba.lnk_info.lnk_tp, |
| 7726 | phba->sli4_hba.lnk_info.lnk_no); |
| 7727 | } else |
| 7728 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 7729 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 7730 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 7731 | if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) { |
| 7732 | phba->bbcredit_support = 1; |
| 7733 | phba->sli4_hba.bbscn_params.word0 = rd_config->word8; |
| 7734 | } |
| 7735 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7736 | phba->sli4_hba.extents_in_use = |
| 7737 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7738 | phba->sli4_hba.max_cfg_param.max_xri = |
| 7739 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
| 7740 | phba->sli4_hba.max_cfg_param.xri_base = |
| 7741 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 7742 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 7743 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
| 7744 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 7745 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 7746 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 7747 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 7748 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 7749 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 7750 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 7751 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 7752 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 7753 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 7754 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 7755 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7756 | phba->sli4_hba.max_cfg_param.max_eq = |
| 7757 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 7758 | phba->sli4_hba.max_cfg_param.max_rq = |
| 7759 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 7760 | phba->sli4_hba.max_cfg_param.max_wq = |
| 7761 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 7762 | phba->sli4_hba.max_cfg_param.max_cq = |
| 7763 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 7764 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 7765 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 7766 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 7767 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 7768 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 7769 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7770 | phba->max_vports = phba->max_vpi; |
| 7771 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7772 | "2003 cfg params Extents? %d " |
| 7773 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7774 | "VPI(B:%d M:%d) " |
| 7775 | "VFI(B:%d M:%d) " |
| 7776 | "RPI(B:%d M:%d) " |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7777 | "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n", |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7778 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7779 | phba->sli4_hba.max_cfg_param.xri_base, |
| 7780 | phba->sli4_hba.max_cfg_param.max_xri, |
| 7781 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 7782 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 7783 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 7784 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 7785 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 7786 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7787 | phba->sli4_hba.max_cfg_param.max_fcfi, |
| 7788 | phba->sli4_hba.max_cfg_param.max_eq, |
| 7789 | phba->sli4_hba.max_cfg_param.max_cq, |
| 7790 | phba->sli4_hba.max_cfg_param.max_wq, |
| 7791 | phba->sli4_hba.max_cfg_param.max_rq); |
| 7792 | |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 7793 | /* |
| 7794 | * Calculate NVME queue resources based on how |
| 7795 | * many WQ/CQs are available. |
| 7796 | */ |
| 7797 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 7798 | length = phba->sli4_hba.max_cfg_param.max_wq; |
| 7799 | if (phba->sli4_hba.max_cfg_param.max_cq < |
| 7800 | phba->sli4_hba.max_cfg_param.max_wq) |
| 7801 | length = phba->sli4_hba.max_cfg_param.max_cq; |
| 7802 | |
| 7803 | /* |
| 7804 | * Whats left after this can go toward NVME. |
| 7805 | * The minus 6 accounts for ELS, NVME LS, MBOX |
| 7806 | * fof plus a couple extra. When configured for |
| 7807 | * NVMET, FCP io channel WQs are not created. |
| 7808 | */ |
| 7809 | length -= 6; |
| 7810 | if (!phba->nvmet_support) |
| 7811 | length -= phba->cfg_fcp_io_channel; |
| 7812 | |
| 7813 | if (phba->cfg_nvme_io_channel > length) { |
| 7814 | lpfc_printf_log( |
| 7815 | phba, KERN_ERR, LOG_SLI, |
| 7816 | "2005 Reducing NVME IO channel to %d: " |
| 7817 | "WQ %d CQ %d NVMEIO %d FCPIO %d\n", |
| 7818 | length, |
| 7819 | phba->sli4_hba.max_cfg_param.max_wq, |
| 7820 | phba->sli4_hba.max_cfg_param.max_cq, |
| 7821 | phba->cfg_nvme_io_channel, |
| 7822 | phba->cfg_fcp_io_channel); |
| 7823 | |
| 7824 | phba->cfg_nvme_io_channel = length; |
| 7825 | } |
| 7826 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7827 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7828 | |
| 7829 | if (rc) |
| 7830 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7831 | |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 7832 | /* Update link speed if forced link speed is supported */ |
| 7833 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7834 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 7835 | forced_link_speed = |
| 7836 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); |
| 7837 | if (forced_link_speed) { |
| 7838 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; |
| 7839 | |
| 7840 | switch (forced_link_speed) { |
| 7841 | case LINK_SPEED_1G: |
| 7842 | phba->cfg_link_speed = |
| 7843 | LPFC_USER_LINK_SPEED_1G; |
| 7844 | break; |
| 7845 | case LINK_SPEED_2G: |
| 7846 | phba->cfg_link_speed = |
| 7847 | LPFC_USER_LINK_SPEED_2G; |
| 7848 | break; |
| 7849 | case LINK_SPEED_4G: |
| 7850 | phba->cfg_link_speed = |
| 7851 | LPFC_USER_LINK_SPEED_4G; |
| 7852 | break; |
| 7853 | case LINK_SPEED_8G: |
| 7854 | phba->cfg_link_speed = |
| 7855 | LPFC_USER_LINK_SPEED_8G; |
| 7856 | break; |
| 7857 | case LINK_SPEED_10G: |
| 7858 | phba->cfg_link_speed = |
| 7859 | LPFC_USER_LINK_SPEED_10G; |
| 7860 | break; |
| 7861 | case LINK_SPEED_16G: |
| 7862 | phba->cfg_link_speed = |
| 7863 | LPFC_USER_LINK_SPEED_16G; |
| 7864 | break; |
| 7865 | case LINK_SPEED_32G: |
| 7866 | phba->cfg_link_speed = |
| 7867 | LPFC_USER_LINK_SPEED_32G; |
| 7868 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 7869 | case LINK_SPEED_64G: |
| 7870 | phba->cfg_link_speed = |
| 7871 | LPFC_USER_LINK_SPEED_64G; |
| 7872 | break; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 7873 | case 0xffff: |
| 7874 | phba->cfg_link_speed = |
| 7875 | LPFC_USER_LINK_SPEED_AUTO; |
| 7876 | break; |
| 7877 | default: |
| 7878 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7879 | "0047 Unrecognized link " |
| 7880 | "speed : %d\n", |
| 7881 | forced_link_speed); |
| 7882 | phba->cfg_link_speed = |
| 7883 | LPFC_USER_LINK_SPEED_AUTO; |
| 7884 | } |
| 7885 | } |
| 7886 | } |
| 7887 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7888 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 7889 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 7890 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 7891 | if (phba->cfg_hba_queue_depth > length) { |
| 7892 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7893 | "3361 HBA queue depth changed from %d to %d\n", |
| 7894 | phba->cfg_hba_queue_depth, length); |
| 7895 | phba->cfg_hba_queue_depth = length; |
| 7896 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7897 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7898 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7899 | LPFC_SLI_INTF_IF_TYPE_2) |
| 7900 | goto read_cfg_out; |
| 7901 | |
| 7902 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 7903 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 7904 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 7905 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 7906 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 7907 | length, LPFC_SLI4_MBX_EMBED); |
| 7908 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7909 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7910 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 7911 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 7912 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 7913 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7914 | if (rc2 || shdr_status || shdr_add_status) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7915 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7916 | "3026 Mailbox failed , mbxCmd x%x " |
| 7917 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 7918 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 7919 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7920 | goto read_cfg_out; |
| 7921 | } |
| 7922 | |
| 7923 | /* search for fc_fcoe resrouce descriptor */ |
| 7924 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7925 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7926 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 7927 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 7928 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 7929 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 7930 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 7931 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 7932 | goto read_cfg_out; |
| 7933 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7934 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7935 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7936 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7937 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7938 | phba->sli4_hba.iov.pf_number = |
| 7939 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 7940 | phba->sli4_hba.iov.vf_number = |
| 7941 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 7942 | break; |
| 7943 | } |
| 7944 | } |
| 7945 | |
| 7946 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 7947 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 7948 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 7949 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 7950 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 7951 | else |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7952 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
| 7953 | "3028 GET_FUNCTION_CONFIG: failed to find " |
| 7954 | "Resrouce Descriptor:x%x\n", |
| 7955 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7956 | |
| 7957 | read_cfg_out: |
| 7958 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7959 | return rc; |
| 7960 | } |
| 7961 | |
| 7962 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7963 | * 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] | 7964 | * @phba: pointer to lpfc hba data structure. |
| 7965 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7966 | * This routine is invoked to setup the port-side endian order when |
| 7967 | * the port if_type is 0. This routine has no function for other |
| 7968 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7969 | * |
| 7970 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7971 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7972 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 7973 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7974 | **/ |
| 7975 | static int |
| 7976 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 7977 | { |
| 7978 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7979 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7980 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 7981 | HOST_ENDIAN_HIGH_WORD1}; |
| 7982 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7983 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 7984 | switch (if_type) { |
| 7985 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 7986 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7987 | GFP_KERNEL); |
| 7988 | if (!mboxq) { |
| 7989 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 7990 | "0492 Unable to allocate memory for " |
| 7991 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 7992 | "command\n"); |
| 7993 | return -ENOMEM; |
| 7994 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7995 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7996 | /* |
| 7997 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 7998 | * two words to contain special data values and no other data. |
| 7999 | */ |
| 8000 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 8001 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 8002 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8003 | if (rc != MBX_SUCCESS) { |
| 8004 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8005 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 8006 | "failed with status x%x\n", |
| 8007 | rc); |
| 8008 | rc = -EIO; |
| 8009 | } |
| 8010 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8011 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8012 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8013 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8014 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8015 | default: |
| 8016 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8017 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8018 | return rc; |
| 8019 | } |
| 8020 | |
| 8021 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8022 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8023 | * @phba: pointer to lpfc hba data structure. |
| 8024 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8025 | * This routine is invoked to check the user settable queue counts for EQs. |
| 8026 | * 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] | 8027 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 8028 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8029 | * |
| 8030 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8031 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8032 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8033 | **/ |
| 8034 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8035 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8036 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8037 | int io_channel; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8038 | int fof_vectors = phba->cfg_fof ? 1 : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8039 | |
| 8040 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8041 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8042 | * device parameters |
| 8043 | */ |
| 8044 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8045 | /* Sanity check on HBA EQ parameters */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8046 | io_channel = phba->io_channel_irqs; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8047 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8048 | if (phba->sli4_hba.num_online_cpu < io_channel) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8049 | lpfc_printf_log(phba, |
| 8050 | KERN_ERR, LOG_INIT, |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 8051 | "3188 Reducing IO channels to match number of " |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8052 | "online CPUs: from %d to %d\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8053 | io_channel, phba->sli4_hba.num_online_cpu); |
| 8054 | io_channel = phba->sli4_hba.num_online_cpu; |
James Smart | 90695ee | 2012-08-14 14:25:36 -0400 | [diff] [blame] | 8055 | } |
| 8056 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8057 | 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] | 8058 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8059 | "2575 Reducing IO channels to match number of " |
| 8060 | "available EQs: from %d to %d\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8061 | io_channel, |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 8062 | phba->sli4_hba.max_cfg_param.max_eq); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8063 | io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8064 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8065 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8066 | /* The actual number of FCP / NVME event queues adopted */ |
| 8067 | if (io_channel != phba->io_channel_irqs) |
| 8068 | phba->io_channel_irqs = io_channel; |
| 8069 | if (phba->cfg_fcp_io_channel > io_channel) |
| 8070 | phba->cfg_fcp_io_channel = io_channel; |
| 8071 | if (phba->cfg_nvme_io_channel > io_channel) |
| 8072 | phba->cfg_nvme_io_channel = io_channel; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8073 | if (phba->nvmet_support) { |
| 8074 | if (phba->cfg_nvme_io_channel < phba->cfg_nvmet_mrq) |
| 8075 | phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel; |
| 8076 | } |
| 8077 | if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) |
| 8078 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8079 | |
| 8080 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8081 | "2574 IO channels: irqs %d fcp %d nvme %d MRQ: %d\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8082 | phba->io_channel_irqs, phba->cfg_fcp_io_channel, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8083 | phba->cfg_nvme_io_channel, phba->cfg_nvmet_mrq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8084 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8085 | /* Get EQ depth from module parameter, fake the default for now */ |
| 8086 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8087 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8088 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8089 | /* Get CQ depth from module parameter, fake the default for now */ |
| 8090 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8091 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8092 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8093 | } |
| 8094 | |
| 8095 | static int |
| 8096 | lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx) |
| 8097 | { |
| 8098 | struct lpfc_queue *qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8099 | |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8100 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8101 | phba->sli4_hba.cq_esize, |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8102 | LPFC_CQE_EXP_COUNT); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8103 | if (!qdesc) { |
| 8104 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8105 | "0508 Failed allocate fast-path NVME CQ (%d)\n", |
| 8106 | wqidx); |
| 8107 | return 1; |
| 8108 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8109 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8110 | phba->sli4_hba.nvme_cq[wqidx] = qdesc; |
| 8111 | |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8112 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8113 | LPFC_WQE128_SIZE, LPFC_WQE_EXP_COUNT); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8114 | if (!qdesc) { |
| 8115 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8116 | "0509 Failed allocate fast-path NVME WQ (%d)\n", |
| 8117 | wqidx); |
| 8118 | return 1; |
| 8119 | } |
| 8120 | phba->sli4_hba.nvme_wq[wqidx] = qdesc; |
| 8121 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8122 | return 0; |
| 8123 | } |
| 8124 | |
| 8125 | static int |
| 8126 | lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx) |
| 8127 | { |
| 8128 | struct lpfc_queue *qdesc; |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8129 | uint32_t wqesize; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8130 | |
| 8131 | /* Create Fast Path FCP CQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8132 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8133 | /* Increase the CQ size when WQEs contain an embedded cdb */ |
| 8134 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8135 | phba->sli4_hba.cq_esize, |
| 8136 | LPFC_CQE_EXP_COUNT); |
| 8137 | |
| 8138 | else |
| 8139 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8140 | phba->sli4_hba.cq_esize, |
| 8141 | phba->sli4_hba.cq_ecount); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8142 | if (!qdesc) { |
| 8143 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8144 | "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx); |
| 8145 | return 1; |
| 8146 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8147 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8148 | phba->sli4_hba.fcp_cq[wqidx] = qdesc; |
| 8149 | |
| 8150 | /* Create Fast Path FCP WQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8151 | if (phba->enab_exp_wqcq_pages) { |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8152 | /* Increase the WQ size when WQEs contain an embedded cdb */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8153 | wqesize = (phba->fcp_embed_io) ? |
| 8154 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8155 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8156 | wqesize, |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8157 | LPFC_WQE_EXP_COUNT); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8158 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8159 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8160 | phba->sli4_hba.wq_esize, |
| 8161 | phba->sli4_hba.wq_ecount); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8162 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8163 | if (!qdesc) { |
| 8164 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8165 | "0503 Failed allocate fast-path FCP WQ (%d)\n", |
| 8166 | wqidx); |
| 8167 | return 1; |
| 8168 | } |
| 8169 | phba->sli4_hba.fcp_wq[wqidx] = qdesc; |
| 8170 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8171 | return 0; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8172 | } |
| 8173 | |
| 8174 | /** |
| 8175 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 8176 | * @phba: pointer to lpfc hba data structure. |
| 8177 | * |
| 8178 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 8179 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 8180 | * count (queue depth) shall be taken from the module parameter. For now, |
| 8181 | * we just use some constant number as place holder. |
| 8182 | * |
| 8183 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 8184 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8185 | * -ENOMEM - No availble memory |
| 8186 | * -EIO - The mailbox failed to complete successfully. |
| 8187 | **/ |
| 8188 | int |
| 8189 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 8190 | { |
| 8191 | struct lpfc_queue *qdesc; |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 8192 | int idx, io_channel; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8193 | |
| 8194 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8195 | * Create HBA Record arrays. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8196 | * Both NVME and FCP will share that same vectors / EQs |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8197 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8198 | io_channel = phba->io_channel_irqs; |
| 8199 | if (!io_channel) |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8200 | return -ERANGE; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8201 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8202 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 8203 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 8204 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 8205 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 8206 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 8207 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8208 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8209 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8210 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8211 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8212 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8213 | phba->sli4_hba.hba_eq = kcalloc(io_channel, |
| 8214 | sizeof(struct lpfc_queue *), |
| 8215 | GFP_KERNEL); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8216 | if (!phba->sli4_hba.hba_eq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8217 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8218 | "2576 Failed allocate memory for " |
| 8219 | "fast-path EQ record array\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8220 | goto out_error; |
| 8221 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8222 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8223 | if (phba->cfg_fcp_io_channel) { |
| 8224 | phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel, |
| 8225 | sizeof(struct lpfc_queue *), |
| 8226 | GFP_KERNEL); |
| 8227 | if (!phba->sli4_hba.fcp_cq) { |
| 8228 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8229 | "2577 Failed allocate memory for " |
| 8230 | "fast-path CQ record array\n"); |
| 8231 | goto out_error; |
| 8232 | } |
| 8233 | phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel, |
| 8234 | sizeof(struct lpfc_queue *), |
| 8235 | GFP_KERNEL); |
| 8236 | if (!phba->sli4_hba.fcp_wq) { |
| 8237 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8238 | "2578 Failed allocate memory for " |
| 8239 | "fast-path FCP WQ record array\n"); |
| 8240 | goto out_error; |
| 8241 | } |
| 8242 | /* |
| 8243 | * Since the first EQ can have multiple CQs associated with it, |
| 8244 | * this array is used to quickly see if we have a FCP fast-path |
| 8245 | * CQ match. |
| 8246 | */ |
| 8247 | phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel, |
| 8248 | sizeof(uint16_t), |
| 8249 | GFP_KERNEL); |
| 8250 | if (!phba->sli4_hba.fcp_cq_map) { |
| 8251 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8252 | "2545 Failed allocate memory for " |
| 8253 | "fast-path CQ map\n"); |
| 8254 | goto out_error; |
| 8255 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8256 | } |
| 8257 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8258 | if (phba->cfg_nvme_io_channel) { |
| 8259 | phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel, |
| 8260 | sizeof(struct lpfc_queue *), |
| 8261 | GFP_KERNEL); |
| 8262 | if (!phba->sli4_hba.nvme_cq) { |
| 8263 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8264 | "6077 Failed allocate memory for " |
| 8265 | "fast-path CQ record array\n"); |
| 8266 | goto out_error; |
| 8267 | } |
| 8268 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8269 | phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel, |
| 8270 | sizeof(struct lpfc_queue *), |
| 8271 | GFP_KERNEL); |
| 8272 | if (!phba->sli4_hba.nvme_wq) { |
| 8273 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8274 | "2581 Failed allocate memory for " |
| 8275 | "fast-path NVME WQ record array\n"); |
| 8276 | goto out_error; |
| 8277 | } |
| 8278 | |
| 8279 | /* |
| 8280 | * Since the first EQ can have multiple CQs associated with it, |
| 8281 | * this array is used to quickly see if we have a NVME fast-path |
| 8282 | * CQ match. |
| 8283 | */ |
| 8284 | phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel, |
| 8285 | sizeof(uint16_t), |
| 8286 | GFP_KERNEL); |
| 8287 | if (!phba->sli4_hba.nvme_cq_map) { |
| 8288 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8289 | "6078 Failed allocate memory for " |
| 8290 | "fast-path CQ map\n"); |
| 8291 | goto out_error; |
| 8292 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8293 | |
| 8294 | if (phba->nvmet_support) { |
| 8295 | phba->sli4_hba.nvmet_cqset = kcalloc( |
| 8296 | phba->cfg_nvmet_mrq, |
| 8297 | sizeof(struct lpfc_queue *), |
| 8298 | GFP_KERNEL); |
| 8299 | if (!phba->sli4_hba.nvmet_cqset) { |
| 8300 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8301 | "3121 Fail allocate memory for " |
| 8302 | "fast-path CQ set array\n"); |
| 8303 | goto out_error; |
| 8304 | } |
| 8305 | phba->sli4_hba.nvmet_mrq_hdr = kcalloc( |
| 8306 | phba->cfg_nvmet_mrq, |
| 8307 | sizeof(struct lpfc_queue *), |
| 8308 | GFP_KERNEL); |
| 8309 | if (!phba->sli4_hba.nvmet_mrq_hdr) { |
| 8310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8311 | "3122 Fail allocate memory for " |
| 8312 | "fast-path RQ set hdr array\n"); |
| 8313 | goto out_error; |
| 8314 | } |
| 8315 | phba->sli4_hba.nvmet_mrq_data = kcalloc( |
| 8316 | phba->cfg_nvmet_mrq, |
| 8317 | sizeof(struct lpfc_queue *), |
| 8318 | GFP_KERNEL); |
| 8319 | if (!phba->sli4_hba.nvmet_mrq_data) { |
| 8320 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8321 | "3124 Fail allocate memory for " |
| 8322 | "fast-path RQ set data array\n"); |
| 8323 | goto out_error; |
| 8324 | } |
| 8325 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8326 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8327 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8328 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8329 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8330 | /* Create HBA Event Queues (EQs) */ |
| 8331 | for (idx = 0; idx < io_channel; idx++) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8332 | /* Create EQs */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8333 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8334 | phba->sli4_hba.eq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8335 | phba->sli4_hba.eq_ecount); |
| 8336 | if (!qdesc) { |
| 8337 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8338 | "0497 Failed allocate EQ (%d)\n", idx); |
| 8339 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8340 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8341 | qdesc->qe_valid = 1; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8342 | phba->sli4_hba.hba_eq[idx] = qdesc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8343 | } |
| 8344 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8345 | /* FCP and NVME io channels are not required to be balanced */ |
| 8346 | |
| 8347 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) |
| 8348 | if (lpfc_alloc_fcp_wq_cq(phba, idx)) |
| 8349 | goto out_error; |
| 8350 | |
| 8351 | for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++) |
| 8352 | if (lpfc_alloc_nvme_wq_cq(phba, idx)) |
| 8353 | goto out_error; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8354 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8355 | if (phba->nvmet_support) { |
| 8356 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
| 8357 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8358 | LPFC_DEFAULT_PAGE_SIZE, |
| 8359 | phba->sli4_hba.cq_esize, |
| 8360 | phba->sli4_hba.cq_ecount); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8361 | if (!qdesc) { |
| 8362 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8363 | "3142 Failed allocate NVME " |
| 8364 | "CQ Set (%d)\n", idx); |
| 8365 | goto out_error; |
| 8366 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8367 | qdesc->qe_valid = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8368 | phba->sli4_hba.nvmet_cqset[idx] = qdesc; |
| 8369 | } |
| 8370 | } |
| 8371 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8372 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8373 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8374 | */ |
| 8375 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8376 | /* Create slow-path Mailbox Command Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8377 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8378 | phba->sli4_hba.cq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8379 | phba->sli4_hba.cq_ecount); |
| 8380 | if (!qdesc) { |
| 8381 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8382 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8383 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8384 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8385 | qdesc->qe_valid = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8386 | phba->sli4_hba.mbx_cq = qdesc; |
| 8387 | |
| 8388 | /* Create slow-path ELS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8389 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8390 | phba->sli4_hba.cq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8391 | phba->sli4_hba.cq_ecount); |
| 8392 | if (!qdesc) { |
| 8393 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8394 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8395 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8396 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8397 | qdesc->qe_valid = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8398 | phba->sli4_hba.els_cq = qdesc; |
| 8399 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8400 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8401 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8402 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8403 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8404 | |
| 8405 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8406 | |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8407 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8408 | phba->sli4_hba.mq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8409 | phba->sli4_hba.mq_ecount); |
| 8410 | if (!qdesc) { |
| 8411 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8412 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8413 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8414 | } |
| 8415 | phba->sli4_hba.mbx_wq = qdesc; |
| 8416 | |
| 8417 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8418 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8419 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8420 | |
| 8421 | /* Create slow-path ELS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8422 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8423 | phba->sli4_hba.wq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8424 | phba->sli4_hba.wq_ecount); |
| 8425 | if (!qdesc) { |
| 8426 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8427 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8428 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8429 | } |
| 8430 | phba->sli4_hba.els_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8431 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8432 | |
| 8433 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 8434 | /* Create NVME LS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8435 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8436 | phba->sli4_hba.cq_esize, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8437 | phba->sli4_hba.cq_ecount); |
| 8438 | if (!qdesc) { |
| 8439 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8440 | "6079 Failed allocate NVME LS CQ\n"); |
| 8441 | goto out_error; |
| 8442 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8443 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8444 | phba->sli4_hba.nvmels_cq = qdesc; |
| 8445 | |
| 8446 | /* Create NVME LS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8447 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8448 | phba->sli4_hba.wq_esize, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8449 | phba->sli4_hba.wq_ecount); |
| 8450 | if (!qdesc) { |
| 8451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8452 | "6080 Failed allocate NVME LS WQ\n"); |
| 8453 | goto out_error; |
| 8454 | } |
| 8455 | phba->sli4_hba.nvmels_wq = qdesc; |
| 8456 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8457 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8458 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8459 | /* |
| 8460 | * Create Receive Queue (RQ) |
| 8461 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8462 | |
| 8463 | /* Create Receive Queue for header */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8464 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8465 | phba->sli4_hba.rq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8466 | phba->sli4_hba.rq_ecount); |
| 8467 | if (!qdesc) { |
| 8468 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8469 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8470 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8471 | } |
| 8472 | phba->sli4_hba.hdr_rq = qdesc; |
| 8473 | |
| 8474 | /* Create Receive Queue for data */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8475 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8476 | phba->sli4_hba.rq_esize, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8477 | phba->sli4_hba.rq_ecount); |
| 8478 | if (!qdesc) { |
| 8479 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8480 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8481 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8482 | } |
| 8483 | phba->sli4_hba.dat_rq = qdesc; |
| 8484 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8485 | if (phba->nvmet_support) { |
| 8486 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
| 8487 | /* Create NVMET Receive Queue for header */ |
| 8488 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8489 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8490 | phba->sli4_hba.rq_esize, |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 8491 | LPFC_NVMET_RQE_DEF_COUNT); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8492 | if (!qdesc) { |
| 8493 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8494 | "3146 Failed allocate " |
| 8495 | "receive HRQ\n"); |
| 8496 | goto out_error; |
| 8497 | } |
| 8498 | phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc; |
| 8499 | |
| 8500 | /* Only needed for header of RQ pair */ |
| 8501 | qdesc->rqbp = kzalloc(sizeof(struct lpfc_rqb), |
| 8502 | GFP_KERNEL); |
| 8503 | if (qdesc->rqbp == NULL) { |
| 8504 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8505 | "6131 Failed allocate " |
| 8506 | "Header RQBP\n"); |
| 8507 | goto out_error; |
| 8508 | } |
| 8509 | |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 8510 | /* Put list in known state in case driver load fails. */ |
| 8511 | INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list); |
| 8512 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8513 | /* Create NVMET Receive Queue for data */ |
| 8514 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8515 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8516 | phba->sli4_hba.rq_esize, |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 8517 | LPFC_NVMET_RQE_DEF_COUNT); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8518 | if (!qdesc) { |
| 8519 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8520 | "3156 Failed allocate " |
| 8521 | "receive DRQ\n"); |
| 8522 | goto out_error; |
| 8523 | } |
| 8524 | phba->sli4_hba.nvmet_mrq_data[idx] = qdesc; |
| 8525 | } |
| 8526 | } |
| 8527 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8528 | /* Create the Queues needed for Flash Optimized Fabric operations */ |
| 8529 | if (phba->cfg_fof) |
| 8530 | lpfc_fof_queue_create(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8531 | return 0; |
| 8532 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8533 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8534 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8535 | return -ENOMEM; |
| 8536 | } |
| 8537 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8538 | static inline void |
| 8539 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) |
| 8540 | { |
| 8541 | if (*qp != NULL) { |
| 8542 | lpfc_sli4_queue_free(*qp); |
| 8543 | *qp = NULL; |
| 8544 | } |
| 8545 | } |
| 8546 | |
| 8547 | static inline void |
| 8548 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) |
| 8549 | { |
| 8550 | int idx; |
| 8551 | |
| 8552 | if (*qs == NULL) |
| 8553 | return; |
| 8554 | |
| 8555 | for (idx = 0; idx < max; idx++) |
| 8556 | __lpfc_sli4_release_queue(&(*qs)[idx]); |
| 8557 | |
| 8558 | kfree(*qs); |
| 8559 | *qs = NULL; |
| 8560 | } |
| 8561 | |
| 8562 | static inline void |
| 8563 | lpfc_sli4_release_queue_map(uint16_t **qmap) |
| 8564 | { |
| 8565 | if (*qmap != NULL) { |
| 8566 | kfree(*qmap); |
| 8567 | *qmap = NULL; |
| 8568 | } |
| 8569 | } |
| 8570 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8571 | /** |
| 8572 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 8573 | * @phba: pointer to lpfc hba data structure. |
| 8574 | * |
| 8575 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 8576 | * operation. |
| 8577 | * |
| 8578 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8579 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8580 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8581 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8582 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8583 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8584 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 8585 | { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8586 | if (phba->cfg_fof) |
| 8587 | lpfc_fof_queue_destroy(phba); |
| 8588 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8589 | /* Release HBA eqs */ |
| 8590 | 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] | 8591 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8592 | /* Release FCP cqs */ |
| 8593 | lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 8594 | phba->cfg_fcp_io_channel); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8595 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8596 | /* Release FCP wqs */ |
| 8597 | lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 8598 | phba->cfg_fcp_io_channel); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8599 | |
| 8600 | /* Release FCP CQ mapping array */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8601 | lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map); |
| 8602 | |
| 8603 | /* Release NVME cqs */ |
| 8604 | lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq, |
| 8605 | phba->cfg_nvme_io_channel); |
| 8606 | |
| 8607 | /* Release NVME wqs */ |
| 8608 | lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq, |
| 8609 | phba->cfg_nvme_io_channel); |
| 8610 | |
| 8611 | /* Release NVME CQ mapping array */ |
| 8612 | lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8613 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8614 | if (phba->nvmet_support) { |
| 8615 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset, |
| 8616 | phba->cfg_nvmet_mrq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8617 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8618 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr, |
| 8619 | phba->cfg_nvmet_mrq); |
| 8620 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data, |
| 8621 | phba->cfg_nvmet_mrq); |
| 8622 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8623 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8624 | /* Release mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8625 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8626 | |
| 8627 | /* Release ELS work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8628 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); |
| 8629 | |
| 8630 | /* Release ELS work queue */ |
| 8631 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8632 | |
| 8633 | /* Release unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8634 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); |
| 8635 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8636 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8637 | /* Release ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8638 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); |
| 8639 | |
| 8640 | /* Release NVME LS complete queue */ |
| 8641 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8642 | |
| 8643 | /* Release mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8644 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); |
| 8645 | |
| 8646 | /* Everything on this list has been freed */ |
| 8647 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
| 8648 | } |
| 8649 | |
| 8650 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8651 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) |
| 8652 | { |
| 8653 | struct lpfc_rqb *rqbp; |
| 8654 | struct lpfc_dmabuf *h_buf; |
| 8655 | struct rqb_dmabuf *rqb_buffer; |
| 8656 | |
| 8657 | rqbp = rq->rqbp; |
| 8658 | while (!list_empty(&rqbp->rqb_buffer_list)) { |
| 8659 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 8660 | struct lpfc_dmabuf, list); |
| 8661 | |
| 8662 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 8663 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); |
| 8664 | rqbp->buffer_count--; |
| 8665 | } |
| 8666 | return 1; |
| 8667 | } |
| 8668 | |
| 8669 | static int |
| 8670 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 8671 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, |
| 8672 | int qidx, uint32_t qtype) |
| 8673 | { |
| 8674 | struct lpfc_sli_ring *pring; |
| 8675 | int rc; |
| 8676 | |
| 8677 | if (!eq || !cq || !wq) { |
| 8678 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8679 | "6085 Fast-path %s (%d) not allocated\n", |
| 8680 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); |
| 8681 | return -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8682 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8683 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8684 | /* create the Cq first */ |
| 8685 | rc = lpfc_cq_create(phba, cq, eq, |
| 8686 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); |
| 8687 | if (rc) { |
| 8688 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8689 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", |
| 8690 | qidx, (uint32_t)rc); |
| 8691 | return rc; |
| 8692 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8693 | cq->chann = qidx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8694 | |
| 8695 | if (qtype != LPFC_MBOX) { |
| 8696 | /* Setup nvme_cq_map for fast lookup */ |
| 8697 | if (cq_map) |
| 8698 | *cq_map = cq->queue_id; |
| 8699 | |
| 8700 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8701 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", |
| 8702 | qidx, cq->queue_id, qidx, eq->queue_id); |
| 8703 | |
| 8704 | /* create the wq */ |
| 8705 | rc = lpfc_wq_create(phba, wq, cq, qtype); |
| 8706 | if (rc) { |
| 8707 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8708 | "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n", |
| 8709 | qidx, (uint32_t)rc); |
| 8710 | /* no need to tear down cq - caller will do so */ |
| 8711 | return rc; |
| 8712 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8713 | wq->chann = qidx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8714 | |
| 8715 | /* Bind this CQ/WQ to the NVME ring */ |
| 8716 | pring = wq->pring; |
| 8717 | pring->sli.sli4.wqp = (void *)wq; |
| 8718 | cq->pring = pring; |
| 8719 | |
| 8720 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8721 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", |
| 8722 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); |
| 8723 | } else { |
| 8724 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); |
| 8725 | if (rc) { |
| 8726 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8727 | "0539 Failed setup of slow-path MQ: " |
| 8728 | "rc = 0x%x\n", rc); |
| 8729 | /* no need to tear down cq - caller will do so */ |
| 8730 | return rc; |
| 8731 | } |
| 8732 | |
| 8733 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8734 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 8735 | phba->sli4_hba.mbx_wq->queue_id, |
| 8736 | phba->sli4_hba.mbx_cq->queue_id); |
| 8737 | } |
| 8738 | |
| 8739 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8740 | } |
| 8741 | |
| 8742 | /** |
| 8743 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 8744 | * @phba: pointer to lpfc hba data structure. |
| 8745 | * |
| 8746 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 8747 | * operation. |
| 8748 | * |
| 8749 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8750 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8751 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8752 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8753 | **/ |
| 8754 | int |
| 8755 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 8756 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8757 | uint32_t shdr_status, shdr_add_status; |
| 8758 | union lpfc_sli4_cfg_shdr *shdr; |
| 8759 | LPFC_MBOXQ_t *mboxq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8760 | int qidx; |
| 8761 | uint32_t length, io_channel; |
| 8762 | int rc = -ENOMEM; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8763 | |
| 8764 | /* Check for dual-ULP support */ |
| 8765 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8766 | if (!mboxq) { |
| 8767 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8768 | "3249 Unable to allocate memory for " |
| 8769 | "QUERY_FW_CFG mailbox command\n"); |
| 8770 | return -ENOMEM; |
| 8771 | } |
| 8772 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 8773 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8774 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8775 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 8776 | length, LPFC_SLI4_MBX_EMBED); |
| 8777 | |
| 8778 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8779 | |
| 8780 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8781 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8782 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8783 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 8784 | if (shdr_status || shdr_add_status || rc) { |
| 8785 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8786 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 8787 | "x%x add_status x%x, mbx status x%x\n", |
| 8788 | shdr_status, shdr_add_status, rc); |
| 8789 | if (rc != MBX_TIMEOUT) |
| 8790 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8791 | rc = -ENXIO; |
| 8792 | goto out_error; |
| 8793 | } |
| 8794 | |
| 8795 | phba->sli4_hba.fw_func_mode = |
| 8796 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 8797 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 8798 | 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] | 8799 | phba->sli4_hba.physical_port = |
| 8800 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8801 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8802 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 8803 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 8804 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 8805 | |
| 8806 | if (rc != MBX_TIMEOUT) |
| 8807 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8808 | |
| 8809 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8810 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8811 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8812 | io_channel = phba->io_channel_irqs; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8813 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8814 | /* Set up HBA event queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8815 | if (io_channel && !phba->sli4_hba.hba_eq) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8816 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8817 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8818 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8819 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 8820 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8821 | for (qidx = 0; qidx < io_channel; qidx++) { |
| 8822 | if (!phba->sli4_hba.hba_eq[qidx]) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8823 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8824 | "0522 Fast-path EQ (%d) not " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8825 | "allocated\n", qidx); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8826 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8827 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8828 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8829 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx], |
| 8830 | phba->cfg_fcp_imax); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8831 | if (rc) { |
| 8832 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8833 | "0523 Failed setup of fast-path EQ " |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8834 | "(%d), rc = 0x%x\n", qidx, |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 8835 | (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8836 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8837 | } |
| 8838 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8839 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
| 8840 | qidx, phba->sli4_hba.hba_eq[qidx]->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8841 | } |
| 8842 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8843 | if (phba->cfg_nvme_io_channel) { |
| 8844 | if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8845 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8846 | "6084 Fast-path NVME %s array not allocated\n", |
| 8847 | (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8848 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8849 | goto out_destroy; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8850 | } |
| 8851 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8852 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) { |
| 8853 | rc = lpfc_create_wq_cq(phba, |
| 8854 | phba->sli4_hba.hba_eq[ |
| 8855 | qidx % io_channel], |
| 8856 | phba->sli4_hba.nvme_cq[qidx], |
| 8857 | phba->sli4_hba.nvme_wq[qidx], |
| 8858 | &phba->sli4_hba.nvme_cq_map[qidx], |
| 8859 | qidx, LPFC_NVME); |
| 8860 | if (rc) { |
| 8861 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8862 | "6123 Failed to setup fastpath " |
| 8863 | "NVME WQ/CQ (%d), rc = 0x%x\n", |
| 8864 | qidx, (uint32_t)rc); |
| 8865 | goto out_destroy; |
| 8866 | } |
| 8867 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8868 | } |
| 8869 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8870 | if (phba->cfg_fcp_io_channel) { |
| 8871 | /* Set up fast-path FCP Response Complete Queue */ |
| 8872 | if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8873 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8874 | "3148 Fast-path FCP %s array not allocated\n", |
| 8875 | phba->sli4_hba.fcp_cq ? "WQ" : "CQ"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8876 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8877 | goto out_destroy; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8878 | } |
| 8879 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8880 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) { |
| 8881 | rc = lpfc_create_wq_cq(phba, |
| 8882 | phba->sli4_hba.hba_eq[ |
| 8883 | qidx % io_channel], |
| 8884 | phba->sli4_hba.fcp_cq[qidx], |
| 8885 | phba->sli4_hba.fcp_wq[qidx], |
| 8886 | &phba->sli4_hba.fcp_cq_map[qidx], |
| 8887 | qidx, LPFC_FCP); |
| 8888 | if (rc) { |
| 8889 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8890 | "0535 Failed to setup fastpath " |
| 8891 | "FCP WQ/CQ (%d), rc = 0x%x\n", |
| 8892 | qidx, (uint32_t)rc); |
| 8893 | goto out_destroy; |
| 8894 | } |
| 8895 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8896 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8897 | |
| 8898 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8899 | * Set up Slow Path Complete Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8900 | */ |
| 8901 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8902 | /* Set up slow-path MBOX CQ/MQ */ |
| 8903 | |
| 8904 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8905 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8906 | "0528 %s not allocated\n", |
| 8907 | phba->sli4_hba.mbx_cq ? |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 8908 | "Mailbox WQ" : "Mailbox CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8909 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8910 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8911 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8912 | |
| 8913 | rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0], |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 8914 | phba->sli4_hba.mbx_cq, |
| 8915 | phba->sli4_hba.mbx_wq, |
| 8916 | NULL, 0, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8917 | if (rc) { |
| 8918 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8919 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
| 8920 | (uint32_t)rc); |
| 8921 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8922 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8923 | if (phba->nvmet_support) { |
| 8924 | if (!phba->sli4_hba.nvmet_cqset) { |
| 8925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8926 | "3165 Fast-path NVME CQ Set " |
| 8927 | "array not allocated\n"); |
| 8928 | rc = -ENOMEM; |
| 8929 | goto out_destroy; |
| 8930 | } |
| 8931 | if (phba->cfg_nvmet_mrq > 1) { |
| 8932 | rc = lpfc_cq_create_set(phba, |
| 8933 | phba->sli4_hba.nvmet_cqset, |
| 8934 | phba->sli4_hba.hba_eq, |
| 8935 | LPFC_WCQ, LPFC_NVMET); |
| 8936 | if (rc) { |
| 8937 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8938 | "3164 Failed setup of NVME CQ " |
| 8939 | "Set, rc = 0x%x\n", |
| 8940 | (uint32_t)rc); |
| 8941 | goto out_destroy; |
| 8942 | } |
| 8943 | } else { |
| 8944 | /* Set up NVMET Receive Complete Queue */ |
| 8945 | rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0], |
| 8946 | phba->sli4_hba.hba_eq[0], |
| 8947 | LPFC_WCQ, LPFC_NVMET); |
| 8948 | if (rc) { |
| 8949 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8950 | "6089 Failed setup NVMET CQ: " |
| 8951 | "rc = 0x%x\n", (uint32_t)rc); |
| 8952 | goto out_destroy; |
| 8953 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 8954 | phba->sli4_hba.nvmet_cqset[0]->chann = 0; |
| 8955 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8956 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8957 | "6090 NVMET CQ setup: cq-id=%d, " |
| 8958 | "parent eq-id=%d\n", |
| 8959 | phba->sli4_hba.nvmet_cqset[0]->queue_id, |
| 8960 | phba->sli4_hba.hba_eq[0]->queue_id); |
| 8961 | } |
| 8962 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8963 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8964 | /* Set up slow-path ELS WQ/CQ */ |
| 8965 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8966 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8967 | "0530 ELS %s not allocated\n", |
| 8968 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 8969 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8970 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8971 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8972 | rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0], |
| 8973 | phba->sli4_hba.els_cq, |
| 8974 | phba->sli4_hba.els_wq, |
| 8975 | NULL, 0, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8976 | if (rc) { |
| 8977 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8978 | "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
| 8979 | (uint32_t)rc); |
| 8980 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8981 | } |
| 8982 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 8983 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 8984 | phba->sli4_hba.els_wq->queue_id, |
| 8985 | phba->sli4_hba.els_cq->queue_id); |
| 8986 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8987 | if (phba->cfg_nvme_io_channel) { |
| 8988 | /* Set up NVME LS Complete Queue */ |
| 8989 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { |
| 8990 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 8991 | "6091 LS %s not allocated\n", |
| 8992 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); |
| 8993 | rc = -ENOMEM; |
| 8994 | goto out_destroy; |
| 8995 | } |
| 8996 | rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0], |
| 8997 | phba->sli4_hba.nvmels_cq, |
| 8998 | phba->sli4_hba.nvmels_wq, |
| 8999 | NULL, 0, LPFC_NVME_LS); |
| 9000 | if (rc) { |
| 9001 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9002 | "0529 Failed setup of NVVME LS WQ/CQ: " |
| 9003 | "rc = 0x%x\n", (uint32_t)rc); |
| 9004 | goto out_destroy; |
| 9005 | } |
| 9006 | |
| 9007 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9008 | "6096 ELS WQ setup: wq-id=%d, " |
| 9009 | "parent cq-id=%d\n", |
| 9010 | phba->sli4_hba.nvmels_wq->queue_id, |
| 9011 | phba->sli4_hba.nvmels_cq->queue_id); |
| 9012 | } |
| 9013 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9014 | /* |
| 9015 | * Create NVMET Receive Queue (RQ) |
| 9016 | */ |
| 9017 | if (phba->nvmet_support) { |
| 9018 | if ((!phba->sli4_hba.nvmet_cqset) || |
| 9019 | (!phba->sli4_hba.nvmet_mrq_hdr) || |
| 9020 | (!phba->sli4_hba.nvmet_mrq_data)) { |
| 9021 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9022 | "6130 MRQ CQ Queues not " |
| 9023 | "allocated\n"); |
| 9024 | rc = -ENOMEM; |
| 9025 | goto out_destroy; |
| 9026 | } |
| 9027 | if (phba->cfg_nvmet_mrq > 1) { |
| 9028 | rc = lpfc_mrq_create(phba, |
| 9029 | phba->sli4_hba.nvmet_mrq_hdr, |
| 9030 | phba->sli4_hba.nvmet_mrq_data, |
| 9031 | phba->sli4_hba.nvmet_cqset, |
| 9032 | LPFC_NVMET); |
| 9033 | if (rc) { |
| 9034 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9035 | "6098 Failed setup of NVMET " |
| 9036 | "MRQ: rc = 0x%x\n", |
| 9037 | (uint32_t)rc); |
| 9038 | goto out_destroy; |
| 9039 | } |
| 9040 | |
| 9041 | } else { |
| 9042 | rc = lpfc_rq_create(phba, |
| 9043 | phba->sli4_hba.nvmet_mrq_hdr[0], |
| 9044 | phba->sli4_hba.nvmet_mrq_data[0], |
| 9045 | phba->sli4_hba.nvmet_cqset[0], |
| 9046 | LPFC_NVMET); |
| 9047 | if (rc) { |
| 9048 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9049 | "6057 Failed setup of NVMET " |
| 9050 | "Receive Queue: rc = 0x%x\n", |
| 9051 | (uint32_t)rc); |
| 9052 | goto out_destroy; |
| 9053 | } |
| 9054 | |
| 9055 | lpfc_printf_log( |
| 9056 | phba, KERN_INFO, LOG_INIT, |
| 9057 | "6099 NVMET RQ setup: hdr-rq-id=%d, " |
| 9058 | "dat-rq-id=%d parent cq-id=%d\n", |
| 9059 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id, |
| 9060 | phba->sli4_hba.nvmet_mrq_data[0]->queue_id, |
| 9061 | phba->sli4_hba.nvmet_cqset[0]->queue_id); |
| 9062 | |
| 9063 | } |
| 9064 | } |
| 9065 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9066 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
| 9067 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9068 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9069 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9070 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9071 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9072 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9073 | 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] | 9074 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9075 | if (rc) { |
| 9076 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9077 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9078 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9079 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9080 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9081 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9082 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9083 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 9084 | "parent cq-id=%d\n", |
| 9085 | phba->sli4_hba.hdr_rq->queue_id, |
| 9086 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 9087 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9088 | |
| 9089 | if (phba->cfg_fof) { |
| 9090 | rc = lpfc_fof_queue_setup(phba); |
| 9091 | if (rc) { |
| 9092 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9093 | "0549 Failed setup of FOF Queues: " |
| 9094 | "rc = 0x%x\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9095 | goto out_destroy; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9096 | } |
| 9097 | } |
James Smart | 2c9c5a0 | 2015-04-07 15:07:15 -0400 | [diff] [blame] | 9098 | |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 9099 | 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] | 9100 | lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT, |
| 9101 | phba->cfg_fcp_imax); |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 9102 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9103 | return 0; |
| 9104 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9105 | out_destroy: |
| 9106 | lpfc_sli4_queue_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9107 | out_error: |
| 9108 | return rc; |
| 9109 | } |
| 9110 | |
| 9111 | /** |
| 9112 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 9113 | * @phba: pointer to lpfc hba data structure. |
| 9114 | * |
| 9115 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 9116 | * operation. |
| 9117 | * |
| 9118 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9119 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9120 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9121 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9122 | **/ |
| 9123 | void |
| 9124 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 9125 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9126 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9127 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9128 | /* Unset the queues created for Flash Optimized Fabric operations */ |
| 9129 | if (phba->cfg_fof) |
| 9130 | lpfc_fof_queue_destroy(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9131 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9132 | /* Unset mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9133 | if (phba->sli4_hba.mbx_wq) |
| 9134 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 9135 | |
| 9136 | /* Unset NVME LS work queue */ |
| 9137 | if (phba->sli4_hba.nvmels_wq) |
| 9138 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); |
| 9139 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9140 | /* Unset ELS work queue */ |
Colin Ian King | 019c0d6 | 2017-05-06 23:13:55 +0100 | [diff] [blame] | 9141 | if (phba->sli4_hba.els_wq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9142 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 9143 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9144 | /* Unset unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9145 | if (phba->sli4_hba.hdr_rq) |
| 9146 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, |
| 9147 | phba->sli4_hba.dat_rq); |
| 9148 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9149 | /* Unset FCP work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9150 | if (phba->sli4_hba.fcp_wq) |
| 9151 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) |
| 9152 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]); |
| 9153 | |
| 9154 | /* Unset NVME work queue */ |
| 9155 | if (phba->sli4_hba.nvme_wq) { |
| 9156 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) |
| 9157 | lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9158 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9159 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9160 | /* Unset mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9161 | if (phba->sli4_hba.mbx_cq) |
| 9162 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 9163 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9164 | /* Unset ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9165 | if (phba->sli4_hba.els_cq) |
| 9166 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 9167 | |
| 9168 | /* Unset NVME LS complete queue */ |
| 9169 | if (phba->sli4_hba.nvmels_cq) |
| 9170 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); |
| 9171 | |
| 9172 | /* Unset NVME response complete queue */ |
| 9173 | if (phba->sli4_hba.nvme_cq) |
| 9174 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) |
| 9175 | lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]); |
| 9176 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9177 | if (phba->nvmet_support) { |
| 9178 | /* Unset NVMET MRQ queue */ |
| 9179 | if (phba->sli4_hba.nvmet_mrq_hdr) { |
| 9180 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9181 | lpfc_rq_destroy( |
| 9182 | phba, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9183 | phba->sli4_hba.nvmet_mrq_hdr[qidx], |
| 9184 | phba->sli4_hba.nvmet_mrq_data[qidx]); |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9185 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9186 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9187 | /* Unset NVMET CQ Set complete queue */ |
| 9188 | if (phba->sli4_hba.nvmet_cqset) { |
| 9189 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9190 | lpfc_cq_destroy( |
| 9191 | phba, phba->sli4_hba.nvmet_cqset[qidx]); |
| 9192 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9193 | } |
| 9194 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9195 | /* Unset FCP response complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9196 | if (phba->sli4_hba.fcp_cq) |
| 9197 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) |
| 9198 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]); |
| 9199 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9200 | /* Unset fast-path event queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9201 | if (phba->sli4_hba.hba_eq) |
| 9202 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) |
| 9203 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9204 | } |
| 9205 | |
| 9206 | /** |
| 9207 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 9208 | * @phba: pointer to lpfc hba data structure. |
| 9209 | * |
| 9210 | * This routine is invoked to allocate and set up a pool of completion queue |
| 9211 | * events. The body of the completion queue event is a completion queue entry |
| 9212 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 9213 | * the following HBA completion queue events for the worker thread to process: |
| 9214 | * - Mailbox asynchronous events |
| 9215 | * - Receive queue completion unsolicited events |
| 9216 | * Later, this can be used for all the slow-path events. |
| 9217 | * |
| 9218 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9219 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9220 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9221 | **/ |
| 9222 | static int |
| 9223 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 9224 | { |
| 9225 | struct lpfc_cq_event *cq_event; |
| 9226 | int i; |
| 9227 | |
| 9228 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 9229 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 9230 | if (!cq_event) |
| 9231 | goto out_pool_create_fail; |
| 9232 | list_add_tail(&cq_event->list, |
| 9233 | &phba->sli4_hba.sp_cqe_event_pool); |
| 9234 | } |
| 9235 | return 0; |
| 9236 | |
| 9237 | out_pool_create_fail: |
| 9238 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 9239 | return -ENOMEM; |
| 9240 | } |
| 9241 | |
| 9242 | /** |
| 9243 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 9244 | * @phba: pointer to lpfc hba data structure. |
| 9245 | * |
| 9246 | * This routine is invoked to free the pool of completion queue events at |
| 9247 | * driver unload time. Note that, it is the responsibility of the driver |
| 9248 | * cleanup routine to free all the outstanding completion-queue events |
| 9249 | * allocated from this pool back into the pool before invoking this routine |
| 9250 | * to destroy the pool. |
| 9251 | **/ |
| 9252 | static void |
| 9253 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 9254 | { |
| 9255 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 9256 | |
| 9257 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 9258 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 9259 | list_del(&cq_event->list); |
| 9260 | kfree(cq_event); |
| 9261 | } |
| 9262 | } |
| 9263 | |
| 9264 | /** |
| 9265 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9266 | * @phba: pointer to lpfc hba data structure. |
| 9267 | * |
| 9268 | * This routine is the lock free version of the API invoked to allocate a |
| 9269 | * completion-queue event from the free pool. |
| 9270 | * |
| 9271 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9272 | * NULL otherwise. |
| 9273 | **/ |
| 9274 | struct lpfc_cq_event * |
| 9275 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9276 | { |
| 9277 | struct lpfc_cq_event *cq_event = NULL; |
| 9278 | |
| 9279 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 9280 | struct lpfc_cq_event, list); |
| 9281 | return cq_event; |
| 9282 | } |
| 9283 | |
| 9284 | /** |
| 9285 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 9286 | * @phba: pointer to lpfc hba data structure. |
| 9287 | * |
| 9288 | * This routine is the lock version of the API invoked to allocate a |
| 9289 | * completion-queue event from the free pool. |
| 9290 | * |
| 9291 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 9292 | * NULL otherwise. |
| 9293 | **/ |
| 9294 | struct lpfc_cq_event * |
| 9295 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 9296 | { |
| 9297 | struct lpfc_cq_event *cq_event; |
| 9298 | unsigned long iflags; |
| 9299 | |
| 9300 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9301 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 9302 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9303 | return cq_event; |
| 9304 | } |
| 9305 | |
| 9306 | /** |
| 9307 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 9308 | * @phba: pointer to lpfc hba data structure. |
| 9309 | * @cq_event: pointer to the completion queue event to be freed. |
| 9310 | * |
| 9311 | * This routine is the lock free version of the API invoked to release a |
| 9312 | * completion-queue event back into the free pool. |
| 9313 | **/ |
| 9314 | void |
| 9315 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 9316 | struct lpfc_cq_event *cq_event) |
| 9317 | { |
| 9318 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 9319 | } |
| 9320 | |
| 9321 | /** |
| 9322 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 9323 | * @phba: pointer to lpfc hba data structure. |
| 9324 | * @cq_event: pointer to the completion queue event to be freed. |
| 9325 | * |
| 9326 | * This routine is the lock version of the API invoked to release a |
| 9327 | * completion-queue event back into the free pool. |
| 9328 | **/ |
| 9329 | void |
| 9330 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 9331 | struct lpfc_cq_event *cq_event) |
| 9332 | { |
| 9333 | unsigned long iflags; |
| 9334 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9335 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 9336 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9337 | } |
| 9338 | |
| 9339 | /** |
| 9340 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 9341 | * @phba: pointer to lpfc hba data structure. |
| 9342 | * |
| 9343 | * This routine is to free all the pending completion-queue events to the |
| 9344 | * back into the free pool for device reset. |
| 9345 | **/ |
| 9346 | static void |
| 9347 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 9348 | { |
| 9349 | LIST_HEAD(cqelist); |
| 9350 | struct lpfc_cq_event *cqe; |
| 9351 | unsigned long iflags; |
| 9352 | |
| 9353 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
| 9354 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 9355 | /* Pending FCP XRI abort events */ |
| 9356 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, |
| 9357 | &cqelist); |
| 9358 | /* Pending ELS XRI abort events */ |
| 9359 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 9360 | &cqelist); |
| 9361 | /* Pending asynnc events */ |
| 9362 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 9363 | &cqelist); |
| 9364 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 9365 | |
| 9366 | while (!list_empty(&cqelist)) { |
| 9367 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); |
| 9368 | lpfc_sli4_cq_event_release(phba, cqe); |
| 9369 | } |
| 9370 | } |
| 9371 | |
| 9372 | /** |
| 9373 | * lpfc_pci_function_reset - Reset pci function. |
| 9374 | * @phba: pointer to lpfc hba data structure. |
| 9375 | * |
| 9376 | * This routine is invoked to request a PCI function reset. It will destroys |
| 9377 | * all resources assigned to the PCI function which originates this request. |
| 9378 | * |
| 9379 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9380 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9381 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9382 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9383 | **/ |
| 9384 | int |
| 9385 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 9386 | { |
| 9387 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9388 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9389 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9390 | uint32_t rdy_chk; |
| 9391 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9392 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9393 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 9394 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9395 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9396 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 9397 | switch (if_type) { |
| 9398 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 9399 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 9400 | GFP_KERNEL); |
| 9401 | if (!mboxq) { |
| 9402 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9403 | "0494 Unable to allocate memory for " |
| 9404 | "issuing SLI_FUNCTION_RESET mailbox " |
| 9405 | "command\n"); |
| 9406 | return -ENOMEM; |
| 9407 | } |
| 9408 | |
| 9409 | /* Setup PCI function reset mailbox-ioctl command */ |
| 9410 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9411 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 9412 | LPFC_SLI4_MBX_EMBED); |
| 9413 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9414 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 9415 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 9416 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 9417 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 9418 | &shdr->response); |
| 9419 | if (rc != MBX_TIMEOUT) |
| 9420 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 9421 | if (shdr_status || shdr_add_status || rc) { |
| 9422 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9423 | "0495 SLI_FUNCTION_RESET mailbox " |
| 9424 | "failed with status x%x add_status x%x," |
| 9425 | " mbx status x%x\n", |
| 9426 | shdr_status, shdr_add_status, rc); |
| 9427 | rc = -ENXIO; |
| 9428 | } |
| 9429 | break; |
| 9430 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9431 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9432 | wait: |
| 9433 | /* |
| 9434 | * Poll the Port Status Register and wait for RDY for |
| 9435 | * up to 30 seconds. If the port doesn't respond, treat |
| 9436 | * it as an error. |
| 9437 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 9438 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9439 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 9440 | STATUSregaddr, ®_data.word0)) { |
| 9441 | rc = -ENODEV; |
| 9442 | goto out; |
| 9443 | } |
| 9444 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 9445 | break; |
| 9446 | msleep(20); |
| 9447 | } |
| 9448 | |
| 9449 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 9450 | phba->work_status[0] = readl( |
| 9451 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 9452 | phba->work_status[1] = readl( |
| 9453 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
| 9454 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9455 | "2890 Port not ready, port status reg " |
| 9456 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 9457 | reg_data.word0, |
| 9458 | phba->work_status[0], |
| 9459 | phba->work_status[1]); |
| 9460 | rc = -ENODEV; |
| 9461 | goto out; |
| 9462 | } |
| 9463 | |
| 9464 | if (!port_reset) { |
| 9465 | /* |
| 9466 | * Reset the port now |
| 9467 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9468 | reg_data.word0 = 0; |
| 9469 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 9470 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 9471 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 9472 | LPFC_SLIPORT_INIT_PORT); |
| 9473 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 9474 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 9475 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 9476 | pci_read_config_word(phba->pcidev, |
| 9477 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9478 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9479 | port_reset = 1; |
| 9480 | msleep(20); |
| 9481 | goto wait; |
| 9482 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 9483 | rc = -ENODEV; |
| 9484 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9485 | } |
| 9486 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9487 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9488 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 9489 | default: |
| 9490 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9491 | } |
| 9492 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9493 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9494 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9495 | if (rc) { |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 9496 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9497 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 9498 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9499 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 9500 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9501 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9502 | return rc; |
| 9503 | } |
| 9504 | |
| 9505 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9506 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 9507 | * @phba: pointer to lpfc hba data structure. |
| 9508 | * |
| 9509 | * This routine is invoked to set up the PCI device memory space for device |
| 9510 | * with SLI-4 interface spec. |
| 9511 | * |
| 9512 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9513 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9514 | * other values - error |
| 9515 | **/ |
| 9516 | static int |
| 9517 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 9518 | { |
| 9519 | struct pci_dev *pdev; |
| 9520 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
| 9521 | int error = -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9522 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9523 | |
| 9524 | /* Obtain PCI device reference */ |
| 9525 | if (!phba->pcidev) |
| 9526 | return error; |
| 9527 | else |
| 9528 | pdev = phba->pcidev; |
| 9529 | |
| 9530 | /* Set the device DMA mask size */ |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 9531 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
| 9532 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { |
| 9533 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 |
| 9534 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9535 | return error; |
Michael Reed | 8e68597 | 2009-09-18 12:02:05 -0500 | [diff] [blame] | 9536 | } |
| 9537 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9538 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9539 | /* |
| 9540 | * The BARs and register set definitions and offset locations are |
| 9541 | * dependent on the if_type. |
| 9542 | */ |
| 9543 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 9544 | &phba->sli4_hba.sli_intf.word0)) { |
| 9545 | return error; |
| 9546 | } |
| 9547 | |
| 9548 | /* There is no SLI3 failback for SLI4 devices. */ |
| 9549 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 9550 | LPFC_SLI_INTF_VALID) { |
| 9551 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9552 | "2894 SLI_INTF reg contents invalid " |
| 9553 | "sli_intf reg 0x%x\n", |
| 9554 | phba->sli4_hba.sli_intf.word0); |
| 9555 | return error; |
| 9556 | } |
| 9557 | |
| 9558 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 9559 | /* |
| 9560 | * Get the bus address of SLI4 device Bar regions and the |
| 9561 | * number of bytes required by each mapping. The mapping of the |
| 9562 | * particular PCI BARs regions is dependent on the type of |
| 9563 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9564 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 9565 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 9566 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 9567 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9568 | |
| 9569 | /* |
| 9570 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 9571 | * addr |
| 9572 | */ |
| 9573 | phba->sli4_hba.conf_regs_memmap_p = |
| 9574 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 9575 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 9576 | dev_printk(KERN_ERR, &pdev->dev, |
| 9577 | "ioremap failed for SLI4 PCI config " |
| 9578 | "registers.\n"); |
| 9579 | goto out; |
| 9580 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 9581 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9582 | /* Set up BAR0 PCI config space register memory map */ |
| 9583 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 9584 | } else { |
| 9585 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 9586 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9587 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9588 | dev_printk(KERN_ERR, &pdev->dev, |
| 9589 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
| 9590 | goto out; |
| 9591 | } |
| 9592 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9593 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9594 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 9595 | dev_printk(KERN_ERR, &pdev->dev, |
| 9596 | "ioremap failed for SLI4 PCI config " |
| 9597 | "registers.\n"); |
| 9598 | goto out; |
| 9599 | } |
| 9600 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9601 | } |
| 9602 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 9603 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 9604 | if (pci_resource_start(pdev, PCI_64BIT_BAR2)) { |
| 9605 | /* |
| 9606 | * Map SLI4 if type 0 HBA Control Register base to a |
| 9607 | * kernel virtual address and setup the registers. |
| 9608 | */ |
| 9609 | phba->pci_bar1_map = pci_resource_start(pdev, |
| 9610 | PCI_64BIT_BAR2); |
| 9611 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 9612 | phba->sli4_hba.ctrl_regs_memmap_p = |
| 9613 | ioremap(phba->pci_bar1_map, |
| 9614 | bar1map_len); |
| 9615 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 9616 | dev_err(&pdev->dev, |
| 9617 | "ioremap failed for SLI4 HBA " |
| 9618 | "control registers.\n"); |
| 9619 | error = -ENOMEM; |
| 9620 | goto out_iounmap_conf; |
| 9621 | } |
| 9622 | phba->pci_bar2_memmap_p = |
| 9623 | phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9624 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 9625 | } else { |
| 9626 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9627 | goto out_iounmap_conf; |
| 9628 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9629 | } |
| 9630 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9631 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) && |
| 9632 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
| 9633 | /* |
| 9634 | * Map SLI4 if type 6 HBA Doorbell Register base to a kernel |
| 9635 | * virtual address and setup the registers. |
| 9636 | */ |
| 9637 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 9638 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 9639 | phba->sli4_hba.drbl_regs_memmap_p = |
| 9640 | ioremap(phba->pci_bar1_map, bar1map_len); |
| 9641 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 9642 | dev_err(&pdev->dev, |
| 9643 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
| 9644 | goto out_iounmap_conf; |
| 9645 | } |
| 9646 | phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
| 9647 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
| 9648 | } |
| 9649 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 9650 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 9651 | if (pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 9652 | /* |
| 9653 | * Map SLI4 if type 0 HBA Doorbell Register base to |
| 9654 | * a kernel virtual address and setup the registers. |
| 9655 | */ |
| 9656 | phba->pci_bar2_map = pci_resource_start(pdev, |
| 9657 | PCI_64BIT_BAR4); |
| 9658 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 9659 | phba->sli4_hba.drbl_regs_memmap_p = |
| 9660 | ioremap(phba->pci_bar2_map, |
| 9661 | bar2map_len); |
| 9662 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 9663 | dev_err(&pdev->dev, |
| 9664 | "ioremap failed for SLI4 HBA" |
| 9665 | " doorbell registers.\n"); |
| 9666 | error = -ENOMEM; |
| 9667 | goto out_iounmap_ctrl; |
| 9668 | } |
| 9669 | phba->pci_bar4_memmap_p = |
| 9670 | phba->sli4_hba.drbl_regs_memmap_p; |
| 9671 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 9672 | if (error) |
| 9673 | goto out_iounmap_all; |
| 9674 | } else { |
| 9675 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9676 | goto out_iounmap_all; |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 9677 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9678 | } |
| 9679 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 9680 | if (if_type == LPFC_SLI_INTF_IF_TYPE_6 && |
| 9681 | pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 9682 | /* |
| 9683 | * Map SLI4 if type 6 HBA DPP Register base to a kernel |
| 9684 | * virtual address and setup the registers. |
| 9685 | */ |
| 9686 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 9687 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 9688 | phba->sli4_hba.dpp_regs_memmap_p = |
| 9689 | ioremap(phba->pci_bar2_map, bar2map_len); |
| 9690 | if (!phba->sli4_hba.dpp_regs_memmap_p) { |
| 9691 | dev_err(&pdev->dev, |
| 9692 | "ioremap failed for SLI4 HBA dpp registers.\n"); |
| 9693 | goto out_iounmap_ctrl; |
| 9694 | } |
| 9695 | phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; |
| 9696 | } |
| 9697 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 9698 | /* Set up the EQ/CQ register handeling functions now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9699 | switch (if_type) { |
| 9700 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 9701 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 9702 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr; |
| 9703 | phba->sli4_hba.sli4_eq_release = lpfc_sli4_eq_release; |
| 9704 | phba->sli4_hba.sli4_cq_release = lpfc_sli4_cq_release; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9705 | break; |
| 9706 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 9707 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr; |
| 9708 | phba->sli4_hba.sli4_eq_release = lpfc_sli4_if6_eq_release; |
| 9709 | phba->sli4_hba.sli4_cq_release = lpfc_sli4_if6_cq_release; |
| 9710 | break; |
| 9711 | default: |
| 9712 | break; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 9713 | } |
| 9714 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9715 | return 0; |
| 9716 | |
| 9717 | out_iounmap_all: |
| 9718 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 9719 | out_iounmap_ctrl: |
| 9720 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 9721 | out_iounmap_conf: |
| 9722 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 9723 | out: |
| 9724 | return error; |
| 9725 | } |
| 9726 | |
| 9727 | /** |
| 9728 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 9729 | * @phba: pointer to lpfc hba data structure. |
| 9730 | * |
| 9731 | * This routine is invoked to unset the PCI device memory space for device |
| 9732 | * with SLI-4 interface spec. |
| 9733 | **/ |
| 9734 | static void |
| 9735 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 9736 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9737 | uint32_t if_type; |
| 9738 | 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] | 9739 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9740 | switch (if_type) { |
| 9741 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 9742 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 9743 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 9744 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 9745 | break; |
| 9746 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 9747 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 9748 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9749 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 9750 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 9751 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 9752 | break; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9753 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 9754 | default: |
| 9755 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 9756 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 9757 | if_type); |
| 9758 | break; |
| 9759 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9760 | } |
| 9761 | |
| 9762 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9763 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 9764 | * @phba: pointer to lpfc hba data structure. |
| 9765 | * |
| 9766 | * 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] | 9767 | * with SLI-3 interface specs. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9768 | * |
| 9769 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9770 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9771 | * other values - error |
| 9772 | **/ |
| 9773 | static int |
| 9774 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 9775 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9776 | int rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9777 | LPFC_MBOXQ_t *pmb; |
| 9778 | |
| 9779 | /* Set up MSI-X multi-message vectors */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9780 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 9781 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); |
| 9782 | if (rc < 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9783 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9784 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 9785 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9786 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9787 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9788 | /* |
| 9789 | * Assign MSI-X vectors to interrupt handlers |
| 9790 | */ |
| 9791 | |
| 9792 | /* vector-0 is associated to slow-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9793 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9794 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9795 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 9796 | if (rc) { |
| 9797 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 9798 | "0421 MSI-X slow-path request_irq failed " |
| 9799 | "(%d)\n", rc); |
| 9800 | goto msi_fail_out; |
| 9801 | } |
| 9802 | |
| 9803 | /* vector-1 is associated to fast-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9804 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9805 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9806 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 9807 | |
| 9808 | if (rc) { |
| 9809 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 9810 | "0429 MSI-X fast-path request_irq failed " |
| 9811 | "(%d)\n", rc); |
| 9812 | goto irq_fail_out; |
| 9813 | } |
| 9814 | |
| 9815 | /* |
| 9816 | * Configure HBA MSI-X attention conditions to messages |
| 9817 | */ |
| 9818 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9819 | |
| 9820 | if (!pmb) { |
| 9821 | rc = -ENOMEM; |
| 9822 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 9823 | "0474 Unable to allocate memory for issuing " |
| 9824 | "MBOX_CONFIG_MSI command\n"); |
| 9825 | goto mem_fail_out; |
| 9826 | } |
| 9827 | rc = lpfc_config_msi(phba, pmb); |
| 9828 | if (rc) |
| 9829 | goto mbx_fail_out; |
| 9830 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 9831 | if (rc != MBX_SUCCESS) { |
| 9832 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 9833 | "0351 Config MSI mailbox command failed, " |
| 9834 | "mbxCmd x%x, mbxStatus x%x\n", |
| 9835 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 9836 | goto mbx_fail_out; |
| 9837 | } |
| 9838 | |
| 9839 | /* Free memory allocated for mailbox command */ |
| 9840 | mempool_free(pmb, phba->mbox_mem_pool); |
| 9841 | return rc; |
| 9842 | |
| 9843 | mbx_fail_out: |
| 9844 | /* Free memory allocated for mailbox command */ |
| 9845 | mempool_free(pmb, phba->mbox_mem_pool); |
| 9846 | |
| 9847 | mem_fail_out: |
| 9848 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9849 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9850 | |
| 9851 | irq_fail_out: |
| 9852 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9853 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9854 | |
| 9855 | msi_fail_out: |
| 9856 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9857 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 9858 | |
| 9859 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9860 | return rc; |
| 9861 | } |
| 9862 | |
| 9863 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9864 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 9865 | * @phba: pointer to lpfc hba data structure. |
| 9866 | * |
| 9867 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 9868 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 9869 | * enable the MSI vector. The device driver is responsible for calling the |
| 9870 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 9871 | * is done in this function. |
| 9872 | * |
| 9873 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9874 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9875 | * other values - error |
| 9876 | */ |
| 9877 | static int |
| 9878 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 9879 | { |
| 9880 | int rc; |
| 9881 | |
| 9882 | rc = pci_enable_msi(phba->pcidev); |
| 9883 | if (!rc) |
| 9884 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9885 | "0462 PCI enable MSI mode success.\n"); |
| 9886 | else { |
| 9887 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9888 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 9889 | return rc; |
| 9890 | } |
| 9891 | |
| 9892 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 9893 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9894 | if (rc) { |
| 9895 | pci_disable_msi(phba->pcidev); |
| 9896 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 9897 | "0478 MSI request_irq failed (%d)\n", rc); |
| 9898 | } |
| 9899 | return rc; |
| 9900 | } |
| 9901 | |
| 9902 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9903 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 9904 | * @phba: pointer to lpfc hba data structure. |
| 9905 | * |
| 9906 | * This routine is invoked to enable device interrupt and associate driver's |
| 9907 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 9908 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 9909 | * will try to fallback from the configured interrupt mode to an interrupt |
| 9910 | * mode which is supported by the platform, kernel, and device in the order |
| 9911 | * of: |
| 9912 | * MSI-X -> MSI -> IRQ. |
| 9913 | * |
| 9914 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9915 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9916 | * other values - error |
| 9917 | **/ |
| 9918 | static uint32_t |
| 9919 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 9920 | { |
| 9921 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 9922 | int retval; |
| 9923 | |
| 9924 | if (cfg_mode == 2) { |
| 9925 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 9926 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 9927 | if (!retval) { |
| 9928 | /* Now, try to enable MSI-X interrupt mode */ |
| 9929 | retval = lpfc_sli_enable_msix(phba); |
| 9930 | if (!retval) { |
| 9931 | /* Indicate initialization to MSI-X mode */ |
| 9932 | phba->intr_type = MSIX; |
| 9933 | intr_mode = 2; |
| 9934 | } |
| 9935 | } |
| 9936 | } |
| 9937 | |
| 9938 | /* Fallback to MSI if MSI-X initialization failed */ |
| 9939 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 9940 | retval = lpfc_sli_enable_msi(phba); |
| 9941 | if (!retval) { |
| 9942 | /* Indicate initialization to MSI mode */ |
| 9943 | phba->intr_type = MSI; |
| 9944 | intr_mode = 1; |
| 9945 | } |
| 9946 | } |
| 9947 | |
| 9948 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 9949 | if (phba->intr_type == NONE) { |
| 9950 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 9951 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 9952 | if (!retval) { |
| 9953 | /* Indicate initialization to INTx mode */ |
| 9954 | phba->intr_type = INTx; |
| 9955 | intr_mode = 0; |
| 9956 | } |
| 9957 | } |
| 9958 | return intr_mode; |
| 9959 | } |
| 9960 | |
| 9961 | /** |
| 9962 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 9963 | * @phba: pointer to lpfc hba data structure. |
| 9964 | * |
| 9965 | * This routine is invoked to disable device interrupt and disassociate the |
| 9966 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 9967 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 9968 | * release the interrupt vector(s) for the message signaled interrupt. |
| 9969 | **/ |
| 9970 | static void |
| 9971 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 9972 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9973 | int nr_irqs, i; |
| 9974 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9975 | if (phba->intr_type == MSIX) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 9976 | nr_irqs = LPFC_MSIX_VECTORS; |
| 9977 | else |
| 9978 | nr_irqs = 1; |
| 9979 | |
| 9980 | for (i = 0; i < nr_irqs; i++) |
| 9981 | free_irq(pci_irq_vector(phba->pcidev, i), phba); |
| 9982 | pci_free_irq_vectors(phba->pcidev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9983 | |
| 9984 | /* Reset interrupt management states */ |
| 9985 | phba->intr_type = NONE; |
| 9986 | phba->sli.slistat.sli_intr = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9987 | } |
| 9988 | |
| 9989 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9990 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9991 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9992 | * @vectors: number of msix vectors allocated. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 9993 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9994 | * The routine will figure out the CPU affinity assignment for every |
| 9995 | * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated |
| 9996 | * with a pointer to the CPU mask that defines ALL the CPUs this vector |
| 9997 | * can be associated with. If the vector can be unquely associated with |
| 9998 | * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu. |
| 9999 | * In addition, the CPU to IO channel mapping will be calculated |
| 10000 | * and the phba->sli4_hba.cpu_map array will reflect this. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10001 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10002 | static void |
| 10003 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10004 | { |
| 10005 | struct lpfc_vector_map_info *cpup; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10006 | int index = 0; |
| 10007 | int vec = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10008 | int cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10009 | #ifdef CONFIG_X86 |
| 10010 | struct cpuinfo_x86 *cpuinfo; |
| 10011 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10012 | |
| 10013 | /* Init cpu_map array */ |
| 10014 | memset(phba->sli4_hba.cpu_map, 0xff, |
| 10015 | (sizeof(struct lpfc_vector_map_info) * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10016 | phba->sli4_hba.num_present_cpu)); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10017 | |
| 10018 | /* Update CPU map with physical id and core id of each CPU */ |
| 10019 | cpup = phba->sli4_hba.cpu_map; |
| 10020 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { |
| 10021 | #ifdef CONFIG_X86 |
| 10022 | cpuinfo = &cpu_data(cpu); |
| 10023 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 10024 | cpup->core_id = cpuinfo->cpu_core_id; |
| 10025 | #else |
| 10026 | /* No distinction between CPUs for other platforms */ |
| 10027 | cpup->phys_id = 0; |
| 10028 | cpup->core_id = 0; |
| 10029 | #endif |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10030 | cpup->channel_id = index; /* For now round robin */ |
| 10031 | cpup->irq = pci_irq_vector(phba->pcidev, vec); |
| 10032 | vec++; |
| 10033 | if (vec >= vectors) |
| 10034 | vec = 0; |
| 10035 | index++; |
| 10036 | if (index >= phba->cfg_fcp_io_channel) |
| 10037 | index = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10038 | cpup++; |
| 10039 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10040 | } |
| 10041 | |
| 10042 | |
| 10043 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10044 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 10045 | * @phba: pointer to lpfc hba data structure. |
| 10046 | * |
| 10047 | * 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] | 10048 | * with SLI-4 interface spec. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10049 | * |
| 10050 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10051 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10052 | * other values - error |
| 10053 | **/ |
| 10054 | static int |
| 10055 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 10056 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10057 | int vectors, rc, index; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 10058 | char *name; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10059 | |
| 10060 | /* Set up MSI-X multi-message vectors */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10061 | vectors = phba->io_channel_irqs; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10062 | if (phba->cfg_fof) |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10063 | vectors++; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10064 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 10065 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 10066 | (phba->nvmet_support) ? 1 : 2, |
| 10067 | vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY); |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 10068 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10069 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10070 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10071 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10072 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 10073 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10074 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10075 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10076 | for (index = 0; index < vectors; index++) { |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 10077 | name = phba->sli4_hba.hba_eq_hdl[index].handler_name; |
| 10078 | memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ); |
| 10079 | snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 10080 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10081 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10082 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 10083 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
| 10084 | 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] | 10085 | if (phba->cfg_fof && (index == (vectors - 1))) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10086 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10087 | &lpfc_sli4_fof_intr_handler, 0, |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 10088 | name, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10089 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10090 | else |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10091 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10092 | &lpfc_sli4_hba_intr_handler, 0, |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 10093 | name, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10094 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10095 | if (rc) { |
| 10096 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10097 | "0486 MSI-X fast-path (%d) " |
| 10098 | "request_irq failed (%d)\n", index, rc); |
| 10099 | goto cfg_fail_out; |
| 10100 | } |
| 10101 | } |
| 10102 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10103 | if (phba->cfg_fof) |
| 10104 | vectors--; |
| 10105 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10106 | if (vectors != phba->io_channel_irqs) { |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 10107 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10108 | "3238 Reducing IO channels to match number of " |
| 10109 | "MSI-X vectors, requested %d got %d\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10110 | phba->io_channel_irqs, vectors); |
| 10111 | if (phba->cfg_fcp_io_channel > vectors) |
| 10112 | phba->cfg_fcp_io_channel = vectors; |
| 10113 | if (phba->cfg_nvme_io_channel > vectors) |
| 10114 | phba->cfg_nvme_io_channel = vectors; |
| 10115 | if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel) |
| 10116 | phba->io_channel_irqs = phba->cfg_fcp_io_channel; |
| 10117 | else |
| 10118 | phba->io_channel_irqs = phba->cfg_nvme_io_channel; |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 10119 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10120 | lpfc_cpu_affinity_check(phba, vectors); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10121 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10122 | return rc; |
| 10123 | |
| 10124 | cfg_fail_out: |
| 10125 | /* free the irq already requested */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10126 | for (--index; index >= 0; index--) |
| 10127 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 10128 | &phba->sli4_hba.hba_eq_hdl[index]); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10129 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10130 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10131 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10132 | |
| 10133 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10134 | return rc; |
| 10135 | } |
| 10136 | |
| 10137 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10138 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 10139 | * @phba: pointer to lpfc hba data structure. |
| 10140 | * |
| 10141 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 10142 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called |
| 10143 | * to enable the MSI vector. The device driver is responsible for calling |
| 10144 | * the request_irq() to register MSI vector with a interrupt the handler, |
| 10145 | * which is done in this function. |
| 10146 | * |
| 10147 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10148 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10149 | * other values - error |
| 10150 | **/ |
| 10151 | static int |
| 10152 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 10153 | { |
| 10154 | int rc, index; |
| 10155 | |
| 10156 | rc = pci_enable_msi(phba->pcidev); |
| 10157 | if (!rc) |
| 10158 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10159 | "0487 PCI enable MSI mode success.\n"); |
| 10160 | else { |
| 10161 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10162 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
| 10163 | return rc; |
| 10164 | } |
| 10165 | |
| 10166 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10167 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10168 | if (rc) { |
| 10169 | pci_disable_msi(phba->pcidev); |
| 10170 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10171 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10172 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10173 | } |
| 10174 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10175 | for (index = 0; index < phba->io_channel_irqs; index++) { |
| 10176 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 10177 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10178 | } |
| 10179 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10180 | if (phba->cfg_fof) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10181 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
| 10182 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10183 | } |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 10184 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10185 | } |
| 10186 | |
| 10187 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10188 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 10189 | * @phba: pointer to lpfc hba data structure. |
| 10190 | * |
| 10191 | * This routine is invoked to enable device interrupt and associate driver's |
| 10192 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 10193 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 10194 | * the driver will try to fallback from the configured interrupt mode to an |
| 10195 | * interrupt mode which is supported by the platform, kernel, and device in |
| 10196 | * the order of: |
| 10197 | * MSI-X -> MSI -> IRQ. |
| 10198 | * |
| 10199 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10200 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10201 | * other values - error |
| 10202 | **/ |
| 10203 | static uint32_t |
| 10204 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 10205 | { |
| 10206 | uint32_t intr_mode = LPFC_INTR_ERROR; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10207 | int retval, idx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10208 | |
| 10209 | if (cfg_mode == 2) { |
| 10210 | /* Preparation before conf_msi mbox cmd */ |
| 10211 | retval = 0; |
| 10212 | if (!retval) { |
| 10213 | /* Now, try to enable MSI-X interrupt mode */ |
| 10214 | retval = lpfc_sli4_enable_msix(phba); |
| 10215 | if (!retval) { |
| 10216 | /* Indicate initialization to MSI-X mode */ |
| 10217 | phba->intr_type = MSIX; |
| 10218 | intr_mode = 2; |
| 10219 | } |
| 10220 | } |
| 10221 | } |
| 10222 | |
| 10223 | /* Fallback to MSI if MSI-X initialization failed */ |
| 10224 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 10225 | retval = lpfc_sli4_enable_msi(phba); |
| 10226 | if (!retval) { |
| 10227 | /* Indicate initialization to MSI mode */ |
| 10228 | phba->intr_type = MSI; |
| 10229 | intr_mode = 1; |
| 10230 | } |
| 10231 | } |
| 10232 | |
| 10233 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 10234 | if (phba->intr_type == NONE) { |
| 10235 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 10236 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 10237 | if (!retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10238 | struct lpfc_hba_eq_hdl *eqhdl; |
| 10239 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10240 | /* Indicate initialization to INTx mode */ |
| 10241 | phba->intr_type = INTx; |
| 10242 | intr_mode = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10243 | |
| 10244 | for (idx = 0; idx < phba->io_channel_irqs; idx++) { |
| 10245 | eqhdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
| 10246 | eqhdl->idx = idx; |
| 10247 | eqhdl->phba = phba; |
| 10248 | atomic_set(&eqhdl->hba_eq_in_use, 1); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10249 | } |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10250 | if (phba->cfg_fof) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10251 | eqhdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
| 10252 | eqhdl->idx = idx; |
| 10253 | eqhdl->phba = phba; |
| 10254 | atomic_set(&eqhdl->hba_eq_in_use, 1); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10255 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10256 | } |
| 10257 | } |
| 10258 | return intr_mode; |
| 10259 | } |
| 10260 | |
| 10261 | /** |
| 10262 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 10263 | * @phba: pointer to lpfc hba data structure. |
| 10264 | * |
| 10265 | * This routine is invoked to disable device interrupt and disassociate |
| 10266 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 10267 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 10268 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 10269 | **/ |
| 10270 | static void |
| 10271 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 10272 | { |
| 10273 | /* Disable the currently initialized interrupt mode */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10274 | if (phba->intr_type == MSIX) { |
| 10275 | int index; |
| 10276 | |
| 10277 | /* Free up MSI-X multi-message vectors */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10278 | for (index = 0; index < phba->io_channel_irqs; index++) |
| 10279 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 10280 | &phba->sli4_hba.hba_eq_hdl[index]); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10281 | |
| 10282 | if (phba->cfg_fof) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10283 | free_irq(pci_irq_vector(phba->pcidev, index), |
| 10284 | &phba->sli4_hba.hba_eq_hdl[index]); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10285 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10286 | free_irq(phba->pcidev->irq, phba); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10287 | } |
| 10288 | |
| 10289 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10290 | |
| 10291 | /* Reset interrupt management states */ |
| 10292 | phba->intr_type = NONE; |
| 10293 | phba->sli.slistat.sli_intr = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10294 | } |
| 10295 | |
| 10296 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10297 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 10298 | * @phba: pointer to lpfc hba data structure. |
| 10299 | * |
| 10300 | * This routine is invoked to unset the HBA device initialization steps to |
| 10301 | * a device with SLI-3 interface spec. |
| 10302 | **/ |
| 10303 | static void |
| 10304 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 10305 | { |
| 10306 | struct lpfc_vport *vport = phba->pport; |
| 10307 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 10308 | |
| 10309 | spin_lock_irq(shost->host_lock); |
| 10310 | vport->load_flag |= FC_UNLOADING; |
| 10311 | spin_unlock_irq(shost->host_lock); |
| 10312 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 10313 | kfree(phba->vpi_bmask); |
| 10314 | kfree(phba->vpi_ids); |
| 10315 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10316 | lpfc_stop_hba_timers(phba); |
| 10317 | |
| 10318 | phba->pport->work_port_events = 0; |
| 10319 | |
| 10320 | lpfc_sli_hba_down(phba); |
| 10321 | |
| 10322 | lpfc_sli_brdrestart(phba); |
| 10323 | |
| 10324 | lpfc_sli_disable_intr(phba); |
| 10325 | |
| 10326 | return; |
| 10327 | } |
| 10328 | |
| 10329 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10330 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 10331 | * @phba: Pointer to HBA context object. |
| 10332 | * |
| 10333 | * This function is called in the SLI4 code path to wait for completion |
| 10334 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 10335 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 10336 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 10337 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 10338 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 10339 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 10340 | * the rest of the driver unload resource release. |
| 10341 | **/ |
| 10342 | static void |
| 10343 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 10344 | { |
| 10345 | int wait_time = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10346 | int nvme_xri_cmpl = 1; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 10347 | int nvmet_xri_cmpl = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10348 | int fcp_xri_cmpl = 1; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10349 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 10350 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 10351 | /* Driver just aborted IOs during the hba_unset process. Pause |
| 10352 | * here to give the HBA time to complete the IO and get entries |
| 10353 | * into the abts lists. |
| 10354 | */ |
| 10355 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5); |
| 10356 | |
| 10357 | /* Wait for NVME pending IO to flush back to transport. */ |
| 10358 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 10359 | lpfc_nvme_wait_for_io_drain(phba); |
| 10360 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10361 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) |
| 10362 | fcp_xri_cmpl = |
| 10363 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 10364 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10365 | nvme_xri_cmpl = |
| 10366 | list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 10367 | nvmet_xri_cmpl = |
| 10368 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 10369 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10370 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 10371 | while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl || |
| 10372 | !nvmet_xri_cmpl) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10373 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10374 | if (!nvme_xri_cmpl) |
| 10375 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10376 | "6100 NVME XRI exchange busy " |
| 10377 | "wait time: %d seconds.\n", |
| 10378 | wait_time/1000); |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10379 | if (!fcp_xri_cmpl) |
| 10380 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10381 | "2877 FCP XRI exchange busy " |
| 10382 | "wait time: %d seconds.\n", |
| 10383 | wait_time/1000); |
| 10384 | if (!els_xri_cmpl) |
| 10385 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10386 | "2878 ELS XRI exchange busy " |
| 10387 | "wait time: %d seconds.\n", |
| 10388 | wait_time/1000); |
| 10389 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 10390 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 10391 | } else { |
| 10392 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 10393 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 10394 | } |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 10395 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10396 | nvme_xri_cmpl = list_empty( |
| 10397 | &phba->sli4_hba.lpfc_abts_nvme_buf_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 10398 | nvmet_xri_cmpl = list_empty( |
| 10399 | &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 10400 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10401 | |
| 10402 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) |
| 10403 | fcp_xri_cmpl = list_empty( |
| 10404 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); |
| 10405 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10406 | els_xri_cmpl = |
| 10407 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 10408 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10409 | } |
| 10410 | } |
| 10411 | |
| 10412 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10413 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 10414 | * @phba: Pointer to HBA context object. |
| 10415 | * |
| 10416 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 10417 | * function. The caller is not required to hold any lock. This routine |
| 10418 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 10419 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 10420 | * free any pending commands. |
| 10421 | **/ |
| 10422 | static void |
| 10423 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 10424 | { |
| 10425 | int wait_cnt = 0; |
| 10426 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10427 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10428 | |
| 10429 | lpfc_stop_hba_timers(phba); |
| 10430 | phba->sli4_hba.intr_enable = 0; |
| 10431 | |
| 10432 | /* |
| 10433 | * Gracefully wait out the potential current outstanding asynchronous |
| 10434 | * mailbox command. |
| 10435 | */ |
| 10436 | |
| 10437 | /* First, block any pending async mailbox command from posted */ |
| 10438 | spin_lock_irq(&phba->hbalock); |
| 10439 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 10440 | spin_unlock_irq(&phba->hbalock); |
| 10441 | /* Now, trying to wait it out if we can */ |
| 10442 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 10443 | msleep(10); |
| 10444 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 10445 | break; |
| 10446 | } |
| 10447 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 10448 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 10449 | spin_lock_irq(&phba->hbalock); |
| 10450 | mboxq = phba->sli.mbox_active; |
| 10451 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 10452 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 10453 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 10454 | phba->sli.mbox_active = NULL; |
| 10455 | spin_unlock_irq(&phba->hbalock); |
| 10456 | } |
| 10457 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 10458 | /* Abort all iocbs associated with the hba */ |
| 10459 | lpfc_sli_hba_iocb_abort(phba); |
| 10460 | |
| 10461 | /* Wait for completion of device XRI exchange busy */ |
| 10462 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 10463 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10464 | /* Disable PCI subsystem interrupt */ |
| 10465 | lpfc_sli4_disable_intr(phba); |
| 10466 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10467 | /* Disable SR-IOV if enabled */ |
| 10468 | if (phba->cfg_sriov_nr_virtfn) |
| 10469 | pci_disable_sriov(pdev); |
| 10470 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10471 | /* Stop kthread signal shall trigger work_done one more time */ |
| 10472 | kthread_stop(phba->worker_thread); |
| 10473 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 10474 | /* Unset the queues shared with the hardware then release all |
| 10475 | * allocated resources. |
| 10476 | */ |
| 10477 | lpfc_sli4_queue_unset(phba); |
| 10478 | lpfc_sli4_queue_destroy(phba); |
| 10479 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 10480 | /* Reset SLI4 HBA FCoE function */ |
| 10481 | lpfc_pci_function_reset(phba); |
| 10482 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10483 | /* Stop the SLI4 device port */ |
| 10484 | phba->pport->work_port_events = 0; |
| 10485 | } |
| 10486 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10487 | /** |
| 10488 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 10489 | * @phba: Pointer to HBA context object. |
| 10490 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 10491 | * |
| 10492 | * This function is called in the SLI4 code path to read the port's |
| 10493 | * sli4 capabilities. |
| 10494 | * |
| 10495 | * This function may be be called from any context that can block-wait |
| 10496 | * for the completion. The expectation is that this routine is called |
| 10497 | * typically from probe_one or from the online routine. |
| 10498 | **/ |
| 10499 | int |
| 10500 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 10501 | { |
| 10502 | int rc; |
| 10503 | struct lpfc_mqe *mqe; |
| 10504 | struct lpfc_pc_sli4_params *sli4_params; |
| 10505 | uint32_t mbox_tmo; |
| 10506 | |
| 10507 | rc = 0; |
| 10508 | mqe = &mboxq->u.mqe; |
| 10509 | |
| 10510 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10511 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10512 | if (!phba->sli4_hba.intr_enable) |
| 10513 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10514 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10515 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10516 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 10517 | } |
| 10518 | |
| 10519 | if (unlikely(rc)) |
| 10520 | return 1; |
| 10521 | |
| 10522 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 10523 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 10524 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 10525 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 10526 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 10527 | &mqe->un.sli4_params); |
| 10528 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 10529 | &mqe->un.sli4_params); |
| 10530 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 10531 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 10532 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 10533 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 10534 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 10535 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 10536 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 10537 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 10538 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 10539 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 10540 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 10541 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 10542 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 10543 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 10544 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 10545 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 10546 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 10547 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 10548 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 10549 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 10550 | 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] | 10551 | |
| 10552 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 10553 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 10554 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 10555 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 10556 | return rc; |
| 10557 | } |
| 10558 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10559 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10560 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 10561 | * @phba: Pointer to HBA context object. |
| 10562 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 10563 | * |
| 10564 | * This function is called in the SLI4 code path to read the port's |
| 10565 | * sli4 capabilities. |
| 10566 | * |
| 10567 | * This function may be be called from any context that can block-wait |
| 10568 | * for the completion. The expectation is that this routine is called |
| 10569 | * typically from probe_one or from the online routine. |
| 10570 | **/ |
| 10571 | int |
| 10572 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 10573 | { |
| 10574 | int rc; |
| 10575 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 10576 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10577 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10578 | int length; |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 10579 | bool exp_wqcq_pages = true; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10580 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 10581 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10582 | /* |
| 10583 | * By default, the driver assumes the SLI4 port requires RPI |
| 10584 | * header postings. The SLI4_PARAM response will correct this |
| 10585 | * assumption. |
| 10586 | */ |
| 10587 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 10588 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10589 | /* Read the port's SLI4 Config Parameters */ |
| 10590 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 10591 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 10592 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10593 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 10594 | length, LPFC_SLI4_MBX_EMBED); |
| 10595 | if (!phba->sli4_hba.intr_enable) |
| 10596 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 10597 | else { |
| 10598 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 10599 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 10600 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10601 | if (unlikely(rc)) |
| 10602 | return rc; |
| 10603 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 10604 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 10605 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 10606 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 10607 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 10608 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 10609 | mbx_sli4_parameters); |
| 10610 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 10611 | mbx_sli4_parameters); |
| 10612 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 10613 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 10614 | else |
| 10615 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 10616 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 10617 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10618 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10619 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 10620 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 10621 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 10622 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 10623 | sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters); |
| 10624 | sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 10625 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10626 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 10627 | mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10628 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10629 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 10630 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 10631 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 10632 | 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] | 10633 | phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
| 10634 | bf_get(cfg_xib, mbx_sli4_parameters)); |
| 10635 | |
| 10636 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) || |
| 10637 | !phba->nvme_support) { |
| 10638 | phba->nvme_support = 0; |
| 10639 | phba->nvmet_support = 0; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 10640 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10641 | phba->cfg_nvme_io_channel = 0; |
| 10642 | phba->io_channel_irqs = phba->cfg_fcp_io_channel; |
| 10643 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, |
| 10644 | "6101 Disabling NVME support: " |
| 10645 | "Not supported by firmware: %d %d\n", |
| 10646 | bf_get(cfg_nvme, mbx_sli4_parameters), |
| 10647 | bf_get(cfg_xib, mbx_sli4_parameters)); |
| 10648 | |
| 10649 | /* If firmware doesn't support NVME, just use SCSI support */ |
| 10650 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 10651 | return -ENODEV; |
| 10652 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; |
| 10653 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 10654 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 10655 | /* Only embed PBDE for if_type 6 */ |
| 10656 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 10657 | LPFC_SLI_INTF_IF_TYPE_6) { |
| 10658 | phba->fcp_embed_pbde = 1; |
| 10659 | phba->nvme_embed_pbde = 1; |
| 10660 | } |
| 10661 | |
| 10662 | /* PBDE support requires xib be set */ |
| 10663 | if (!bf_get(cfg_xib, mbx_sli4_parameters)) { |
| 10664 | phba->fcp_embed_pbde = 0; |
| 10665 | phba->nvme_embed_pbde = 0; |
| 10666 | } |
| 10667 | |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 10668 | /* |
| 10669 | * To support Suppress Response feature we must satisfy 3 conditions. |
| 10670 | * lpfc_suppress_rsp module parameter must be set (default). |
| 10671 | * In SLI4-Parameters Descriptor: |
| 10672 | * Extended Inline Buffers (XIB) must be supported. |
| 10673 | * Suppress Response IU Not Supported (SRIUNS) must NOT be supported |
| 10674 | * (double negative). |
| 10675 | */ |
| 10676 | if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) && |
| 10677 | !(bf_get(cfg_nosr, mbx_sli4_parameters))) |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 10678 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 10679 | else |
| 10680 | phba->cfg_suppress_rsp = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 10681 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 10682 | if (bf_get(cfg_eqdr, mbx_sli4_parameters)) |
| 10683 | phba->sli.sli_flag |= LPFC_SLI_USE_EQDR; |
| 10684 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 10685 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 10686 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 10687 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 10688 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10689 | /* |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10690 | * Check whether the adapter supports an embedded copy of the |
| 10691 | * FCP CMD IU within the WQE for FCP_Ixxx commands. In order |
| 10692 | * to use this option, 128-byte WQEs must be used. |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 10693 | */ |
| 10694 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 10695 | phba->fcp_embed_io = 1; |
| 10696 | else |
| 10697 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 10698 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 10699 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 10700 | "6422 XIB %d: FCP %d %d NVME %d %d %d %d\n", |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 10701 | bf_get(cfg_xib, mbx_sli4_parameters), |
| 10702 | phba->fcp_embed_pbde, phba->fcp_embed_io, |
| 10703 | phba->nvme_support, phba->nvme_embed_pbde, |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 10704 | phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp); |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 10705 | |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 10706 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 10707 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 10708 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
James Smart | c221768 | 2018-05-24 21:09:00 -0700 | [diff] [blame^] | 10709 | LPFC_SLI_INTF_FAMILY_LNCR_A0)) |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 10710 | exp_wqcq_pages = false; |
| 10711 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10712 | if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) && |
| 10713 | (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) && |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 10714 | exp_wqcq_pages && |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10715 | (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT)) |
| 10716 | phba->enab_exp_wqcq_pages = 1; |
| 10717 | else |
| 10718 | phba->enab_exp_wqcq_pages = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 10719 | /* |
| 10720 | * Check if the SLI port supports MDS Diagnostics |
| 10721 | */ |
| 10722 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 10723 | phba->mds_diags_support = 1; |
| 10724 | else |
| 10725 | phba->mds_diags_support = 0; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 10726 | return 0; |
| 10727 | } |
| 10728 | |
| 10729 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10730 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 10731 | * @pdev: pointer to PCI device |
| 10732 | * @pid: pointer to PCI device identifier |
| 10733 | * |
| 10734 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 10735 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 10736 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 10737 | * information of the device and driver to see if the driver state that it can |
| 10738 | * support this kind of device. If the match is successful, the driver core |
| 10739 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 10740 | * does all the initialization that it needs to do to handle the HBA properly. |
| 10741 | * |
| 10742 | * Return code |
| 10743 | * 0 - driver can claim the device |
| 10744 | * negative value - driver can not claim the device |
| 10745 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10746 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10747 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 10748 | { |
| 10749 | struct lpfc_hba *phba; |
| 10750 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10751 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10752 | int error; |
| 10753 | uint32_t cfg_mode, intr_mode; |
| 10754 | |
| 10755 | /* Allocate memory for HBA structure */ |
| 10756 | phba = lpfc_hba_alloc(pdev); |
| 10757 | if (!phba) |
| 10758 | return -ENOMEM; |
| 10759 | |
| 10760 | /* Perform generic PCI device enabling operation */ |
| 10761 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10762 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10763 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10764 | |
| 10765 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 10766 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 10767 | if (error) |
| 10768 | goto out_disable_pci_dev; |
| 10769 | |
| 10770 | /* Set up SLI-3 specific device PCI memory space */ |
| 10771 | error = lpfc_sli_pci_mem_setup(phba); |
| 10772 | if (error) { |
| 10773 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10774 | "1402 Failed to set up pci memory space.\n"); |
| 10775 | goto out_disable_pci_dev; |
| 10776 | } |
| 10777 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10778 | /* Set up SLI-3 specific device driver resources */ |
| 10779 | error = lpfc_sli_driver_resource_setup(phba); |
| 10780 | if (error) { |
| 10781 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10782 | "1404 Failed to set up driver resource.\n"); |
| 10783 | goto out_unset_pci_mem_s3; |
| 10784 | } |
| 10785 | |
| 10786 | /* Initialize and populate the iocb list per host */ |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 10787 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10788 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 10789 | if (error) { |
| 10790 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10791 | "1405 Failed to initialize iocb list.\n"); |
| 10792 | goto out_unset_driver_resource_s3; |
| 10793 | } |
| 10794 | |
| 10795 | /* Set up common device driver resources */ |
| 10796 | error = lpfc_setup_driver_resource_phase2(phba); |
| 10797 | if (error) { |
| 10798 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10799 | "1406 Failed to set up driver resource.\n"); |
| 10800 | goto out_free_iocb_list; |
| 10801 | } |
| 10802 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 10803 | /* Get the default values for Model Name and Description */ |
| 10804 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 10805 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10806 | /* Create SCSI host to the physical port */ |
| 10807 | error = lpfc_create_shost(phba); |
| 10808 | if (error) { |
| 10809 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10810 | "1407 Failed to create scsi host.\n"); |
| 10811 | goto out_unset_driver_resource; |
| 10812 | } |
| 10813 | |
| 10814 | /* Configure sysfs attributes */ |
| 10815 | vport = phba->pport; |
| 10816 | error = lpfc_alloc_sysfs_attr(vport); |
| 10817 | if (error) { |
| 10818 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10819 | "1476 Failed to allocate sysfs attr\n"); |
| 10820 | goto out_destroy_shost; |
| 10821 | } |
| 10822 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10823 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10824 | /* Now, trying to enable interrupt and bring up the device */ |
| 10825 | cfg_mode = phba->cfg_use_msi; |
| 10826 | while (true) { |
| 10827 | /* Put device to a known state before enabling interrupt */ |
| 10828 | lpfc_stop_port(phba); |
| 10829 | /* Configure and enable interrupt */ |
| 10830 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 10831 | if (intr_mode == LPFC_INTR_ERROR) { |
| 10832 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10833 | "0431 Failed to enable interrupt.\n"); |
| 10834 | error = -ENODEV; |
| 10835 | goto out_free_sysfs_attr; |
| 10836 | } |
| 10837 | /* SLI-3 HBA setup */ |
| 10838 | if (lpfc_sli_hba_setup(phba)) { |
| 10839 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 10840 | "1477 Failed to set up hba\n"); |
| 10841 | error = -ENODEV; |
| 10842 | goto out_remove_device; |
| 10843 | } |
| 10844 | |
| 10845 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 10846 | msleep(50); |
| 10847 | /* Check active interrupts on message signaled interrupts */ |
| 10848 | if (intr_mode == 0 || |
| 10849 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 10850 | /* Log the current active interrupt mode */ |
| 10851 | phba->intr_mode = intr_mode; |
| 10852 | lpfc_log_intr_mode(phba, intr_mode); |
| 10853 | break; |
| 10854 | } else { |
| 10855 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10856 | "0447 Configure interrupt mode (%d) " |
| 10857 | "failed active interrupt test.\n", |
| 10858 | intr_mode); |
| 10859 | /* Disable the current interrupt mode */ |
| 10860 | lpfc_sli_disable_intr(phba); |
| 10861 | /* Try next level of interrupt mode */ |
| 10862 | cfg_mode = --intr_mode; |
| 10863 | } |
| 10864 | } |
| 10865 | |
| 10866 | /* Perform post initialization setup */ |
| 10867 | lpfc_post_init_setup(phba); |
| 10868 | |
| 10869 | /* Check if there are static vports to be created. */ |
| 10870 | lpfc_create_static_vport(phba); |
| 10871 | |
| 10872 | return 0; |
| 10873 | |
| 10874 | out_remove_device: |
| 10875 | lpfc_unset_hba(phba); |
| 10876 | out_free_sysfs_attr: |
| 10877 | lpfc_free_sysfs_attr(vport); |
| 10878 | out_destroy_shost: |
| 10879 | lpfc_destroy_shost(phba); |
| 10880 | out_unset_driver_resource: |
| 10881 | lpfc_unset_driver_resource_phase2(phba); |
| 10882 | out_free_iocb_list: |
| 10883 | lpfc_free_iocb_list(phba); |
| 10884 | out_unset_driver_resource_s3: |
| 10885 | lpfc_sli_driver_resource_unset(phba); |
| 10886 | out_unset_pci_mem_s3: |
| 10887 | lpfc_sli_pci_mem_unset(phba); |
| 10888 | out_disable_pci_dev: |
| 10889 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 10890 | if (shost) |
| 10891 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10892 | out_free_phba: |
| 10893 | lpfc_hba_free(phba); |
| 10894 | return error; |
| 10895 | } |
| 10896 | |
| 10897 | /** |
| 10898 | * 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] | 10899 | * @pdev: pointer to PCI device |
| 10900 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10901 | * This routine is to be called to disattach a device with SLI-3 interface |
| 10902 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 10903 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 10904 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 10905 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 10906 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10907 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10908 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10909 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 10910 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 10911 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10912 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 10913 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 10914 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 10915 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 10916 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 10917 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10918 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10919 | lpfc_free_sysfs_attr(vport); |
| 10920 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 10921 | /* Release all the vports against this physical port */ |
| 10922 | vports = lpfc_create_vport_work_array(phba); |
| 10923 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10924 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 10925 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 10926 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 10927 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 10928 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 10929 | lpfc_destroy_vport_work_array(phba, vports); |
| 10930 | |
| 10931 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10932 | fc_remove_host(shost); |
| 10933 | scsi_remove_host(shost); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 10934 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 10935 | lpfc_cleanup(vport); |
| 10936 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10937 | /* |
| 10938 | * Bring down the SLI Layer. This step disable all interrupts, |
| 10939 | * clears the rings, discards all mailbox commands, and resets |
| 10940 | * the HBA. |
| 10941 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10942 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 10943 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10944 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 10945 | /* Stop kthread signal shall trigger work_done one more time */ |
| 10946 | kthread_stop(phba->worker_thread); |
| 10947 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10948 | lpfc_sli_brdrestart(phba); |
| 10949 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 10950 | kfree(phba->vpi_bmask); |
| 10951 | kfree(phba->vpi_ids); |
| 10952 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10953 | lpfc_stop_hba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10954 | spin_lock_irq(&phba->hbalock); |
| 10955 | list_del_init(&vport->listentry); |
| 10956 | spin_unlock_irq(&phba->hbalock); |
| 10957 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10958 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10959 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10960 | /* Disable SR-IOV if enabled */ |
| 10961 | if (phba->cfg_sriov_nr_virtfn) |
| 10962 | pci_disable_sriov(pdev); |
| 10963 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 10964 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10965 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10966 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 10967 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10968 | |
| 10969 | /* |
| 10970 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 10971 | * corresponding pools here. |
| 10972 | */ |
| 10973 | lpfc_scsi_free(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10974 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10975 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10976 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 10977 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 10978 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10979 | /* Free resources associated with SLI2 interface */ |
| 10980 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 10981 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10982 | |
| 10983 | /* unmap adapter SLIM and Control Registers */ |
| 10984 | iounmap(phba->ctrl_regs_memmap_p); |
| 10985 | iounmap(phba->slim_memmap_p); |
| 10986 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10987 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10988 | |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 10989 | pci_release_mem_regions(pdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 10990 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10991 | } |
| 10992 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 10993 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10994 | * 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] | 10995 | * @pdev: pointer to PCI device |
| 10996 | * @msg: power management message |
| 10997 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10998 | * This routine is to be called from the kernel's PCI subsystem to support |
| 10999 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 11000 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 11001 | * worker thread for the device, turning off device's interrupt and DMA, |
| 11002 | * and bring the device offline. Note that as the driver implements the |
| 11003 | * minimum PM requirements to a power-aware driver's PM support for the |
| 11004 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 11005 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 11006 | * fully reinitialize its device during resume() method call, the driver will |
| 11007 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 11008 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11009 | * |
| 11010 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11011 | * 0 - driver suspended the device |
| 11012 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11013 | **/ |
| 11014 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11015 | 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] | 11016 | { |
| 11017 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11018 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11019 | |
| 11020 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11021 | "0473 PCI device Power Management suspend.\n"); |
| 11022 | |
| 11023 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11024 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11025 | lpfc_offline(phba); |
| 11026 | kthread_stop(phba->worker_thread); |
| 11027 | |
| 11028 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11029 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11030 | |
| 11031 | /* Save device state to PCI config space */ |
| 11032 | pci_save_state(pdev); |
| 11033 | pci_set_power_state(pdev, PCI_D3hot); |
| 11034 | |
| 11035 | return 0; |
| 11036 | } |
| 11037 | |
| 11038 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11039 | * 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] | 11040 | * @pdev: pointer to PCI device |
| 11041 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11042 | * This routine is to be called from the kernel's PCI subsystem to support |
| 11043 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 11044 | * invokes this method, it restores the device's PCI config space state and |
| 11045 | * fully reinitializes the device and brings it online. Note that as the |
| 11046 | * driver implements the minimum PM requirements to a power-aware driver's |
| 11047 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 11048 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 11049 | * driver will fully reinitialize its device during resume() method call, |
| 11050 | * the device will be set to PCI_D0 directly in PCI config space before |
| 11051 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11052 | * |
| 11053 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11054 | * 0 - driver suspended the device |
| 11055 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11056 | **/ |
| 11057 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11058 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11059 | { |
| 11060 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11061 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11062 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11063 | int error; |
| 11064 | |
| 11065 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11066 | "0452 PCI device Power Management resume.\n"); |
| 11067 | |
| 11068 | /* Restore device state from PCI config space */ |
| 11069 | pci_set_power_state(pdev, PCI_D0); |
| 11070 | pci_restore_state(pdev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11071 | |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 11072 | /* |
| 11073 | * As the new kernel behavior of pci_restore_state() API call clears |
| 11074 | * device saved_state flag, need to save the restored state again. |
| 11075 | */ |
| 11076 | pci_save_state(pdev); |
| 11077 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11078 | if (pdev->is_busmaster) |
| 11079 | pci_set_master(pdev); |
| 11080 | |
| 11081 | /* Startup the kernel thread for this host adapter. */ |
| 11082 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 11083 | "lpfc_worker_%d", phba->brd_no); |
| 11084 | if (IS_ERR(phba->worker_thread)) { |
| 11085 | error = PTR_ERR(phba->worker_thread); |
| 11086 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11087 | "0434 PM resume failed to start worker " |
| 11088 | "thread: error=x%x.\n", error); |
| 11089 | return error; |
| 11090 | } |
| 11091 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11092 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11093 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11094 | if (intr_mode == LPFC_INTR_ERROR) { |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11095 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11096 | "0430 PM resume Failed to enable interrupt\n"); |
| 11097 | return -EIO; |
| 11098 | } else |
| 11099 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11100 | |
| 11101 | /* Restart HBA and bring it online */ |
| 11102 | lpfc_sli_brdrestart(phba); |
| 11103 | lpfc_online(phba); |
| 11104 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11105 | /* Log the current active interrupt mode */ |
| 11106 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 11107 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 11108 | return 0; |
| 11109 | } |
| 11110 | |
| 11111 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 11112 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 11113 | * @phba: pointer to lpfc hba data structure. |
| 11114 | * |
| 11115 | * 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] | 11116 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 11117 | **/ |
| 11118 | static void |
| 11119 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 11120 | { |
| 11121 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11122 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 11123 | |
| 11124 | /* |
| 11125 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 11126 | * and let the SCSI mid-layer to retry them to recover. |
| 11127 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11128 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 11129 | } |
| 11130 | |
| 11131 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11132 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 11133 | * @phba: pointer to lpfc hba data structure. |
| 11134 | * |
| 11135 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 11136 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 11137 | * pending I/Os. |
| 11138 | **/ |
| 11139 | static void |
| 11140 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 11141 | { |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11142 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 11143 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 11144 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11145 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11146 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11147 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 11148 | /* Block all SCSI devices' I/Os on the host */ |
| 11149 | lpfc_scsi_dev_block(phba); |
| 11150 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 11151 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 11152 | lpfc_sli_flush_fcp_rings(phba); |
| 11153 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 11154 | /* stop all timers */ |
| 11155 | lpfc_stop_hba_timers(phba); |
| 11156 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11157 | /* Disable interrupt and pci device */ |
| 11158 | lpfc_sli_disable_intr(phba); |
| 11159 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11160 | } |
| 11161 | |
| 11162 | /** |
| 11163 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 11164 | * @phba: pointer to lpfc hba data structure. |
| 11165 | * |
| 11166 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 11167 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 11168 | * pending I/Os. |
| 11169 | **/ |
| 11170 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11171 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11172 | { |
| 11173 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 11174 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 11175 | /* Block all SCSI devices' I/Os on the host */ |
| 11176 | lpfc_scsi_dev_block(phba); |
| 11177 | |
| 11178 | /* stop all timers */ |
| 11179 | lpfc_stop_hba_timers(phba); |
| 11180 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11181 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 11182 | lpfc_sli_flush_fcp_rings(phba); |
| 11183 | } |
| 11184 | |
| 11185 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11186 | * 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] | 11187 | * @pdev: pointer to PCI device. |
| 11188 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11189 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11190 | * This routine is called from the PCI subsystem for I/O error handling to |
| 11191 | * device with SLI-3 interface spec. This function is called by the PCI |
| 11192 | * subsystem after a PCI bus error affecting this device has been detected. |
| 11193 | * When this function is invoked, it will need to stop all the I/Os and |
| 11194 | * interrupt(s) to the device. Once that is done, it will return |
| 11195 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 11196 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11197 | * |
| 11198 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11199 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11200 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 11201 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11202 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11203 | static pci_ers_result_t |
| 11204 | 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] | 11205 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11206 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11207 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11208 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11209 | switch (state) { |
| 11210 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 11211 | /* Non-fatal error, prepare for recovery */ |
| 11212 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11213 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 11214 | case pci_channel_io_frozen: |
| 11215 | /* Fatal error, prepare for slot reset */ |
| 11216 | lpfc_sli_prep_dev_for_reset(phba); |
| 11217 | return PCI_ERS_RESULT_NEED_RESET; |
| 11218 | case pci_channel_io_perm_failure: |
| 11219 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11220 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11221 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11222 | default: |
| 11223 | /* Unknown state, prepare and request slot reset */ |
| 11224 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11225 | "0472 Unknown PCI error state: x%x\n", state); |
| 11226 | lpfc_sli_prep_dev_for_reset(phba); |
| 11227 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 11228 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11229 | } |
| 11230 | |
| 11231 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11232 | * 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] | 11233 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11234 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11235 | * This routine is called from the PCI subsystem for error handling to |
| 11236 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 11237 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 11238 | * During the PCI subsystem error recovery, after driver returns |
| 11239 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 11240 | * recovery and then call this routine before calling the .resume method |
| 11241 | * to recover the device. This function will initialize the HBA device, |
| 11242 | * enable the interrupt, but it will just put the HBA to offline state |
| 11243 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 11244 | * |
| 11245 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11246 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 11247 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11248 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11249 | static pci_ers_result_t |
| 11250 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11251 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11252 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11253 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11254 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11255 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11256 | |
| 11257 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 11258 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11259 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 11260 | "PCI device after reset.\n"); |
| 11261 | return PCI_ERS_RESULT_DISCONNECT; |
| 11262 | } |
| 11263 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 11264 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 11265 | |
| 11266 | /* |
| 11267 | * As the new kernel behavior of pci_restore_state() API call clears |
| 11268 | * device saved_state flag, need to save the restored state again. |
| 11269 | */ |
| 11270 | pci_save_state(pdev); |
| 11271 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 11272 | if (pdev->is_busmaster) |
| 11273 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11274 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11275 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11276 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 11277 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11278 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11279 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11280 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11281 | if (intr_mode == LPFC_INTR_ERROR) { |
| 11282 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11283 | "0427 Cannot re-enable interrupt after " |
| 11284 | "slot reset.\n"); |
| 11285 | return PCI_ERS_RESULT_DISCONNECT; |
| 11286 | } else |
| 11287 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11288 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11289 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11290 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11291 | lpfc_offline(phba); |
| 11292 | lpfc_sli_brdrestart(phba); |
| 11293 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 11294 | /* Log the current active interrupt mode */ |
| 11295 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 11296 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11297 | return PCI_ERS_RESULT_RECOVERED; |
| 11298 | } |
| 11299 | |
| 11300 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11301 | * 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] | 11302 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11303 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11304 | * This routine is called from the PCI subsystem for error handling to device |
| 11305 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 11306 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 11307 | * error recovery. After this call, traffic can start to flow from this device |
| 11308 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11309 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11310 | static void |
| 11311 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11312 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 11313 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11314 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11315 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 11316 | /* 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] | 11317 | lpfc_online(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 11318 | |
| 11319 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 11320 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 11321 | pci_cleanup_aer_uncorrect_error_status(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 11322 | } |
| 11323 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11324 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11325 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 11326 | * @phba: pointer to lpfc hba data structure. |
| 11327 | * |
| 11328 | * returns the number of ELS/CT IOCBs to reserve |
| 11329 | **/ |
| 11330 | int |
| 11331 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 11332 | { |
| 11333 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 11334 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 11335 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 11336 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11337 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 11338 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11339 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 11340 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11341 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 11342 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11343 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 11344 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 11345 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 11346 | else if (max_xri <= 2048) |
| 11347 | return 200; |
| 11348 | else |
| 11349 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 11350 | } else |
| 11351 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11352 | } |
| 11353 | |
| 11354 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11355 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve |
| 11356 | * @phba: pointer to lpfc hba data structure. |
| 11357 | * |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11358 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11359 | **/ |
| 11360 | int |
| 11361 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) |
| 11362 | { |
| 11363 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); |
| 11364 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11365 | if (phba->nvmet_support) |
| 11366 | max_xri += LPFC_NVMET_BUF_POST; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11367 | return max_xri; |
| 11368 | } |
| 11369 | |
| 11370 | |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 11371 | static void |
| 11372 | lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset, |
| 11373 | uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize, |
| 11374 | const struct firmware *fw) |
| 11375 | { |
James Smart | a72d56b | 2018-05-04 20:37:52 -0700 | [diff] [blame] | 11376 | if ((offset == ADD_STATUS_FW_NOT_SUPPORTED) || |
| 11377 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
| 11378 | magic_number != MAGIC_NUMER_G6) || |
| 11379 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC && |
| 11380 | magic_number != MAGIC_NUMER_G7)) |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 11381 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11382 | "3030 This firmware version is not supported on " |
| 11383 | "this HBA model. Device:%x Magic:%x Type:%x " |
| 11384 | "ID:%x Size %d %zd\n", |
| 11385 | phba->pcidev->device, magic_number, ftype, fid, |
| 11386 | fsize, fw->size); |
| 11387 | else |
| 11388 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11389 | "3022 FW Download failed. Device:%x Magic:%x Type:%x " |
| 11390 | "ID:%x Size %d %zd\n", |
| 11391 | phba->pcidev->device, magic_number, ftype, fid, |
| 11392 | fsize, fw->size); |
| 11393 | } |
| 11394 | |
| 11395 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11396 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11397 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11398 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11399 | * @phba: pointer to lpfc hba data structure. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11400 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11401 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11402 | static void |
| 11403 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11404 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11405 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 11406 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11407 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11408 | struct list_head dma_buffer_list; |
| 11409 | int i, rc = 0; |
| 11410 | struct lpfc_dmabuf *dmabuf, *next; |
| 11411 | uint32_t offset = 0, temp_offset = 0; |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 11412 | uint32_t magic_number, ftype, fid, fsize; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11413 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 11414 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11415 | if (!fw) { |
| 11416 | rc = -ENXIO; |
| 11417 | goto out; |
| 11418 | } |
| 11419 | image = (struct lpfc_grp_hdr *)fw->data; |
| 11420 | |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 11421 | magic_number = be32_to_cpu(image->magic_number); |
| 11422 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 11423 | fid = bf_get_be32(lpfc_grp_hdr_id, image); |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 11424 | fsize = be32_to_cpu(image->size); |
| 11425 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11426 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11427 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 11428 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11429 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11430 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11431 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 11432 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11433 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 11434 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 11435 | GFP_KERNEL); |
| 11436 | if (!dmabuf) { |
| 11437 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11438 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11439 | } |
| 11440 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 11441 | SLI4_PAGE_SIZE, |
| 11442 | &dmabuf->phys, |
| 11443 | GFP_KERNEL); |
| 11444 | if (!dmabuf->virt) { |
| 11445 | kfree(dmabuf); |
| 11446 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11447 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11448 | } |
| 11449 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 11450 | } |
| 11451 | while (offset < fw->size) { |
| 11452 | temp_offset = offset; |
| 11453 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11454 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11455 | memcpy(dmabuf->virt, |
| 11456 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11457 | fw->size - temp_offset); |
| 11458 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11459 | break; |
| 11460 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11461 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 11462 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 11463 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11464 | } |
| 11465 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 11466 | (fw->size - offset), &offset); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 11467 | if (rc) { |
| 11468 | lpfc_log_write_firmware_error(phba, offset, |
| 11469 | magic_number, ftype, fid, fsize, fw); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11470 | goto release_out; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 11471 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11472 | } |
| 11473 | rc = offset; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 11474 | } else |
| 11475 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11476 | "3029 Skipped Firmware update, Current " |
| 11477 | "Version:%s New Version:%s\n", |
| 11478 | fwrev, image->revision); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11479 | |
| 11480 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11481 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 11482 | list_del(&dmabuf->list); |
| 11483 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 11484 | dmabuf->virt, dmabuf->phys); |
| 11485 | kfree(dmabuf); |
| 11486 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11487 | release_firmware(fw); |
| 11488 | out: |
| 11489 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 11490 | "3024 Firmware update done: %d.\n", rc); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 11491 | return; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11492 | } |
| 11493 | |
| 11494 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 11495 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 11496 | * @phba: pointer to lpfc hba data structure. |
| 11497 | * |
| 11498 | * This routine is called to perform Linux generic firmware upgrade on device |
| 11499 | * that supports such feature. |
| 11500 | **/ |
| 11501 | int |
| 11502 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 11503 | { |
| 11504 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 11505 | int ret; |
| 11506 | const struct firmware *fw; |
| 11507 | |
| 11508 | /* Only supported on SLI4 interface type 2 for now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11509 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) < |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 11510 | LPFC_SLI_INTF_IF_TYPE_2) |
| 11511 | return -EPERM; |
| 11512 | |
| 11513 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 11514 | |
| 11515 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 11516 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 11517 | file_name, &phba->pcidev->dev, |
| 11518 | GFP_KERNEL, (void *)phba, |
| 11519 | lpfc_write_firmware); |
| 11520 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 11521 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 11522 | if (!ret) |
| 11523 | lpfc_write_firmware(fw, (void *)phba); |
| 11524 | } else { |
| 11525 | ret = -EINVAL; |
| 11526 | } |
| 11527 | |
| 11528 | return ret; |
| 11529 | } |
| 11530 | |
| 11531 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11532 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 11533 | * @pdev: pointer to PCI device |
| 11534 | * @pid: pointer to PCI device identifier |
| 11535 | * |
| 11536 | * This routine is called from the kernel's PCI subsystem to device with |
| 11537 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 11538 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 11539 | * information of the device and driver to see if the driver state that it |
| 11540 | * can support this kind of device. If the match is successful, the driver |
| 11541 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 11542 | * it does all the initialization that it needs to do to handle the HBA |
| 11543 | * properly. |
| 11544 | * |
| 11545 | * Return code |
| 11546 | * 0 - driver can claim the device |
| 11547 | * negative value - driver can not claim the device |
| 11548 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11549 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11550 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 11551 | { |
| 11552 | struct lpfc_hba *phba; |
| 11553 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11554 | struct Scsi_Host *shost = NULL; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 11555 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11556 | uint32_t cfg_mode, intr_mode; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11557 | |
| 11558 | /* Allocate memory for HBA structure */ |
| 11559 | phba = lpfc_hba_alloc(pdev); |
| 11560 | if (!phba) |
| 11561 | return -ENOMEM; |
| 11562 | |
| 11563 | /* Perform generic PCI device enabling operation */ |
| 11564 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11565 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11566 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11567 | |
| 11568 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 11569 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 11570 | if (error) |
| 11571 | goto out_disable_pci_dev; |
| 11572 | |
| 11573 | /* Set up SLI-4 specific device PCI memory space */ |
| 11574 | error = lpfc_sli4_pci_mem_setup(phba); |
| 11575 | if (error) { |
| 11576 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11577 | "1410 Failed to set up pci memory space.\n"); |
| 11578 | goto out_disable_pci_dev; |
| 11579 | } |
| 11580 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11581 | /* Set up SLI-4 Specific device driver resources */ |
| 11582 | error = lpfc_sli4_driver_resource_setup(phba); |
| 11583 | if (error) { |
| 11584 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11585 | "1412 Failed to set up driver resource.\n"); |
| 11586 | goto out_unset_pci_mem_s4; |
| 11587 | } |
| 11588 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 11589 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 11590 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 11591 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11592 | /* Set up common device driver resources */ |
| 11593 | error = lpfc_setup_driver_resource_phase2(phba); |
| 11594 | if (error) { |
| 11595 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11596 | "1414 Failed to set up driver resource.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 11597 | goto out_unset_driver_resource_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11598 | } |
| 11599 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 11600 | /* Get the default values for Model Name and Description */ |
| 11601 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 11602 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11603 | /* Create SCSI host to the physical port */ |
| 11604 | error = lpfc_create_shost(phba); |
| 11605 | if (error) { |
| 11606 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11607 | "1415 Failed to create scsi host.\n"); |
| 11608 | goto out_unset_driver_resource; |
| 11609 | } |
| 11610 | |
| 11611 | /* Configure sysfs attributes */ |
| 11612 | vport = phba->pport; |
| 11613 | error = lpfc_alloc_sysfs_attr(vport); |
| 11614 | if (error) { |
| 11615 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11616 | "1416 Failed to allocate sysfs attr\n"); |
| 11617 | goto out_destroy_shost; |
| 11618 | } |
| 11619 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11620 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11621 | /* Now, trying to enable interrupt and bring up the device */ |
| 11622 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11623 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 11624 | /* Put device to a known state before enabling interrupt */ |
| 11625 | lpfc_stop_port(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11626 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 11627 | /* Configure and enable interrupt */ |
| 11628 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 11629 | if (intr_mode == LPFC_INTR_ERROR) { |
| 11630 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11631 | "0426 Failed to enable interrupt.\n"); |
| 11632 | error = -ENODEV; |
| 11633 | goto out_free_sysfs_attr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11634 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 11635 | /* Default to single EQ for non-MSI-X */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11636 | if (phba->intr_type != MSIX) { |
| 11637 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) |
| 11638 | phba->cfg_fcp_io_channel = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11639 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11640 | phba->cfg_nvme_io_channel = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11641 | if (phba->nvmet_support) |
| 11642 | phba->cfg_nvmet_mrq = 1; |
| 11643 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11644 | phba->io_channel_irqs = 1; |
| 11645 | } |
| 11646 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 11647 | /* Set up SLI-4 HBA */ |
| 11648 | if (lpfc_sli4_hba_setup(phba)) { |
| 11649 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11650 | "1421 Failed to set up hba\n"); |
| 11651 | error = -ENODEV; |
| 11652 | goto out_disable_intr; |
| 11653 | } |
| 11654 | |
| 11655 | /* Log the current active interrupt mode */ |
| 11656 | phba->intr_mode = intr_mode; |
| 11657 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11658 | |
| 11659 | /* Perform post initialization setup */ |
| 11660 | lpfc_post_init_setup(phba); |
| 11661 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11662 | /* NVME support in FW earlier in the driver load corrects the |
| 11663 | * FC4 type making a check for nvme_support unnecessary. |
| 11664 | */ |
| 11665 | if ((phba->nvmet_support == 0) && |
| 11666 | (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) { |
| 11667 | /* Create NVME binding with nvme_fc_transport. This |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11668 | * ensures the vport is initialized. If the localport |
| 11669 | * create fails, it should not unload the driver to |
| 11670 | * support field issues. |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11671 | */ |
| 11672 | error = lpfc_nvme_create_localport(vport); |
| 11673 | if (error) { |
| 11674 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11675 | "6004 NVME registration failed, " |
| 11676 | "error x%x\n", |
| 11677 | error); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11678 | } |
| 11679 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11680 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 11681 | /* check for firmware upgrade or downgrade */ |
| 11682 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 11683 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 11684 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 11685 | /* Check if there are static vports to be created. */ |
| 11686 | lpfc_create_static_vport(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11687 | return 0; |
| 11688 | |
| 11689 | out_disable_intr: |
| 11690 | lpfc_sli4_disable_intr(phba); |
| 11691 | out_free_sysfs_attr: |
| 11692 | lpfc_free_sysfs_attr(vport); |
| 11693 | out_destroy_shost: |
| 11694 | lpfc_destroy_shost(phba); |
| 11695 | out_unset_driver_resource: |
| 11696 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11697 | out_unset_driver_resource_s4: |
| 11698 | lpfc_sli4_driver_resource_unset(phba); |
| 11699 | out_unset_pci_mem_s4: |
| 11700 | lpfc_sli4_pci_mem_unset(phba); |
| 11701 | out_disable_pci_dev: |
| 11702 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 11703 | if (shost) |
| 11704 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11705 | out_free_phba: |
| 11706 | lpfc_hba_free(phba); |
| 11707 | return error; |
| 11708 | } |
| 11709 | |
| 11710 | /** |
| 11711 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 11712 | * @pdev: pointer to PCI device |
| 11713 | * |
| 11714 | * This routine is called from the kernel's PCI subsystem to device with |
| 11715 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 11716 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 11717 | * device to be removed from the PCI subsystem properly. |
| 11718 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 11719 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11720 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 11721 | { |
| 11722 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11723 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 11724 | struct lpfc_vport **vports; |
| 11725 | struct lpfc_hba *phba = vport->phba; |
| 11726 | int i; |
| 11727 | |
| 11728 | /* Mark the device unloading flag */ |
| 11729 | spin_lock_irq(&phba->hbalock); |
| 11730 | vport->load_flag |= FC_UNLOADING; |
| 11731 | spin_unlock_irq(&phba->hbalock); |
| 11732 | |
| 11733 | /* Free the HBA sysfs attributes */ |
| 11734 | lpfc_free_sysfs_attr(vport); |
| 11735 | |
| 11736 | /* Release all the vports against this physical port */ |
| 11737 | vports = lpfc_create_vport_work_array(phba); |
| 11738 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 11739 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 11740 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 11741 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11742 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 11743 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11744 | lpfc_destroy_vport_work_array(phba, vports); |
| 11745 | |
| 11746 | /* Remove FC host and then SCSI host with the physical port */ |
| 11747 | fc_remove_host(shost); |
| 11748 | scsi_remove_host(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11749 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11750 | /* Perform ndlp cleanup on the physical port. The nvme and nvmet |
| 11751 | * localports are destroyed after to cleanup all transport memory. |
| 11752 | */ |
| 11753 | lpfc_cleanup(vport); |
| 11754 | lpfc_nvmet_destroy_targetport(phba); |
| 11755 | lpfc_nvme_destroy_localport(vport); |
| 11756 | |
James Smart | 281d619 | 2018-01-30 15:58:47 -0800 | [diff] [blame] | 11757 | /* |
| 11758 | * Bring down the SLI Layer. This step disables all interrupts, |
| 11759 | * clears the rings, discards all mailbox commands, and resets |
| 11760 | * the HBA FCoE function. |
| 11761 | */ |
| 11762 | lpfc_debugfs_terminate(vport); |
| 11763 | lpfc_sli4_hba_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11764 | |
Dick Kennedy | 1901762 | 2017-09-29 17:34:27 -0700 | [diff] [blame] | 11765 | lpfc_stop_hba_timers(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11766 | spin_lock_irq(&phba->hbalock); |
| 11767 | list_del_init(&vport->listentry); |
| 11768 | spin_unlock_irq(&phba->hbalock); |
| 11769 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 11770 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11771 | * buffers are released to their corresponding pools here. |
| 11772 | */ |
| 11773 | lpfc_scsi_free(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11774 | lpfc_nvme_free(phba); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 11775 | lpfc_free_iocb_list(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11776 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 11777 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11778 | lpfc_sli4_driver_resource_unset(phba); |
| 11779 | |
| 11780 | /* Unmap adapter Control and Doorbell registers */ |
| 11781 | lpfc_sli4_pci_mem_unset(phba); |
| 11782 | |
| 11783 | /* Release PCI resources and disable device's PCI function */ |
| 11784 | scsi_host_put(shost); |
| 11785 | lpfc_disable_pci_dev(phba); |
| 11786 | |
| 11787 | /* Finally, free the driver's device data structure */ |
| 11788 | lpfc_hba_free(phba); |
| 11789 | |
| 11790 | return; |
| 11791 | } |
| 11792 | |
| 11793 | /** |
| 11794 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
| 11795 | * @pdev: pointer to PCI device |
| 11796 | * @msg: power management message |
| 11797 | * |
| 11798 | * This routine is called from the kernel's PCI subsystem to support system |
| 11799 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 11800 | * this method, it quiesces the device by stopping the driver's worker |
| 11801 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 11802 | * the device offline. Note that as the driver implements the minimum PM |
| 11803 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 11804 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 11805 | * method call will be treated as SUSPEND and the driver will fully |
| 11806 | * reinitialize its device during resume() method call, the driver will set |
| 11807 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 11808 | * according to the @msg provided by the PM. |
| 11809 | * |
| 11810 | * Return code |
| 11811 | * 0 - driver suspended the device |
| 11812 | * Error otherwise |
| 11813 | **/ |
| 11814 | static int |
| 11815 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
| 11816 | { |
| 11817 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11818 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11819 | |
| 11820 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11821 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11822 | |
| 11823 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11824 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11825 | lpfc_offline(phba); |
| 11826 | kthread_stop(phba->worker_thread); |
| 11827 | |
| 11828 | /* Disable interrupt from device */ |
| 11829 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11830 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11831 | |
| 11832 | /* Save device state to PCI config space */ |
| 11833 | pci_save_state(pdev); |
| 11834 | pci_set_power_state(pdev, PCI_D3hot); |
| 11835 | |
| 11836 | return 0; |
| 11837 | } |
| 11838 | |
| 11839 | /** |
| 11840 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
| 11841 | * @pdev: pointer to PCI device |
| 11842 | * |
| 11843 | * This routine is called from the kernel's PCI subsystem to support system |
| 11844 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 11845 | * this method, it restores the device's PCI config space state and fully |
| 11846 | * reinitializes the device and brings it online. Note that as the driver |
| 11847 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 11848 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 11849 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 11850 | * will fully reinitialize its device during resume() method call, the device |
| 11851 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 11852 | * state. |
| 11853 | * |
| 11854 | * Return code |
| 11855 | * 0 - driver suspended the device |
| 11856 | * Error otherwise |
| 11857 | **/ |
| 11858 | static int |
| 11859 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
| 11860 | { |
| 11861 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 11862 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 11863 | uint32_t intr_mode; |
| 11864 | int error; |
| 11865 | |
| 11866 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11867 | "0292 PCI device Power Management resume.\n"); |
| 11868 | |
| 11869 | /* Restore device state from PCI config space */ |
| 11870 | pci_set_power_state(pdev, PCI_D0); |
| 11871 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 11872 | |
| 11873 | /* |
| 11874 | * As the new kernel behavior of pci_restore_state() API call clears |
| 11875 | * device saved_state flag, need to save the restored state again. |
| 11876 | */ |
| 11877 | pci_save_state(pdev); |
| 11878 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11879 | if (pdev->is_busmaster) |
| 11880 | pci_set_master(pdev); |
| 11881 | |
| 11882 | /* Startup the kernel thread for this host adapter. */ |
| 11883 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 11884 | "lpfc_worker_%d", phba->brd_no); |
| 11885 | if (IS_ERR(phba->worker_thread)) { |
| 11886 | error = PTR_ERR(phba->worker_thread); |
| 11887 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11888 | "0293 PM resume failed to start worker " |
| 11889 | "thread: error=x%x.\n", error); |
| 11890 | return error; |
| 11891 | } |
| 11892 | |
| 11893 | /* Configure and enable interrupt */ |
| 11894 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 11895 | if (intr_mode == LPFC_INTR_ERROR) { |
| 11896 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11897 | "0294 PM resume Failed to enable interrupt\n"); |
| 11898 | return -EIO; |
| 11899 | } else |
| 11900 | phba->intr_mode = intr_mode; |
| 11901 | |
| 11902 | /* Restart HBA and bring it online */ |
| 11903 | lpfc_sli_brdrestart(phba); |
| 11904 | lpfc_online(phba); |
| 11905 | |
| 11906 | /* Log the current active interrupt mode */ |
| 11907 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 11908 | |
| 11909 | return 0; |
| 11910 | } |
| 11911 | |
| 11912 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11913 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 11914 | * @phba: pointer to lpfc hba data structure. |
| 11915 | * |
| 11916 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 11917 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 11918 | **/ |
| 11919 | static void |
| 11920 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 11921 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11922 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11923 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 11924 | /* |
| 11925 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 11926 | * and let the SCSI mid-layer to retry them to recover. |
| 11927 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 11928 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11929 | } |
| 11930 | |
| 11931 | /** |
| 11932 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 11933 | * @phba: pointer to lpfc hba data structure. |
| 11934 | * |
| 11935 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 11936 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 11937 | * pending I/Os. |
| 11938 | **/ |
| 11939 | static void |
| 11940 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 11941 | { |
| 11942 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11943 | "2826 PCI channel disable preparing for reset\n"); |
| 11944 | |
| 11945 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 11946 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11947 | |
| 11948 | /* Block all SCSI devices' I/Os on the host */ |
| 11949 | lpfc_scsi_dev_block(phba); |
| 11950 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 11951 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
| 11952 | lpfc_sli_flush_fcp_rings(phba); |
| 11953 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11954 | /* Flush the outstanding NVME IOs if fc4 type enabled. */ |
| 11955 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11956 | lpfc_sli_flush_nvme_rings(phba); |
| 11957 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11958 | /* stop all timers */ |
| 11959 | lpfc_stop_hba_timers(phba); |
| 11960 | |
| 11961 | /* Disable interrupt and pci device */ |
| 11962 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 11963 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11964 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11965 | } |
| 11966 | |
| 11967 | /** |
| 11968 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 11969 | * @phba: pointer to lpfc hba data structure. |
| 11970 | * |
| 11971 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 11972 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 11973 | * pending I/Os. |
| 11974 | **/ |
| 11975 | static void |
| 11976 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 11977 | { |
| 11978 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11979 | "2827 PCI channel permanent disable for failure\n"); |
| 11980 | |
| 11981 | /* Block all SCSI devices' I/Os on the host */ |
| 11982 | lpfc_scsi_dev_block(phba); |
| 11983 | |
| 11984 | /* stop all timers */ |
| 11985 | lpfc_stop_hba_timers(phba); |
| 11986 | |
| 11987 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 11988 | lpfc_sli_flush_fcp_rings(phba); |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11989 | |
| 11990 | /* Flush the outstanding NVME IOs if fc4 type enabled. */ |
| 11991 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11992 | lpfc_sli_flush_nvme_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11993 | } |
| 11994 | |
| 11995 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11996 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 11997 | * @pdev: pointer to PCI device. |
| 11998 | * @state: the current PCI connection state. |
| 11999 | * |
| 12000 | * This routine is called from the PCI subsystem for error handling to device |
| 12001 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 12002 | * after a PCI bus error affecting this device has been detected. When this |
| 12003 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 12004 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 12005 | * for the PCI subsystem to perform proper recovery as desired. |
| 12006 | * |
| 12007 | * Return codes |
| 12008 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12009 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 12010 | **/ |
| 12011 | static pci_ers_result_t |
| 12012 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 12013 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12014 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12015 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12016 | |
| 12017 | switch (state) { |
| 12018 | case pci_channel_io_normal: |
| 12019 | /* Non-fatal error, prepare for recovery */ |
| 12020 | lpfc_sli4_prep_dev_for_recover(phba); |
| 12021 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 12022 | case pci_channel_io_frozen: |
| 12023 | /* Fatal error, prepare for slot reset */ |
| 12024 | lpfc_sli4_prep_dev_for_reset(phba); |
| 12025 | return PCI_ERS_RESULT_NEED_RESET; |
| 12026 | case pci_channel_io_perm_failure: |
| 12027 | /* Permanent failure, prepare for device down */ |
| 12028 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 12029 | return PCI_ERS_RESULT_DISCONNECT; |
| 12030 | default: |
| 12031 | /* Unknown state, prepare and request slot reset */ |
| 12032 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12033 | "2825 Unknown PCI error state: x%x\n", state); |
| 12034 | lpfc_sli4_prep_dev_for_reset(phba); |
| 12035 | return PCI_ERS_RESULT_NEED_RESET; |
| 12036 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12037 | } |
| 12038 | |
| 12039 | /** |
| 12040 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 12041 | * @pdev: pointer to PCI device. |
| 12042 | * |
| 12043 | * This routine is called from the PCI subsystem for error handling to device |
| 12044 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 12045 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 12046 | * PCI subsystem error recovery, after the driver returns |
| 12047 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 12048 | * recovery and then call this routine before calling the .resume method to |
| 12049 | * recover the device. This function will initialize the HBA device, enable |
| 12050 | * the interrupt, but it will just put the HBA to offline state without |
| 12051 | * passing any I/O traffic. |
| 12052 | * |
| 12053 | * Return codes |
| 12054 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 12055 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 12056 | */ |
| 12057 | static pci_ers_result_t |
| 12058 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 12059 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12060 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12061 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12062 | struct lpfc_sli *psli = &phba->sli; |
| 12063 | uint32_t intr_mode; |
| 12064 | |
| 12065 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 12066 | if (pci_enable_device_mem(pdev)) { |
| 12067 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 12068 | "PCI device after reset.\n"); |
| 12069 | return PCI_ERS_RESULT_DISCONNECT; |
| 12070 | } |
| 12071 | |
| 12072 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 12073 | |
| 12074 | /* |
| 12075 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12076 | * device saved_state flag, need to save the restored state again. |
| 12077 | */ |
| 12078 | pci_save_state(pdev); |
| 12079 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12080 | if (pdev->is_busmaster) |
| 12081 | pci_set_master(pdev); |
| 12082 | |
| 12083 | spin_lock_irq(&phba->hbalock); |
| 12084 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 12085 | spin_unlock_irq(&phba->hbalock); |
| 12086 | |
| 12087 | /* Configure and enable interrupt */ |
| 12088 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 12089 | if (intr_mode == LPFC_INTR_ERROR) { |
| 12090 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12091 | "2824 Cannot re-enable interrupt after " |
| 12092 | "slot reset.\n"); |
| 12093 | return PCI_ERS_RESULT_DISCONNECT; |
| 12094 | } else |
| 12095 | phba->intr_mode = intr_mode; |
| 12096 | |
| 12097 | /* Log the current active interrupt mode */ |
| 12098 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12099 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12100 | return PCI_ERS_RESULT_RECOVERED; |
| 12101 | } |
| 12102 | |
| 12103 | /** |
| 12104 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 12105 | * @pdev: pointer to PCI device |
| 12106 | * |
| 12107 | * This routine is called from the PCI subsystem for error handling to device |
| 12108 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 12109 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 12110 | * error recovery. After this call, traffic can start to flow from this device |
| 12111 | * again. |
| 12112 | **/ |
| 12113 | static void |
| 12114 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 12115 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12116 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12117 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12118 | |
| 12119 | /* |
| 12120 | * In case of slot reset, as function reset is performed through |
| 12121 | * mailbox command which needs DMA to be enabled, this operation |
| 12122 | * has to be moved to the io resume phase. Taking device offline |
| 12123 | * will perform the necessary cleanup. |
| 12124 | */ |
| 12125 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 12126 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12127 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12128 | lpfc_offline(phba); |
| 12129 | lpfc_sli_brdrestart(phba); |
| 12130 | /* Bring the device back online */ |
| 12131 | lpfc_online(phba); |
| 12132 | } |
| 12133 | |
| 12134 | /* Clean up Advanced Error Reporting (AER) if needed */ |
| 12135 | if (phba->hba_flag & HBA_AER_ENABLED) |
| 12136 | pci_cleanup_aer_uncorrect_error_status(pdev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12137 | } |
| 12138 | |
| 12139 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12140 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 12141 | * @pdev: pointer to PCI device |
| 12142 | * @pid: pointer to PCI device identifier |
| 12143 | * |
| 12144 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 12145 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 12146 | * at PCI device-specific information of the device and driver to see if the |
| 12147 | * driver state that it can support this kind of device. If the match is |
| 12148 | * successful, the driver core invokes this routine. This routine dispatches |
| 12149 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 12150 | * do all the initialization that it needs to do to handle the HBA device |
| 12151 | * properly. |
| 12152 | * |
| 12153 | * Return code |
| 12154 | * 0 - driver can claim the device |
| 12155 | * negative value - driver can not claim the device |
| 12156 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12157 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12158 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 12159 | { |
| 12160 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12161 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12162 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 12163 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12164 | return -ENODEV; |
| 12165 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12166 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 12167 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12168 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12169 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12170 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 12171 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12172 | return rc; |
| 12173 | } |
| 12174 | |
| 12175 | /** |
| 12176 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 12177 | * @pdev: pointer to PCI device |
| 12178 | * |
| 12179 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 12180 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 12181 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 12182 | * remove routine, which will perform all the necessary cleanup for the |
| 12183 | * device to be removed from the PCI subsystem properly. |
| 12184 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12185 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12186 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 12187 | { |
| 12188 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12189 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12190 | |
| 12191 | switch (phba->pci_dev_grp) { |
| 12192 | case LPFC_PCI_DEV_LP: |
| 12193 | lpfc_pci_remove_one_s3(pdev); |
| 12194 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12195 | case LPFC_PCI_DEV_OC: |
| 12196 | lpfc_pci_remove_one_s4(pdev); |
| 12197 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12198 | default: |
| 12199 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12200 | "1424 Invalid PCI device group: 0x%x\n", |
| 12201 | phba->pci_dev_grp); |
| 12202 | break; |
| 12203 | } |
| 12204 | return; |
| 12205 | } |
| 12206 | |
| 12207 | /** |
| 12208 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
| 12209 | * @pdev: pointer to PCI device |
| 12210 | * @msg: power management message |
| 12211 | * |
| 12212 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 12213 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 12214 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 12215 | * suspend the device. |
| 12216 | * |
| 12217 | * Return code |
| 12218 | * 0 - driver suspended the device |
| 12219 | * Error otherwise |
| 12220 | **/ |
| 12221 | static int |
| 12222 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 12223 | { |
| 12224 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12225 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12226 | int rc = -ENODEV; |
| 12227 | |
| 12228 | switch (phba->pci_dev_grp) { |
| 12229 | case LPFC_PCI_DEV_LP: |
| 12230 | rc = lpfc_pci_suspend_one_s3(pdev, msg); |
| 12231 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12232 | case LPFC_PCI_DEV_OC: |
| 12233 | rc = lpfc_pci_suspend_one_s4(pdev, msg); |
| 12234 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12235 | default: |
| 12236 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12237 | "1425 Invalid PCI device group: 0x%x\n", |
| 12238 | phba->pci_dev_grp); |
| 12239 | break; |
| 12240 | } |
| 12241 | return rc; |
| 12242 | } |
| 12243 | |
| 12244 | /** |
| 12245 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
| 12246 | * @pdev: pointer to PCI device |
| 12247 | * |
| 12248 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 12249 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 12250 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 12251 | * resume the device. |
| 12252 | * |
| 12253 | * Return code |
| 12254 | * 0 - driver suspended the device |
| 12255 | * Error otherwise |
| 12256 | **/ |
| 12257 | static int |
| 12258 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 12259 | { |
| 12260 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12261 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12262 | int rc = -ENODEV; |
| 12263 | |
| 12264 | switch (phba->pci_dev_grp) { |
| 12265 | case LPFC_PCI_DEV_LP: |
| 12266 | rc = lpfc_pci_resume_one_s3(pdev); |
| 12267 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12268 | case LPFC_PCI_DEV_OC: |
| 12269 | rc = lpfc_pci_resume_one_s4(pdev); |
| 12270 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12271 | default: |
| 12272 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12273 | "1426 Invalid PCI device group: 0x%x\n", |
| 12274 | phba->pci_dev_grp); |
| 12275 | break; |
| 12276 | } |
| 12277 | return rc; |
| 12278 | } |
| 12279 | |
| 12280 | /** |
| 12281 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 12282 | * @pdev: pointer to PCI device. |
| 12283 | * @state: the current PCI connection state. |
| 12284 | * |
| 12285 | * This routine is registered to the PCI subsystem for error handling. This |
| 12286 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 12287 | * this device has been detected. When this routine is invoked, it dispatches |
| 12288 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 12289 | * routine, which will perform the proper error detected operation. |
| 12290 | * |
| 12291 | * Return codes |
| 12292 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12293 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 12294 | **/ |
| 12295 | static pci_ers_result_t |
| 12296 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 12297 | { |
| 12298 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12299 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12300 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 12301 | |
| 12302 | switch (phba->pci_dev_grp) { |
| 12303 | case LPFC_PCI_DEV_LP: |
| 12304 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 12305 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12306 | case LPFC_PCI_DEV_OC: |
| 12307 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 12308 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12309 | default: |
| 12310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12311 | "1427 Invalid PCI device group: 0x%x\n", |
| 12312 | phba->pci_dev_grp); |
| 12313 | break; |
| 12314 | } |
| 12315 | return rc; |
| 12316 | } |
| 12317 | |
| 12318 | /** |
| 12319 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 12320 | * @pdev: pointer to PCI device. |
| 12321 | * |
| 12322 | * This routine is registered to the PCI subsystem for error handling. This |
| 12323 | * function is called after PCI bus has been reset to restart the PCI card |
| 12324 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 12325 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 12326 | * routine, which will perform the proper device reset. |
| 12327 | * |
| 12328 | * Return codes |
| 12329 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 12330 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 12331 | **/ |
| 12332 | static pci_ers_result_t |
| 12333 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 12334 | { |
| 12335 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12336 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12337 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 12338 | |
| 12339 | switch (phba->pci_dev_grp) { |
| 12340 | case LPFC_PCI_DEV_LP: |
| 12341 | rc = lpfc_io_slot_reset_s3(pdev); |
| 12342 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12343 | case LPFC_PCI_DEV_OC: |
| 12344 | rc = lpfc_io_slot_reset_s4(pdev); |
| 12345 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12346 | default: |
| 12347 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12348 | "1428 Invalid PCI device group: 0x%x\n", |
| 12349 | phba->pci_dev_grp); |
| 12350 | break; |
| 12351 | } |
| 12352 | return rc; |
| 12353 | } |
| 12354 | |
| 12355 | /** |
| 12356 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 12357 | * @pdev: pointer to PCI device |
| 12358 | * |
| 12359 | * This routine is registered to the PCI subsystem for error handling. It |
| 12360 | * is called when kernel error recovery tells the lpfc driver that it is |
| 12361 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 12362 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 12363 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 12364 | **/ |
| 12365 | static void |
| 12366 | lpfc_io_resume(struct pci_dev *pdev) |
| 12367 | { |
| 12368 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12369 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12370 | |
| 12371 | switch (phba->pci_dev_grp) { |
| 12372 | case LPFC_PCI_DEV_LP: |
| 12373 | lpfc_io_resume_s3(pdev); |
| 12374 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12375 | case LPFC_PCI_DEV_OC: |
| 12376 | lpfc_io_resume_s4(pdev); |
| 12377 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12378 | default: |
| 12379 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12380 | "1429 Invalid PCI device group: 0x%x\n", |
| 12381 | phba->pci_dev_grp); |
| 12382 | break; |
| 12383 | } |
| 12384 | return; |
| 12385 | } |
| 12386 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12387 | /** |
| 12388 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 12389 | * @phba: pointer to lpfc hba data structure. |
| 12390 | * |
| 12391 | * This routine checks to see if OAS is supported for this adapter. If |
| 12392 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 12393 | * the enable oas flag is cleared and the pool created for OAS device data |
| 12394 | * is destroyed. |
| 12395 | * |
| 12396 | **/ |
| 12397 | void |
| 12398 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 12399 | { |
| 12400 | |
| 12401 | if (!phba->cfg_EnableXLane) |
| 12402 | return; |
| 12403 | |
| 12404 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 12405 | phba->cfg_fof = 1; |
| 12406 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 12407 | phba->cfg_fof = 0; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12408 | if (phba->device_data_mem_pool) |
| 12409 | mempool_destroy(phba->device_data_mem_pool); |
| 12410 | phba->device_data_mem_pool = NULL; |
| 12411 | } |
| 12412 | |
| 12413 | return; |
| 12414 | } |
| 12415 | |
| 12416 | /** |
| 12417 | * lpfc_fof_queue_setup - Set up all the fof queues |
| 12418 | * @phba: pointer to lpfc hba data structure. |
| 12419 | * |
| 12420 | * This routine is invoked to set up all the fof queues for the FC HBA |
| 12421 | * operation. |
| 12422 | * |
| 12423 | * Return codes |
| 12424 | * 0 - successful |
| 12425 | * -ENOMEM - No available memory |
| 12426 | **/ |
| 12427 | int |
| 12428 | lpfc_fof_queue_setup(struct lpfc_hba *phba) |
| 12429 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12430 | struct lpfc_sli_ring *pring; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12431 | int rc; |
| 12432 | |
| 12433 | rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX); |
| 12434 | if (rc) |
| 12435 | return -ENOMEM; |
| 12436 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 12437 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12438 | |
| 12439 | rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq, |
| 12440 | phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP); |
| 12441 | if (rc) |
| 12442 | goto out_oas_cq; |
| 12443 | |
| 12444 | rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq, |
| 12445 | phba->sli4_hba.oas_cq, LPFC_FCP); |
| 12446 | if (rc) |
| 12447 | goto out_oas_wq; |
| 12448 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12449 | /* Bind this CQ/WQ to the NVME ring */ |
| 12450 | pring = phba->sli4_hba.oas_wq->pring; |
| 12451 | pring->sli.sli4.wqp = |
| 12452 | (void *)phba->sli4_hba.oas_wq; |
| 12453 | phba->sli4_hba.oas_cq->pring = pring; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12454 | } |
| 12455 | |
| 12456 | return 0; |
| 12457 | |
| 12458 | out_oas_wq: |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 12459 | lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12460 | out_oas_cq: |
| 12461 | lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq); |
| 12462 | return rc; |
| 12463 | |
| 12464 | } |
| 12465 | |
| 12466 | /** |
| 12467 | * lpfc_fof_queue_create - Create all the fof queues |
| 12468 | * @phba: pointer to lpfc hba data structure. |
| 12469 | * |
| 12470 | * This routine is invoked to allocate all the fof queues for the FC HBA |
| 12471 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 12472 | * count (queue depth) shall be taken from the module parameter. For now, |
| 12473 | * we just use some constant number as place holder. |
| 12474 | * |
| 12475 | * Return codes |
| 12476 | * 0 - successful |
| 12477 | * -ENOMEM - No availble memory |
| 12478 | * -EIO - The mailbox failed to complete successfully. |
| 12479 | **/ |
| 12480 | int |
| 12481 | lpfc_fof_queue_create(struct lpfc_hba *phba) |
| 12482 | { |
| 12483 | struct lpfc_queue *qdesc; |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12484 | uint32_t wqesize; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12485 | |
| 12486 | /* Create FOF EQ */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 12487 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 12488 | phba->sli4_hba.eq_esize, |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12489 | phba->sli4_hba.eq_ecount); |
| 12490 | if (!qdesc) |
| 12491 | goto out_error; |
| 12492 | |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 12493 | qdesc->qe_valid = 1; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12494 | phba->sli4_hba.fof_eq = qdesc; |
| 12495 | |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 12496 | if (phba->cfg_fof) { |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12497 | |
| 12498 | /* Create OAS CQ */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12499 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 12500 | qdesc = lpfc_sli4_queue_alloc(phba, |
| 12501 | LPFC_EXPANDED_PAGE_SIZE, |
| 12502 | phba->sli4_hba.cq_esize, |
| 12503 | LPFC_CQE_EXP_COUNT); |
| 12504 | else |
| 12505 | qdesc = lpfc_sli4_queue_alloc(phba, |
| 12506 | LPFC_DEFAULT_PAGE_SIZE, |
| 12507 | phba->sli4_hba.cq_esize, |
| 12508 | phba->sli4_hba.cq_ecount); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12509 | if (!qdesc) |
| 12510 | goto out_error; |
| 12511 | |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 12512 | qdesc->qe_valid = 1; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12513 | phba->sli4_hba.oas_cq = qdesc; |
| 12514 | |
| 12515 | /* Create OAS WQ */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12516 | if (phba->enab_exp_wqcq_pages) { |
| 12517 | wqesize = (phba->fcp_embed_io) ? |
| 12518 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 12519 | qdesc = lpfc_sli4_queue_alloc(phba, |
| 12520 | LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12521 | wqesize, |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 12522 | LPFC_WQE_EXP_COUNT); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12523 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 12524 | qdesc = lpfc_sli4_queue_alloc(phba, |
| 12525 | LPFC_DEFAULT_PAGE_SIZE, |
| 12526 | phba->sli4_hba.wq_esize, |
| 12527 | phba->sli4_hba.wq_ecount); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12528 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12529 | if (!qdesc) |
| 12530 | goto out_error; |
| 12531 | |
| 12532 | phba->sli4_hba.oas_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12533 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12534 | |
| 12535 | } |
| 12536 | return 0; |
| 12537 | |
| 12538 | out_error: |
| 12539 | lpfc_fof_queue_destroy(phba); |
| 12540 | return -ENOMEM; |
| 12541 | } |
| 12542 | |
| 12543 | /** |
| 12544 | * lpfc_fof_queue_destroy - Destroy all the fof queues |
| 12545 | * @phba: pointer to lpfc hba data structure. |
| 12546 | * |
| 12547 | * This routine is invoked to release all the SLI4 queues with the FC HBA |
| 12548 | * operation. |
| 12549 | * |
| 12550 | * Return codes |
| 12551 | * 0 - successful |
| 12552 | **/ |
| 12553 | int |
| 12554 | lpfc_fof_queue_destroy(struct lpfc_hba *phba) |
| 12555 | { |
| 12556 | /* Release FOF Event queue */ |
| 12557 | if (phba->sli4_hba.fof_eq != NULL) { |
| 12558 | lpfc_sli4_queue_free(phba->sli4_hba.fof_eq); |
| 12559 | phba->sli4_hba.fof_eq = NULL; |
| 12560 | } |
| 12561 | |
| 12562 | /* Release OAS Completion queue */ |
| 12563 | if (phba->sli4_hba.oas_cq != NULL) { |
| 12564 | lpfc_sli4_queue_free(phba->sli4_hba.oas_cq); |
| 12565 | phba->sli4_hba.oas_cq = NULL; |
| 12566 | } |
| 12567 | |
| 12568 | /* Release OAS Work queue */ |
| 12569 | if (phba->sli4_hba.oas_wq != NULL) { |
| 12570 | lpfc_sli4_queue_free(phba->sli4_hba.oas_wq); |
| 12571 | phba->sli4_hba.oas_wq = NULL; |
| 12572 | } |
| 12573 | return 0; |
| 12574 | } |
| 12575 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12576 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 12577 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 12578 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12579 | .error_detected = lpfc_io_error_detected, |
| 12580 | .slot_reset = lpfc_io_slot_reset, |
| 12581 | .resume = lpfc_io_resume, |
| 12582 | }; |
| 12583 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12584 | static struct pci_driver lpfc_driver = { |
| 12585 | .name = LPFC_DRIVER_NAME, |
| 12586 | .id_table = lpfc_id_table, |
| 12587 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12588 | .remove = lpfc_pci_remove_one, |
Anton Blanchard | 85e8a23 | 2017-02-13 08:49:20 +1100 | [diff] [blame] | 12589 | .shutdown = lpfc_pci_remove_one, |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12590 | .suspend = lpfc_pci_suspend_one, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12591 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12592 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12593 | }; |
| 12594 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 12595 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 12596 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 12597 | }; |
| 12598 | |
| 12599 | static struct miscdevice lpfc_mgmt_dev = { |
| 12600 | .minor = MISC_DYNAMIC_MINOR, |
| 12601 | .name = "lpfcmgmt", |
| 12602 | .fops = &lpfc_mgmt_fop, |
| 12603 | }; |
| 12604 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12605 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12606 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12607 | * |
| 12608 | * This routine is to be invoked when the lpfc module is loaded into the |
| 12609 | * kernel. The special kernel macro module_init() is used to indicate the |
| 12610 | * role of this routine to the kernel as lpfc module entry point. |
| 12611 | * |
| 12612 | * Return codes |
| 12613 | * 0 - successful |
| 12614 | * -ENOMEM - FC attach transport failed |
| 12615 | * all others - failed |
| 12616 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12617 | static int __init |
| 12618 | lpfc_init(void) |
| 12619 | { |
| 12620 | int error = 0; |
| 12621 | |
| 12622 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12623 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12624 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 12625 | error = misc_register(&lpfc_mgmt_dev); |
| 12626 | if (error) |
| 12627 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 12628 | "misc_register returned with status %d", error); |
| 12629 | |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 12630 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 12631 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12632 | lpfc_transport_template = |
| 12633 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 12634 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12635 | return -ENOMEM; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 12636 | lpfc_vport_transport_template = |
| 12637 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 12638 | if (lpfc_vport_transport_template == NULL) { |
| 12639 | fc_release_transport(lpfc_transport_template); |
| 12640 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 12641 | } |
James Smart | 5fd1108 | 2018-03-05 12:04:04 -0800 | [diff] [blame] | 12642 | lpfc_nvme_cmd_template(); |
James Smart | bd3061b | 2018-03-05 12:04:05 -0800 | [diff] [blame] | 12643 | lpfc_nvmet_cmd_template(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12644 | |
| 12645 | /* Initialize in case vector mapping is needed */ |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 12646 | lpfc_used_cpu = NULL; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 12647 | lpfc_present_cpu = num_present_cpus(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12648 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12649 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12650 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12651 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 12652 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12653 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12654 | |
| 12655 | return error; |
| 12656 | } |
| 12657 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12658 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 12659 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12660 | * |
| 12661 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 12662 | * The special kernel macro module_exit() is used to indicate the role of |
| 12663 | * this routine to the kernel as lpfc module exit point. |
| 12664 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12665 | static void __exit |
| 12666 | lpfc_exit(void) |
| 12667 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 12668 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12669 | pci_unregister_driver(&lpfc_driver); |
| 12670 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 12671 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 12672 | if (_dump_buf_data) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12673 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
| 12674 | "_dump_buf_data at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 12675 | (1L << _dump_buf_data_order), _dump_buf_data); |
| 12676 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); |
| 12677 | } |
| 12678 | |
| 12679 | if (_dump_buf_dif) { |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12680 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
| 12681 | "_dump_buf_dif at 0x%p\n", |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 12682 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
| 12683 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); |
| 12684 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 12685 | kfree(lpfc_used_cpu); |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 12686 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12687 | } |
| 12688 | |
| 12689 | module_init(lpfc_init); |
| 12690 | module_exit(lpfc_exit); |
| 12691 | MODULE_LICENSE("GPL"); |
| 12692 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 12693 | MODULE_AUTHOR("Broadcom"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12694 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |