| 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 | 67073c6 | 2021-03-01 09:18:21 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2021 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> |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 40 | #include <linux/irq.h> |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 41 | #include <linux/bitops.h> |
James Smart | 31f06d2 | 2019-08-14 16:56:31 -0700 | [diff] [blame] | 42 | #include <linux/crash_dump.h> |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 43 | #include <linux/cpu.h> |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 44 | #include <linux/cpuhotplug.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 46 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include <scsi/scsi_device.h> |
| 48 | #include <scsi/scsi_host.h> |
| 49 | #include <scsi/scsi_transport_fc.h> |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 50 | #include <scsi/scsi_tcq.h> |
| 51 | #include <scsi/fc/fc_fs.h> |
| 52 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 53 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | #include "lpfc_hw.h" |
| 55 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 56 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 57 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 59 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 60 | #include "lpfc_scsi.h" |
| 61 | #include "lpfc_nvme.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 62 | #include "lpfc_logmsg.h" |
| 63 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 64 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 65 | #include "lpfc_version.h" |
James Smart | 12f4445 | 2016-07-06 12:36:03 -0700 | [diff] [blame] | 66 | #include "lpfc_ids.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 67 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 68 | static enum cpuhp_state lpfc_cpuhp_state; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 69 | /* Used when mapping IRQ vectors in a driver centric manner */ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 70 | static uint32_t lpfc_present_cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 71 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 72 | static void __lpfc_cpuhp_remove(struct lpfc_hba *phba); |
| 73 | static void lpfc_cpuhp_remove(struct lpfc_hba *phba); |
| 74 | static void lpfc_cpuhp_add(struct lpfc_hba *phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 75 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 76 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 77 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 78 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
| 79 | static int lpfc_setup_endian_order(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 80 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 81 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 82 | static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 83 | static void lpfc_init_sgl_list(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 84 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); |
| 85 | static void lpfc_free_active_sgl(struct lpfc_hba *); |
| 86 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); |
| 87 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); |
| 88 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); |
| 89 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); |
| 90 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 91 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
| 92 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 93 | static void lpfc_sli4_oas_verify(struct lpfc_hba *phba); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 94 | static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int); |
James Smart | aa6ff30 | 2019-05-21 17:49:09 -0700 | [diff] [blame] | 95 | static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *); |
| 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 |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 101 | static int lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 102 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 103 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 104 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 105 | * @phba: pointer to lpfc hba data structure. |
| 106 | * |
| 107 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 108 | * mailbox command. It retrieves the revision information from the HBA and |
| 109 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 110 | * configuration of the HBA. |
| 111 | * |
| 112 | * Return codes: |
| 113 | * 0 - success. |
| 114 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 115 | * Any other value - indicates an error. |
| 116 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 117 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 118 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 119 | { |
| 120 | lpfc_vpd_t *vp = &phba->vpd; |
| 121 | int i = 0, rc; |
| 122 | LPFC_MBOXQ_t *pmb; |
| 123 | MAILBOX_t *mb; |
| 124 | char *lpfc_vpd_data = NULL; |
| 125 | uint16_t offset = 0; |
| 126 | static char licensed[56] = |
| 127 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 128 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 129 | |
| 130 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 131 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 132 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 133 | return -ENOMEM; |
| 134 | } |
| 135 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 136 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 137 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 138 | |
| 139 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 140 | if (init_key) { |
| 141 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 142 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 143 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 144 | *ptext = cpu_to_be32(*ptext); |
| 145 | init_key = 0; |
| 146 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 147 | |
| 148 | lpfc_read_nv(phba, pmb); |
| 149 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 150 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 151 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 152 | sizeof (licensed)); |
| 153 | |
| 154 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 155 | |
| 156 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 157 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 158 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 159 | "error, mbxCmd x%x READ_NVPARM, " |
| 160 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 161 | mb->mbxCommand, mb->mbxStatus); |
| 162 | mempool_free(pmb, phba->mbox_mem_pool); |
| 163 | return -ERESTART; |
| 164 | } |
| 165 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 166 | sizeof(phba->wwnn)); |
| 167 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 168 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Martin Wilck | dfb7513 | 2018-11-12 09:58:37 +0100 | [diff] [blame] | 171 | /* |
| 172 | * Clear all option bits except LPFC_SLI3_BG_ENABLED, |
| 173 | * which was already set in lpfc_get_cfgparam() |
| 174 | */ |
| 175 | phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 176 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 177 | /* Setup and issue mailbox READ REV command */ |
| 178 | lpfc_read_rev(phba, pmb); |
| 179 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 180 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 181 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 182 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 183 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 184 | mb->mbxCommand, mb->mbxStatus); |
| 185 | mempool_free( pmb, phba->mbox_mem_pool); |
| 186 | return -ERESTART; |
| 187 | } |
| 188 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 189 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 190 | /* |
| 191 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 192 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 193 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 194 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 195 | vp->rev.rBit = 0; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 196 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 197 | "0440 Adapter failed to init, READ_REV has " |
| 198 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 199 | mempool_free(pmb, phba->mbox_mem_pool); |
| 200 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 201 | } |
| 202 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 203 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 204 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 205 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 206 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 207 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 208 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 209 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 210 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 211 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 212 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 213 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 214 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 215 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 216 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 217 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 218 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 219 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 220 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 221 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 222 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 223 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 224 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 225 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 226 | /* If the sli feature level is less then 9, we must |
| 227 | * tear down all RPIs and VPIs on link down if NPIV |
| 228 | * is enabled. |
| 229 | */ |
| 230 | if (vp->rev.feaLevelHigh < 9) |
| 231 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 232 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 233 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 234 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 235 | sizeof (phba->RandomData)); |
| 236 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 239 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 240 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 241 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 242 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 243 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 244 | |
| 245 | if (rc != MBX_SUCCESS) { |
| 246 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 247 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 249 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 250 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 251 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 252 | /* dump mem may return a zero when finished or we got a |
| 253 | * mailbox error, either way we are done. |
| 254 | */ |
| 255 | if (mb->un.varDmp.word_cnt == 0) |
| 256 | break; |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 257 | |
James Smart | e4ec102 | 2021-04-21 16:45:11 -0700 | [diff] [blame] | 258 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 259 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 260 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | e4ec102 | 2021-04-21 16:45:11 -0700 | [diff] [blame] | 261 | lpfc_vpd_data + offset, |
| 262 | mb->un.varDmp.word_cnt); |
| 263 | offset += mb->un.varDmp.word_cnt; |
| 264 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 265 | |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 266 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 267 | |
| 268 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 269 | out_free_mbox: |
| 270 | mempool_free(pmb, phba->mbox_mem_pool); |
| 271 | return 0; |
| 272 | } |
| 273 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 274 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 275 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 276 | * @phba: pointer to lpfc hba data structure. |
| 277 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 278 | * |
| 279 | * This is the completion handler for driver's configuring asynchronous event |
| 280 | * mailbox command to the device. If the mailbox command returns successfully, |
| 281 | * it will set internal async event support flag to 1; otherwise, it will |
| 282 | * set internal async event support flag to 0. |
| 283 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 284 | static void |
| 285 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 286 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 287 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 288 | phba->temp_sensor_support = 1; |
| 289 | else |
| 290 | phba->temp_sensor_support = 0; |
| 291 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 292 | return; |
| 293 | } |
| 294 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 295 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 296 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 297 | * @phba: pointer to lpfc hba data structure. |
| 298 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 299 | * |
| 300 | * This is the completion handler for dump mailbox command for getting |
| 301 | * wake up parameters. When this command complete, the response contain |
| 302 | * Option rom version of the HBA. This function translate the version number |
| 303 | * into a human readable string and store it in OptionROMVersion. |
| 304 | **/ |
| 305 | static void |
| 306 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 307 | { |
| 308 | struct prog_id *prg; |
| 309 | uint32_t prog_id_word; |
| 310 | char dist = ' '; |
| 311 | /* character array used for decoding dist type. */ |
| 312 | char dist_char[] = "nabx"; |
| 313 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 314 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 315 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 316 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 317 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 318 | |
| 319 | prg = (struct prog_id *) &prog_id_word; |
| 320 | |
| 321 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 322 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 323 | |
| 324 | /* Decode the Option rom version word to a readable string */ |
| 325 | if (prg->dist < 4) |
| 326 | dist = dist_char[prg->dist]; |
| 327 | |
| 328 | if ((prg->dist == 3) && (prg->num == 0)) |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 329 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 330 | prg->ver, prg->rev, prg->lev); |
| 331 | else |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 332 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 333 | prg->ver, prg->rev, prg->lev, |
| 334 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 335 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 336 | return; |
| 337 | } |
| 338 | |
| 339 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 340 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 341 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 342 | * @vport: pointer to lpfc vport data structure. |
| 343 | * |
| 344 | * |
| 345 | * Return codes |
| 346 | * None. |
| 347 | **/ |
| 348 | void |
| 349 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 350 | { |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 351 | uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level; |
| 352 | u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0]; |
| 353 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 354 | /* If the soft name exists then update it using the service params */ |
| 355 | if (vport->phba->cfg_soft_wwnn) |
| 356 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 357 | vport->fc_sparam.nodeName.u.wwn); |
| 358 | if (vport->phba->cfg_soft_wwpn) |
| 359 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 360 | vport->fc_sparam.portName.u.wwn); |
| 361 | |
| 362 | /* |
| 363 | * If the name is empty or there exists a soft name |
| 364 | * then copy the service params name, otherwise use the fc name |
| 365 | */ |
| 366 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 367 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 368 | sizeof(struct lpfc_name)); |
| 369 | else |
| 370 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 371 | sizeof(struct lpfc_name)); |
| 372 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 373 | /* |
| 374 | * If the port name has changed, then set the Param changes flag |
| 375 | * to unreg the login |
| 376 | */ |
| 377 | if (vport->fc_portname.u.wwn[0] != 0 && |
| 378 | memcmp(&vport->fc_portname, &vport->fc_sparam.portName, |
| 379 | sizeof(struct lpfc_name))) |
| 380 | vport->vport_flag |= FAWWPN_PARAM_CHG; |
| 381 | |
| 382 | if (vport->fc_portname.u.wwn[0] == 0 || |
| 383 | vport->phba->cfg_soft_wwpn || |
| 384 | (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) || |
| 385 | vport->vport_flag & FAWWPN_SET) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 386 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 387 | sizeof(struct lpfc_name)); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 388 | vport->vport_flag &= ~FAWWPN_SET; |
| 389 | if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) |
| 390 | vport->vport_flag |= FAWWPN_SET; |
| 391 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 392 | else |
| 393 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 394 | sizeof(struct lpfc_name)); |
| 395 | } |
| 396 | |
| 397 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 398 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 399 | * @phba: pointer to lpfc hba data structure. |
| 400 | * |
| 401 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 402 | * command call. It performs all internal resource and state setups on the |
| 403 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 404 | * ELS ring timers, etc. |
| 405 | * |
| 406 | * Return codes |
| 407 | * 0 - success. |
| 408 | * Any other value - error. |
| 409 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 410 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 411 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 412 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 413 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 414 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 415 | LPFC_MBOXQ_t *pmb; |
| 416 | MAILBOX_t *mb; |
| 417 | struct lpfc_dmabuf *mp; |
| 418 | struct lpfc_sli *psli = &phba->sli; |
| 419 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 420 | int i, j; |
| 421 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 422 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 423 | spin_lock_irq(&phba->hbalock); |
| 424 | /* |
| 425 | * If the Config port completed correctly the HBA is not |
| 426 | * over heated any more. |
| 427 | */ |
| 428 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 429 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 430 | spin_unlock_irq(&phba->hbalock); |
| 431 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 432 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 433 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 434 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 435 | return -ENOMEM; |
| 436 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 437 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 438 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 440 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 441 | if (rc) { |
| 442 | mempool_free(pmb, phba->mbox_mem_pool); |
| 443 | return -ENOMEM; |
| 444 | } |
| 445 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 446 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 447 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 448 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 449 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 450 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 451 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 452 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 453 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 454 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 455 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 456 | kfree(mp); |
| 457 | return -EIO; |
| 458 | } |
| 459 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 460 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 461 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 462 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 463 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 464 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 465 | pmb->ctx_buf = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 466 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 467 | |
| 468 | /* Update the fc_host data structures with new wwn. */ |
| 469 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 470 | 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] | 471 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 472 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 473 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 474 | /* This should be consolidated into parse_vpd ? - mr */ |
| 475 | if (phba->SerialNumber[0] == 0) { |
| 476 | uint8_t *outptr; |
| 477 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 478 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 479 | for (i = 0; i < 12; i++) { |
| 480 | status = *outptr++; |
| 481 | j = ((status & 0xf0) >> 4); |
| 482 | if (j <= 9) |
| 483 | phba->SerialNumber[i] = |
| 484 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 485 | else |
| 486 | phba->SerialNumber[i] = |
| 487 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 488 | i++; |
| 489 | j = (status & 0xf); |
| 490 | if (j <= 9) |
| 491 | phba->SerialNumber[i] = |
| 492 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 493 | else |
| 494 | phba->SerialNumber[i] = |
| 495 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 496 | } |
| 497 | } |
| 498 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 499 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 500 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 501 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 502 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 503 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 506 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 507 | mempool_free( pmb, phba->mbox_mem_pool); |
| 508 | return -EIO; |
| 509 | } |
| 510 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 511 | /* Check if the port is disabled */ |
| 512 | lpfc_sli_read_link_ste(phba); |
| 513 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 514 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | f6770e7 | 2020-01-27 16:23:09 -0800 | [diff] [blame] | 515 | if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) { |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 516 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 517 | "3359 HBA queue depth changed from %d to %d\n", |
James Smart | f6770e7 | 2020-01-27 16:23:09 -0800 | [diff] [blame] | 518 | phba->cfg_hba_queue_depth, |
| 519 | mb->un.varRdConfig.max_xri); |
| 520 | phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri; |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 521 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 522 | |
| 523 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 524 | |
| 525 | /* Get the default values for Model Name and Description */ |
| 526 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 527 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 528 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 529 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 530 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 531 | if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr) |
| 532 | psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 533 | if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr) |
| 534 | psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 535 | |
| 536 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 537 | if (phba->sli_rev != 3) |
| 538 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 539 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 540 | /* |
| 541 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 542 | */ |
| 543 | if (phba->intr_type == MSIX) { |
| 544 | rc = lpfc_config_msi(phba, pmb); |
| 545 | if (rc) { |
| 546 | mempool_free(pmb, phba->mbox_mem_pool); |
| 547 | return -EIO; |
| 548 | } |
| 549 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 550 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 551 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 552 | "0352 Config MSI mailbox command " |
| 553 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 554 | pmb->u.mb.mbxCommand, |
| 555 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 556 | mempool_free(pmb, phba->mbox_mem_pool); |
| 557 | return -EIO; |
| 558 | } |
| 559 | } |
| 560 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 561 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 562 | /* Initialize ERATT handling flag */ |
| 563 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 564 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 565 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 566 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 567 | spin_unlock_irq(&phba->hbalock); |
| 568 | return -EIO; |
| 569 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 570 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 571 | if (psli->num_rings > 0) |
| 572 | status |= HC_R0INT_ENA; |
| 573 | if (psli->num_rings > 1) |
| 574 | status |= HC_R1INT_ENA; |
| 575 | if (psli->num_rings > 2) |
| 576 | status |= HC_R2INT_ENA; |
| 577 | if (psli->num_rings > 3) |
| 578 | status |= HC_R3INT_ENA; |
| 579 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 580 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 581 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 582 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 583 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 584 | writel(status, phba->HCregaddr); |
| 585 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 586 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 587 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 588 | /* Set up ring-0 (ELS) timer */ |
| 589 | timeout = phba->fc_ratov * 2; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 590 | mod_timer(&vport->els_tmofunc, |
| 591 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 592 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 593 | mod_timer(&phba->hb_tmofunc, |
| 594 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 595 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 596 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 597 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 598 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 599 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 600 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 601 | if (phba->hba_flag & LINK_DISABLED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 602 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 603 | "2598 Adapter Link is disabled.\n"); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 604 | lpfc_down_link(phba, pmb); |
| 605 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 606 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 607 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 608 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 609 | "2599 Adapter failed to issue DOWN_LINK" |
| 610 | " mbox command rc 0x%x\n", rc); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 611 | |
| 612 | mempool_free(pmb, phba->mbox_mem_pool); |
| 613 | return -EIO; |
| 614 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 615 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 616 | mempool_free(pmb, phba->mbox_mem_pool); |
| 617 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 618 | if (rc) |
| 619 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 620 | } |
| 621 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 622 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 623 | if (!pmb) { |
| 624 | phba->link_state = LPFC_HBA_ERROR; |
| 625 | return -ENOMEM; |
| 626 | } |
| 627 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 628 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 629 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 630 | pmb->vport = phba->pport; |
| 631 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 632 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 633 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 634 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 635 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 636 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 637 | rc); |
| 638 | mempool_free(pmb, phba->mbox_mem_pool); |
| 639 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 640 | |
| 641 | /* Get Option rom version */ |
| 642 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 643 | if (!pmb) { |
| 644 | phba->link_state = LPFC_HBA_ERROR; |
| 645 | return -ENOMEM; |
| 646 | } |
| 647 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 648 | lpfc_dump_wakeup_param(phba, pmb); |
| 649 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 650 | pmb->vport = phba->pport; |
| 651 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 652 | |
| 653 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 654 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 655 | "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 656 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 657 | mempool_free(pmb, phba->mbox_mem_pool); |
| 658 | } |
| 659 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 660 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 661 | } |
| 662 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 663 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 664 | * lpfc_hba_init_link - Initialize the FC link |
| 665 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 666 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 667 | * |
| 668 | * This routine will issue the INIT_LINK mailbox command call. |
| 669 | * It is available to other drivers through the lpfc_hba data |
| 670 | * structure for use as a delayed link up mechanism with the |
| 671 | * module parameter lpfc_suppress_link_up. |
| 672 | * |
| 673 | * Return code |
| 674 | * 0 - success |
| 675 | * Any other value - error |
| 676 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 677 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 678 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 679 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 680 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 685 | * @phba: pointer to lpfc hba data structure. |
| 686 | * @fc_topology: desired fc topology. |
| 687 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 688 | * |
| 689 | * This routine will issue the INIT_LINK mailbox command call. |
| 690 | * It is available to other drivers through the lpfc_hba data |
| 691 | * structure for use as a delayed link up mechanism with the |
| 692 | * module parameter lpfc_suppress_link_up. |
| 693 | * |
| 694 | * Return code |
| 695 | * 0 - success |
| 696 | * Any other value - error |
| 697 | **/ |
| 698 | int |
| 699 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 700 | uint32_t flag) |
| 701 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 702 | struct lpfc_vport *vport = phba->pport; |
| 703 | LPFC_MBOXQ_t *pmb; |
| 704 | MAILBOX_t *mb; |
| 705 | int rc; |
| 706 | |
| 707 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 708 | if (!pmb) { |
| 709 | phba->link_state = LPFC_HBA_ERROR; |
| 710 | return -ENOMEM; |
| 711 | } |
| 712 | mb = &pmb->u.mb; |
| 713 | pmb->vport = vport; |
| 714 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 715 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 716 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 717 | !(phba->lmt & LMT_1Gb)) || |
| 718 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 719 | !(phba->lmt & LMT_2Gb)) || |
| 720 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 721 | !(phba->lmt & LMT_4Gb)) || |
| 722 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 723 | !(phba->lmt & LMT_8Gb)) || |
| 724 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 725 | !(phba->lmt & LMT_10Gb)) || |
| 726 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 727 | !(phba->lmt & LMT_16Gb)) || |
| 728 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) && |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 729 | !(phba->lmt & LMT_32Gb)) || |
| 730 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) && |
| 731 | !(phba->lmt & LMT_64Gb))) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 732 | /* Reset link speed to auto */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 733 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 734 | "1302 Invalid speed for this board:%d " |
| 735 | "Reset link speed to auto.\n", |
| 736 | phba->cfg_link_speed); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 737 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 738 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 739 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 740 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 741 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 742 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 743 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 744 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 745 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 746 | "0498 Adapter failed to init, mbxCmd x%x " |
| 747 | "INIT_LINK, mbxStatus x%x\n", |
| 748 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 749 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 750 | /* Clear all interrupt enable conditions */ |
| 751 | writel(0, phba->HCregaddr); |
| 752 | readl(phba->HCregaddr); /* flush */ |
| 753 | /* Clear all pending interrupts */ |
| 754 | writel(0xffffffff, phba->HAregaddr); |
| 755 | readl(phba->HAregaddr); /* flush */ |
| 756 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 757 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 758 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 759 | mempool_free(pmb, phba->mbox_mem_pool); |
| 760 | return -EIO; |
| 761 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 762 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 763 | if (flag == MBX_POLL) |
| 764 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 765 | |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 771 | * @phba: pointer to lpfc hba data structure. |
| 772 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 773 | * |
| 774 | * This routine will issue the DOWN_LINK mailbox command call. |
| 775 | * It is available to other drivers through the lpfc_hba data |
| 776 | * structure for use to stop the link. |
| 777 | * |
| 778 | * Return code |
| 779 | * 0 - success |
| 780 | * Any other value - error |
| 781 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 782 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 783 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 784 | { |
| 785 | LPFC_MBOXQ_t *pmb; |
| 786 | int rc; |
| 787 | |
| 788 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 789 | if (!pmb) { |
| 790 | phba->link_state = LPFC_HBA_ERROR; |
| 791 | return -ENOMEM; |
| 792 | } |
| 793 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 794 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 795 | "0491 Adapter Link is disabled.\n"); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 796 | lpfc_down_link(phba, pmb); |
| 797 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 798 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 799 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 800 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 801 | "2522 Adapter failed to issue DOWN_LINK" |
| 802 | " mbox command rc 0x%x\n", rc); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 803 | |
| 804 | mempool_free(pmb, phba->mbox_mem_pool); |
| 805 | return -EIO; |
| 806 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 807 | if (flag == MBX_POLL) |
| 808 | mempool_free(pmb, phba->mbox_mem_pool); |
| 809 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 814 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 815 | * @phba: pointer to lpfc HBA data structure. |
| 816 | * |
| 817 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 818 | * bringing down the SLI Layer. |
| 819 | * |
| 820 | * Return codes |
| 821 | * 0 - success. |
| 822 | * Any other value - error. |
| 823 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 824 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 825 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 826 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 827 | struct lpfc_vport **vports; |
| 828 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 829 | |
| 830 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 831 | /* Disable interrupts */ |
| 832 | writel(0, phba->HCregaddr); |
| 833 | readl(phba->HCregaddr); /* flush */ |
| 834 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 835 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 836 | if (phba->pport->load_flag & FC_UNLOADING) |
| 837 | lpfc_cleanup_discovery_resources(phba->pport); |
| 838 | else { |
| 839 | vports = lpfc_create_vport_work_array(phba); |
| 840 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 841 | for (i = 0; i <= phba->max_vports && |
| 842 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 843 | lpfc_cleanup_discovery_resources(vports[i]); |
| 844 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 845 | } |
| 846 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 847 | } |
| 848 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 849 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 850 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 851 | * rspiocb which got deferred |
| 852 | * |
| 853 | * @phba: pointer to lpfc HBA data structure. |
| 854 | * |
| 855 | * This routine will cleanup completed slow path events after HBA is reset |
| 856 | * when bringing down the SLI Layer. |
| 857 | * |
| 858 | * |
| 859 | * Return codes |
| 860 | * void. |
| 861 | **/ |
| 862 | static void |
| 863 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 864 | { |
| 865 | struct lpfc_iocbq *rspiocbq; |
| 866 | struct hbq_dmabuf *dmabuf; |
| 867 | struct lpfc_cq_event *cq_event; |
| 868 | |
| 869 | spin_lock_irq(&phba->hbalock); |
| 870 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 871 | spin_unlock_irq(&phba->hbalock); |
| 872 | |
| 873 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 874 | /* Get the response iocb from the head of work queue */ |
| 875 | spin_lock_irq(&phba->hbalock); |
| 876 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 877 | cq_event, struct lpfc_cq_event, list); |
| 878 | spin_unlock_irq(&phba->hbalock); |
| 879 | |
| 880 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 881 | case CQE_CODE_COMPL_WQE: |
| 882 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 883 | cq_event); |
| 884 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 885 | break; |
| 886 | case CQE_CODE_RECEIVE: |
| 887 | case CQE_CODE_RECEIVE_V1: |
| 888 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 889 | cq_event); |
| 890 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 896 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 897 | * @phba: pointer to lpfc HBA data structure. |
| 898 | * |
| 899 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 900 | * when bringing down the SLI Layer. |
| 901 | * |
| 902 | * |
| 903 | * Return codes |
| 904 | * void. |
| 905 | **/ |
| 906 | static void |
| 907 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 908 | { |
| 909 | struct lpfc_sli *psli = &phba->sli; |
| 910 | struct lpfc_sli_ring *pring; |
| 911 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 912 | LIST_HEAD(buflist); |
| 913 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 914 | |
| 915 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 916 | lpfc_sli_hbqbuf_free_all(phba); |
| 917 | else { |
| 918 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 919 | pring = &psli->sli3_ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 920 | spin_lock_irq(&phba->hbalock); |
| 921 | list_splice_init(&pring->postbufq, &buflist); |
| 922 | spin_unlock_irq(&phba->hbalock); |
| 923 | |
| 924 | count = 0; |
| 925 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 926 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 927 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 928 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 929 | kfree(mp); |
| 930 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 931 | |
| 932 | spin_lock_irq(&phba->hbalock); |
| 933 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 934 | spin_unlock_irq(&phba->hbalock); |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | /** |
| 939 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 940 | * @phba: pointer to lpfc HBA data structure. |
| 941 | * |
| 942 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 943 | * down the SLI Layer. |
| 944 | * |
| 945 | * Return codes |
| 946 | * void |
| 947 | **/ |
| 948 | static void |
| 949 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 950 | { |
| 951 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 952 | struct lpfc_queue *qp = NULL; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 953 | struct lpfc_sli_ring *pring; |
| 954 | LIST_HEAD(completions); |
| 955 | int i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 956 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 957 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 958 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 959 | for (i = 0; i < psli->num_rings; i++) { |
| 960 | pring = &psli->sli3_ring[i]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 961 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 962 | /* At this point in time the HBA is either reset or DOA |
| 963 | * Nothing should be on txcmplq as it will |
| 964 | * NEVER complete. |
| 965 | */ |
| 966 | list_splice_init(&pring->txcmplq, &completions); |
| 967 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 968 | spin_unlock_irq(&phba->hbalock); |
| 969 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 970 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 971 | } |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 972 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 973 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 974 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
| 975 | return; |
| 976 | } |
| 977 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 978 | pring = qp->pring; |
| 979 | if (!pring) |
| 980 | continue; |
| 981 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 982 | list_for_each_entry_safe(piocb, next_iocb, |
| 983 | &pring->txcmplq, list) |
| 984 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 985 | list_splice_init(&pring->txcmplq, &completions); |
| 986 | pring->txcmplq_cnt = 0; |
| 987 | spin_unlock_irq(&pring->ring_lock); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 988 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 989 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 990 | /* Cancel all the IOCBs from the completions list */ |
| 991 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 992 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 996 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 997 | * @phba: pointer to lpfc HBA data structure. |
| 998 | * |
| 999 | * This routine will do uninitialization after the HBA is reset when bring |
| 1000 | * down the SLI Layer. |
| 1001 | * |
| 1002 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1003 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1004 | * Any other value - error. |
| 1005 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1006 | static int |
| 1007 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1008 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1009 | lpfc_hba_free_post_buf(phba); |
| 1010 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1011 | return 0; |
| 1012 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 1013 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1014 | /** |
| 1015 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 1016 | * @phba: pointer to lpfc HBA data structure. |
| 1017 | * |
| 1018 | * This routine will do uninitialization after the HBA is reset when bring |
| 1019 | * down the SLI Layer. |
| 1020 | * |
| 1021 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1022 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1023 | * Any other value - error. |
| 1024 | **/ |
| 1025 | static int |
| 1026 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 1027 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1028 | struct lpfc_io_buf *psb, *psb_next; |
James Smart | 7cacae2 | 2020-03-31 09:50:03 -0700 | [diff] [blame] | 1029 | struct lpfc_async_xchg_ctx *ctxp, *ctxp_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1030 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1031 | LIST_HEAD(aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1032 | LIST_HEAD(nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1033 | LIST_HEAD(nvmet_aborts); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1034 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1035 | int cnt, idx; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1036 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1037 | |
| 1038 | lpfc_sli_hbqbuf_free_all(phba); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1039 | lpfc_hba_clean_txcmplq(phba); |
| 1040 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1041 | /* At this point in time the HBA is either reset or DOA. Either |
| 1042 | * 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] | 1043 | * 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] | 1044 | * driver is unloading or reposted if the driver is restarting |
| 1045 | * the port. |
| 1046 | */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1047 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1048 | /* sgl_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1049 | * list. |
| 1050 | */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1051 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1052 | list_for_each_entry(sglq_entry, |
| 1053 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1054 | sglq_entry->state = SGL_FREED; |
| 1055 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1056 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1057 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1058 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1059 | |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1060 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1061 | |
| 1062 | /* abts_xxxx_buf_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1063 | * list. |
| 1064 | */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1065 | spin_lock_irq(&phba->hbalock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1066 | cnt = 0; |
| 1067 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 1068 | qp = &phba->sli4_hba.hdwq[idx]; |
| 1069 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1070 | spin_lock(&qp->abts_io_buf_list_lock); |
| 1071 | list_splice_init(&qp->lpfc_abts_io_buf_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1072 | &aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1073 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 1074 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1075 | psb->pCmd = NULL; |
| 1076 | psb->status = IOSTAT_SUCCESS; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1077 | cnt++; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1078 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1079 | spin_lock(&qp->io_buf_list_put_lock); |
| 1080 | list_splice_init(&aborts, &qp->lpfc_io_buf_list_put); |
| 1081 | qp->put_io_bufs += qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1082 | qp->put_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1083 | qp->abts_scsi_io_bufs = 0; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1084 | qp->abts_nvme_io_bufs = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1085 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1086 | spin_unlock(&qp->abts_io_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1087 | } |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1088 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1089 | |
| 1090 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1091 | spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1092 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list, |
| 1093 | &nvmet_aborts); |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1094 | spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1095 | list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) { |
James Smart | 7b7f551 | 2020-03-31 09:50:04 -0700 | [diff] [blame] | 1096 | ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 1097 | lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1098 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1099 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1100 | |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1101 | lpfc_sli4_free_sp_events(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1102 | return cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | /** |
| 1106 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1107 | * @phba: pointer to lpfc HBA data structure. |
| 1108 | * |
| 1109 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1110 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1111 | * |
| 1112 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1113 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1114 | * Any other value - error. |
| 1115 | **/ |
| 1116 | int |
| 1117 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1118 | { |
| 1119 | return (*phba->lpfc_hba_down_post)(phba); |
| 1120 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1121 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1122 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1123 | * lpfc_hb_timeout - The HBA-timer timeout handler |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1124 | * @t: timer context used to obtain the pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1125 | * |
| 1126 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1127 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1128 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1129 | * event will be used by the worker thread to invoke the actual timeout |
| 1130 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1131 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1132 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1133 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1134 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1135 | lpfc_hb_timeout(struct timer_list *t) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1136 | { |
| 1137 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1138 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1139 | unsigned long iflag; |
| 1140 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1141 | phba = from_timer(phba, t, hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1142 | |
| 1143 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1144 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1145 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1146 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1147 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1148 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1149 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1150 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1151 | if (!tmo_posted) |
| 1152 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1153 | return; |
| 1154 | } |
| 1155 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1156 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1157 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1158 | * @t: timer context used to obtain the pointer to lpfc hba data structure. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1159 | * |
| 1160 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1161 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1162 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1163 | * event will be used by the worker thread to invoke the actual timeout |
| 1164 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1165 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1166 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1167 | **/ |
| 1168 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1169 | lpfc_rrq_timeout(struct timer_list *t) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1170 | { |
| 1171 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1172 | unsigned long iflag; |
| 1173 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1174 | phba = from_timer(phba, t, rrq_tmr); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1175 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1176 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1177 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1178 | else |
| 1179 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1180 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1181 | |
| 1182 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1183 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1187 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1188 | * @phba: pointer to lpfc hba data structure. |
| 1189 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1190 | * |
| 1191 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1192 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1193 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1194 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1195 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1196 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1197 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1198 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1199 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1200 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1201 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1202 | static void |
| 1203 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1204 | { |
| 1205 | unsigned long drvr_flag; |
| 1206 | |
| 1207 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1208 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1209 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1210 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1211 | /* Check and reset heart-beat timer if necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1212 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1213 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1214 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1215 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1216 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1217 | jiffies + |
| 1218 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1219 | return; |
| 1220 | } |
| 1221 | |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1222 | /* |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 1223 | * lpfc_idle_stat_delay_work - idle_stat tracking |
| 1224 | * |
| 1225 | * This routine tracks per-cq idle_stat and determines polling decisions. |
| 1226 | * |
| 1227 | * Return codes: |
| 1228 | * None |
| 1229 | **/ |
| 1230 | static void |
| 1231 | lpfc_idle_stat_delay_work(struct work_struct *work) |
| 1232 | { |
| 1233 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1234 | struct lpfc_hba, |
| 1235 | idle_stat_delay_work); |
| 1236 | struct lpfc_queue *cq; |
| 1237 | struct lpfc_sli4_hdw_queue *hdwq; |
| 1238 | struct lpfc_idle_stat *idle_stat; |
| 1239 | u32 i, idle_percent; |
| 1240 | u64 wall, wall_idle, diff_wall, diff_idle, busy_time; |
| 1241 | |
| 1242 | if (phba->pport->load_flag & FC_UNLOADING) |
| 1243 | return; |
| 1244 | |
| 1245 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1246 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1247 | goto requeue; |
| 1248 | |
| 1249 | for_each_present_cpu(i) { |
| 1250 | hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq]; |
| 1251 | cq = hdwq->io_cq; |
| 1252 | |
| 1253 | /* Skip if we've already handled this cq's primary CPU */ |
| 1254 | if (cq->chann != i) |
| 1255 | continue; |
| 1256 | |
| 1257 | idle_stat = &phba->sli4_hba.idle_stat[i]; |
| 1258 | |
| 1259 | /* get_cpu_idle_time returns values as running counters. Thus, |
| 1260 | * to know the amount for this period, the prior counter values |
| 1261 | * need to be subtracted from the current counter values. |
| 1262 | * From there, the idle time stat can be calculated as a |
| 1263 | * percentage of 100 - the sum of the other consumption times. |
| 1264 | */ |
| 1265 | wall_idle = get_cpu_idle_time(i, &wall, 1); |
| 1266 | diff_idle = wall_idle - idle_stat->prev_idle; |
| 1267 | diff_wall = wall - idle_stat->prev_wall; |
| 1268 | |
| 1269 | if (diff_wall <= diff_idle) |
| 1270 | busy_time = 0; |
| 1271 | else |
| 1272 | busy_time = diff_wall - diff_idle; |
| 1273 | |
| 1274 | idle_percent = div64_u64(100 * busy_time, diff_wall); |
| 1275 | idle_percent = 100 - idle_percent; |
| 1276 | |
| 1277 | if (idle_percent < 15) |
| 1278 | cq->poll_mode = LPFC_QUEUE_WORK; |
| 1279 | else |
| 1280 | cq->poll_mode = LPFC_IRQ_POLL; |
| 1281 | |
| 1282 | idle_stat->prev_idle = wall_idle; |
| 1283 | idle_stat->prev_wall = wall; |
| 1284 | } |
| 1285 | |
| 1286 | requeue: |
| 1287 | schedule_delayed_work(&phba->idle_stat_delay_work, |
| 1288 | msecs_to_jiffies(LPFC_IDLE_STAT_DELAY)); |
| 1289 | } |
| 1290 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1291 | static void |
| 1292 | lpfc_hb_eq_delay_work(struct work_struct *work) |
| 1293 | { |
| 1294 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1295 | struct lpfc_hba, eq_delay_work); |
| 1296 | struct lpfc_eq_intr_info *eqi, *eqi_new; |
| 1297 | struct lpfc_queue *eq, *eq_next; |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1298 | unsigned char *ena_delay = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1299 | uint32_t usdelay; |
| 1300 | int i; |
| 1301 | |
| 1302 | if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING) |
| 1303 | return; |
| 1304 | |
| 1305 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1306 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1307 | goto requeue; |
| 1308 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1309 | ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay), |
| 1310 | GFP_KERNEL); |
| 1311 | if (!ena_delay) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1312 | goto requeue; |
| 1313 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1314 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 1315 | /* Get the EQ corresponding to the IRQ vector */ |
| 1316 | eq = phba->sli4_hba.hba_eq_hdl[i].eq; |
| 1317 | if (!eq) |
| 1318 | continue; |
| 1319 | if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) { |
| 1320 | eq->q_flag &= ~HBA_EQ_DELAY_CHK; |
| 1321 | ena_delay[eq->last_cpu] = 1; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame] | 1322 | } |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1323 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1324 | |
| 1325 | for_each_present_cpu(i) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1326 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i); |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1327 | if (ena_delay[i]) { |
| 1328 | usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP; |
| 1329 | if (usdelay > LPFC_MAX_AUTO_EQ_DELAY) |
| 1330 | usdelay = LPFC_MAX_AUTO_EQ_DELAY; |
| 1331 | } else { |
| 1332 | usdelay = 0; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame] | 1333 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1334 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1335 | eqi->icnt = 0; |
| 1336 | |
| 1337 | list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) { |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1338 | if (unlikely(eq->last_cpu != i)) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1339 | eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info, |
| 1340 | eq->last_cpu); |
| 1341 | list_move_tail(&eq->cpu_list, &eqi_new->list); |
| 1342 | continue; |
| 1343 | } |
| 1344 | if (usdelay != eq->q_mode) |
| 1345 | lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1, |
| 1346 | usdelay); |
| 1347 | } |
| 1348 | } |
| 1349 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1350 | kfree(ena_delay); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1351 | |
| 1352 | requeue: |
| 1353 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 1354 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 1355 | } |
| 1356 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1357 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1358 | * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution |
| 1359 | * @phba: pointer to lpfc hba data structure. |
| 1360 | * |
| 1361 | * For each heartbeat, this routine does some heuristic methods to adjust |
| 1362 | * XRI distribution. The goal is to fully utilize free XRIs. |
| 1363 | **/ |
| 1364 | static void lpfc_hb_mxp_handler(struct lpfc_hba *phba) |
| 1365 | { |
| 1366 | u32 i; |
| 1367 | u32 hwq_count; |
| 1368 | |
| 1369 | hwq_count = phba->cfg_hdw_queue; |
| 1370 | for (i = 0; i < hwq_count; i++) { |
| 1371 | /* Adjust XRIs in private pool */ |
| 1372 | lpfc_adjust_pvt_pool_count(phba, i); |
| 1373 | |
| 1374 | /* Adjust high watermark */ |
| 1375 | lpfc_adjust_high_watermark(phba, i); |
| 1376 | |
| 1377 | #ifdef LPFC_MXP_STAT |
| 1378 | /* Snapshot pbl, pvt and busy count */ |
| 1379 | lpfc_snapshot_mxp(phba, i); |
| 1380 | #endif |
| 1381 | } |
| 1382 | } |
| 1383 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1384 | /** |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1385 | * lpfc_issue_hb_mbox - Issues heart-beat mailbox command |
| 1386 | * @phba: pointer to lpfc hba data structure. |
| 1387 | * |
| 1388 | * If a HB mbox is not already in progrees, this routine will allocate |
| 1389 | * a LPFC_MBOXQ_t, populate it with a MBX_HEARTBEAT (0x31) command, |
| 1390 | * and issue it. The HBA_HBEAT_INP flag means the command is in progress. |
| 1391 | **/ |
| 1392 | int |
| 1393 | lpfc_issue_hb_mbox(struct lpfc_hba *phba) |
| 1394 | { |
| 1395 | LPFC_MBOXQ_t *pmboxq; |
| 1396 | int retval; |
| 1397 | |
| 1398 | /* Is a Heartbeat mbox already in progress */ |
| 1399 | if (phba->hba_flag & HBA_HBEAT_INP) |
| 1400 | return 0; |
| 1401 | |
| 1402 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1403 | if (!pmboxq) |
| 1404 | return -ENOMEM; |
| 1405 | |
| 1406 | lpfc_heart_beat(phba, pmboxq); |
| 1407 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1408 | pmboxq->vport = phba->pport; |
| 1409 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 1410 | |
| 1411 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { |
| 1412 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1413 | return -ENXIO; |
| 1414 | } |
| 1415 | phba->hba_flag |= HBA_HBEAT_INP; |
| 1416 | |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
| 1420 | /** |
| 1421 | * lpfc_issue_hb_tmo - Signals heartbeat timer to issue mbox command |
| 1422 | * @phba: pointer to lpfc hba data structure. |
| 1423 | * |
| 1424 | * The heartbeat timer (every 5 sec) will fire. If the HBA_HBEAT_TMO |
| 1425 | * flag is set, it will force a MBX_HEARTBEAT mbox command, regardless |
| 1426 | * of the value of lpfc_enable_hba_heartbeat. |
| 1427 | * If lpfc_enable_hba_heartbeat is set, the timeout routine will always |
| 1428 | * try to issue a MBX_HEARTBEAT mbox command. |
| 1429 | **/ |
| 1430 | void |
| 1431 | lpfc_issue_hb_tmo(struct lpfc_hba *phba) |
| 1432 | { |
| 1433 | if (phba->cfg_enable_hba_heartbeat) |
| 1434 | return; |
| 1435 | phba->hba_flag |= HBA_HBEAT_TMO; |
| 1436 | } |
| 1437 | |
| 1438 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1439 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1440 | * @phba: pointer to lpfc hba data structure. |
| 1441 | * |
| 1442 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1443 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1444 | * handler performs any periodic operations needed for the device. If such |
| 1445 | * periodic event has already been attended to either in the interrupt handler |
| 1446 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1447 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1448 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1449 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1450 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1451 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1452 | * to offline. |
| 1453 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1454 | void |
| 1455 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1456 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1457 | struct lpfc_vport **vports; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1458 | struct lpfc_dmabuf *buf_ptr; |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1459 | int retval = 0; |
| 1460 | int i, tmo; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1461 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1462 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1463 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1464 | if (phba->cfg_xri_rebalancing) { |
| 1465 | /* Multi-XRI pools handler */ |
| 1466 | lpfc_hb_mxp_handler(phba); |
| 1467 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1468 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1469 | vports = lpfc_create_vport_work_array(phba); |
| 1470 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1471 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1472 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | e3ba04c | 2019-12-18 15:58:02 -0800 | [diff] [blame] | 1473 | lpfc_fdmi_change_check(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1474 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1475 | lpfc_destroy_vport_work_array(phba, vports); |
| 1476 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1477 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1478 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1479 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1480 | return; |
| 1481 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1482 | if (phba->elsbuf_cnt && |
| 1483 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1484 | spin_lock_irq(&phba->hbalock); |
| 1485 | list_splice_init(&phba->elsbuf, &completions); |
| 1486 | phba->elsbuf_cnt = 0; |
| 1487 | phba->elsbuf_prev_cnt = 0; |
| 1488 | spin_unlock_irq(&phba->hbalock); |
| 1489 | |
| 1490 | while (!list_empty(&completions)) { |
| 1491 | list_remove_head(&completions, buf_ptr, |
| 1492 | struct lpfc_dmabuf, list); |
| 1493 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1494 | kfree(buf_ptr); |
| 1495 | } |
| 1496 | } |
| 1497 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1498 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1499 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1500 | if (phba->cfg_enable_hba_heartbeat) { |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1501 | /* If IOs are completing, no need to issue a MBX_HEARTBEAT */ |
| 1502 | spin_lock_irq(&phba->pport->work_port_lock); |
| 1503 | if (time_after(phba->last_completion_time + |
| 1504 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1505 | jiffies)) { |
| 1506 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1507 | if (phba->hba_flag & HBA_HBEAT_INP) |
| 1508 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1509 | else |
| 1510 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
| 1511 | goto out; |
| 1512 | } |
| 1513 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1514 | |
| 1515 | /* Check if a MBX_HEARTBEAT is already in progress */ |
| 1516 | if (phba->hba_flag & HBA_HBEAT_INP) { |
| 1517 | /* |
| 1518 | * If heart beat timeout called with HBA_HBEAT_INP set |
| 1519 | * we need to give the hb mailbox cmd a chance to |
| 1520 | * complete or TMO. |
| 1521 | */ |
| 1522 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1523 | "0459 Adapter heartbeat still outstanding: " |
| 1524 | "last compl time was %d ms.\n", |
| 1525 | jiffies_to_msecs(jiffies |
| 1526 | - phba->last_completion_time)); |
| 1527 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1528 | } else { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1529 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1530 | (list_empty(&psli->mboxq))) { |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1531 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1532 | retval = lpfc_issue_hb_mbox(phba); |
| 1533 | if (retval) { |
| 1534 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
| 1535 | goto out; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1536 | } |
| 1537 | phba->skipped_hb = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1538 | } else if (time_before_eq(phba->last_completion_time, |
| 1539 | phba->skipped_hb)) { |
| 1540 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1541 | "2857 Last completion time not " |
| 1542 | " updated in %d ms\n", |
| 1543 | jiffies_to_msecs(jiffies |
| 1544 | - phba->last_completion_time)); |
| 1545 | } else |
| 1546 | phba->skipped_hb = jiffies; |
| 1547 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1548 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1549 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1550 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1551 | } else { |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1552 | /* Check to see if we want to force a MBX_HEARTBEAT */ |
| 1553 | if (phba->hba_flag & HBA_HBEAT_TMO) { |
| 1554 | retval = lpfc_issue_hb_mbox(phba); |
| 1555 | if (retval) |
| 1556 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
| 1557 | else |
| 1558 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1559 | goto out; |
| 1560 | } |
| 1561 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1562 | } |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1563 | out: |
| 1564 | mod_timer(&phba->hb_tmofunc, jiffies + msecs_to_jiffies(tmo)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1565 | } |
| 1566 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1567 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1568 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1569 | * @phba: pointer to lpfc hba data structure. |
| 1570 | * |
| 1571 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1572 | * other than Port Error 6 has been detected. |
| 1573 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1574 | static void |
| 1575 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1576 | { |
| 1577 | struct lpfc_sli *psli = &phba->sli; |
| 1578 | |
| 1579 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1580 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1581 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1582 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1583 | |
| 1584 | lpfc_offline(phba); |
| 1585 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1586 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1587 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1588 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1589 | lpfc_hba_down_post(phba); |
| 1590 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1591 | lpfc_unblock_mgmt_io(phba); |
| 1592 | phba->link_state = LPFC_HBA_ERROR; |
| 1593 | return; |
| 1594 | } |
| 1595 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1596 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1597 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1598 | * @phba: pointer to lpfc hba data structure. |
| 1599 | * |
| 1600 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1601 | * other than Port Error 6 has been detected. |
| 1602 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1603 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1604 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1605 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1606 | spin_lock_irq(&phba->hbalock); |
| 1607 | phba->link_state = LPFC_HBA_ERROR; |
| 1608 | spin_unlock_irq(&phba->hbalock); |
| 1609 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1610 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1611 | lpfc_sli_flush_io_rings(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1612 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1613 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1614 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1618 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1619 | * @phba: pointer to lpfc hba data structure. |
| 1620 | * |
| 1621 | * This routine is invoked to handle the deferred HBA hardware error |
| 1622 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1623 | * and another ER bit in the host status register. The driver will |
| 1624 | * wait until the ER1 bit clears before handling the error condition. |
| 1625 | **/ |
| 1626 | static void |
| 1627 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1628 | { |
| 1629 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1630 | struct lpfc_sli *psli = &phba->sli; |
| 1631 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1632 | /* If the pci channel is offline, ignore possible errors, |
| 1633 | * since we cannot communicate with the pci card anyway. |
| 1634 | */ |
| 1635 | if (pci_channel_offline(phba->pcidev)) { |
| 1636 | spin_lock_irq(&phba->hbalock); |
| 1637 | phba->hba_flag &= ~DEFER_ERATT; |
| 1638 | spin_unlock_irq(&phba->hbalock); |
| 1639 | return; |
| 1640 | } |
| 1641 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1642 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 1643 | "0479 Deferred Adapter Hardware Error " |
| 1644 | "Data: x%x x%x x%x\n", |
| 1645 | phba->work_hs, phba->work_status[0], |
| 1646 | phba->work_status[1]); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1647 | |
| 1648 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1649 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1650 | spin_unlock_irq(&phba->hbalock); |
| 1651 | |
| 1652 | |
| 1653 | /* |
| 1654 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1655 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1656 | * SCSI layer retry it after re-establishing link. |
| 1657 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1658 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1659 | |
| 1660 | /* |
| 1661 | * There was a firmware error. Take the hba offline and then |
| 1662 | * attempt to restart it. |
| 1663 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1664 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1665 | lpfc_offline(phba); |
| 1666 | |
| 1667 | /* Wait for the ER1 bit to clear.*/ |
| 1668 | while (phba->work_hs & HS_FFER1) { |
| 1669 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1670 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1671 | phba->work_hs = UNPLUG_ERR ; |
| 1672 | break; |
| 1673 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1674 | /* If driver is unloading let the worker thread continue */ |
| 1675 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1676 | phba->work_hs = 0; |
| 1677 | break; |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | /* |
| 1682 | * This is to ptrotect against a race condition in which |
| 1683 | * first write to the host attention register clear the |
| 1684 | * host status register. |
| 1685 | */ |
| 1686 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1687 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1688 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1689 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1690 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1691 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1692 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1693 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1694 | } |
| 1695 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1696 | static void |
| 1697 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1698 | { |
| 1699 | struct lpfc_board_event_header board_event; |
| 1700 | struct Scsi_Host *shost; |
| 1701 | |
| 1702 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1703 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1704 | shost = lpfc_shost_from_vport(phba->pport); |
| 1705 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1706 | sizeof(board_event), |
| 1707 | (char *) &board_event, |
| 1708 | LPFC_NL_VENDOR_ID); |
| 1709 | } |
| 1710 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1711 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1712 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1713 | * @phba: pointer to lpfc hba data structure. |
| 1714 | * |
| 1715 | * This routine is invoked to handle the following HBA hardware error |
| 1716 | * conditions: |
| 1717 | * 1 - HBA error attention interrupt |
| 1718 | * 2 - DMA ring index out of range |
| 1719 | * 3 - Mailbox command came back as unknown |
| 1720 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1721 | static void |
| 1722 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1723 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1724 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1725 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1726 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1727 | unsigned long temperature; |
| 1728 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1729 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1730 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1731 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1732 | * since we cannot communicate with the pci card anyway. |
| 1733 | */ |
| 1734 | if (pci_channel_offline(phba->pcidev)) { |
| 1735 | spin_lock_irq(&phba->hbalock); |
| 1736 | phba->hba_flag &= ~DEFER_ERATT; |
| 1737 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1738 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1739 | } |
| 1740 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1741 | /* If resets are disabled then leave the HBA alone and return */ |
| 1742 | if (!phba->cfg_enable_hba_reset) |
| 1743 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1744 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1745 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1746 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1747 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1748 | if (phba->hba_flag & DEFER_ERATT) |
| 1749 | lpfc_handle_deferred_eratt(phba); |
| 1750 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1751 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1752 | if (phba->work_hs & HS_FFER6) |
| 1753 | /* Re-establishing Link */ |
| 1754 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1755 | "1301 Re-establishing Link " |
| 1756 | "Data: x%x x%x x%x\n", |
| 1757 | phba->work_hs, phba->work_status[0], |
| 1758 | phba->work_status[1]); |
| 1759 | if (phba->work_hs & HS_FFER8) |
| 1760 | /* Device Zeroization */ |
| 1761 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1762 | "2861 Host Authentication device " |
| 1763 | "zeroization Data:x%x x%x x%x\n", |
| 1764 | phba->work_hs, phba->work_status[0], |
| 1765 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1766 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1767 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1768 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1769 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1770 | |
| 1771 | /* |
| 1772 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1773 | * That could cause the I/Os dropped by the firmware. |
| 1774 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1775 | * retry it after re-establishing link. |
| 1776 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1777 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1778 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1779 | /* |
| 1780 | * There was a firmware error. Take the hba offline and then |
| 1781 | * attempt to restart it. |
| 1782 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1783 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1784 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1785 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1786 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1787 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1788 | return; |
| 1789 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1790 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1791 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1792 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1793 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1794 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1795 | temp_event_data.data = (uint32_t)temperature; |
| 1796 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1797 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1798 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1799 | "(%ld), taking this port offline " |
| 1800 | "Data: x%x x%x x%x\n", |
| 1801 | temperature, phba->work_hs, |
| 1802 | phba->work_status[0], phba->work_status[1]); |
| 1803 | |
| 1804 | shost = lpfc_shost_from_vport(phba->pport); |
| 1805 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1806 | sizeof(temp_event_data), |
| 1807 | (char *) &temp_event_data, |
| 1808 | SCSI_NL_VID_TYPE_PCI |
| 1809 | | PCI_VENDOR_ID_EMULEX); |
| 1810 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1811 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1812 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1813 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1814 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1815 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1816 | } else { |
| 1817 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1818 | * failure is a value other than FFER6. Do not call the offline |
| 1819 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1820 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1821 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1822 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1824 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1825 | phba->work_status[0], phba->work_status[1]); |
| 1826 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1827 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1828 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1829 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1830 | sizeof(event_data), (char *) &event_data, |
| 1831 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1832 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1833 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1834 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1835 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1836 | } |
| 1837 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1838 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1839 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1840 | * @phba: pointer to lpfc hba data structure. |
| 1841 | * @mbx_action: flag for mailbox shutdown action. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1842 | * @en_rn_msg: send reset/port recovery message. |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1843 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1844 | * response to port status register polling attention. It waits for port |
| 1845 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1846 | * During this process, interrupt vectors are freed and later requested |
| 1847 | * for handling possible port resource change. |
| 1848 | **/ |
| 1849 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1850 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1851 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1852 | { |
| 1853 | int rc; |
| 1854 | uint32_t intr_mode; |
| 1855 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1856 | 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] | 1857 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1858 | /* |
| 1859 | * On error status condition, driver need to wait for port |
| 1860 | * ready before performing reset. |
| 1861 | */ |
| 1862 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1863 | if (rc) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1864 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1865 | } |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1866 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1867 | /* need reset: attempt for port recovery */ |
| 1868 | if (en_rn_msg) |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 1869 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1870 | "2887 Reset Needed: Attempting Port " |
| 1871 | "Recovery...\n"); |
James Smart | 3ba6216 | 2021-01-04 10:02:31 -0800 | [diff] [blame] | 1872 | |
| 1873 | /* If we are no wait, the HBA has been reset and is not |
| 1874 | * functional, thus we should clear LPFC_SLI_ACTIVE flag. |
| 1875 | */ |
| 1876 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 1877 | spin_lock_irq(&phba->hbalock); |
| 1878 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
| 1879 | spin_unlock_irq(&phba->hbalock); |
| 1880 | } |
| 1881 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1882 | lpfc_offline_prep(phba, mbx_action); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1883 | lpfc_sli_flush_io_rings(phba); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1884 | lpfc_offline(phba); |
| 1885 | /* release interrupt for possible resource change */ |
| 1886 | lpfc_sli4_disable_intr(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1887 | rc = lpfc_sli_brdrestart(phba); |
| 1888 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1889 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1890 | "6309 Failed to restart board\n"); |
| 1891 | return rc; |
| 1892 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1893 | /* request and enable interrupt */ |
| 1894 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1895 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1896 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1897 | "3175 Failed to enable interrupt\n"); |
| 1898 | return -EIO; |
| 1899 | } |
| 1900 | phba->intr_mode = intr_mode; |
| 1901 | rc = lpfc_online(phba); |
| 1902 | if (rc == 0) |
| 1903 | lpfc_unblock_mgmt_io(phba); |
| 1904 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1905 | return rc; |
| 1906 | } |
| 1907 | |
| 1908 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1909 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1910 | * @phba: pointer to lpfc hba data structure. |
| 1911 | * |
| 1912 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1913 | * conditions. |
| 1914 | **/ |
| 1915 | static void |
| 1916 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1917 | { |
| 1918 | struct lpfc_vport *vport = phba->pport; |
| 1919 | uint32_t event_data; |
| 1920 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1921 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1922 | struct lpfc_register portstat_reg = {0}; |
| 1923 | uint32_t reg_err1, reg_err2; |
| 1924 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1925 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1926 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1927 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1928 | struct lpfc_register portsmphr_reg; |
| 1929 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1930 | |
| 1931 | /* If the pci channel is offline, ignore possible errors, since |
| 1932 | * we cannot communicate with the pci card anyway. |
| 1933 | */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1934 | if (pci_channel_offline(phba->pcidev)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1935 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1936 | "3166 pci channel is offline\n"); |
| 1937 | lpfc_sli4_offline_eratt(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1938 | return; |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1939 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1940 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1941 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1942 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1943 | switch (if_type) { |
| 1944 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1945 | pci_rd_rc1 = lpfc_readl( |
| 1946 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1947 | &uerrlo_reg); |
| 1948 | pci_rd_rc2 = lpfc_readl( |
| 1949 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1950 | &uemasklo_reg); |
| 1951 | /* consider PCI bus read error as pci_channel_offline */ |
| 1952 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1953 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1954 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1955 | lpfc_sli4_offline_eratt(phba); |
| 1956 | return; |
| 1957 | } |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1958 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1959 | "7623 Checking UE recoverable"); |
| 1960 | |
| 1961 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1962 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1963 | &portsmphr_reg.word0)) |
| 1964 | continue; |
| 1965 | |
| 1966 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1967 | &portsmphr_reg); |
| 1968 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1969 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1970 | break; |
| 1971 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1972 | msleep(1000); |
| 1973 | } |
| 1974 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1975 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1976 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1977 | smphr_port_status, i); |
| 1978 | |
| 1979 | /* Recoverable UE, reset the HBA device */ |
| 1980 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1981 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1982 | for (i = 0; i < 20; i++) { |
| 1983 | msleep(1000); |
| 1984 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1985 | &portsmphr_reg.word0) && |
| 1986 | (LPFC_POST_STAGE_PORT_READY == |
| 1987 | bf_get(lpfc_port_smphr_port_status, |
| 1988 | &portsmphr_reg))) { |
| 1989 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 1990 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 1991 | if (rc == 0) |
| 1992 | return; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1993 | lpfc_printf_log(phba, KERN_ERR, |
| 1994 | LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1995 | "4215 Failed to recover UE"); |
| 1996 | break; |
| 1997 | } |
| 1998 | } |
| 1999 | } |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2000 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 2001 | "7624 Firmware not ready: Failing UE recovery," |
| 2002 | " waited %dSec", i); |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 2003 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2004 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2005 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2006 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2007 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2008 | pci_rd_rc1 = lpfc_readl( |
| 2009 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 2010 | &portstat_reg.word0); |
| 2011 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2012 | if (pci_rd_rc1 == -EIO) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2013 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2014 | "3151 PCI bus read access failure: x%x\n", |
| 2015 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 2016 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2017 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2018 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2019 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 2020 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2021 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2022 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 2023 | "2889 Port Overtemperature event, " |
| 2024 | "taking port offline Data: x%x x%x\n", |
| 2025 | reg_err1, reg_err2); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2026 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 2027 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2028 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 2029 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 2030 | temp_event_data.data = 0xFFFFFFFF; |
| 2031 | |
| 2032 | shost = lpfc_shost_from_vport(phba->pport); |
| 2033 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2034 | sizeof(temp_event_data), |
| 2035 | (char *)&temp_event_data, |
| 2036 | SCSI_NL_VID_TYPE_PCI |
| 2037 | | PCI_VENDOR_ID_EMULEX); |
| 2038 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2039 | spin_lock_irq(&phba->hbalock); |
| 2040 | phba->over_temp_state = HBA_OVER_TEMP; |
| 2041 | spin_unlock_irq(&phba->hbalock); |
| 2042 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2043 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2044 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2045 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2046 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2047 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2048 | "3143 Port Down: Firmware Update " |
| 2049 | "Detected\n"); |
| 2050 | en_rn_msg = false; |
| 2051 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2052 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2053 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2054 | "3144 Port Down: Debug Dump\n"); |
| 2055 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 2056 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2057 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2058 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2059 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2060 | /* If resets are disabled then leave the HBA alone and return */ |
| 2061 | if (!phba->cfg_enable_hba_reset) |
| 2062 | return; |
| 2063 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2064 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2065 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 2066 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2067 | if (rc == 0) { |
| 2068 | /* don't report event on forced debug dump */ |
| 2069 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 2070 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 2071 | return; |
| 2072 | else |
| 2073 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2074 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2075 | /* fall through for not able to recover */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2076 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 2077 | "3152 Unrecoverable error\n"); |
| 2078 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2079 | break; |
| 2080 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 2081 | default: |
| 2082 | break; |
| 2083 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2084 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2085 | "3123 Report dump event to upper layer\n"); |
| 2086 | /* Send an internal error event to mgmt application */ |
| 2087 | lpfc_board_errevt_to_mgmt(phba); |
| 2088 | |
| 2089 | event_data = FC_REG_DUMP_EVENT; |
| 2090 | shost = lpfc_shost_from_vport(vport); |
| 2091 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2092 | sizeof(event_data), (char *) &event_data, |
| 2093 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | /** |
| 2097 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 2098 | * @phba: pointer to lpfc HBA data structure. |
| 2099 | * |
| 2100 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 2101 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 2102 | * |
| 2103 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2104 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2105 | * Any other value - error. |
| 2106 | **/ |
| 2107 | void |
| 2108 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 2109 | { |
| 2110 | (*phba->lpfc_handle_eratt)(phba); |
| 2111 | } |
| 2112 | |
| 2113 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2114 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2115 | * @phba: pointer to lpfc hba data structure. |
| 2116 | * |
| 2117 | * 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] | 2118 | * attention link event. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2119 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2120 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2121 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2123 | struct lpfc_vport *vport = phba->pport; |
| 2124 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2125 | LPFC_MBOXQ_t *pmb; |
| 2126 | volatile uint32_t control; |
| 2127 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2128 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2129 | |
| 2130 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2131 | if (!pmb) { |
| 2132 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2133 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2134 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | |
| 2136 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2137 | if (!mp) { |
| 2138 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2139 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2140 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2141 | |
| 2142 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2143 | if (!mp->virt) { |
| 2144 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2145 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2146 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 2148 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2149 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | |
| 2151 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2152 | lpfc_read_topology(phba, pmb, mp); |
| 2153 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2154 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2155 | /* Block ELS IOCBs until we have processed this mbox command */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2156 | phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2157 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2158 | if (rc == MBX_NOT_FINISHED) { |
| 2159 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2160 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2161 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | |
| 2163 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2164 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2165 | writel(HA_LATT, phba->HAregaddr); |
| 2166 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2167 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2168 | |
| 2169 | return; |
| 2170 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2171 | lpfc_handle_latt_free_mbuf: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2172 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2173 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2174 | lpfc_handle_latt_free_mp: |
| 2175 | kfree(mp); |
| 2176 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2177 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2178 | lpfc_handle_latt_err_exit: |
| 2179 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2180 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2181 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 2182 | control = readl(phba->HCregaddr); |
| 2183 | control |= HC_LAINT_ENA; |
| 2184 | writel(control, phba->HCregaddr); |
| 2185 | readl(phba->HCregaddr); /* flush */ |
| 2186 | |
| 2187 | /* Clear Link Attention in HA REG */ |
| 2188 | writel(HA_LATT, phba->HAregaddr); |
| 2189 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2190 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2192 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2193 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2194 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 2195 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | |
| 2197 | return; |
| 2198 | } |
| 2199 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2200 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2201 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2202 | * @phba: pointer to lpfc hba data structure. |
| 2203 | * @vpd: pointer to the vital product data. |
| 2204 | * @len: length of the vital product data in bytes. |
| 2205 | * |
| 2206 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 2207 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 2208 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 2209 | * |
| 2210 | * Return codes |
| 2211 | * 0 - pointer to the VPD passed in is NULL |
| 2212 | * 1 - success |
| 2213 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2214 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2215 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2216 | { |
| 2217 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 2218 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2219 | int i, j; |
| 2220 | int finished = 0; |
| 2221 | int index = 0; |
| 2222 | |
| 2223 | if (!vpd) |
| 2224 | return 0; |
| 2225 | |
| 2226 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2227 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2228 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2229 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 2230 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2231 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2232 | switch (vpd[index]) { |
| 2233 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2234 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2235 | index += 1; |
| 2236 | lenlo = vpd[index]; |
| 2237 | index += 1; |
| 2238 | lenhi = vpd[index]; |
| 2239 | index += 1; |
| 2240 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 2241 | index += i; |
| 2242 | break; |
| 2243 | case 0x90: |
| 2244 | index += 1; |
| 2245 | lenlo = vpd[index]; |
| 2246 | index += 1; |
| 2247 | lenhi = vpd[index]; |
| 2248 | index += 1; |
| 2249 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2250 | if (Length > len - index) |
| 2251 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2252 | while (Length > 0) { |
| 2253 | /* Look for Serial Number */ |
| 2254 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 2255 | index += 2; |
| 2256 | i = vpd[index]; |
| 2257 | index += 1; |
| 2258 | j = 0; |
| 2259 | Length -= (3+i); |
| 2260 | while(i--) { |
| 2261 | phba->SerialNumber[j++] = vpd[index++]; |
| 2262 | if (j == 31) |
| 2263 | break; |
| 2264 | } |
| 2265 | phba->SerialNumber[j] = 0; |
| 2266 | continue; |
| 2267 | } |
| 2268 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 2269 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 2270 | index += 2; |
| 2271 | i = vpd[index]; |
| 2272 | index += 1; |
| 2273 | j = 0; |
| 2274 | Length -= (3+i); |
| 2275 | while(i--) { |
| 2276 | phba->ModelDesc[j++] = vpd[index++]; |
| 2277 | if (j == 255) |
| 2278 | break; |
| 2279 | } |
| 2280 | phba->ModelDesc[j] = 0; |
| 2281 | continue; |
| 2282 | } |
| 2283 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 2284 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 2285 | index += 2; |
| 2286 | i = vpd[index]; |
| 2287 | index += 1; |
| 2288 | j = 0; |
| 2289 | Length -= (3+i); |
| 2290 | while(i--) { |
| 2291 | phba->ModelName[j++] = vpd[index++]; |
| 2292 | if (j == 79) |
| 2293 | break; |
| 2294 | } |
| 2295 | phba->ModelName[j] = 0; |
| 2296 | continue; |
| 2297 | } |
| 2298 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2299 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2300 | index += 2; |
| 2301 | i = vpd[index]; |
| 2302 | index += 1; |
| 2303 | j = 0; |
| 2304 | Length -= (3+i); |
| 2305 | while(i--) { |
| 2306 | phba->ProgramType[j++] = vpd[index++]; |
| 2307 | if (j == 255) |
| 2308 | break; |
| 2309 | } |
| 2310 | phba->ProgramType[j] = 0; |
| 2311 | continue; |
| 2312 | } |
| 2313 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2314 | phba->vpd_flag |= VPD_PORT; |
| 2315 | index += 2; |
| 2316 | i = vpd[index]; |
| 2317 | index += 1; |
| 2318 | j = 0; |
| 2319 | Length -= (3+i); |
| 2320 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2321 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2322 | (phba->sli4_hba.pport_name_sta == |
| 2323 | LPFC_SLI4_PPNAME_GET)) { |
| 2324 | j++; |
| 2325 | index++; |
| 2326 | } else |
| 2327 | phba->Port[j++] = vpd[index++]; |
| 2328 | if (j == 19) |
| 2329 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2330 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2331 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 2332 | (phba->sli4_hba.pport_name_sta == |
| 2333 | LPFC_SLI4_PPNAME_NON)) |
| 2334 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2335 | continue; |
| 2336 | } |
| 2337 | else { |
| 2338 | index += 2; |
| 2339 | i = vpd[index]; |
| 2340 | index += 1; |
| 2341 | index += i; |
| 2342 | Length -= (3 + i); |
| 2343 | } |
| 2344 | } |
| 2345 | finished = 0; |
| 2346 | break; |
| 2347 | case 0x78: |
| 2348 | finished = 1; |
| 2349 | break; |
| 2350 | default: |
| 2351 | index ++; |
| 2352 | break; |
| 2353 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2354 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2355 | |
| 2356 | return(1); |
| 2357 | } |
| 2358 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2359 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2360 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2361 | * @phba: pointer to lpfc hba data structure. |
| 2362 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2363 | * @descp: pointer to the data structure to hold the derived description. |
| 2364 | * |
| 2365 | * This routine retrieves HBA's description based on its registered PCI device |
| 2366 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2367 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2368 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2369 | * function returns, the @mdp will be filled with the model name. |
| 2370 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2371 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2372 | 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] | 2373 | { |
| 2374 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2375 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2376 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2377 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2378 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2379 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2380 | char *name; |
| 2381 | char *bus; |
| 2382 | char *function; |
| 2383 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2384 | |
| 2385 | if (mdp && mdp[0] != '\0' |
| 2386 | && descp && descp[0] != '\0') |
| 2387 | return; |
| 2388 | |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 2389 | if (phba->lmt & LMT_64Gb) |
| 2390 | max_speed = 64; |
| 2391 | else if (phba->lmt & LMT_32Gb) |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2392 | max_speed = 32; |
| 2393 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2394 | max_speed = 16; |
| 2395 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2396 | max_speed = 10; |
| 2397 | else if (phba->lmt & LMT_8Gb) |
| 2398 | max_speed = 8; |
| 2399 | else if (phba->lmt & LMT_4Gb) |
| 2400 | max_speed = 4; |
| 2401 | else if (phba->lmt & LMT_2Gb) |
| 2402 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2403 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2404 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2405 | else |
| 2406 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | |
| 2408 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2409 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2410 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2411 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2412 | m = (typeof(m)){"LP6000", "PCI", |
| 2413 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2414 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2415 | case PCI_DEVICE_ID_SUPERFLY: |
| 2416 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2417 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2418 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2419 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2420 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2421 | break; |
| 2422 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2423 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2424 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2425 | break; |
| 2426 | case PCI_DEVICE_ID_CENTAUR: |
| 2427 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2428 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2429 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2430 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2431 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2432 | break; |
| 2433 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2434 | m = (typeof(m)){"LP952", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2435 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2436 | break; |
| 2437 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2438 | m = (typeof(m)){"LP9802", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2439 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | break; |
| 2441 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2442 | m = (typeof(m)){"LP10000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2443 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | break; |
| 2445 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2446 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2447 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2448 | break; |
| 2449 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2450 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2451 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2452 | break; |
| 2453 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2454 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2455 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | break; |
| 2457 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2458 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2459 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2460 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2461 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2462 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2463 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2464 | break; |
| 2465 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2466 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2467 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2468 | break; |
| 2469 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2470 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2471 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2472 | break; |
| 2473 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2474 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2475 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2476 | break; |
| 2477 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2478 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2479 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2480 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2481 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2482 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2483 | break; |
| 2484 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2485 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2486 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2487 | break; |
| 2488 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2489 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2490 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2491 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2492 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2493 | break; |
| 2494 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2495 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2496 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2497 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2498 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2499 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2500 | break; |
| 2501 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2502 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2503 | break; |
| 2504 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2505 | m = (typeof(m)){"LP101", "PCI-X", |
| 2506 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2507 | break; |
| 2508 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2509 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2510 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2511 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2512 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2513 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2514 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2515 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2516 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2517 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2518 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2519 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2520 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2521 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2522 | break; |
| 2523 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2524 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2525 | break; |
| 2526 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2527 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2528 | break; |
| 2529 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2530 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2531 | break; |
| 2532 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2533 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2534 | break; |
| 2535 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2536 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2537 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2538 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2539 | m = (typeof(m)){"LP21000", "PCIe", |
| 2540 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2541 | GE = 1; |
| 2542 | break; |
| 2543 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2544 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2545 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2546 | break; |
| 2547 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2548 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2549 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2550 | break; |
| 2551 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2552 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2553 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2554 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2555 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2556 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2557 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2558 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2559 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2560 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2561 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2562 | break; |
| 2563 | case PCI_DEVICE_ID_FALCON: |
| 2564 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2565 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2566 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2567 | case PCI_DEVICE_ID_BALIUS: |
| 2568 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2569 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2570 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2571 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2572 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2573 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2574 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2575 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2576 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2577 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2578 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2579 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2580 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2581 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2582 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2583 | oneConnect = 1; |
| 2584 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2585 | "Obsolete, Unsupported FCoE"}; |
| 2586 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2587 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2588 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2589 | break; |
James Smart | c238b9b | 2018-02-22 08:18:44 -0800 | [diff] [blame] | 2590 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 2591 | m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"}; |
| 2592 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2593 | case PCI_DEVICE_ID_SKYHAWK: |
| 2594 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2595 | oneConnect = 1; |
| 2596 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2597 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2598 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2599 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2600 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2601 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2602 | |
| 2603 | if (mdp && mdp[0] == '\0') |
| 2604 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2605 | /* |
| 2606 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2607 | * and we put the port number on the end |
| 2608 | */ |
| 2609 | if (descp && descp[0] == '\0') { |
| 2610 | if (oneConnect) |
| 2611 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2612 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2613 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2614 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2615 | else if (max_speed == 0) |
| 2616 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2617 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2618 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2619 | else |
| 2620 | snprintf(descp, 255, |
| 2621 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2622 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2623 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2624 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2625 | } |
| 2626 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2627 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2628 | * 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] | 2629 | * @phba: pointer to lpfc hba data structure. |
| 2630 | * @pring: pointer to a IOCB ring. |
| 2631 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2632 | * |
| 2633 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2634 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2635 | * |
| 2636 | * Return codes |
| 2637 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2638 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2639 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2640 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2641 | { |
| 2642 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2643 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2644 | struct lpfc_dmabuf *mp1, *mp2; |
| 2645 | |
| 2646 | cnt += pring->missbufcnt; |
| 2647 | |
| 2648 | /* While there are buffers to post */ |
| 2649 | while (cnt > 0) { |
| 2650 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2651 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2652 | if (iocb == NULL) { |
| 2653 | pring->missbufcnt = cnt; |
| 2654 | return cnt; |
| 2655 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2656 | icmd = &iocb->iocb; |
| 2657 | |
| 2658 | /* 2 buffers can be posted per command */ |
| 2659 | /* Allocate buffer to post */ |
| 2660 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2661 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2662 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2663 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2664 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2665 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2666 | pring->missbufcnt = cnt; |
| 2667 | return cnt; |
| 2668 | } |
| 2669 | |
| 2670 | INIT_LIST_HEAD(&mp1->list); |
| 2671 | /* Allocate buffer to post */ |
| 2672 | if (cnt > 1) { |
| 2673 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2674 | if (mp2) |
| 2675 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2676 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2677 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2678 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2679 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2680 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2681 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | pring->missbufcnt = cnt; |
| 2683 | return cnt; |
| 2684 | } |
| 2685 | |
| 2686 | INIT_LIST_HEAD(&mp2->list); |
| 2687 | } else { |
| 2688 | mp2 = NULL; |
| 2689 | } |
| 2690 | |
| 2691 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2692 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2693 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2694 | icmd->ulpBdeCount = 1; |
| 2695 | cnt--; |
| 2696 | if (mp2) { |
| 2697 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2698 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2699 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2700 | cnt--; |
| 2701 | icmd->ulpBdeCount = 2; |
| 2702 | } |
| 2703 | |
| 2704 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2705 | icmd->ulpLe = 1; |
| 2706 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2707 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2708 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2709 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2710 | kfree(mp1); |
| 2711 | cnt++; |
| 2712 | if (mp2) { |
| 2713 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2714 | kfree(mp2); |
| 2715 | cnt++; |
| 2716 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2717 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2718 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2719 | return cnt; |
| 2720 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2721 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2722 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2723 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2724 | } |
| 2725 | pring->missbufcnt = 0; |
| 2726 | return 0; |
| 2727 | } |
| 2728 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2729 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2730 | * 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] | 2731 | * @phba: pointer to lpfc hba data structure. |
| 2732 | * |
| 2733 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2734 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2735 | * set to 64 IOCBs. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2736 | * |
| 2737 | * Return codes |
| 2738 | * 0 - success (currently always success) |
| 2739 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2740 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2741 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | { |
| 2743 | struct lpfc_sli *psli = &phba->sli; |
| 2744 | |
| 2745 | /* Ring 0, ELS / CT buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2746 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2747 | /* Ring 2 - FCP no buffers needed */ |
| 2748 | |
| 2749 | return 0; |
| 2750 | } |
| 2751 | |
| 2752 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2753 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2754 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2755 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2756 | * @HashResultPointer: pointer to an array as hash table. |
| 2757 | * |
| 2758 | * This routine sets up the initial values to the array of hash table entries |
| 2759 | * for the LC HBAs. |
| 2760 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2761 | static void |
| 2762 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2763 | { |
| 2764 | HashResultPointer[0] = 0x67452301; |
| 2765 | HashResultPointer[1] = 0xEFCDAB89; |
| 2766 | HashResultPointer[2] = 0x98BADCFE; |
| 2767 | HashResultPointer[3] = 0x10325476; |
| 2768 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2769 | } |
| 2770 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2771 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2772 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2773 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2774 | * @HashWorkingPointer: pointer to an working hash table. |
| 2775 | * |
| 2776 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2777 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2778 | * The results are putting back to the initial hash table, returned through |
| 2779 | * the @HashResultPointer as the result hash table. |
| 2780 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2781 | static void |
| 2782 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2783 | { |
| 2784 | int t; |
| 2785 | uint32_t TEMP; |
| 2786 | uint32_t A, B, C, D, E; |
| 2787 | t = 16; |
| 2788 | do { |
| 2789 | HashWorkingPointer[t] = |
| 2790 | S(1, |
| 2791 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2792 | 8] ^ |
| 2793 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2794 | } while (++t <= 79); |
| 2795 | t = 0; |
| 2796 | A = HashResultPointer[0]; |
| 2797 | B = HashResultPointer[1]; |
| 2798 | C = HashResultPointer[2]; |
| 2799 | D = HashResultPointer[3]; |
| 2800 | E = HashResultPointer[4]; |
| 2801 | |
| 2802 | do { |
| 2803 | if (t < 20) { |
| 2804 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2805 | } else if (t < 40) { |
| 2806 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2807 | } else if (t < 60) { |
| 2808 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2809 | } else { |
| 2810 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2811 | } |
| 2812 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2813 | E = D; |
| 2814 | D = C; |
| 2815 | C = S(30, B); |
| 2816 | B = A; |
| 2817 | A = TEMP; |
| 2818 | } while (++t <= 79); |
| 2819 | |
| 2820 | HashResultPointer[0] += A; |
| 2821 | HashResultPointer[1] += B; |
| 2822 | HashResultPointer[2] += C; |
| 2823 | HashResultPointer[3] += D; |
| 2824 | HashResultPointer[4] += E; |
| 2825 | |
| 2826 | } |
| 2827 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2828 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2829 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2830 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2831 | * @HashWorking: pointer to the entry of the working hash array. |
| 2832 | * |
| 2833 | * This routine calculates the working hash array referred by @HashWorking |
| 2834 | * from the challenge random numbers associated with the host, referred by |
| 2835 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2836 | * array and returned by reference through @HashWorking. |
| 2837 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2838 | static void |
| 2839 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2840 | { |
| 2841 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2842 | } |
| 2843 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2844 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2845 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2846 | * @phba: pointer to lpfc hba data structure. |
| 2847 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2848 | * |
| 2849 | * This routine performs the special handling for LC HBA initialization. |
| 2850 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2851 | void |
| 2852 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2853 | { |
| 2854 | int t; |
| 2855 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2856 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2857 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2858 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2859 | if (!HashWorking) |
| 2860 | return; |
| 2861 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2862 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2863 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2864 | |
| 2865 | for (t = 0; t < 7; t++) |
| 2866 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2867 | |
| 2868 | lpfc_sha_init(hbainit); |
| 2869 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2870 | kfree(HashWorking); |
| 2871 | } |
| 2872 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2873 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2874 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2875 | * @vport: pointer to a virtual N_Port data structure. |
| 2876 | * |
| 2877 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2878 | * It invokes the discovery state machine to perform necessary state |
| 2879 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2880 | * the physical port is treated as @vport 0. |
| 2881 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2882 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2883 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2884 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2885 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2886 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2887 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2888 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2889 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2890 | lpfc_port_link_failure(vport); |
| 2891 | |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 2892 | /* Clean up VMID resources */ |
| 2893 | if (lpfc_is_vmid_enabled(phba)) |
| 2894 | lpfc_vmid_vport_cleanup(vport); |
| 2895 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2896 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 2897 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2898 | ndlp->nlp_DID == Fabric_DID) { |
| 2899 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2900 | lpfc_nlp_put(ndlp); |
| 2901 | continue; |
| 2902 | } |
| 2903 | |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 2904 | if (ndlp->nlp_DID == Fabric_Cntl_DID && |
| 2905 | ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2906 | lpfc_nlp_put(ndlp); |
| 2907 | continue; |
| 2908 | } |
| 2909 | |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2910 | /* Fabric Ports not in UNMAPPED state are cleaned up in the |
| 2911 | * DEVICE_RM event. |
| 2912 | */ |
| 2913 | if (ndlp->nlp_type & NLP_FABRIC && |
| 2914 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2915 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2916 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2917 | |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2918 | if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD))) |
| 2919 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2920 | NLP_EVT_DEVICE_RM); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2921 | } |
| 2922 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2923 | /* At this point, ALL ndlp's should be gone |
| 2924 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2925 | * Lets wait for this to happen, if needed. |
| 2926 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2927 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2928 | if (i++ > 3000) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2929 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2930 | LOG_TRACE_EVENT, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2931 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2932 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2933 | &vport->fc_nodes, nlp_listp) { |
| 2934 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2935 | LOG_TRACE_EVENT, |
| 2936 | "0282 did:x%x ndlp:x%px " |
| 2937 | "refcnt:%d xflags x%x nflag x%x\n", |
| 2938 | ndlp->nlp_DID, (void *)ndlp, |
| 2939 | kref_read(&ndlp->kref), |
| 2940 | ndlp->fc4_xpt_flags, |
| 2941 | ndlp->nlp_flag); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2942 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2943 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2944 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2945 | |
| 2946 | /* Wait for any activity on ndlps to settle */ |
| 2947 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2948 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2949 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2950 | } |
| 2951 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2952 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2953 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2954 | * @vport: pointer to a virtual N_Port data structure. |
| 2955 | * |
| 2956 | * This routine stops all the timers associated with a @vport. This function |
| 2957 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2958 | * port is treated as @vport 0. |
| 2959 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2960 | void |
| 2961 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2962 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2963 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2964 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2965 | lpfc_can_disctmo(vport); |
| 2966 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2967 | } |
| 2968 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2969 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2970 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2971 | * @phba: pointer to lpfc hba data structure. |
| 2972 | * |
| 2973 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2974 | * caller of this routine should already hold the host lock. |
| 2975 | **/ |
| 2976 | void |
| 2977 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2978 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2979 | /* Clear pending FCF rediscovery wait flag */ |
| 2980 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2981 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2982 | /* Now, try to stop the timer */ |
| 2983 | del_timer(&phba->fcf.redisc_wait); |
| 2984 | } |
| 2985 | |
| 2986 | /** |
| 2987 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2988 | * @phba: pointer to lpfc hba data structure. |
| 2989 | * |
| 2990 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2991 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2992 | * lock held before proceeding with disabling the timer and clearing the |
| 2993 | * wait timer pendig flag. |
| 2994 | **/ |
| 2995 | void |
| 2996 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2997 | { |
| 2998 | spin_lock_irq(&phba->hbalock); |
| 2999 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 3000 | /* FCF rediscovery timer already fired or stopped */ |
| 3001 | spin_unlock_irq(&phba->hbalock); |
| 3002 | return; |
| 3003 | } |
| 3004 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 3005 | /* Clear failover in progress flags */ |
| 3006 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3007 | spin_unlock_irq(&phba->hbalock); |
| 3008 | } |
| 3009 | |
| 3010 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3011 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3012 | * @phba: pointer to lpfc hba data structure. |
| 3013 | * |
| 3014 | * This routine stops all the timers associated with a HBA. This function is |
| 3015 | * invoked before either putting a HBA offline or unloading the driver. |
| 3016 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3017 | void |
| 3018 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3019 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 3020 | if (phba->pport) |
| 3021 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 3022 | cancel_delayed_work_sync(&phba->eq_delay_work); |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 3023 | cancel_delayed_work_sync(&phba->idle_stat_delay_work); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3024 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3025 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3026 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3027 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3028 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3029 | del_timer_sync(&phba->rrq_tmr); |
| 3030 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 3031 | } |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 3032 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3033 | |
| 3034 | switch (phba->pci_dev_grp) { |
| 3035 | case LPFC_PCI_DEV_LP: |
| 3036 | /* Stop any LightPulse device specific driver timers */ |
| 3037 | del_timer_sync(&phba->fcp_poll_timer); |
| 3038 | break; |
| 3039 | case LPFC_PCI_DEV_OC: |
Paul Walmsley | cc0e5f1 | 2019-07-11 20:52:33 -0700 | [diff] [blame] | 3040 | /* Stop any OneConnect device specific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3041 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3042 | break; |
| 3043 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3044 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3045 | "0297 Invalid device group (x%x)\n", |
| 3046 | phba->pci_dev_grp); |
| 3047 | break; |
| 3048 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3049 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3050 | } |
| 3051 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3052 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3053 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3054 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 3055 | * @mbx_action: flag for mailbox no wait action. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3056 | * |
| 3057 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 3058 | * management interface is marked as blocked, all the user space access to |
| 3059 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 3060 | * all be blocked. The HBA is set to block the management interface when the |
| 3061 | * driver prepares the HBA interface for online or offline. |
| 3062 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3063 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3064 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3065 | { |
| 3066 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3067 | uint8_t actcmd = MBX_HEARTBEAT; |
| 3068 | unsigned long timeout; |
| 3069 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3070 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3071 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3072 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3073 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 3074 | return; |
| 3075 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 3076 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3077 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3078 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3079 | /* Determine how long we might wait for the active mailbox |
| 3080 | * command to be gracefully completed by firmware. |
| 3081 | */ |
| 3082 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3083 | phba->sli.mbox_active) * 1000) + jiffies; |
| 3084 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3085 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3086 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3087 | /* Wait for the outstnading mailbox command to complete */ |
| 3088 | while (phba->sli.mbox_active) { |
| 3089 | /* Check active mailbox complete status every 2ms */ |
| 3090 | msleep(2); |
| 3091 | if (time_after(jiffies, timeout)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3092 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 3093 | "2813 Mgmt IO is Blocked %x " |
| 3094 | "- mbox cmd %x still active\n", |
| 3095 | phba->sli.sli_flag, actcmd); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3096 | break; |
| 3097 | } |
| 3098 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3099 | } |
| 3100 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3101 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3102 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 3103 | * @phba: pointer to lpfc hba data structure. |
| 3104 | * |
| 3105 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 3106 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 3107 | * is to fixup the temporary rpi assignments. |
| 3108 | **/ |
| 3109 | void |
| 3110 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 3111 | { |
| 3112 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3113 | struct lpfc_vport **vports; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3114 | int i, rpi; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3115 | |
| 3116 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 3117 | return; |
| 3118 | |
| 3119 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3120 | if (vports == NULL) |
| 3121 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3122 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3123 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3124 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3125 | continue; |
| 3126 | |
| 3127 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3128 | &vports[i]->fc_nodes, |
| 3129 | nlp_listp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3130 | rpi = lpfc_sli4_alloc_rpi(phba); |
| 3131 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3132 | /* TODO print log? */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3133 | continue; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3134 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3135 | ndlp->nlp_rpi = rpi; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3136 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, |
| 3137 | LOG_NODE | LOG_DISCOVERY, |
| 3138 | "0009 Assign RPI x%x to ndlp x%px " |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3139 | "DID:x%06x flg:x%x\n", |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3140 | ndlp->nlp_rpi, ndlp, ndlp->nlp_DID, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3141 | ndlp->nlp_flag); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | lpfc_destroy_vport_work_array(phba, vports); |
| 3145 | } |
| 3146 | |
| 3147 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3148 | * lpfc_create_expedite_pool - create expedite pool |
| 3149 | * @phba: pointer to lpfc hba data structure. |
| 3150 | * |
| 3151 | * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0 |
| 3152 | * to expedite pool. Mark them as expedite. |
| 3153 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3154 | static void lpfc_create_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3155 | { |
| 3156 | struct lpfc_sli4_hdw_queue *qp; |
| 3157 | struct lpfc_io_buf *lpfc_ncmd; |
| 3158 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3159 | struct lpfc_epd_pool *epd_pool; |
| 3160 | unsigned long iflag; |
| 3161 | |
| 3162 | epd_pool = &phba->epd_pool; |
| 3163 | qp = &phba->sli4_hba.hdwq[0]; |
| 3164 | |
| 3165 | spin_lock_init(&epd_pool->lock); |
| 3166 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3167 | spin_lock(&epd_pool->lock); |
| 3168 | INIT_LIST_HEAD(&epd_pool->list); |
| 3169 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3170 | &qp->lpfc_io_buf_list_put, list) { |
| 3171 | list_move_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 3172 | lpfc_ncmd->expedite = true; |
| 3173 | qp->put_io_bufs--; |
| 3174 | epd_pool->count++; |
| 3175 | if (epd_pool->count >= XRI_BATCH) |
| 3176 | break; |
| 3177 | } |
| 3178 | spin_unlock(&epd_pool->lock); |
| 3179 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3180 | } |
| 3181 | |
| 3182 | /** |
| 3183 | * lpfc_destroy_expedite_pool - destroy expedite pool |
| 3184 | * @phba: pointer to lpfc hba data structure. |
| 3185 | * |
| 3186 | * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put |
| 3187 | * of HWQ 0. Clear the mark. |
| 3188 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3189 | static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3190 | { |
| 3191 | struct lpfc_sli4_hdw_queue *qp; |
| 3192 | struct lpfc_io_buf *lpfc_ncmd; |
| 3193 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3194 | struct lpfc_epd_pool *epd_pool; |
| 3195 | unsigned long iflag; |
| 3196 | |
| 3197 | epd_pool = &phba->epd_pool; |
| 3198 | qp = &phba->sli4_hba.hdwq[0]; |
| 3199 | |
| 3200 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3201 | spin_lock(&epd_pool->lock); |
| 3202 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3203 | &epd_pool->list, list) { |
| 3204 | list_move_tail(&lpfc_ncmd->list, |
| 3205 | &qp->lpfc_io_buf_list_put); |
| 3206 | lpfc_ncmd->flags = false; |
| 3207 | qp->put_io_bufs++; |
| 3208 | epd_pool->count--; |
| 3209 | } |
| 3210 | spin_unlock(&epd_pool->lock); |
| 3211 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3212 | } |
| 3213 | |
| 3214 | /** |
| 3215 | * lpfc_create_multixri_pools - create multi-XRI pools |
| 3216 | * @phba: pointer to lpfc hba data structure. |
| 3217 | * |
| 3218 | * This routine initialize public, private per HWQ. Then, move XRIs from |
| 3219 | * lpfc_io_buf_list_put to public pool. High and low watermark are also |
| 3220 | * Initialized. |
| 3221 | **/ |
| 3222 | void lpfc_create_multixri_pools(struct lpfc_hba *phba) |
| 3223 | { |
| 3224 | u32 i, j; |
| 3225 | u32 hwq_count; |
| 3226 | u32 count_per_hwq; |
| 3227 | struct lpfc_io_buf *lpfc_ncmd; |
| 3228 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3229 | unsigned long iflag; |
| 3230 | struct lpfc_sli4_hdw_queue *qp; |
| 3231 | struct lpfc_multixri_pool *multixri_pool; |
| 3232 | struct lpfc_pbl_pool *pbl_pool; |
| 3233 | struct lpfc_pvt_pool *pvt_pool; |
| 3234 | |
| 3235 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3236 | "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n", |
| 3237 | phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu, |
| 3238 | phba->sli4_hba.io_xri_cnt); |
| 3239 | |
| 3240 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3241 | lpfc_create_expedite_pool(phba); |
| 3242 | |
| 3243 | hwq_count = phba->cfg_hdw_queue; |
| 3244 | count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count; |
| 3245 | |
| 3246 | for (i = 0; i < hwq_count; i++) { |
| 3247 | multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL); |
| 3248 | |
| 3249 | if (!multixri_pool) { |
| 3250 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3251 | "1238 Failed to allocate memory for " |
| 3252 | "multixri_pool\n"); |
| 3253 | |
| 3254 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3255 | lpfc_destroy_expedite_pool(phba); |
| 3256 | |
| 3257 | j = 0; |
| 3258 | while (j < i) { |
| 3259 | qp = &phba->sli4_hba.hdwq[j]; |
| 3260 | kfree(qp->p_multixri_pool); |
| 3261 | j++; |
| 3262 | } |
| 3263 | phba->cfg_xri_rebalancing = 0; |
| 3264 | return; |
| 3265 | } |
| 3266 | |
| 3267 | qp = &phba->sli4_hba.hdwq[i]; |
| 3268 | qp->p_multixri_pool = multixri_pool; |
| 3269 | |
| 3270 | multixri_pool->xri_limit = count_per_hwq; |
| 3271 | multixri_pool->rrb_next_hwqid = i; |
| 3272 | |
| 3273 | /* Deal with public free xri pool */ |
| 3274 | pbl_pool = &multixri_pool->pbl_pool; |
| 3275 | spin_lock_init(&pbl_pool->lock); |
| 3276 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3277 | spin_lock(&pbl_pool->lock); |
| 3278 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3279 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3280 | &qp->lpfc_io_buf_list_put, list) { |
| 3281 | list_move_tail(&lpfc_ncmd->list, &pbl_pool->list); |
| 3282 | qp->put_io_bufs--; |
| 3283 | pbl_pool->count++; |
| 3284 | } |
| 3285 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3286 | "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n", |
| 3287 | pbl_pool->count, i); |
| 3288 | spin_unlock(&pbl_pool->lock); |
| 3289 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3290 | |
| 3291 | /* Deal with private free xri pool */ |
| 3292 | pvt_pool = &multixri_pool->pvt_pool; |
| 3293 | pvt_pool->high_watermark = multixri_pool->xri_limit / 2; |
| 3294 | pvt_pool->low_watermark = XRI_BATCH; |
| 3295 | spin_lock_init(&pvt_pool->lock); |
| 3296 | spin_lock_irqsave(&pvt_pool->lock, iflag); |
| 3297 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3298 | pvt_pool->count = 0; |
| 3299 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | /** |
| 3304 | * lpfc_destroy_multixri_pools - destroy multi-XRI pools |
| 3305 | * @phba: pointer to lpfc hba data structure. |
| 3306 | * |
| 3307 | * This routine returns XRIs from public/private to lpfc_io_buf_list_put. |
| 3308 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3309 | static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3310 | { |
| 3311 | u32 i; |
| 3312 | u32 hwq_count; |
| 3313 | struct lpfc_io_buf *lpfc_ncmd; |
| 3314 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3315 | unsigned long iflag; |
| 3316 | struct lpfc_sli4_hdw_queue *qp; |
| 3317 | struct lpfc_multixri_pool *multixri_pool; |
| 3318 | struct lpfc_pbl_pool *pbl_pool; |
| 3319 | struct lpfc_pvt_pool *pvt_pool; |
| 3320 | |
| 3321 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3322 | lpfc_destroy_expedite_pool(phba); |
| 3323 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 3324 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3325 | lpfc_sli_flush_io_rings(phba); |
James Smart | c66a919 | 2019-03-12 16:30:19 -0700 | [diff] [blame] | 3326 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3327 | hwq_count = phba->cfg_hdw_queue; |
| 3328 | |
| 3329 | for (i = 0; i < hwq_count; i++) { |
| 3330 | qp = &phba->sli4_hba.hdwq[i]; |
| 3331 | multixri_pool = qp->p_multixri_pool; |
| 3332 | if (!multixri_pool) |
| 3333 | continue; |
| 3334 | |
| 3335 | qp->p_multixri_pool = NULL; |
| 3336 | |
| 3337 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3338 | |
| 3339 | /* Deal with public free xri pool */ |
| 3340 | pbl_pool = &multixri_pool->pbl_pool; |
| 3341 | spin_lock(&pbl_pool->lock); |
| 3342 | |
| 3343 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3344 | "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n", |
| 3345 | pbl_pool->count, i); |
| 3346 | |
| 3347 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3348 | &pbl_pool->list, list) { |
| 3349 | list_move_tail(&lpfc_ncmd->list, |
| 3350 | &qp->lpfc_io_buf_list_put); |
| 3351 | qp->put_io_bufs++; |
| 3352 | pbl_pool->count--; |
| 3353 | } |
| 3354 | |
| 3355 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3356 | pbl_pool->count = 0; |
| 3357 | |
| 3358 | spin_unlock(&pbl_pool->lock); |
| 3359 | |
| 3360 | /* Deal with private free xri pool */ |
| 3361 | pvt_pool = &multixri_pool->pvt_pool; |
| 3362 | spin_lock(&pvt_pool->lock); |
| 3363 | |
| 3364 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3365 | "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n", |
| 3366 | pvt_pool->count, i); |
| 3367 | |
| 3368 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3369 | &pvt_pool->list, list) { |
| 3370 | list_move_tail(&lpfc_ncmd->list, |
| 3371 | &qp->lpfc_io_buf_list_put); |
| 3372 | qp->put_io_bufs++; |
| 3373 | pvt_pool->count--; |
| 3374 | } |
| 3375 | |
| 3376 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3377 | pvt_pool->count = 0; |
| 3378 | |
| 3379 | spin_unlock(&pvt_pool->lock); |
| 3380 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3381 | |
| 3382 | kfree(multixri_pool); |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3387 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3388 | * @phba: pointer to lpfc hba data structure. |
| 3389 | * |
| 3390 | * This routine initializes the HBA and brings a HBA online. During this |
| 3391 | * process, the management interface is blocked to prevent user space access |
| 3392 | * to the HBA interfering with the driver initialization. |
| 3393 | * |
| 3394 | * Return codes |
| 3395 | * 0 - successful |
| 3396 | * 1 - failed |
| 3397 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3398 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3399 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3400 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3401 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3402 | struct lpfc_vport **vports; |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3403 | int i, error = 0; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3404 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3405 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | if (!phba) |
| 3407 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3408 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3409 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3410 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3411 | return 0; |
| 3412 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3413 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3414 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3415 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3416 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3418 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3419 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 3420 | lpfc_unblock_mgmt_io(phba); |
| 3421 | return 1; |
| 3422 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3423 | spin_lock_irq(&phba->hbalock); |
| 3424 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 3425 | vpis_cleared = true; |
| 3426 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3427 | |
| 3428 | /* Reestablish the local initiator port. |
| 3429 | * The offline process destroyed the previous lport. |
| 3430 | */ |
| 3431 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
| 3432 | !phba->nvmet_support) { |
| 3433 | error = lpfc_nvme_create_localport(phba->pport); |
| 3434 | if (error) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3435 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3436 | "6132 NVME restore reg failed " |
| 3437 | "on nvmei error x%x\n", error); |
| 3438 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3439 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3440 | lpfc_sli_queue_init(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3441 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 3442 | lpfc_unblock_mgmt_io(phba); |
| 3443 | return 1; |
| 3444 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3445 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3446 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3447 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3448 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3449 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3450 | struct Scsi_Host *shost; |
| 3451 | shost = lpfc_shost_from_vport(vports[i]); |
| 3452 | spin_lock_irq(shost->host_lock); |
| 3453 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 3454 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3455 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3456 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3457 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3458 | if ((vpis_cleared) && |
| 3459 | (vports[i]->port_type != |
| 3460 | LPFC_PHYSICAL_PORT)) |
| 3461 | vports[i]->vpi = 0; |
| 3462 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3463 | spin_unlock_irq(shost->host_lock); |
| 3464 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3465 | } |
| 3466 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3467 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3468 | if (phba->cfg_xri_rebalancing) |
| 3469 | lpfc_create_multixri_pools(phba); |
| 3470 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 3471 | lpfc_cpuhp_add(phba); |
| 3472 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3473 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3474 | return 0; |
| 3475 | } |
| 3476 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3477 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3478 | * 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] | 3479 | * @phba: pointer to lpfc hba data structure. |
| 3480 | * |
| 3481 | * This routine marks a HBA's management interface as not blocked. Once the |
| 3482 | * HBA's management interface is marked as not blocked, all the user space |
| 3483 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 3484 | * interface will be allowed. The HBA is set to block the management interface |
| 3485 | * when the driver prepares the HBA interface for online or offline and then |
| 3486 | * set to unblock the management interface afterwards. |
| 3487 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3488 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3489 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 3490 | { |
| 3491 | unsigned long iflag; |
| 3492 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3493 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3494 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 3495 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3496 | } |
| 3497 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3498 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3499 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3500 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 3501 | * @mbx_action: flag for mailbox shutdown action. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3502 | * |
| 3503 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 3504 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 3505 | * queue to make it ready to be brought offline. |
| 3506 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3507 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3508 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3509 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3510 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3511 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3512 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3513 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3514 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3515 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3516 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3517 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3518 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3519 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3520 | |
| 3521 | lpfc_linkdown(phba); |
| 3522 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3523 | /* Issue an unreg_login to all nodes on all vports */ |
| 3524 | vports = lpfc_create_vport_work_array(phba); |
| 3525 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3526 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3527 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3528 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3529 | shost = lpfc_shost_from_vport(vports[i]); |
| 3530 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3531 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3532 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 3533 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3534 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3535 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3536 | shost = lpfc_shost_from_vport(vports[i]); |
| 3537 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3538 | &vports[i]->fc_nodes, |
| 3539 | nlp_listp) { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3540 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3541 | spin_lock_irq(&ndlp->lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3542 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3543 | spin_unlock_irq(&ndlp->lock); |
James Smart | affbe24 | 2021-07-07 11:43:42 -0700 | [diff] [blame^] | 3544 | |
| 3545 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3546 | /* |
| 3547 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3548 | * RPI. Get a new RPI when the adapter port |
| 3549 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3550 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3551 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 3552 | lpfc_printf_vlog(vports[i], KERN_INFO, |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3553 | LOG_NODE | LOG_DISCOVERY, |
| 3554 | "0011 Free RPI x%x on " |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 3555 | "ndlp: x%px did x%x\n", |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3556 | ndlp->nlp_rpi, ndlp, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3557 | ndlp->nlp_DID); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3558 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3559 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3560 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3561 | |
| 3562 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3563 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3564 | NULL, NLP_EVT_DEVICE_RECOVERY); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 3565 | |
| 3566 | /* Don't remove the node unless the |
| 3567 | * has been unregistered with the |
| 3568 | * transport. If so, let dev_loss |
| 3569 | * take care of the node. |
| 3570 | */ |
| 3571 | if (!(ndlp->fc4_xpt_flags & |
| 3572 | (NVME_XPT_REGD | SCSI_XPT_REGD))) |
| 3573 | lpfc_disc_state_machine |
| 3574 | (vports[i], ndlp, |
| 3575 | NULL, |
| 3576 | NLP_EVT_DEVICE_RM); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3577 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3578 | } |
| 3579 | } |
| 3580 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3581 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3582 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3583 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 3584 | |
| 3585 | if (phba->wq) |
| 3586 | flush_workqueue(phba->wq); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3587 | } |
| 3588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3589 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3590 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3591 | * @phba: pointer to lpfc hba data structure. |
| 3592 | * |
| 3593 | * This routine actually brings a HBA offline. It stops all the timers |
| 3594 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3595 | * marks the HBA as in offline state for the upper layer protocol. |
| 3596 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3597 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3598 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3599 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3600 | struct Scsi_Host *shost; |
| 3601 | struct lpfc_vport **vports; |
| 3602 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3603 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3604 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3605 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3606 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3607 | /* stop port and all timers associated with this hba */ |
| 3608 | lpfc_stop_port(phba); |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 3609 | |
| 3610 | /* Tear down the local and target port registrations. The |
| 3611 | * nvme transports need to cleanup. |
| 3612 | */ |
| 3613 | lpfc_nvmet_destroy_targetport(phba); |
| 3614 | lpfc_nvme_destroy_localport(phba->pport); |
| 3615 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3616 | vports = lpfc_create_vport_work_array(phba); |
| 3617 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3618 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3619 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3620 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3621 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3622 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3623 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3624 | now. */ |
| 3625 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3626 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3627 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3628 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3629 | vports = lpfc_create_vport_work_array(phba); |
| 3630 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3631 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3632 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3633 | spin_lock_irq(shost->host_lock); |
| 3634 | vports[i]->work_port_events = 0; |
| 3635 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3636 | spin_unlock_irq(shost->host_lock); |
| 3637 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3638 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | f0871ab | 2021-01-04 10:02:32 -0800 | [diff] [blame] | 3639 | /* If OFFLINE flag is clear (i.e. unloading), cpuhp removal is handled |
| 3640 | * in hba_unset |
| 3641 | */ |
| 3642 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 3643 | __lpfc_cpuhp_remove(phba); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3644 | |
| 3645 | if (phba->cfg_xri_rebalancing) |
| 3646 | lpfc_destroy_multixri_pools(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3647 | } |
| 3648 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3649 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3650 | * 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] | 3651 | * @phba: pointer to lpfc hba data structure. |
| 3652 | * |
| 3653 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3654 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3655 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3656 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3657 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3658 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3659 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3660 | struct lpfc_io_buf *sb, *sb_next; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3661 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3662 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3663 | return; |
| 3664 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3665 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3666 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3667 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3668 | |
| 3669 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3670 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3671 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3672 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3673 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3674 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3675 | kfree(sb); |
| 3676 | phba->total_scsi_bufs--; |
| 3677 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3678 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3679 | |
| 3680 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3681 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3682 | list) { |
| 3683 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3684 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3685 | sb->dma_handle); |
| 3686 | kfree(sb); |
| 3687 | phba->total_scsi_bufs--; |
| 3688 | } |
| 3689 | spin_unlock(&phba->scsi_buf_list_get_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3690 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3691 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3692 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3693 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3694 | * lpfc_io_free - Free all the IO buffers and IOCBs from driver lists |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3695 | * @phba: pointer to lpfc hba data structure. |
| 3696 | * |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3697 | * This routine is to free all the IO buffers and IOCBs from the driver |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3698 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3699 | * the internal resources before the device is removed from the system. |
| 3700 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3701 | void |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3702 | lpfc_io_free(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3703 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3704 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3705 | struct lpfc_sli4_hdw_queue *qp; |
| 3706 | int idx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3707 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3708 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3709 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3710 | /* Release all the lpfc_nvme_bufs maintained by this host. */ |
| 3711 | spin_lock(&qp->io_buf_list_put_lock); |
| 3712 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3713 | &qp->lpfc_io_buf_list_put, |
| 3714 | list) { |
| 3715 | list_del(&lpfc_ncmd->list); |
| 3716 | qp->put_io_bufs--; |
| 3717 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3718 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3719 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 3720 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 3721 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3722 | kfree(lpfc_ncmd); |
| 3723 | qp->total_io_bufs--; |
| 3724 | } |
| 3725 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3726 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3727 | spin_lock(&qp->io_buf_list_get_lock); |
| 3728 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3729 | &qp->lpfc_io_buf_list_get, |
| 3730 | list) { |
| 3731 | list_del(&lpfc_ncmd->list); |
| 3732 | qp->get_io_bufs--; |
| 3733 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3734 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3735 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 3736 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 3737 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3738 | kfree(lpfc_ncmd); |
| 3739 | qp->total_io_bufs--; |
| 3740 | } |
| 3741 | spin_unlock(&qp->io_buf_list_get_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3742 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3743 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3744 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3745 | /** |
| 3746 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3747 | * @phba: pointer to lpfc hba data structure. |
| 3748 | * |
| 3749 | * This routine first calculates the sizes of the current els and allocated |
| 3750 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3751 | * XRIs assigned due to port function reset. During port initialization, the |
| 3752 | * current els and allocated scsi sgl lists are 0s. |
| 3753 | * |
| 3754 | * Return codes |
| 3755 | * 0 - successful (for now, it always returns 0) |
| 3756 | **/ |
| 3757 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3758 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3759 | { |
| 3760 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3761 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3762 | LIST_HEAD(els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3763 | int rc; |
| 3764 | |
| 3765 | /* |
| 3766 | * update on pci function's els xri-sgl list |
| 3767 | */ |
| 3768 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3769 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3770 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3771 | /* els xri-sgl expanded */ |
| 3772 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3773 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3774 | "3157 ELS xri-sgl count increased from " |
| 3775 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3776 | els_xri_cnt); |
| 3777 | /* allocate the additional els sgls */ |
| 3778 | for (i = 0; i < xri_cnt; i++) { |
| 3779 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3780 | GFP_KERNEL); |
| 3781 | if (sglq_entry == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3782 | lpfc_printf_log(phba, KERN_ERR, |
| 3783 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3784 | "2562 Failure to allocate an " |
| 3785 | "ELS sgl entry:%d\n", i); |
| 3786 | rc = -ENOMEM; |
| 3787 | goto out_free_mem; |
| 3788 | } |
| 3789 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3790 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3791 | &sglq_entry->phys); |
| 3792 | if (sglq_entry->virt == NULL) { |
| 3793 | kfree(sglq_entry); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3794 | lpfc_printf_log(phba, KERN_ERR, |
| 3795 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3796 | "2563 Failure to allocate an " |
| 3797 | "ELS mbuf:%d\n", i); |
| 3798 | rc = -ENOMEM; |
| 3799 | goto out_free_mem; |
| 3800 | } |
| 3801 | sglq_entry->sgl = sglq_entry->virt; |
| 3802 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3803 | sglq_entry->state = SGL_FREED; |
| 3804 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3805 | } |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3806 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3807 | list_splice_init(&els_sgl_list, |
| 3808 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3809 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3810 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3811 | /* els xri-sgl shrinked */ |
| 3812 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3813 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3814 | "3158 ELS xri-sgl count decreased from " |
| 3815 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3816 | els_xri_cnt); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3817 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3818 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, |
| 3819 | &els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3820 | /* release extra els sgls from list */ |
| 3821 | for (i = 0; i < xri_cnt; i++) { |
| 3822 | list_remove_head(&els_sgl_list, |
| 3823 | sglq_entry, struct lpfc_sglq, list); |
| 3824 | if (sglq_entry) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3825 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3826 | sglq_entry->phys); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3827 | kfree(sglq_entry); |
| 3828 | } |
| 3829 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3830 | list_splice_init(&els_sgl_list, |
| 3831 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3832 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3833 | } else |
| 3834 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3835 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3836 | els_xri_cnt); |
| 3837 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3838 | |
| 3839 | /* update xris to els sgls on the list */ |
| 3840 | sglq_entry = NULL; |
| 3841 | sglq_entry_next = NULL; |
| 3842 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3843 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3844 | lxri = lpfc_sli4_next_xritag(phba); |
| 3845 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3846 | lpfc_printf_log(phba, KERN_ERR, |
| 3847 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3848 | "2400 Failed to allocate xri for " |
| 3849 | "ELS sgl\n"); |
| 3850 | rc = -ENOMEM; |
| 3851 | goto out_free_mem; |
| 3852 | } |
| 3853 | sglq_entry->sli4_lxritag = lxri; |
| 3854 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3855 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3856 | return 0; |
| 3857 | |
| 3858 | out_free_mem: |
| 3859 | lpfc_free_els_sgl_list(phba); |
| 3860 | return rc; |
| 3861 | } |
| 3862 | |
| 3863 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3864 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping |
| 3865 | * @phba: pointer to lpfc hba data structure. |
| 3866 | * |
| 3867 | * This routine first calculates the sizes of the current els and allocated |
| 3868 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3869 | * XRIs assigned due to port function reset. During port initialization, the |
| 3870 | * current els and allocated scsi sgl lists are 0s. |
| 3871 | * |
| 3872 | * Return codes |
| 3873 | * 0 - successful (for now, it always returns 0) |
| 3874 | **/ |
| 3875 | int |
| 3876 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) |
| 3877 | { |
| 3878 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3879 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3880 | uint16_t nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3881 | LIST_HEAD(nvmet_sgl_list); |
| 3882 | int rc; |
| 3883 | |
| 3884 | /* |
| 3885 | * update on pci function's nvmet xri-sgl list |
| 3886 | */ |
| 3887 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 3888 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3889 | /* For NVMET, ALL remaining XRIs are dedicated for IO processing */ |
| 3890 | 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] | 3891 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { |
| 3892 | /* els xri-sgl expanded */ |
| 3893 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; |
| 3894 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3895 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", |
| 3896 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); |
| 3897 | /* allocate the additional nvmet sgls */ |
| 3898 | for (i = 0; i < xri_cnt; i++) { |
| 3899 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3900 | GFP_KERNEL); |
| 3901 | if (sglq_entry == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3902 | lpfc_printf_log(phba, KERN_ERR, |
| 3903 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3904 | "6303 Failure to allocate an " |
| 3905 | "NVMET sgl entry:%d\n", i); |
| 3906 | rc = -ENOMEM; |
| 3907 | goto out_free_mem; |
| 3908 | } |
| 3909 | sglq_entry->buff_type = NVMET_BUFF_TYPE; |
| 3910 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, |
| 3911 | &sglq_entry->phys); |
| 3912 | if (sglq_entry->virt == NULL) { |
| 3913 | kfree(sglq_entry); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3914 | lpfc_printf_log(phba, KERN_ERR, |
| 3915 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3916 | "6304 Failure to allocate an " |
| 3917 | "NVMET buf:%d\n", i); |
| 3918 | rc = -ENOMEM; |
| 3919 | goto out_free_mem; |
| 3920 | } |
| 3921 | sglq_entry->sgl = sglq_entry->virt; |
| 3922 | memset(sglq_entry->sgl, 0, |
| 3923 | phba->cfg_sg_dma_buf_size); |
| 3924 | sglq_entry->state = SGL_FREED; |
| 3925 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); |
| 3926 | } |
| 3927 | spin_lock_irq(&phba->hbalock); |
| 3928 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3929 | list_splice_init(&nvmet_sgl_list, |
| 3930 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3931 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3932 | spin_unlock_irq(&phba->hbalock); |
| 3933 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { |
| 3934 | /* nvmet xri-sgl shrunk */ |
| 3935 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; |
| 3936 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3937 | "6305 NVMET xri-sgl count decreased from " |
| 3938 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, |
| 3939 | nvmet_xri_cnt); |
| 3940 | spin_lock_irq(&phba->hbalock); |
| 3941 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3942 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 3943 | &nvmet_sgl_list); |
| 3944 | /* release extra nvmet sgls from list */ |
| 3945 | for (i = 0; i < xri_cnt; i++) { |
| 3946 | list_remove_head(&nvmet_sgl_list, |
| 3947 | sglq_entry, struct lpfc_sglq, list); |
| 3948 | if (sglq_entry) { |
| 3949 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, |
| 3950 | sglq_entry->phys); |
| 3951 | kfree(sglq_entry); |
| 3952 | } |
| 3953 | } |
| 3954 | list_splice_init(&nvmet_sgl_list, |
| 3955 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3956 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3957 | spin_unlock_irq(&phba->hbalock); |
| 3958 | } else |
| 3959 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3960 | "6306 NVMET xri-sgl count unchanged: %d\n", |
| 3961 | nvmet_xri_cnt); |
| 3962 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; |
| 3963 | |
| 3964 | /* update xris to nvmet sgls on the list */ |
| 3965 | sglq_entry = NULL; |
| 3966 | sglq_entry_next = NULL; |
| 3967 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3968 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { |
| 3969 | lxri = lpfc_sli4_next_xritag(phba); |
| 3970 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3971 | lpfc_printf_log(phba, KERN_ERR, |
| 3972 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3973 | "6307 Failed to allocate xri for " |
| 3974 | "NVMET sgl\n"); |
| 3975 | rc = -ENOMEM; |
| 3976 | goto out_free_mem; |
| 3977 | } |
| 3978 | sglq_entry->sli4_lxritag = lxri; |
| 3979 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3980 | } |
| 3981 | return 0; |
| 3982 | |
| 3983 | out_free_mem: |
| 3984 | lpfc_free_nvmet_sgl_list(phba); |
| 3985 | return rc; |
| 3986 | } |
| 3987 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3988 | int |
| 3989 | lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3990 | { |
| 3991 | LIST_HEAD(blist); |
| 3992 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3993 | struct lpfc_io_buf *lpfc_cmd; |
| 3994 | struct lpfc_io_buf *iobufp, *prev_iobufp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3995 | int idx, cnt, xri, inserted; |
| 3996 | |
| 3997 | cnt = 0; |
| 3998 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3999 | qp = &phba->sli4_hba.hdwq[idx]; |
| 4000 | spin_lock_irq(&qp->io_buf_list_get_lock); |
| 4001 | spin_lock(&qp->io_buf_list_put_lock); |
| 4002 | |
| 4003 | /* Take everything off the get and put lists */ |
| 4004 | list_splice_init(&qp->lpfc_io_buf_list_get, &blist); |
| 4005 | list_splice(&qp->lpfc_io_buf_list_put, &blist); |
| 4006 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 4007 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 4008 | cnt += qp->get_io_bufs + qp->put_io_bufs; |
| 4009 | qp->get_io_bufs = 0; |
| 4010 | qp->put_io_bufs = 0; |
| 4011 | qp->total_io_bufs = 0; |
| 4012 | spin_unlock(&qp->io_buf_list_put_lock); |
| 4013 | spin_unlock_irq(&qp->io_buf_list_get_lock); |
| 4014 | } |
| 4015 | |
| 4016 | /* |
| 4017 | * Take IO buffers off blist and put on cbuf sorted by XRI. |
| 4018 | * This is because POST_SGL takes a sequential range of XRIs |
| 4019 | * to post to the firmware. |
| 4020 | */ |
| 4021 | for (idx = 0; idx < cnt; idx++) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4022 | list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4023 | if (!lpfc_cmd) |
| 4024 | return cnt; |
| 4025 | if (idx == 0) { |
| 4026 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 4027 | continue; |
| 4028 | } |
| 4029 | xri = lpfc_cmd->cur_iocbq.sli4_xritag; |
| 4030 | inserted = 0; |
| 4031 | prev_iobufp = NULL; |
| 4032 | list_for_each_entry(iobufp, cbuf, list) { |
| 4033 | if (xri < iobufp->cur_iocbq.sli4_xritag) { |
| 4034 | if (prev_iobufp) |
| 4035 | list_add(&lpfc_cmd->list, |
| 4036 | &prev_iobufp->list); |
| 4037 | else |
| 4038 | list_add(&lpfc_cmd->list, cbuf); |
| 4039 | inserted = 1; |
| 4040 | break; |
| 4041 | } |
| 4042 | prev_iobufp = iobufp; |
| 4043 | } |
| 4044 | if (!inserted) |
| 4045 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 4046 | } |
| 4047 | return cnt; |
| 4048 | } |
| 4049 | |
| 4050 | int |
| 4051 | lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf) |
| 4052 | { |
| 4053 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4054 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4055 | int idx, cnt; |
| 4056 | |
| 4057 | qp = phba->sli4_hba.hdwq; |
| 4058 | cnt = 0; |
| 4059 | while (!list_empty(cbuf)) { |
| 4060 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 4061 | list_remove_head(cbuf, lpfc_cmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4062 | struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4063 | if (!lpfc_cmd) |
| 4064 | return cnt; |
| 4065 | cnt++; |
| 4066 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 4067 | lpfc_cmd->hdwq_no = idx; |
| 4068 | lpfc_cmd->hdwq = qp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4069 | lpfc_cmd->cur_iocbq.wqe_cmpl = NULL; |
| 4070 | lpfc_cmd->cur_iocbq.iocb_cmpl = NULL; |
| 4071 | spin_lock(&qp->io_buf_list_put_lock); |
| 4072 | list_add_tail(&lpfc_cmd->list, |
| 4073 | &qp->lpfc_io_buf_list_put); |
| 4074 | qp->put_io_bufs++; |
| 4075 | qp->total_io_bufs++; |
| 4076 | spin_unlock(&qp->io_buf_list_put_lock); |
| 4077 | } |
| 4078 | } |
| 4079 | return cnt; |
| 4080 | } |
| 4081 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 4082 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4083 | * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4084 | * @phba: pointer to lpfc hba data structure. |
| 4085 | * |
| 4086 | * This routine first calculates the sizes of the current els and allocated |
| 4087 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 4088 | * XRIs assigned due to port function reset. During port initialization, the |
| 4089 | * current els and allocated scsi sgl lists are 0s. |
| 4090 | * |
| 4091 | * Return codes |
| 4092 | * 0 - successful (for now, it always returns 0) |
| 4093 | **/ |
| 4094 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4095 | lpfc_sli4_io_sgl_update(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4096 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4097 | struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4098 | uint16_t i, lxri, els_xri_cnt; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4099 | uint16_t io_xri_cnt, io_xri_max; |
| 4100 | LIST_HEAD(io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4101 | int rc, cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4102 | |
| 4103 | /* |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4104 | * update on pci function's allocated nvme xri-sgl list |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4105 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4106 | |
| 4107 | /* maximum number of xris available for nvme buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4108 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4109 | io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 4110 | phba->sli4_hba.io_xri_max = io_xri_max; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4111 | |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4112 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4113 | "6074 Current allocated XRI sgl count:%d, " |
| 4114 | "maximum XRI count:%d\n", |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4115 | phba->sli4_hba.io_xri_cnt, |
| 4116 | phba->sli4_hba.io_xri_max); |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4117 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4118 | cnt = lpfc_io_buf_flush(phba, &io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4119 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4120 | if (phba->sli4_hba.io_xri_cnt > phba->sli4_hba.io_xri_max) { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4121 | /* max nvme xri shrunk below the allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4122 | io_xri_cnt = phba->sli4_hba.io_xri_cnt - |
| 4123 | phba->sli4_hba.io_xri_max; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4124 | /* release the extra allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4125 | for (i = 0; i < io_xri_cnt; i++) { |
| 4126 | list_remove_head(&io_sgl_list, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4127 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4128 | if (lpfc_ncmd) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 4129 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4130 | lpfc_ncmd->data, |
| 4131 | lpfc_ncmd->dma_handle); |
| 4132 | kfree(lpfc_ncmd); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 4133 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4134 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4135 | phba->sli4_hba.io_xri_cnt -= io_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4136 | } |
| 4137 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4138 | /* update xris associated to remaining allocated nvme buffers */ |
| 4139 | lpfc_ncmd = NULL; |
| 4140 | lpfc_ncmd_next = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4141 | phba->sli4_hba.io_xri_cnt = cnt; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4142 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4143 | &io_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4144 | lxri = lpfc_sli4_next_xritag(phba); |
| 4145 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4146 | lpfc_printf_log(phba, KERN_ERR, |
| 4147 | LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4148 | "6075 Failed to allocate xri for " |
| 4149 | "nvme buffer\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4150 | rc = -ENOMEM; |
| 4151 | goto out_free_mem; |
| 4152 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4153 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; |
| 4154 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4155 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4156 | cnt = lpfc_io_buf_replenish(phba, &io_sgl_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4157 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4158 | |
| 4159 | out_free_mem: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4160 | lpfc_io_free(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4161 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4162 | } |
| 4163 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4164 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4165 | * lpfc_new_io_buf - IO buffer allocator for HBA with SLI4 IF spec |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 4166 | * @phba: Pointer to lpfc hba data structure. |
| 4167 | * @num_to_alloc: The requested number of buffers to allocate. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4168 | * |
| 4169 | * This routine allocates nvme buffers for device with SLI-4 interface spec, |
| 4170 | * the nvme buffer contains all the necessary information needed to initiate |
| 4171 | * an I/O. After allocating up to @num_to_allocate IO buffers and put |
| 4172 | * them on a list, it post them to the port by using SGL block post. |
| 4173 | * |
| 4174 | * Return codes: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4175 | * int - number of IO buffers that were allocated and posted. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4176 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 4177 | **/ |
| 4178 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4179 | lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4180 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4181 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4182 | struct lpfc_iocbq *pwqeq; |
| 4183 | uint16_t iotag, lxri = 0; |
| 4184 | int bcnt, num_posted; |
| 4185 | LIST_HEAD(prep_nblist); |
| 4186 | LIST_HEAD(post_nblist); |
| 4187 | LIST_HEAD(nvme_nblist); |
| 4188 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4189 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4190 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
James Smart | 7f9989b | 2019-08-27 14:27:46 -0700 | [diff] [blame] | 4191 | lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4192 | if (!lpfc_ncmd) |
| 4193 | break; |
| 4194 | /* |
| 4195 | * Get memory from the pci pool to map the virt space to |
| 4196 | * pci bus space for an I/O. The DMA buffer includes the |
| 4197 | * number of SGE's necessary to support the sg_tablesize. |
| 4198 | */ |
Thomas Meyer | a5c990e | 2019-05-29 22:21:36 +0200 | [diff] [blame] | 4199 | lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
| 4200 | GFP_KERNEL, |
| 4201 | &lpfc_ncmd->dma_handle); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4202 | if (!lpfc_ncmd->data) { |
| 4203 | kfree(lpfc_ncmd); |
| 4204 | break; |
| 4205 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4206 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4207 | if (phba->cfg_xpsgl && !phba->nvmet_support) { |
| 4208 | INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list); |
| 4209 | } else { |
| 4210 | /* |
| 4211 | * 4K Page alignment is CRITICAL to BlockGuard, double |
| 4212 | * check to be sure. |
| 4213 | */ |
| 4214 | if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 4215 | (((unsigned long)(lpfc_ncmd->data) & |
| 4216 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4217 | lpfc_printf_log(phba, KERN_ERR, |
| 4218 | LOG_TRACE_EVENT, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4219 | "3369 Memory alignment err: " |
| 4220 | "addr=%lx\n", |
| 4221 | (unsigned long)lpfc_ncmd->data); |
| 4222 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4223 | lpfc_ncmd->data, |
| 4224 | lpfc_ncmd->dma_handle); |
| 4225 | kfree(lpfc_ncmd); |
| 4226 | break; |
| 4227 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4228 | } |
| 4229 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4230 | INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list); |
| 4231 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4232 | lxri = lpfc_sli4_next_xritag(phba); |
| 4233 | if (lxri == NO_XRI) { |
| 4234 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4235 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4236 | kfree(lpfc_ncmd); |
| 4237 | break; |
| 4238 | } |
| 4239 | pwqeq = &lpfc_ncmd->cur_iocbq; |
| 4240 | |
| 4241 | /* Allocate iotag for lpfc_ncmd->cur_iocbq. */ |
| 4242 | iotag = lpfc_sli_next_iotag(phba, pwqeq); |
| 4243 | if (iotag == 0) { |
| 4244 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4245 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4246 | kfree(lpfc_ncmd); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4247 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4248 | "6121 Failed to allocate IOTAG for" |
| 4249 | " XRI:0x%x\n", lxri); |
| 4250 | lpfc_sli4_free_xri(phba, lxri); |
| 4251 | break; |
| 4252 | } |
| 4253 | pwqeq->sli4_lxritag = lxri; |
| 4254 | pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 4255 | pwqeq->context1 = lpfc_ncmd; |
| 4256 | |
| 4257 | /* Initialize local short-hand pointers. */ |
| 4258 | lpfc_ncmd->dma_sgl = lpfc_ncmd->data; |
| 4259 | lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle; |
| 4260 | lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4261 | spin_lock_init(&lpfc_ncmd->buf_lock); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4262 | |
| 4263 | /* add the nvme buffer to a post list */ |
| 4264 | list_add_tail(&lpfc_ncmd->list, &post_nblist); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4265 | phba->sli4_hba.io_xri_cnt++; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4266 | } |
| 4267 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME, |
| 4268 | "6114 Allocate %d out of %d requested new NVME " |
| 4269 | "buffers\n", bcnt, num_to_alloc); |
| 4270 | |
| 4271 | /* post the list of nvme buffer sgls to port if available */ |
| 4272 | if (!list_empty(&post_nblist)) |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4273 | num_posted = lpfc_sli4_post_io_sgl_list( |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4274 | phba, &post_nblist, bcnt); |
| 4275 | else |
| 4276 | num_posted = 0; |
| 4277 | |
| 4278 | return num_posted; |
| 4279 | } |
| 4280 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4281 | static uint64_t |
| 4282 | lpfc_get_wwpn(struct lpfc_hba *phba) |
| 4283 | { |
| 4284 | uint64_t wwn; |
| 4285 | int rc; |
| 4286 | LPFC_MBOXQ_t *mboxq; |
| 4287 | MAILBOX_t *mb; |
| 4288 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4289 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4290 | GFP_KERNEL); |
| 4291 | if (!mboxq) |
| 4292 | return (uint64_t)-1; |
| 4293 | |
| 4294 | /* First get WWN of HBA instance */ |
| 4295 | lpfc_read_nv(phba, mboxq); |
| 4296 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4297 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4298 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4299 | "6019 Mailbox failed , mbxCmd x%x " |
| 4300 | "READ_NV, mbxStatus x%x\n", |
| 4301 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4302 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 4303 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4304 | return (uint64_t) -1; |
| 4305 | } |
| 4306 | mb = &mboxq->u.mb; |
| 4307 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t)); |
| 4308 | /* wwn is WWPN of HBA instance */ |
| 4309 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4310 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4311 | return be64_to_cpu(wwn); |
| 4312 | else |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 4313 | return rol64(wwn, 32); |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4314 | } |
| 4315 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4316 | /** |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 4317 | * lpfc_vmid_res_alloc - Allocates resources for VMID |
| 4318 | * @phba: pointer to lpfc hba data structure. |
| 4319 | * @vport: pointer to vport data structure |
| 4320 | * |
| 4321 | * This routine allocated the resources needed for the VMID. |
| 4322 | * |
| 4323 | * Return codes |
| 4324 | * 0 on Success |
| 4325 | * Non-0 on Failure |
| 4326 | */ |
| 4327 | static int |
| 4328 | lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 4329 | { |
| 4330 | /* VMID feature is supported only on SLI4 */ |
| 4331 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4332 | phba->cfg_vmid_app_header = 0; |
| 4333 | phba->cfg_vmid_priority_tagging = 0; |
| 4334 | } |
| 4335 | |
| 4336 | if (lpfc_is_vmid_enabled(phba)) { |
| 4337 | vport->vmid = |
| 4338 | kcalloc(phba->cfg_max_vmid, sizeof(struct lpfc_vmid), |
| 4339 | GFP_KERNEL); |
| 4340 | if (!vport->vmid) |
| 4341 | return -ENOMEM; |
| 4342 | |
| 4343 | rwlock_init(&vport->vmid_lock); |
| 4344 | |
| 4345 | /* Set the VMID parameters for the vport */ |
| 4346 | vport->vmid_priority_tagging = phba->cfg_vmid_priority_tagging; |
| 4347 | vport->vmid_inactivity_timeout = |
| 4348 | phba->cfg_vmid_inactivity_timeout; |
| 4349 | vport->max_vmid = phba->cfg_max_vmid; |
| 4350 | vport->cur_vmid_cnt = 0; |
| 4351 | |
| 4352 | vport->vmid_priority_range = bitmap_zalloc |
| 4353 | (LPFC_VMID_MAX_PRIORITY_RANGE, GFP_KERNEL); |
| 4354 | |
| 4355 | if (!vport->vmid_priority_range) { |
| 4356 | kfree(vport->vmid); |
| 4357 | return -ENOMEM; |
| 4358 | } |
| 4359 | |
| 4360 | hash_init(vport->hash_table); |
| 4361 | } |
| 4362 | return 0; |
| 4363 | } |
| 4364 | |
| 4365 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4366 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4367 | * @phba: pointer to lpfc hba data structure. |
| 4368 | * @instance: a unique integer ID to this FC port. |
| 4369 | * @dev: pointer to the device data structure. |
| 4370 | * |
| 4371 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 4372 | * can be created on top of either a physical port or a virtual port provided |
| 4373 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 4374 | * and associates the FC port created before adding the shost into the SCSI |
| 4375 | * layer. |
| 4376 | * |
| 4377 | * Return codes |
| 4378 | * @vport - pointer to the virtual N_Port data structure. |
| 4379 | * NULL - port create failed. |
| 4380 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4381 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4382 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4383 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4384 | struct lpfc_vport *vport; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4385 | struct Scsi_Host *shost = NULL; |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4386 | struct scsi_host_template *template; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4387 | int error = 0; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4388 | int i; |
| 4389 | uint64_t wwn; |
| 4390 | bool use_no_reset_hba = false; |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4391 | int rc; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4392 | |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4393 | if (lpfc_no_hba_reset_cnt) { |
| 4394 | if (phba->sli_rev < LPFC_SLI_REV4 && |
| 4395 | dev == &phba->pcidev->dev) { |
| 4396 | /* Reset the port first */ |
| 4397 | lpfc_sli_brdrestart(phba); |
| 4398 | rc = lpfc_sli_chipset_init(phba); |
| 4399 | if (rc) |
| 4400 | return NULL; |
| 4401 | } |
| 4402 | wwn = lpfc_get_wwpn(phba); |
| 4403 | } |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4404 | |
| 4405 | for (i = 0; i < lpfc_no_hba_reset_cnt; i++) { |
| 4406 | if (wwn == lpfc_no_hba_reset[i]) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4407 | lpfc_printf_log(phba, KERN_ERR, |
| 4408 | LOG_TRACE_EVENT, |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4409 | "6020 Setting use_no_reset port=%llx\n", |
| 4410 | wwn); |
| 4411 | use_no_reset_hba = true; |
| 4412 | break; |
| 4413 | } |
| 4414 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4415 | |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4416 | /* Seed template for SCSI host registration */ |
| 4417 | if (dev == &phba->pcidev->dev) { |
| 4418 | template = &phba->port_template; |
| 4419 | |
| 4420 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 4421 | /* Seed physical port template */ |
| 4422 | memcpy(template, &lpfc_template, sizeof(*template)); |
| 4423 | |
James Smart | 7c30bb6 | 2020-10-20 13:27:16 -0700 | [diff] [blame] | 4424 | if (use_no_reset_hba) |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4425 | /* template is for a no reset SCSI Host */ |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4426 | template->eh_host_reset_handler = NULL; |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4427 | |
| 4428 | /* Template for all vports this physical port creates */ |
| 4429 | memcpy(&phba->vport_template, &lpfc_template, |
| 4430 | sizeof(*template)); |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4431 | phba->vport_template.shost_attrs = lpfc_vport_attrs; |
| 4432 | phba->vport_template.eh_bus_reset_handler = NULL; |
| 4433 | phba->vport_template.eh_host_reset_handler = NULL; |
| 4434 | phba->vport_template.vendor_id = 0; |
| 4435 | |
| 4436 | /* Initialize the host templates with updated value */ |
| 4437 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4438 | template->sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 4439 | phba->vport_template.sg_tablesize = |
| 4440 | phba->cfg_scsi_seg_cnt; |
| 4441 | } else { |
| 4442 | template->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4443 | phba->vport_template.sg_tablesize = |
| 4444 | phba->cfg_sg_seg_cnt; |
| 4445 | } |
| 4446 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4447 | } else { |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4448 | /* NVMET is for physical port only */ |
| 4449 | memcpy(template, &lpfc_template_nvme, |
| 4450 | sizeof(*template)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4451 | } |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4452 | } else { |
| 4453 | template = &phba->vport_template; |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 4454 | } |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4455 | |
| 4456 | shost = scsi_host_alloc(template, sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4457 | if (!shost) |
| 4458 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4459 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4460 | vport = (struct lpfc_vport *) shost->hostdata; |
| 4461 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4462 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4463 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4464 | vport->fc_rscn_flush = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4465 | lpfc_get_vport_cfgparam(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4466 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4467 | /* Adjust value in vport */ |
| 4468 | vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type; |
| 4469 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4470 | shost->unique_id = instance; |
| 4471 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4472 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4473 | shost->this_id = -1; |
| 4474 | shost->max_cmd_len = 16; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4475 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4476 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 77ffd34 | 2019-08-15 19:36:49 -0700 | [diff] [blame] | 4477 | if (!phba->cfg_fcp_mq_threshold || |
| 4478 | phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue) |
| 4479 | phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue; |
| 4480 | |
| 4481 | shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(), |
| 4482 | phba->cfg_fcp_mq_threshold); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4483 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4484 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4485 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4486 | |
| 4487 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 4488 | shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE; |
| 4489 | else |
| 4490 | shost->sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 4491 | } else |
| 4492 | /* SLI-3 has a limited number of hardware queues (3), |
| 4493 | * thus there is only one for FCP processing. |
| 4494 | */ |
| 4495 | shost->nr_hw_queues = 1; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 4496 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4497 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4498 | * Set initial can_queue value since 0 is no longer supported and |
| 4499 | * scsi_add_host will fail. This will be adjusted later based on the |
| 4500 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4501 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4502 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4503 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4504 | shost->transportt = lpfc_vport_transport_template; |
| 4505 | vport->port_type = LPFC_NPIV_PORT; |
| 4506 | } else { |
| 4507 | shost->transportt = lpfc_transport_template; |
| 4508 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 4509 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4510 | |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4511 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 4512 | "9081 CreatePort TMPLATE type %x TBLsize %d " |
| 4513 | "SEGcnt %d/%d\n", |
| 4514 | vport->port_type, shost->sg_tablesize, |
| 4515 | phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt); |
| 4516 | |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 4517 | /* Allocate the resources for VMID */ |
| 4518 | rc = lpfc_vmid_res_alloc(phba, vport); |
| 4519 | |
| 4520 | if (rc) |
| 4521 | goto out; |
| 4522 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4523 | /* Initialize all internally managed lists. */ |
| 4524 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4525 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4526 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4527 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4528 | timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4529 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4530 | timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4531 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4532 | timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4533 | |
James Smart | aa6ff30 | 2019-05-21 17:49:09 -0700 | [diff] [blame] | 4534 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 4535 | lpfc_setup_bg(phba, shost); |
| 4536 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 4537 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4538 | if (error) |
| 4539 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4540 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4541 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4542 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4543 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4544 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4545 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4546 | out_put_shost: |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 4547 | kfree(vport->vmid); |
| 4548 | bitmap_free(vport->vmid_priority_range); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4549 | scsi_host_put(shost); |
| 4550 | out: |
| 4551 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4552 | } |
| 4553 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4554 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4555 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4556 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 4557 | * |
| 4558 | * This routine destroys a FC port from the upper layer protocol. All the |
| 4559 | * resources associated with the port are released. |
| 4560 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4561 | void |
| 4562 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4563 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4564 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4565 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4566 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4567 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4568 | fc_remove_host(shost); |
| 4569 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4570 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4571 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4572 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4573 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4574 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4575 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4576 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4577 | } |
| 4578 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4579 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4580 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4581 | * |
| 4582 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 4583 | * uses the kernel idr facility to perform the task. |
| 4584 | * |
| 4585 | * Return codes: |
| 4586 | * instance - a unique integer ID allocated as the new instance. |
| 4587 | * -1 - lpfc get instance failed. |
| 4588 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4589 | int |
| 4590 | lpfc_get_instance(void) |
| 4591 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4592 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4593 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4594 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 4595 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4596 | } |
| 4597 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4598 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4599 | * 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] | 4600 | * @shost: pointer to SCSI host data structure. |
| 4601 | * @time: elapsed time of the scan in jiffies. |
| 4602 | * |
| 4603 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 4604 | * whether the scan host is finished. |
| 4605 | * |
| 4606 | * Note: there is no scan_start function as adapter initialization will have |
| 4607 | * asynchronously kicked off the link initialization. |
| 4608 | * |
| 4609 | * Return codes |
| 4610 | * 0 - SCSI host scan is not over yet. |
| 4611 | * 1 - SCSI host scan is over. |
| 4612 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4613 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 4614 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4615 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4616 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4617 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4618 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4619 | spin_lock_irq(shost->host_lock); |
| 4620 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4621 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4622 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4623 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4624 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4625 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4626 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4627 | "0461 Scanning longer than 30 " |
| 4628 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4629 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4630 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4631 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4632 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 4633 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4634 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4635 | "0465 Link down longer than 15 " |
| 4636 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4637 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4638 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4639 | } |
| 4640 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4641 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4642 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4643 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4644 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4645 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4646 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4647 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4648 | goto finished; |
| 4649 | |
| 4650 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4651 | |
| 4652 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4653 | spin_unlock_irq(shost->host_lock); |
| 4654 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4655 | } |
| 4656 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 4657 | static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost) |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4658 | { |
| 4659 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; |
| 4660 | struct lpfc_hba *phba = vport->phba; |
| 4661 | |
| 4662 | fc_host_supported_speeds(shost) = 0; |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 4663 | /* |
| 4664 | * Avoid reporting supported link speed for FCoE as it can't be |
| 4665 | * controlled via FCoE. |
| 4666 | */ |
| 4667 | if (phba->hba_flag & HBA_FCOE_MODE) |
| 4668 | return; |
| 4669 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4670 | if (phba->lmt & LMT_128Gb) |
| 4671 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4672 | if (phba->lmt & LMT_64Gb) |
| 4673 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT; |
| 4674 | if (phba->lmt & LMT_32Gb) |
| 4675 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
| 4676 | if (phba->lmt & LMT_16Gb) |
| 4677 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
| 4678 | if (phba->lmt & LMT_10Gb) |
| 4679 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
| 4680 | if (phba->lmt & LMT_8Gb) |
| 4681 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
| 4682 | if (phba->lmt & LMT_4Gb) |
| 4683 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 4684 | if (phba->lmt & LMT_2Gb) |
| 4685 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 4686 | if (phba->lmt & LMT_1Gb) |
| 4687 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 4688 | } |
| 4689 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4690 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4691 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4692 | * @shost: pointer to SCSI host data structure. |
| 4693 | * |
| 4694 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 4695 | * SCSI host can be either on top of a physical port or a virtual port. |
| 4696 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4697 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 4698 | { |
| 4699 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4700 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4701 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4702 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4703 | */ |
| 4704 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4705 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 4706 | 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] | 4707 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 4708 | |
| 4709 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4710 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4711 | fc_host_supported_fc4s(shost)[2] = 1; |
| 4712 | fc_host_supported_fc4s(shost)[7] = 1; |
| 4713 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4714 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 4715 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4716 | |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4717 | lpfc_host_supported_speeds_set(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4718 | |
| 4719 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4720 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 4721 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4722 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 4723 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 4724 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4725 | /* This value is also unchanging */ |
| 4726 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4727 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4728 | fc_host_active_fc4s(shost)[2] = 1; |
| 4729 | fc_host_active_fc4s(shost)[7] = 1; |
| 4730 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4731 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4732 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4733 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4734 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4735 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4736 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4737 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4738 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4739 | * @phba: pointer to lpfc hba data structure. |
| 4740 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4741 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 4742 | * from generating interrupts and stops the device driver's timers for the |
| 4743 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4744 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4745 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4746 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4747 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4748 | /* Clear all interrupt enable conditions */ |
| 4749 | writel(0, phba->HCregaddr); |
| 4750 | readl(phba->HCregaddr); /* flush */ |
| 4751 | /* Clear all pending interrupts */ |
| 4752 | writel(0xffffffff, phba->HAregaddr); |
| 4753 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4754 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4755 | /* Reset some HBA SLI setup states */ |
| 4756 | lpfc_stop_hba_timers(phba); |
| 4757 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4758 | } |
| 4759 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4760 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4761 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4762 | * @phba: pointer to lpfc hba data structure. |
| 4763 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4764 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 4765 | * from generating interrupts and stops the device driver's timers for the |
| 4766 | * device. |
| 4767 | **/ |
| 4768 | static void |
| 4769 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 4770 | { |
| 4771 | /* Reset some HBA SLI4 setup states */ |
| 4772 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4773 | if (phba->pport) |
| 4774 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4775 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | /** |
| 4779 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 4780 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4781 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4782 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 4783 | * the API jump table function pointer from the lpfc_hba struct. |
| 4784 | **/ |
| 4785 | void |
| 4786 | lpfc_stop_port(struct lpfc_hba *phba) |
| 4787 | { |
| 4788 | phba->lpfc_stop_port(phba); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 4789 | |
| 4790 | if (phba->wq) |
| 4791 | flush_workqueue(phba->wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4795 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 4796 | * @phba: Pointer to hba for which this call is being executed. |
| 4797 | * |
| 4798 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 4799 | **/ |
| 4800 | void |
| 4801 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 4802 | { |
| 4803 | unsigned long fcf_redisc_wait_tmo = |
| 4804 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 4805 | /* Start fcf rediscovery wait period timer */ |
| 4806 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 4807 | spin_lock_irq(&phba->hbalock); |
| 4808 | /* Allow action to new fcf asynchronous event */ |
| 4809 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 4810 | /* Mark the FCF rediscovery pending state */ |
| 4811 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 4812 | spin_unlock_irq(&phba->hbalock); |
| 4813 | } |
| 4814 | |
| 4815 | /** |
| 4816 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 4817 | * @t: Timer context used to obtain the pointer to lpfc hba data structure. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4818 | * |
| 4819 | * This routine is invoked when waiting for FCF table rediscover has been |
| 4820 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 4821 | * wait period, a new FCF event shall be added to the FCOE async event |
| 4822 | * list, and then worker thread shall be waked up for processing from the |
| 4823 | * worker thread context. |
| 4824 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 4825 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4826 | lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4827 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4828 | struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4829 | |
| 4830 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 4831 | spin_lock_irq(&phba->hbalock); |
| 4832 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 4833 | spin_unlock_irq(&phba->hbalock); |
| 4834 | return; |
| 4835 | } |
| 4836 | /* Clear FCF rediscovery timer pending flag */ |
| 4837 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 4838 | /* FCF rediscovery event to worker thread */ |
| 4839 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 4840 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4841 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4842 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4843 | /* wake up worker thread */ |
| 4844 | lpfc_worker_wake_up(phba); |
| 4845 | } |
| 4846 | |
| 4847 | /** |
Gaurav Srivastava | 2039717 | 2021-06-08 10:05:54 +0530 | [diff] [blame] | 4848 | * lpfc_vmid_poll - VMID timeout detection |
James Smart | 50baa15 | 2021-07-07 11:43:35 -0700 | [diff] [blame] | 4849 | * @t: Timer context used to obtain the pointer to lpfc hba data structure. |
Gaurav Srivastava | 2039717 | 2021-06-08 10:05:54 +0530 | [diff] [blame] | 4850 | * |
| 4851 | * This routine is invoked when there is no I/O on by a VM for the specified |
| 4852 | * amount of time. When this situation is detected, the VMID has to be |
| 4853 | * deregistered from the switch and all the local resources freed. The VMID |
| 4854 | * will be reassigned to the VM once the I/O begins. |
| 4855 | **/ |
| 4856 | static void |
| 4857 | lpfc_vmid_poll(struct timer_list *t) |
| 4858 | { |
| 4859 | struct lpfc_hba *phba = from_timer(phba, t, inactive_vmid_poll); |
| 4860 | u32 wake_up = 0; |
| 4861 | |
| 4862 | /* check if there is a need to issue QFPA */ |
| 4863 | if (phba->pport->vmid_priority_tagging) { |
| 4864 | wake_up = 1; |
| 4865 | phba->pport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA; |
| 4866 | } |
| 4867 | |
| 4868 | /* Is the vmid inactivity timer enabled */ |
| 4869 | if (phba->pport->vmid_inactivity_timeout || |
| 4870 | phba->pport->load_flag & FC_DEREGISTER_ALL_APP_ID) { |
| 4871 | wake_up = 1; |
| 4872 | phba->pport->work_port_events |= WORKER_CHECK_INACTIVE_VMID; |
| 4873 | } |
| 4874 | |
| 4875 | if (wake_up) |
| 4876 | lpfc_worker_wake_up(phba); |
| 4877 | |
| 4878 | /* restart the timer for the next iteration */ |
| 4879 | mod_timer(&phba->inactive_vmid_poll, jiffies + msecs_to_jiffies(1000 * |
| 4880 | LPFC_VMID_TIMER)); |
| 4881 | } |
| 4882 | |
| 4883 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4884 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 4885 | * @phba: pointer to lpfc hba data structure. |
| 4886 | * @acqe_link: pointer to the async link completion queue entry. |
| 4887 | * |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4888 | * This routine is to parse the SLI4 link-attention link fault code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4889 | **/ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4890 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4891 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 4892 | struct lpfc_acqe_link *acqe_link) |
| 4893 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4894 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 4895 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 4896 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 4897 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4898 | case LPFC_ASYNC_LINK_FAULT_LR_LRR: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4899 | break; |
| 4900 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4901 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4902 | "0398 Unknown link fault code: x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4903 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4904 | break; |
| 4905 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | /** |
| 4909 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 4910 | * @phba: pointer to lpfc hba data structure. |
| 4911 | * @acqe_link: pointer to the async link completion queue entry. |
| 4912 | * |
| 4913 | * This routine is to parse the SLI4 link attention type and translate it |
| 4914 | * into the base driver's link attention type coding. |
| 4915 | * |
| 4916 | * Return: Link attention type in terms of base driver's coding. |
| 4917 | **/ |
| 4918 | static uint8_t |
| 4919 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 4920 | struct lpfc_acqe_link *acqe_link) |
| 4921 | { |
| 4922 | uint8_t att_type; |
| 4923 | |
| 4924 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 4925 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 4926 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4927 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4928 | break; |
| 4929 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 4930 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4931 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4932 | break; |
| 4933 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4934 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4935 | break; |
| 4936 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4937 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4938 | "0399 Invalid link attention type: x%x\n", |
| 4939 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4940 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4941 | break; |
| 4942 | } |
| 4943 | return att_type; |
| 4944 | } |
| 4945 | |
| 4946 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4947 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 4948 | * @phba: pointer to lpfc hba data structure. |
| 4949 | * |
| 4950 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 4951 | * |
| 4952 | * Return: link speed in terms of Mbps. |
| 4953 | **/ |
| 4954 | uint32_t |
| 4955 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 4956 | { |
| 4957 | uint32_t link_speed; |
| 4958 | |
| 4959 | if (!lpfc_is_link_up(phba)) |
| 4960 | return 0; |
| 4961 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4962 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 4963 | switch (phba->fc_linkspeed) { |
| 4964 | case LPFC_LINK_SPEED_1GHZ: |
| 4965 | link_speed = 1000; |
| 4966 | break; |
| 4967 | case LPFC_LINK_SPEED_2GHZ: |
| 4968 | link_speed = 2000; |
| 4969 | break; |
| 4970 | case LPFC_LINK_SPEED_4GHZ: |
| 4971 | link_speed = 4000; |
| 4972 | break; |
| 4973 | case LPFC_LINK_SPEED_8GHZ: |
| 4974 | link_speed = 8000; |
| 4975 | break; |
| 4976 | case LPFC_LINK_SPEED_10GHZ: |
| 4977 | link_speed = 10000; |
| 4978 | break; |
| 4979 | case LPFC_LINK_SPEED_16GHZ: |
| 4980 | link_speed = 16000; |
| 4981 | break; |
| 4982 | default: |
| 4983 | link_speed = 0; |
| 4984 | } |
| 4985 | } else { |
| 4986 | if (phba->sli4_hba.link_state.logical_speed) |
| 4987 | link_speed = |
| 4988 | phba->sli4_hba.link_state.logical_speed; |
| 4989 | else |
| 4990 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4991 | } |
| 4992 | return link_speed; |
| 4993 | } |
| 4994 | |
| 4995 | /** |
| 4996 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 4997 | * @phba: pointer to lpfc hba data structure. |
| 4998 | * @evt_code: asynchronous event code. |
| 4999 | * @speed_code: asynchronous event link speed code. |
| 5000 | * |
| 5001 | * This routine is to parse the giving SLI4 async event link speed code into |
| 5002 | * value of Mbps for the link speed. |
| 5003 | * |
| 5004 | * Return: link speed in terms of Mbps. |
| 5005 | **/ |
| 5006 | static uint32_t |
| 5007 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 5008 | uint8_t speed_code) |
| 5009 | { |
| 5010 | uint32_t port_speed; |
| 5011 | |
| 5012 | switch (evt_code) { |
| 5013 | case LPFC_TRAILER_CODE_LINK: |
| 5014 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5015 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5016 | port_speed = 0; |
| 5017 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5018 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5019 | port_speed = 10; |
| 5020 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5021 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5022 | port_speed = 100; |
| 5023 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5024 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5025 | port_speed = 1000; |
| 5026 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5027 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5028 | port_speed = 10000; |
| 5029 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5030 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 5031 | port_speed = 20000; |
| 5032 | break; |
| 5033 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 5034 | port_speed = 25000; |
| 5035 | break; |
| 5036 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 5037 | port_speed = 40000; |
| 5038 | break; |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 5039 | case LPFC_ASYNC_LINK_SPEED_100GBPS: |
| 5040 | port_speed = 100000; |
| 5041 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5042 | default: |
| 5043 | port_speed = 0; |
| 5044 | } |
| 5045 | break; |
| 5046 | case LPFC_TRAILER_CODE_FC: |
| 5047 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5048 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5049 | port_speed = 0; |
| 5050 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5051 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5052 | port_speed = 1000; |
| 5053 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5054 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5055 | port_speed = 2000; |
| 5056 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5057 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5058 | port_speed = 4000; |
| 5059 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5060 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5061 | port_speed = 8000; |
| 5062 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5063 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5064 | port_speed = 10000; |
| 5065 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5066 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5067 | port_speed = 16000; |
| 5068 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 5069 | case LPFC_FC_LA_SPEED_32G: |
| 5070 | port_speed = 32000; |
| 5071 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 5072 | case LPFC_FC_LA_SPEED_64G: |
| 5073 | port_speed = 64000; |
| 5074 | break; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5075 | case LPFC_FC_LA_SPEED_128G: |
| 5076 | port_speed = 128000; |
| 5077 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5078 | default: |
| 5079 | port_speed = 0; |
| 5080 | } |
| 5081 | break; |
| 5082 | default: |
| 5083 | port_speed = 0; |
| 5084 | } |
| 5085 | return port_speed; |
| 5086 | } |
| 5087 | |
| 5088 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5089 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5090 | * @phba: pointer to lpfc hba data structure. |
| 5091 | * @acqe_link: pointer to the async link completion queue entry. |
| 5092 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5093 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5094 | **/ |
| 5095 | static void |
| 5096 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 5097 | struct lpfc_acqe_link *acqe_link) |
| 5098 | { |
| 5099 | struct lpfc_dmabuf *mp; |
| 5100 | LPFC_MBOXQ_t *pmb; |
| 5101 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5102 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5103 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5104 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5105 | |
| 5106 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5107 | 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] | 5108 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 5109 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5110 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5111 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5112 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5113 | "0395 The mboxq allocation failed\n"); |
| 5114 | return; |
| 5115 | } |
| 5116 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5117 | if (!mp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5118 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5119 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 5120 | goto out_free_pmb; |
| 5121 | } |
| 5122 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 5123 | if (!mp->virt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5124 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5125 | "0397 The mbuf allocation failed\n"); |
| 5126 | goto out_free_dmabuf; |
| 5127 | } |
| 5128 | |
| 5129 | /* Cleanup any outstanding ELS commands */ |
| 5130 | lpfc_els_flush_all_cmd(phba); |
| 5131 | |
| 5132 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5133 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5134 | |
| 5135 | /* Update link event statistics */ |
| 5136 | phba->sli.slistat.link_event++; |
| 5137 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5138 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5139 | lpfc_read_topology(phba, pmb, mp); |
| 5140 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5141 | pmb->vport = phba->pport; |
| 5142 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5143 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5144 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5145 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 5146 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5147 | phba->sli4_hba.link_state.duplex = |
| 5148 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 5149 | phba->sli4_hba.link_state.status = |
| 5150 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5151 | phba->sli4_hba.link_state.type = |
| 5152 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 5153 | phba->sli4_hba.link_state.number = |
| 5154 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5155 | phba->sli4_hba.link_state.fault = |
| 5156 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 5157 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5158 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 5159 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5160 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 5161 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 5162 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 5163 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5164 | phba->sli4_hba.link_state.speed, |
| 5165 | phba->sli4_hba.link_state.topology, |
| 5166 | phba->sli4_hba.link_state.status, |
| 5167 | phba->sli4_hba.link_state.type, |
| 5168 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5169 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5170 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5171 | /* |
| 5172 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 5173 | * topology info. Note: Optional for non FC-AL ports. |
| 5174 | */ |
| 5175 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 5176 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5177 | if (rc == MBX_NOT_FINISHED) |
| 5178 | goto out_free_dmabuf; |
| 5179 | return; |
| 5180 | } |
| 5181 | /* |
| 5182 | * For FCoE Mode: fill in all the topology information we need and call |
| 5183 | * the READ_TOPOLOGY completion routine to continue without actually |
| 5184 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 5185 | */ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5186 | /* Initialize completion status */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5187 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5188 | mb->mbxStatus = MBX_SUCCESS; |
| 5189 | |
| 5190 | /* Parse port fault information field */ |
| 5191 | lpfc_sli4_parse_latt_fault(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5192 | |
| 5193 | /* Parse and translate link attention fields */ |
| 5194 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 5195 | la->eventTag = acqe_link->event_tag; |
| 5196 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 5197 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5198 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5199 | |
| 5200 | /* Fake the the following irrelvant fields */ |
| 5201 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 5202 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 5203 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 5204 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 5205 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 5206 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5207 | |
| 5208 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5209 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5210 | |
| 5211 | return; |
| 5212 | |
| 5213 | out_free_dmabuf: |
| 5214 | kfree(mp); |
| 5215 | out_free_pmb: |
| 5216 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5217 | } |
| 5218 | |
| 5219 | /** |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5220 | * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read |
| 5221 | * topology. |
| 5222 | * @phba: pointer to lpfc hba data structure. |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5223 | * @speed_code: asynchronous event link speed code. |
| 5224 | * |
| 5225 | * This routine is to parse the giving SLI4 async event link speed code into |
| 5226 | * value of Read topology link speed. |
| 5227 | * |
| 5228 | * Return: link speed in terms of Read topology. |
| 5229 | **/ |
| 5230 | static uint8_t |
| 5231 | lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code) |
| 5232 | { |
| 5233 | uint8_t port_speed; |
| 5234 | |
| 5235 | switch (speed_code) { |
| 5236 | case LPFC_FC_LA_SPEED_1G: |
| 5237 | port_speed = LPFC_LINK_SPEED_1GHZ; |
| 5238 | break; |
| 5239 | case LPFC_FC_LA_SPEED_2G: |
| 5240 | port_speed = LPFC_LINK_SPEED_2GHZ; |
| 5241 | break; |
| 5242 | case LPFC_FC_LA_SPEED_4G: |
| 5243 | port_speed = LPFC_LINK_SPEED_4GHZ; |
| 5244 | break; |
| 5245 | case LPFC_FC_LA_SPEED_8G: |
| 5246 | port_speed = LPFC_LINK_SPEED_8GHZ; |
| 5247 | break; |
| 5248 | case LPFC_FC_LA_SPEED_16G: |
| 5249 | port_speed = LPFC_LINK_SPEED_16GHZ; |
| 5250 | break; |
| 5251 | case LPFC_FC_LA_SPEED_32G: |
| 5252 | port_speed = LPFC_LINK_SPEED_32GHZ; |
| 5253 | break; |
| 5254 | case LPFC_FC_LA_SPEED_64G: |
| 5255 | port_speed = LPFC_LINK_SPEED_64GHZ; |
| 5256 | break; |
| 5257 | case LPFC_FC_LA_SPEED_128G: |
| 5258 | port_speed = LPFC_LINK_SPEED_128GHZ; |
| 5259 | break; |
| 5260 | case LPFC_FC_LA_SPEED_256G: |
| 5261 | port_speed = LPFC_LINK_SPEED_256GHZ; |
| 5262 | break; |
| 5263 | default: |
| 5264 | port_speed = 0; |
| 5265 | break; |
| 5266 | } |
| 5267 | |
| 5268 | return port_speed; |
| 5269 | } |
| 5270 | |
| 5271 | #define trunk_link_status(__idx)\ |
| 5272 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5273 | ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\ |
| 5274 | "Link up" : "Link down") : "NA" |
| 5275 | /* Did port __idx reported an error */ |
| 5276 | #define trunk_port_fault(__idx)\ |
| 5277 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5278 | (port_fault & (1 << __idx) ? "YES" : "NO") : "NA" |
| 5279 | |
| 5280 | static void |
| 5281 | lpfc_update_trunk_link_status(struct lpfc_hba *phba, |
| 5282 | struct lpfc_acqe_fc_la *acqe_fc) |
| 5283 | { |
| 5284 | uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc); |
| 5285 | uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc); |
| 5286 | |
| 5287 | phba->sli4_hba.link_state.speed = |
| 5288 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5289 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5290 | |
| 5291 | phba->sli4_hba.link_state.logical_speed = |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5292 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5293 | /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */ |
| 5294 | phba->fc_linkspeed = |
| 5295 | lpfc_async_link_speed_to_read_top( |
| 5296 | phba, |
| 5297 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5298 | |
| 5299 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) { |
| 5300 | phba->trunk_link.link0.state = |
| 5301 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc) |
| 5302 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5303 | phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5304 | } |
| 5305 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) { |
| 5306 | phba->trunk_link.link1.state = |
| 5307 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc) |
| 5308 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5309 | phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5310 | } |
| 5311 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) { |
| 5312 | phba->trunk_link.link2.state = |
| 5313 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc) |
| 5314 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5315 | phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5316 | } |
| 5317 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) { |
| 5318 | phba->trunk_link.link3.state = |
| 5319 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc) |
| 5320 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5321 | phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5322 | } |
| 5323 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5324 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5325 | "2910 Async FC Trunking Event - Speed:%d\n" |
| 5326 | "\tLogical speed:%d " |
| 5327 | "port0: %s port1: %s port2: %s port3: %s\n", |
| 5328 | phba->sli4_hba.link_state.speed, |
| 5329 | phba->sli4_hba.link_state.logical_speed, |
| 5330 | trunk_link_status(0), trunk_link_status(1), |
| 5331 | trunk_link_status(2), trunk_link_status(3)); |
| 5332 | |
| 5333 | if (port_fault) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5334 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5335 | "3202 trunk error:0x%x (%s) seen on port0:%s " |
| 5336 | /* |
| 5337 | * SLI-4: We have only 0xA error codes |
| 5338 | * defined as of now. print an appropriate |
| 5339 | * message in case driver needs to be updated. |
| 5340 | */ |
| 5341 | "port1:%s port2:%s port3:%s\n", err, err > 0xA ? |
| 5342 | "UNDEFINED. update driver." : trunk_errmsg[err], |
| 5343 | trunk_port_fault(0), trunk_port_fault(1), |
| 5344 | trunk_port_fault(2), trunk_port_fault(3)); |
| 5345 | } |
| 5346 | |
| 5347 | |
| 5348 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5349 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 5350 | * @phba: pointer to lpfc hba data structure. |
| 5351 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 5352 | * |
| 5353 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 5354 | * that the event was received and then issue a read_topology mailbox command so |
| 5355 | * that the rest of the driver will treat it the same as SLI3. |
| 5356 | **/ |
| 5357 | static void |
| 5358 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 5359 | { |
| 5360 | struct lpfc_dmabuf *mp; |
| 5361 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5362 | MAILBOX_t *mb; |
| 5363 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5364 | int rc; |
| 5365 | |
| 5366 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 5367 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5368 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5369 | "2895 Non FC link Event detected.(%d)\n", |
| 5370 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 5371 | return; |
| 5372 | } |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5373 | |
| 5374 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5375 | LPFC_FC_LA_TYPE_TRUNKING_EVENT) { |
| 5376 | lpfc_update_trunk_link_status(phba, acqe_fc); |
| 5377 | return; |
| 5378 | } |
| 5379 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5380 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5381 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5382 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5383 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5384 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 5385 | phba->sli4_hba.link_state.topology = |
| 5386 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 5387 | phba->sli4_hba.link_state.status = |
| 5388 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 5389 | phba->sli4_hba.link_state.type = |
| 5390 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 5391 | phba->sli4_hba.link_state.number = |
| 5392 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 5393 | phba->sli4_hba.link_state.fault = |
| 5394 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5395 | |
| 5396 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5397 | LPFC_FC_LA_TYPE_LINK_DOWN) |
| 5398 | phba->sli4_hba.link_state.logical_speed = 0; |
| 5399 | else if (!phba->sli4_hba.conf_trunk) |
| 5400 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5401 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5402 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5403 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5404 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 5405 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 5406 | "%dMbps Fault:%d\n", |
| 5407 | phba->sli4_hba.link_state.speed, |
| 5408 | phba->sli4_hba.link_state.topology, |
| 5409 | phba->sli4_hba.link_state.status, |
| 5410 | phba->sli4_hba.link_state.type, |
| 5411 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5412 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5413 | phba->sli4_hba.link_state.fault); |
| 5414 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5415 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5416 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5417 | "2897 The mboxq allocation failed\n"); |
| 5418 | return; |
| 5419 | } |
| 5420 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5421 | if (!mp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5422 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5423 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 5424 | goto out_free_pmb; |
| 5425 | } |
| 5426 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 5427 | if (!mp->virt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5428 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5429 | "2899 The mbuf allocation failed\n"); |
| 5430 | goto out_free_dmabuf; |
| 5431 | } |
| 5432 | |
| 5433 | /* Cleanup any outstanding ELS commands */ |
| 5434 | lpfc_els_flush_all_cmd(phba); |
| 5435 | |
| 5436 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5437 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5438 | |
| 5439 | /* Update link event statistics */ |
| 5440 | phba->sli.slistat.link_event++; |
| 5441 | |
| 5442 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5443 | lpfc_read_topology(phba, pmb, mp); |
| 5444 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 5445 | pmb->vport = phba->pport; |
| 5446 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5447 | 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] | 5448 | phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK); |
| 5449 | |
| 5450 | switch (phba->sli4_hba.link_state.status) { |
| 5451 | case LPFC_FC_LA_TYPE_MDS_LINK_DOWN: |
| 5452 | phba->link_flag |= LS_MDS_LINK_DOWN; |
| 5453 | break; |
| 5454 | case LPFC_FC_LA_TYPE_MDS_LOOPBACK: |
| 5455 | phba->link_flag |= LS_MDS_LOOPBACK; |
| 5456 | break; |
| 5457 | default: |
| 5458 | break; |
| 5459 | } |
| 5460 | |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5461 | /* Initialize completion status */ |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5462 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5463 | mb->mbxStatus = MBX_SUCCESS; |
| 5464 | |
| 5465 | /* Parse port fault information field */ |
| 5466 | lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5467 | |
| 5468 | /* Parse and translate link attention fields */ |
| 5469 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 5470 | la->eventTag = acqe_fc->event_tag; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5471 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 5472 | if (phba->sli4_hba.link_state.status == |
| 5473 | LPFC_FC_LA_TYPE_UNEXP_WWPN) { |
| 5474 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5475 | LPFC_FC_LA_TYPE_UNEXP_WWPN); |
| 5476 | } else { |
| 5477 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5478 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 5479 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5480 | /* Invoke the mailbox command callback function */ |
| 5481 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 5482 | |
| 5483 | return; |
| 5484 | } |
| 5485 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5486 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5487 | if (rc == MBX_NOT_FINISHED) |
| 5488 | goto out_free_dmabuf; |
| 5489 | return; |
| 5490 | |
| 5491 | out_free_dmabuf: |
| 5492 | kfree(mp); |
| 5493 | out_free_pmb: |
| 5494 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5495 | } |
| 5496 | |
| 5497 | /** |
| 5498 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 5499 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5500 | * @acqe_sli: pointer to the async SLI completion queue entry. |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5501 | * |
| 5502 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 5503 | **/ |
| 5504 | static void |
| 5505 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 5506 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5507 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 5508 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5509 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5510 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5511 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5512 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5513 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5514 | struct Scsi_Host *shost; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5515 | struct lpfc_vport **vports; |
| 5516 | int rc, i; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5517 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5518 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 5519 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5520 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5521 | "2901 Async SLI event - Type:%d, Event Data: x%08x " |
| 5522 | "x%08x x%08x x%08x\n", evt_type, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5523 | acqe_sli->event_data1, acqe_sli->event_data2, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5524 | acqe_sli->reserved, acqe_sli->trailer); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5525 | |
| 5526 | port_name = phba->Port[0]; |
| 5527 | if (port_name == 0x00) |
| 5528 | port_name = '?'; /* get port name is empty */ |
| 5529 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5530 | switch (evt_type) { |
| 5531 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 5532 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5533 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 5534 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5535 | |
| 5536 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5537 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 5538 | acqe_sli->event_data1, port_name); |
| 5539 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5540 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5541 | shost = lpfc_shost_from_vport(phba->pport); |
| 5542 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5543 | sizeof(temp_event_data), |
| 5544 | (char *)&temp_event_data, |
| 5545 | SCSI_NL_VID_TYPE_PCI |
| 5546 | | PCI_VENDOR_ID_EMULEX); |
| 5547 | break; |
| 5548 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 5549 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5550 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 5551 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5552 | |
| 5553 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5554 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 5555 | acqe_sli->event_data1, port_name); |
| 5556 | |
| 5557 | shost = lpfc_shost_from_vport(phba->pport); |
| 5558 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5559 | sizeof(temp_event_data), |
| 5560 | (char *)&temp_event_data, |
| 5561 | SCSI_NL_VID_TYPE_PCI |
| 5562 | | PCI_VENDOR_ID_EMULEX); |
| 5563 | break; |
| 5564 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 5565 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5566 | &acqe_sli->event_data1; |
| 5567 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5568 | /* fetch the status for this port */ |
| 5569 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5570 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5571 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 5572 | &misconfigured->theEvent); |
| 5573 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5574 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5575 | break; |
| 5576 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5577 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 5578 | &misconfigured->theEvent); |
| 5579 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5580 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5581 | break; |
| 5582 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5583 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 5584 | &misconfigured->theEvent); |
| 5585 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5586 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5587 | break; |
| 5588 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5589 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 5590 | &misconfigured->theEvent); |
| 5591 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5592 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5593 | break; |
| 5594 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5595 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5596 | "3296 " |
| 5597 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 5598 | "event: Invalid link %d", |
| 5599 | phba->sli4_hba.lnk_info.lnk_no); |
| 5600 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5601 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5602 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5603 | /* Skip if optic state unchanged */ |
| 5604 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 5605 | return; |
| 5606 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5607 | switch (status) { |
| 5608 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5609 | sprintf(message, "Physical Link is functional"); |
| 5610 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5611 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 5612 | sprintf(message, "Optics faulted/incorrectly " |
| 5613 | "installed/not installed - Reseat optics, " |
| 5614 | "if issue not resolved, replace."); |
| 5615 | break; |
| 5616 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 5617 | sprintf(message, |
| 5618 | "Optics of two types installed - Remove one " |
| 5619 | "optic or install matching pair of optics."); |
| 5620 | break; |
| 5621 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 5622 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 5623 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5624 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5625 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 5626 | sprintf(message, "Unqualified optics - Replace with " |
| 5627 | "Avago optics for Warranty and Technical " |
| 5628 | "Support - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5629 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5630 | break; |
| 5631 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 5632 | sprintf(message, "Uncertified optics - Replace with " |
| 5633 | "Avago-certified optics to enable link " |
| 5634 | "operation - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5635 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5636 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5637 | default: |
| 5638 | /* firmware is reporting a status we don't know about */ |
| 5639 | sprintf(message, "Unknown event status x%02x", status); |
| 5640 | break; |
| 5641 | } |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5642 | |
| 5643 | /* Issue READ_CONFIG mbox command to refresh supported speeds */ |
| 5644 | rc = lpfc_sli4_read_config(phba); |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5645 | if (rc) { |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5646 | phba->lmt = 0; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5647 | lpfc_printf_log(phba, KERN_ERR, |
| 5648 | LOG_TRACE_EVENT, |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5649 | "3194 Unable to retrieve supported " |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5650 | "speeds, rc = 0x%x\n", rc); |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5651 | } |
| 5652 | vports = lpfc_create_vport_work_array(phba); |
| 5653 | if (vports != NULL) { |
| 5654 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5655 | i++) { |
| 5656 | shost = lpfc_shost_from_vport(vports[i]); |
| 5657 | lpfc_host_supported_speeds_set(shost); |
| 5658 | } |
| 5659 | } |
| 5660 | lpfc_destroy_vport_work_array(phba, vports); |
| 5661 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5662 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5663 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5664 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5665 | break; |
| 5666 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 5667 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5668 | "3192 Remote DPort Test Initiated - " |
| 5669 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 5670 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5671 | break; |
James Smart | e7d8595 | 2019-10-18 14:18:29 -0700 | [diff] [blame] | 5672 | case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN: |
| 5673 | /* Misconfigured WWN. Reports that the SLI Port is configured |
| 5674 | * to use FA-WWN, but the attached device doesn’t support it. |
| 5675 | * No driver action is required. |
| 5676 | * Event Data1 - N.A, Event Data2 - N.A |
| 5677 | */ |
| 5678 | lpfc_log_msg(phba, KERN_WARNING, LOG_SLI, |
| 5679 | "2699 Misconfigured FA-WWN - Attached device does " |
| 5680 | "not support FA-WWN\n"); |
| 5681 | break; |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5682 | case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE: |
| 5683 | /* EEPROM failure. No driver action is required */ |
| 5684 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5685 | "2518 EEPROM failure - " |
| 5686 | "Event Data1: x%08x Event Data2: x%08x\n", |
| 5687 | acqe_sli->event_data1, acqe_sli->event_data2); |
| 5688 | break; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5689 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5690 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5691 | "3193 Unrecognized SLI event, type: 0x%x", |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5692 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5693 | break; |
| 5694 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5698 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 5699 | * @vport: pointer to vport data structure. |
| 5700 | * |
| 5701 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 5702 | * response to a CVL event. |
| 5703 | * |
| 5704 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 5705 | * return NULL. |
| 5706 | **/ |
| 5707 | static struct lpfc_nodelist * |
| 5708 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 5709 | { |
| 5710 | struct lpfc_nodelist *ndlp; |
| 5711 | struct Scsi_Host *shost; |
| 5712 | struct lpfc_hba *phba; |
| 5713 | |
| 5714 | if (!vport) |
| 5715 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5716 | phba = vport->phba; |
| 5717 | if (!phba) |
| 5718 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5719 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 5720 | if (!ndlp) { |
| 5721 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5722 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5723 | if (!ndlp) |
| 5724 | return 0; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5725 | /* Set the node type */ |
| 5726 | ndlp->nlp_type |= NLP_FABRIC; |
| 5727 | /* Put ndlp onto node list */ |
| 5728 | lpfc_enqueue_node(vport, ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5729 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5730 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 5731 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5732 | return NULL; |
| 5733 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5734 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 5735 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5736 | return NULL; |
| 5737 | shost = lpfc_shost_from_vport(vport); |
| 5738 | if (!shost) |
| 5739 | return NULL; |
| 5740 | lpfc_linkdown_port(vport); |
| 5741 | lpfc_cleanup_pending_mbox(vport); |
| 5742 | spin_lock_irq(shost->host_lock); |
| 5743 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 5744 | spin_unlock_irq(shost->host_lock); |
| 5745 | |
| 5746 | return ndlp; |
| 5747 | } |
| 5748 | |
| 5749 | /** |
| 5750 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5751 | * @phba: pointer to lpfc hba data structure. |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5752 | * |
| 5753 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 5754 | * response to a FCF dead event. |
| 5755 | **/ |
| 5756 | static void |
| 5757 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 5758 | { |
| 5759 | struct lpfc_vport **vports; |
| 5760 | int i; |
| 5761 | |
| 5762 | vports = lpfc_create_vport_work_array(phba); |
| 5763 | if (vports) |
| 5764 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 5765 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 5766 | lpfc_destroy_vport_work_array(phba, vports); |
| 5767 | } |
| 5768 | |
| 5769 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5770 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5771 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5772 | * @acqe_fip: pointer to the async fcoe completion queue entry. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5773 | * |
| 5774 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 5775 | **/ |
| 5776 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5777 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5778 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5779 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5780 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5781 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5782 | struct lpfc_vport *vport; |
| 5783 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5784 | int active_vlink_present; |
| 5785 | struct lpfc_vport **vports; |
| 5786 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5787 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5788 | phba->fc_eventTag = acqe_fip->event_tag; |
| 5789 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5790 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5791 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 5792 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 5793 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5794 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5795 | "2546 New FCF event, evt_tag:x%x, " |
| 5796 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5797 | acqe_fip->event_tag, |
| 5798 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5799 | else |
| 5800 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 5801 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5802 | "2788 FCF param modified event, " |
| 5803 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5804 | acqe_fip->event_tag, |
| 5805 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5806 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5807 | /* |
| 5808 | * During period of FCF discovery, read the FCF |
| 5809 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5810 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5811 | */ |
| 5812 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5813 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5814 | "2779 Read FCF (x%x) for updating " |
| 5815 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5816 | acqe_fip->index); |
| 5817 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5818 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5819 | |
| 5820 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5821 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5822 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5823 | spin_unlock_irq(&phba->hbalock); |
| 5824 | break; |
| 5825 | } |
| 5826 | /* If fast FCF failover rescan event is pending, do nothing */ |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 5827 | if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5828 | spin_unlock_irq(&phba->hbalock); |
| 5829 | break; |
| 5830 | } |
| 5831 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5832 | /* If the FCF has been in discovered state, do nothing. */ |
| 5833 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5834 | spin_unlock_irq(&phba->hbalock); |
| 5835 | break; |
| 5836 | } |
| 5837 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5838 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5839 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 5840 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5841 | "2770 Start FCF table scan per async FCF " |
| 5842 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5843 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5844 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 5845 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5846 | if (rc) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5847 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5848 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5849 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5850 | break; |
| 5851 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5852 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5853 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 5854 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
| 5855 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 5856 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5857 | break; |
| 5858 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5859 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5860 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5861 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 5862 | "2549 FCF (x%x) disconnected from network, " |
| 5863 | "tag:x%x\n", acqe_fip->index, |
| 5864 | acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5865 | /* |
| 5866 | * If we are in the middle of FCF failover process, clear |
| 5867 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5868 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5869 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame] | 5870 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 5871 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5872 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5873 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5874 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5875 | break; |
| 5876 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5877 | spin_unlock_irq(&phba->hbalock); |
| 5878 | |
| 5879 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5880 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5881 | break; |
| 5882 | |
| 5883 | /* |
| 5884 | * Otherwise, request the port to rediscover the entire FCF |
| 5885 | * table for a fast recovery from case that the current FCF |
| 5886 | * is no longer valid as we are not in the middle of FCF |
| 5887 | * failover process already. |
| 5888 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5889 | spin_lock_irq(&phba->hbalock); |
| 5890 | /* Mark the fast failover process in progress */ |
| 5891 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 5892 | spin_unlock_irq(&phba->hbalock); |
| 5893 | |
| 5894 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 5895 | "2771 Start FCF fast failover process due to " |
| 5896 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 5897 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 5898 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 5899 | if (rc) { |
| 5900 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5901 | LOG_TRACE_EVENT, |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5902 | "2772 Issue FCF rediscover mailbox " |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5903 | "command failed, fail through to FCF " |
| 5904 | "dead event\n"); |
| 5905 | spin_lock_irq(&phba->hbalock); |
| 5906 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 5907 | spin_unlock_irq(&phba->hbalock); |
| 5908 | /* |
| 5909 | * Last resort will fail over by treating this |
| 5910 | * as a link down to FCF registration. |
| 5911 | */ |
| 5912 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 5913 | } else { |
| 5914 | /* Reset FCF roundrobin bmask for new discovery */ |
| 5915 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 5916 | /* |
| 5917 | * Handling fast FCF failover to a DEAD FCF event is |
| 5918 | * considered equalivant to receiving CVL to all vports. |
| 5919 | */ |
| 5920 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 5921 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5922 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5923 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5924 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5925 | lpfc_printf_log(phba, KERN_ERR, |
| 5926 | LOG_TRACE_EVENT, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5927 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5928 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5929 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5930 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5931 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5932 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5933 | if (!ndlp) |
| 5934 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5935 | active_vlink_present = 0; |
| 5936 | |
| 5937 | vports = lpfc_create_vport_work_array(phba); |
| 5938 | if (vports) { |
| 5939 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5940 | i++) { |
| 5941 | if ((!(vports[i]->fc_flag & |
| 5942 | FC_VPORT_CVL_RCVD)) && |
| 5943 | (vports[i]->port_state > LPFC_FDISC)) { |
| 5944 | active_vlink_present = 1; |
| 5945 | break; |
| 5946 | } |
| 5947 | } |
| 5948 | lpfc_destroy_vport_work_array(phba, vports); |
| 5949 | } |
| 5950 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 5951 | /* |
| 5952 | * Don't re-instantiate if vport is marked for deletion. |
| 5953 | * If we are here first then vport_delete is going to wait |
| 5954 | * for discovery to complete. |
| 5955 | */ |
| 5956 | if (!(vport->load_flag & FC_UNLOADING) && |
| 5957 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5958 | /* |
| 5959 | * If there are other active VLinks present, |
| 5960 | * re-instantiate the Vlink using FDISC. |
| 5961 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 5962 | mod_timer(&ndlp->nlp_delayfunc, |
| 5963 | jiffies + msecs_to_jiffies(1000)); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5964 | spin_lock_irq(&ndlp->lock); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5965 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5966 | spin_unlock_irq(&ndlp->lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5967 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 5968 | vport->port_state = LPFC_FDISC; |
| 5969 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5970 | /* |
| 5971 | * Otherwise, we request port to rediscover |
| 5972 | * the entire FCF table for a fast recovery |
| 5973 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5974 | * is no longer valid if we are not already |
| 5975 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5976 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5977 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5978 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5979 | spin_unlock_irq(&phba->hbalock); |
| 5980 | break; |
| 5981 | } |
| 5982 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5983 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5984 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5985 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5986 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5987 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5988 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5989 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5990 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5991 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5992 | LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5993 | "2774 Issue FCF rediscover " |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5994 | "mailbox command failed, " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5995 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5996 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5997 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5998 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5999 | /* |
| 6000 | * Last resort will be re-try on the |
| 6001 | * the current registered FCF entry. |
| 6002 | */ |
| 6003 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6004 | } else |
| 6005 | /* |
| 6006 | * Reset FCF roundrobin bmask for new |
| 6007 | * discovery. |
| 6008 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 6009 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6010 | } |
| 6011 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6012 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6013 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6014 | "0288 Unknown FCoE event type 0x%x event tag " |
| 6015 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6016 | break; |
| 6017 | } |
| 6018 | } |
| 6019 | |
| 6020 | /** |
| 6021 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 6022 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 6023 | * @acqe_dcbx: pointer to the async dcbx completion queue entry. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6024 | * |
| 6025 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 6026 | **/ |
| 6027 | static void |
| 6028 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 6029 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 6030 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6031 | phba->fc_eventTag = acqe_dcbx->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6032 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6033 | "0290 The SLI4 DCBX asynchronous event is not " |
| 6034 | "handled yet\n"); |
| 6035 | } |
| 6036 | |
| 6037 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 6038 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 6039 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 6040 | * @acqe_grp5: pointer to the async grp5 completion queue entry. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 6041 | * |
| 6042 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 6043 | * is an asynchronous notified of a logical link speed change. The Port |
| 6044 | * reports the logical link speed in units of 10Mbps. |
| 6045 | **/ |
| 6046 | static void |
| 6047 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 6048 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 6049 | { |
| 6050 | uint16_t prev_ll_spd; |
| 6051 | |
| 6052 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 6053 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 6054 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 6055 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 6056 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 6057 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6058 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 6059 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 6060 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6064 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 6065 | * @phba: pointer to lpfc hba data structure. |
| 6066 | * |
| 6067 | * This routine is invoked by the worker thread to process all the pending |
| 6068 | * SLI4 asynchronous events. |
| 6069 | **/ |
| 6070 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 6071 | { |
| 6072 | struct lpfc_cq_event *cq_event; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6073 | unsigned long iflags; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6074 | |
| 6075 | /* First, declare the async event has been handled */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6076 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6077 | phba->hba_flag &= ~ASYNC_EVENT; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6078 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 6079 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6080 | /* Now, handle all the async events */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6081 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6082 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6083 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 6084 | cq_event, struct lpfc_cq_event, list); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6085 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, |
| 6086 | iflags); |
| 6087 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6088 | /* Process the asynchronous event */ |
| 6089 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 6090 | case LPFC_TRAILER_CODE_LINK: |
| 6091 | lpfc_sli4_async_link_evt(phba, |
| 6092 | &cq_event->cqe.acqe_link); |
| 6093 | break; |
| 6094 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6095 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6096 | break; |
| 6097 | case LPFC_TRAILER_CODE_DCBX: |
| 6098 | lpfc_sli4_async_dcbx_evt(phba, |
| 6099 | &cq_event->cqe.acqe_dcbx); |
| 6100 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 6101 | case LPFC_TRAILER_CODE_GRP5: |
| 6102 | lpfc_sli4_async_grp5_evt(phba, |
| 6103 | &cq_event->cqe.acqe_grp5); |
| 6104 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6105 | case LPFC_TRAILER_CODE_FC: |
| 6106 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 6107 | break; |
| 6108 | case LPFC_TRAILER_CODE_SLI: |
| 6109 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 6110 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6111 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6112 | lpfc_printf_log(phba, KERN_ERR, |
| 6113 | LOG_TRACE_EVENT, |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 6114 | "1804 Invalid asynchronous event code: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6115 | "x%x\n", bf_get(lpfc_trailer_code, |
| 6116 | &cq_event->cqe.mcqe_cmpl)); |
| 6117 | break; |
| 6118 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6119 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6120 | /* Free the completion event processed to the free pool */ |
| 6121 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6122 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6123 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6124 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6125 | } |
| 6126 | |
| 6127 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6128 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 6129 | * @phba: pointer to lpfc hba data structure. |
| 6130 | * |
| 6131 | * This routine is invoked by the worker thread to process FCF table |
| 6132 | * rediscovery pending completion event. |
| 6133 | **/ |
| 6134 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 6135 | { |
| 6136 | int rc; |
| 6137 | |
| 6138 | spin_lock_irq(&phba->hbalock); |
| 6139 | /* Clear FCF rediscovery timeout event */ |
| 6140 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 6141 | /* Clear driver fast failover FCF record flag */ |
| 6142 | phba->fcf.failover_rec.flag = 0; |
| 6143 | /* Set state for FCF fast failover */ |
| 6144 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 6145 | spin_unlock_irq(&phba->hbalock); |
| 6146 | |
| 6147 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6148 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6149 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6150 | 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] | 6151 | if (rc) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6152 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6153 | "2747 Issue FCF scan read FCF mailbox " |
| 6154 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6158 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 6159 | * @phba: pointer to lpfc hba data structure. |
| 6160 | * @dev_grp: The HBA PCI-Device group number. |
| 6161 | * |
| 6162 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 6163 | * API jump table entries. |
| 6164 | * |
| 6165 | * Return: 0 if success, otherwise -ENODEV |
| 6166 | **/ |
| 6167 | int |
| 6168 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6169 | { |
| 6170 | int rc; |
| 6171 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6172 | /* Set up lpfc PCI-device group */ |
| 6173 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6174 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6175 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 6176 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 6177 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6178 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6179 | /* Set up device INIT API function jump table */ |
| 6180 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 6181 | if (rc) |
| 6182 | return -ENODEV; |
| 6183 | /* Set up SCSI API function jump table */ |
| 6184 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 6185 | if (rc) |
| 6186 | return -ENODEV; |
| 6187 | /* Set up SLI API function jump table */ |
| 6188 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 6189 | if (rc) |
| 6190 | return -ENODEV; |
| 6191 | /* Set up MBOX API function jump table */ |
| 6192 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 6193 | if (rc) |
| 6194 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6195 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6196 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6200 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6201 | * @phba: pointer to lpfc hba data structure. |
| 6202 | * @intr_mode: active interrupt mode adopted. |
| 6203 | * |
| 6204 | * This routine it invoked to log the currently used active interrupt mode |
| 6205 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6206 | **/ |
| 6207 | 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] | 6208 | { |
| 6209 | switch (intr_mode) { |
| 6210 | case 0: |
| 6211 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6212 | "0470 Enable INTx interrupt mode.\n"); |
| 6213 | break; |
| 6214 | case 1: |
| 6215 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6216 | "0481 Enabled MSI interrupt mode.\n"); |
| 6217 | break; |
| 6218 | case 2: |
| 6219 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6220 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 6221 | break; |
| 6222 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6223 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6224 | "0482 Illegal interrupt mode.\n"); |
| 6225 | break; |
| 6226 | } |
| 6227 | return; |
| 6228 | } |
| 6229 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6230 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6231 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6232 | * @phba: pointer to lpfc hba data structure. |
| 6233 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6234 | * This routine is invoked to enable the PCI device that is common to all |
| 6235 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6236 | * |
| 6237 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6238 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6239 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6240 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6241 | static int |
| 6242 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6243 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6244 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6245 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6246 | /* Obtain PCI device reference */ |
| 6247 | if (!phba->pcidev) |
| 6248 | goto out_error; |
| 6249 | else |
| 6250 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6251 | /* Enable PCI device */ |
| 6252 | if (pci_enable_device_mem(pdev)) |
| 6253 | goto out_error; |
| 6254 | /* Request PCI resource for the device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6255 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6256 | goto out_disable_device; |
| 6257 | /* Set up device as PCI master and save state for EEH */ |
| 6258 | pci_set_master(pdev); |
| 6259 | pci_try_set_mwi(pdev); |
| 6260 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6261 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6262 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 6263 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6264 | pdev->needs_freset = 1; |
| 6265 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6266 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6267 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6268 | out_disable_device: |
| 6269 | pci_disable_device(pdev); |
| 6270 | out_error: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6271 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6272 | "1401 Failed to enable pci device\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6273 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6274 | } |
| 6275 | |
| 6276 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6277 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6278 | * @phba: pointer to lpfc hba data structure. |
| 6279 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6280 | * This routine is invoked to disable the PCI device that is common to all |
| 6281 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6282 | **/ |
| 6283 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6284 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6285 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6286 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6287 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6288 | /* Obtain PCI device reference */ |
| 6289 | if (!phba->pcidev) |
| 6290 | return; |
| 6291 | else |
| 6292 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6293 | /* Release PCI resource and disable PCI device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6294 | pci_release_mem_regions(pdev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6295 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6296 | |
| 6297 | return; |
| 6298 | } |
| 6299 | |
| 6300 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6301 | * lpfc_reset_hba - Reset a hba |
| 6302 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6303 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6304 | * This routine is invoked to reset a hba device. It brings the HBA |
| 6305 | * offline, performs a board restart, and then brings the board back |
| 6306 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 6307 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6308 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6309 | void |
| 6310 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6311 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6312 | /* If resets are disabled then set error state and return. */ |
| 6313 | if (!phba->cfg_enable_hba_reset) { |
| 6314 | phba->link_state = LPFC_HBA_ERROR; |
| 6315 | return; |
| 6316 | } |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 6317 | |
| 6318 | /* If not LPFC_SLI_ACTIVE, force all IO to be flushed */ |
| 6319 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6320 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 6321 | } else { |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6322 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 6323 | lpfc_sli_flush_io_rings(phba); |
| 6324 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6325 | lpfc_offline(phba); |
| 6326 | lpfc_sli_brdrestart(phba); |
| 6327 | lpfc_online(phba); |
| 6328 | lpfc_unblock_mgmt_io(phba); |
| 6329 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6330 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6331 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6332 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 6333 | * @phba: pointer to lpfc hba data structure. |
| 6334 | * |
| 6335 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6336 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6337 | * enable the number of virtual functions to the physical function. As |
| 6338 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6339 | * API call does not considered as an error condition for most of the device. |
| 6340 | **/ |
| 6341 | uint16_t |
| 6342 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 6343 | { |
| 6344 | struct pci_dev *pdev = phba->pcidev; |
| 6345 | uint16_t nr_virtfn; |
| 6346 | int pos; |
| 6347 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6348 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 6349 | if (pos == 0) |
| 6350 | return 0; |
| 6351 | |
| 6352 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 6353 | return nr_virtfn; |
| 6354 | } |
| 6355 | |
| 6356 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6357 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 6358 | * @phba: pointer to lpfc hba data structure. |
| 6359 | * @nr_vfn: number of virtual functions to be enabled. |
| 6360 | * |
| 6361 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6362 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6363 | * enable the number of virtual functions to the physical function. As |
| 6364 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6365 | * API call does not considered as an error condition for most of the device. |
| 6366 | **/ |
| 6367 | int |
| 6368 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 6369 | { |
| 6370 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6371 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6372 | int rc; |
| 6373 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6374 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 6375 | if (nr_vfn > max_nr_vfn) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6376 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6377 | "3057 Requested vfs (%d) greater than " |
| 6378 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 6379 | return -EINVAL; |
| 6380 | } |
| 6381 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6382 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 6383 | if (rc) { |
| 6384 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6385 | "2806 Failed to enable sriov on this device " |
| 6386 | "with vfn number nr_vf:%d, rc:%d\n", |
| 6387 | nr_vfn, rc); |
| 6388 | } else |
| 6389 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6390 | "2807 Successful enable sriov on this device " |
| 6391 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 6392 | return rc; |
| 6393 | } |
| 6394 | |
| 6395 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6396 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6397 | * @phba: pointer to lpfc hba data structure. |
| 6398 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6399 | * This routine is invoked to set up the driver internal resources before the |
| 6400 | * device specific resource setup to support the HBA device it attached to. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6401 | * |
| 6402 | * Return codes |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6403 | * 0 - successful |
| 6404 | * other values - error |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6405 | **/ |
| 6406 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6407 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6408 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6409 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6410 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6411 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6412 | * Driver resources common to all SLI revisions |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6413 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6414 | atomic_set(&phba->fast_event_count, 0); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6415 | atomic_set(&phba->dbg_log_idx, 0); |
| 6416 | atomic_set(&phba->dbg_log_cnt, 0); |
| 6417 | atomic_set(&phba->dbg_log_dmping, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6418 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6419 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6420 | /* Initialize port_list spinlock */ |
| 6421 | spin_lock_init(&phba->port_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6422 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6423 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6424 | INIT_LIST_HEAD(&phba->work_list); |
| 6425 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| 6426 | |
| 6427 | /* Initialize the wait queue head for the kernel thread */ |
| 6428 | init_waitqueue_head(&phba->work_waitq); |
| 6429 | |
| 6430 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6431 | "1403 Protocols supported %s %s %s\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6432 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
| 6433 | "SCSI" : " "), |
| 6434 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6435 | "NVME" : " "), |
| 6436 | (phba->nvmet_support ? "NVMET" : " ")); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6437 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6438 | /* Initialize the IO buffer list used by driver for SLI3 SCSI */ |
| 6439 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 6440 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 6441 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 6442 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6443 | |
| 6444 | /* Initialize the fabric iocb list */ |
| 6445 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 6446 | |
| 6447 | /* Initialize list to save ELS buffers */ |
| 6448 | INIT_LIST_HEAD(&phba->elsbuf); |
| 6449 | |
| 6450 | /* Initialize FCF connection rec list */ |
| 6451 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| 6452 | |
| 6453 | /* Initialize OAS configuration list */ |
| 6454 | spin_lock_init(&phba->devicelock); |
| 6455 | INIT_LIST_HEAD(&phba->luns); |
| 6456 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6457 | /* MBOX heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6458 | timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6459 | /* Fabric block timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6460 | timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6461 | /* EA polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6462 | timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6463 | /* Heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6464 | timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6465 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6466 | INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work); |
| 6467 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 6468 | INIT_DELAYED_WORK(&phba->idle_stat_delay_work, |
| 6469 | lpfc_idle_stat_delay_work); |
| 6470 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6471 | return 0; |
| 6472 | } |
| 6473 | |
| 6474 | /** |
| 6475 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev |
| 6476 | * @phba: pointer to lpfc hba data structure. |
| 6477 | * |
| 6478 | * This routine is invoked to set up the driver internal resources specific to |
| 6479 | * support the SLI-3 HBA device it attached to. |
| 6480 | * |
| 6481 | * Return codes |
| 6482 | * 0 - successful |
| 6483 | * other values - error |
| 6484 | **/ |
| 6485 | static int |
| 6486 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 6487 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6488 | int rc, entry_sz; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6489 | |
| 6490 | /* |
| 6491 | * Initialize timers used by driver |
| 6492 | */ |
| 6493 | |
| 6494 | /* FCP polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6495 | timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6496 | |
| 6497 | /* Host attention work mask setup */ |
| 6498 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 6499 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 6500 | |
| 6501 | /* Get all the module params for configuring this host */ |
| 6502 | lpfc_get_cfgparam(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6503 | /* Set up phase-1 common device driver resources */ |
| 6504 | |
| 6505 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6506 | if (rc) |
| 6507 | return -ENODEV; |
| 6508 | |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6509 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 6510 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 6511 | /* check for menlo minimum sg count */ |
| 6512 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 6513 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 6514 | } |
| 6515 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6516 | if (!phba->sli.sli3_ring) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6517 | phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING, |
| 6518 | sizeof(struct lpfc_sli_ring), |
| 6519 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6520 | if (!phba->sli.sli3_ring) |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6521 | return -ENOMEM; |
| 6522 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6523 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6524 | * 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] | 6525 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6526 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6527 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6528 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6529 | entry_sz = sizeof(struct sli4_sge); |
| 6530 | else |
| 6531 | entry_sz = sizeof(struct ulp_bde64); |
| 6532 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6533 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 6534 | if (phba->cfg_enable_bg) { |
| 6535 | /* |
| 6536 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 6537 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 6538 | * over how many protection data segments the SCSI Layer |
| 6539 | * will hand us (ie: there could be one for every block |
| 6540 | * in the IO), we just allocate enough BDEs to accomidate |
| 6541 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 6542 | * minimize the risk of running out. |
| 6543 | */ |
| 6544 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6545 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6546 | (LPFC_MAX_SG_SEG_CNT * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6547 | |
| 6548 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 6549 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 6550 | |
| 6551 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 6552 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 6553 | } else { |
| 6554 | /* |
| 6555 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 6556 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 6557 | * cfg_sg_seg_cnt data segments. |
| 6558 | */ |
| 6559 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6560 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6561 | ((phba->cfg_sg_seg_cnt + 2) * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6562 | |
| 6563 | /* Total BDEs in BPL for scsi_sg_list */ |
| 6564 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 6565 | } |
| 6566 | |
| 6567 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 6568 | "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6569 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 6570 | phba->cfg_total_seg_cnt); |
| 6571 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6572 | phba->max_vpi = LPFC_MAX_VPI; |
| 6573 | /* This will be set to correct value after config_port mbox */ |
| 6574 | phba->max_vports = 0; |
| 6575 | |
| 6576 | /* |
| 6577 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 6578 | */ |
| 6579 | lpfc_sli_setup(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6580 | lpfc_sli_queue_init(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6581 | |
| 6582 | /* Allocate device driver memory */ |
| 6583 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 6584 | return -ENOMEM; |
| 6585 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6586 | phba->lpfc_sg_dma_buf_pool = |
| 6587 | dma_pool_create("lpfc_sg_dma_buf_pool", |
| 6588 | &phba->pcidev->dev, phba->cfg_sg_dma_buf_size, |
| 6589 | BPL_ALIGN_SZ, 0); |
| 6590 | |
| 6591 | if (!phba->lpfc_sg_dma_buf_pool) |
| 6592 | goto fail_free_mem; |
| 6593 | |
| 6594 | phba->lpfc_cmd_rsp_buf_pool = |
| 6595 | dma_pool_create("lpfc_cmd_rsp_buf_pool", |
| 6596 | &phba->pcidev->dev, |
| 6597 | sizeof(struct fcp_cmnd) + |
| 6598 | sizeof(struct fcp_rsp), |
| 6599 | BPL_ALIGN_SZ, 0); |
| 6600 | |
| 6601 | if (!phba->lpfc_cmd_rsp_buf_pool) |
| 6602 | goto fail_free_dma_buf_pool; |
| 6603 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6604 | /* |
| 6605 | * Enable sr-iov virtual functions if supported and configured |
| 6606 | * through the module parameter. |
| 6607 | */ |
| 6608 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6609 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6610 | phba->cfg_sriov_nr_virtfn); |
| 6611 | if (rc) { |
| 6612 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6613 | "2808 Requested number of SR-IOV " |
| 6614 | "virtual functions (%d) is not " |
| 6615 | "supported\n", |
| 6616 | phba->cfg_sriov_nr_virtfn); |
| 6617 | phba->cfg_sriov_nr_virtfn = 0; |
| 6618 | } |
| 6619 | } |
| 6620 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6621 | return 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6622 | |
| 6623 | fail_free_dma_buf_pool: |
| 6624 | dma_pool_destroy(phba->lpfc_sg_dma_buf_pool); |
| 6625 | phba->lpfc_sg_dma_buf_pool = NULL; |
| 6626 | fail_free_mem: |
| 6627 | lpfc_mem_free(phba); |
| 6628 | return -ENOMEM; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6629 | } |
| 6630 | |
| 6631 | /** |
| 6632 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 6633 | * @phba: pointer to lpfc hba data structure. |
| 6634 | * |
| 6635 | * This routine is invoked to unset the driver internal resources set up |
| 6636 | * specific for supporting the SLI-3 HBA device it attached to. |
| 6637 | **/ |
| 6638 | static void |
| 6639 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 6640 | { |
| 6641 | /* Free device driver memory allocated */ |
| 6642 | lpfc_mem_free_all(phba); |
| 6643 | |
| 6644 | return; |
| 6645 | } |
| 6646 | |
| 6647 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6648 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 6649 | * @phba: pointer to lpfc hba data structure. |
| 6650 | * |
| 6651 | * This routine is invoked to set up the driver internal resources specific to |
| 6652 | * support the SLI-4 HBA device it attached to. |
| 6653 | * |
| 6654 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6655 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6656 | * other values - error |
| 6657 | **/ |
| 6658 | static int |
| 6659 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 6660 | { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6661 | LPFC_MBOXQ_t *mboxq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6662 | MAILBOX_t *mb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6663 | int rc, i, max_buf_size; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6664 | int longs; |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6665 | int extra; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6666 | uint64_t wwn; |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6667 | u32 if_type; |
| 6668 | u32 if_fam; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6669 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6670 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | eede497 | 2019-11-21 09:55:56 -0800 | [diff] [blame] | 6671 | phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6672 | phba->sli4_hba.curr_disp_cpu = 0; |
| 6673 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 6674 | /* Get all the module params for configuring this host */ |
| 6675 | lpfc_get_cfgparam(phba); |
| 6676 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6677 | /* Set up phase-1 common device driver resources */ |
| 6678 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6679 | if (rc) |
| 6680 | return -ENODEV; |
| 6681 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6682 | /* Before proceed, wait for POST done and device ready */ |
| 6683 | rc = lpfc_sli4_post_status_check(phba); |
| 6684 | if (rc) |
| 6685 | return -ENODEV; |
| 6686 | |
James Smart | 3cee98d | 2019-08-14 16:56:34 -0700 | [diff] [blame] | 6687 | /* Allocate all driver workqueues here */ |
| 6688 | |
| 6689 | /* The lpfc_wq workqueue for deferred irq use */ |
| 6690 | phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); |
| 6691 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6692 | /* |
| 6693 | * Initialize timers used by driver |
| 6694 | */ |
| 6695 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6696 | timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6697 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6698 | /* FCF rediscover timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6699 | 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] | 6700 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6701 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 6702 | * Control structure for handling external multi-buffer mailbox |
| 6703 | * command pass-through. |
| 6704 | */ |
| 6705 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 6706 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 6707 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 6708 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6709 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6710 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6711 | /* This will be set to correct value after the read_config mbox */ |
| 6712 | phba->max_vports = 0; |
| 6713 | |
| 6714 | /* Program the default value of vlan_id and fc_map */ |
| 6715 | phba->valid_vlan = 0; |
| 6716 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 6717 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 6718 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 6719 | |
| 6720 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6721 | * 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] | 6722 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
| 6723 | * The WQ create will allocate the ring. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6724 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6725 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6726 | /* Initialize buffer queue management fields */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6727 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6728 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 6729 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 6730 | |
Gaurav Srivastava | 2039717 | 2021-06-08 10:05:54 +0530 | [diff] [blame] | 6731 | /* for VMID idle timeout if VMID is enabled */ |
| 6732 | if (lpfc_is_vmid_enabled(phba)) |
| 6733 | timer_setup(&phba->inactive_vmid_poll, lpfc_vmid_poll, 0); |
| 6734 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6735 | /* |
| 6736 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 6737 | */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 6738 | /* Initialize the Abort buffer list used by driver */ |
| 6739 | spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock); |
| 6740 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6741 | |
| 6742 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6743 | /* Initialize the Abort nvme buffer list used by driver */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6744 | spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 6745 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6746 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list); |
James Smart | 79d8c4c | 2019-05-21 17:48:56 -0700 | [diff] [blame] | 6747 | spin_lock_init(&phba->sli4_hba.t_active_list_lock); |
| 6748 | INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6749 | } |
| 6750 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6751 | /* This abort list used by worker thread */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6752 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6753 | spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6754 | spin_lock_init(&phba->sli4_hba.asynce_list_lock); |
| 6755 | spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6756 | |
| 6757 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6758 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6759 | */ |
| 6760 | |
| 6761 | /* Driver internel slow-path CQ Event pool */ |
| 6762 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 6763 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6764 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6765 | /* Asynchronous event CQ Event work queue list */ |
| 6766 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6767 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 6768 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 6769 | /* Receive queue CQ Event work queue list */ |
| 6770 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 6771 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6772 | /* Initialize extent block lists. */ |
| 6773 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 6774 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 6775 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 6776 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 6777 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6778 | /* Initialize mboxq lists. If the early init routines fail |
| 6779 | * these lists need to be correctly initialized. |
| 6780 | */ |
| 6781 | INIT_LIST_HEAD(&phba->sli.mboxq); |
| 6782 | INIT_LIST_HEAD(&phba->sli.mboxq_cmpl); |
| 6783 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6784 | /* initialize optic_state to 0xFF */ |
| 6785 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 6786 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6787 | /* Allocate device driver memory */ |
| 6788 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 6789 | if (rc) |
| 6790 | return -ENOMEM; |
| 6791 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6792 | /* IF Type 2 ports get initialized now. */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 6793 | 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] | 6794 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 6795 | rc = lpfc_pci_function_reset(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6796 | if (unlikely(rc)) { |
| 6797 | rc = -ENODEV; |
| 6798 | goto out_free_mem; |
| 6799 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6800 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6801 | } |
| 6802 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6803 | /* Create the bootstrap mailbox command */ |
| 6804 | rc = lpfc_create_bootstrap_mbox(phba); |
| 6805 | if (unlikely(rc)) |
| 6806 | goto out_free_mem; |
| 6807 | |
| 6808 | /* Set up the host's endian order with the device. */ |
| 6809 | rc = lpfc_setup_endian_order(phba); |
| 6810 | if (unlikely(rc)) |
| 6811 | goto out_free_bsmbx; |
| 6812 | |
| 6813 | /* Set up the hba's configuration parameters. */ |
| 6814 | rc = lpfc_sli4_read_config(phba); |
| 6815 | if (unlikely(rc)) |
| 6816 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6817 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 6818 | if (unlikely(rc)) |
| 6819 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6820 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6821 | /* IF Type 0 ports get initialized now. */ |
| 6822 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6823 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6824 | rc = lpfc_pci_function_reset(phba); |
| 6825 | if (unlikely(rc)) |
| 6826 | goto out_free_bsmbx; |
| 6827 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6828 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6829 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6830 | GFP_KERNEL); |
| 6831 | if (!mboxq) { |
| 6832 | rc = -ENOMEM; |
| 6833 | goto out_free_bsmbx; |
| 6834 | } |
| 6835 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6836 | /* Check for NVMET being configured */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6837 | phba->nvmet_support = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6838 | if (lpfc_enable_nvmet_cnt) { |
| 6839 | |
| 6840 | /* First get WWN of HBA instance */ |
| 6841 | lpfc_read_nv(phba, mboxq); |
| 6842 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6843 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6844 | lpfc_printf_log(phba, KERN_ERR, |
| 6845 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6846 | "6016 Mailbox failed , mbxCmd x%x " |
| 6847 | "READ_NV, mbxStatus x%x\n", |
| 6848 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 6849 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6850 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6851 | rc = -EIO; |
| 6852 | goto out_free_bsmbx; |
| 6853 | } |
| 6854 | mb = &mboxq->u.mb; |
| 6855 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, |
| 6856 | sizeof(uint64_t)); |
| 6857 | wwn = cpu_to_be64(wwn); |
| 6858 | phba->sli4_hba.wwnn.u.name = wwn; |
| 6859 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, |
| 6860 | sizeof(uint64_t)); |
| 6861 | /* wwn is WWPN of HBA instance */ |
| 6862 | wwn = cpu_to_be64(wwn); |
| 6863 | phba->sli4_hba.wwpn.u.name = wwn; |
| 6864 | |
| 6865 | /* Check to see if it matches any module parameter */ |
| 6866 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { |
| 6867 | if (wwn == lpfc_enable_nvmet[i]) { |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6868 | #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6869 | if (lpfc_nvmet_mem_alloc(phba)) |
| 6870 | break; |
| 6871 | |
| 6872 | phba->nvmet_support = 1; /* a match */ |
| 6873 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6874 | lpfc_printf_log(phba, KERN_ERR, |
| 6875 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6876 | "6017 NVME Target %016llx\n", |
| 6877 | wwn); |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6878 | #else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6879 | lpfc_printf_log(phba, KERN_ERR, |
| 6880 | LOG_TRACE_EVENT, |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6881 | "6021 Can't enable NVME Target." |
| 6882 | " NVME_TARGET_FC infrastructure" |
| 6883 | " is not in kernel\n"); |
| 6884 | #endif |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 6885 | /* Not supported for NVMET */ |
| 6886 | phba->cfg_xri_rebalancing = 0; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 6887 | if (phba->irq_chann_mode == NHT_MODE) { |
| 6888 | phba->cfg_irq_chann = |
| 6889 | phba->sli4_hba.num_present_cpu; |
| 6890 | phba->cfg_hdw_queue = |
| 6891 | phba->sli4_hba.num_present_cpu; |
| 6892 | phba->irq_chann_mode = NORMAL_MODE; |
| 6893 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6894 | break; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6895 | } |
| 6896 | } |
| 6897 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6898 | |
| 6899 | lpfc_nvme_mod_param_dep(phba); |
| 6900 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6901 | /* |
| 6902 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6903 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 6904 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6905 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6906 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 6907 | if (rc) { |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6908 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6909 | &phba->sli4_hba.sli_intf); |
| 6910 | if_fam = bf_get(lpfc_sli_intf_sli_family, |
| 6911 | &phba->sli4_hba.sli_intf); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6912 | if (phba->sli4_hba.extents_in_use && |
| 6913 | phba->sli4_hba.rpi_hdrs_in_use) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6914 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6915 | "2999 Unsupported SLI4 Parameters " |
| 6916 | "Extents and RPI headers enabled.\n"); |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6917 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6918 | if_fam == LPFC_SLI_INTF_FAMILY_BE2) { |
| 6919 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6920 | rc = -EIO; |
| 6921 | goto out_free_bsmbx; |
| 6922 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6923 | } |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6924 | if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6925 | if_fam == LPFC_SLI_INTF_FAMILY_BE2)) { |
| 6926 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6927 | rc = -EIO; |
| 6928 | goto out_free_bsmbx; |
| 6929 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6930 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6931 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6932 | /* |
| 6933 | * 1 for cmd, 1 for rsp, NVME adds an extra one |
| 6934 | * for boundary conditions in its max_sgl_segment template. |
| 6935 | */ |
| 6936 | extra = 2; |
| 6937 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 6938 | extra++; |
| 6939 | |
| 6940 | /* |
| 6941 | * It doesn't matter what family our adapter is in, we are |
| 6942 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 6943 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 6944 | */ |
| 6945 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
| 6946 | |
| 6947 | /* |
| 6948 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
| 6949 | * used to create the sg_dma_buf_pool must be calculated. |
| 6950 | */ |
| 6951 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 6952 | /* Both cfg_enable_bg and cfg_external_dif code paths */ |
| 6953 | |
| 6954 | /* |
| 6955 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
| 6956 | * the FCP rsp, and a SGE. Sice we have no control |
| 6957 | * over how many protection segments the SCSI Layer |
| 6958 | * will hand us (ie: there could be one for every block |
| 6959 | * in the IO), just allocate enough SGEs to accomidate |
| 6960 | * our max amount and we need to limit lpfc_sg_seg_cnt |
| 6961 | * to minimize the risk of running out. |
| 6962 | */ |
| 6963 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6964 | sizeof(struct fcp_rsp) + max_buf_size; |
| 6965 | |
| 6966 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 6967 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 6968 | |
| 6969 | /* |
| 6970 | * If supporting DIF, reduce the seg count for scsi to |
| 6971 | * allow room for the DIF sges. |
| 6972 | */ |
| 6973 | if (phba->cfg_enable_bg && |
| 6974 | phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF) |
| 6975 | phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF; |
| 6976 | else |
| 6977 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6978 | |
| 6979 | } else { |
| 6980 | /* |
| 6981 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
| 6982 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 6983 | * cfg_sg_seg_cnt data segments. |
| 6984 | */ |
| 6985 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6986 | sizeof(struct fcp_rsp) + |
| 6987 | ((phba->cfg_sg_seg_cnt + extra) * |
| 6988 | sizeof(struct sli4_sge)); |
| 6989 | |
| 6990 | /* Total SGEs for scsi_sg_list */ |
| 6991 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra; |
| 6992 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6993 | |
| 6994 | /* |
| 6995 | * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only |
| 6996 | * need to post 1 page for the SGL. |
| 6997 | */ |
| 6998 | } |
| 6999 | |
| 7000 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 7001 | phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE; |
| 7002 | else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 7003 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 7004 | else |
| 7005 | phba->cfg_sg_dma_buf_size = |
| 7006 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 7007 | |
| 7008 | phba->border_sge_num = phba->cfg_sg_dma_buf_size / |
| 7009 | sizeof(struct sli4_sge); |
| 7010 | |
| 7011 | /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */ |
| 7012 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 7013 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { |
| 7014 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, |
| 7015 | "6300 Reducing NVME sg segment " |
| 7016 | "cnt to %d\n", |
| 7017 | LPFC_MAX_NVME_SEG_CNT); |
| 7018 | phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
| 7019 | } else |
| 7020 | phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; |
| 7021 | } |
| 7022 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 7023 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 7024 | "9087 sg_seg_cnt:%d dmabuf_size:%d " |
| 7025 | "total:%d scsi:%d nvme:%d\n", |
| 7026 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 7027 | phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt, |
| 7028 | phba->cfg_nvme_seg_cnt); |
| 7029 | |
| 7030 | if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE) |
| 7031 | i = phba->cfg_sg_dma_buf_size; |
| 7032 | else |
| 7033 | i = SLI4_PAGE_SIZE; |
| 7034 | |
| 7035 | phba->lpfc_sg_dma_buf_pool = |
| 7036 | dma_pool_create("lpfc_sg_dma_buf_pool", |
| 7037 | &phba->pcidev->dev, |
| 7038 | phba->cfg_sg_dma_buf_size, |
| 7039 | i, 0); |
| 7040 | if (!phba->lpfc_sg_dma_buf_pool) |
| 7041 | goto out_free_bsmbx; |
| 7042 | |
| 7043 | phba->lpfc_cmd_rsp_buf_pool = |
| 7044 | dma_pool_create("lpfc_cmd_rsp_buf_pool", |
| 7045 | &phba->pcidev->dev, |
| 7046 | sizeof(struct fcp_cmnd) + |
| 7047 | sizeof(struct fcp_rsp), |
| 7048 | i, 0); |
| 7049 | if (!phba->lpfc_cmd_rsp_buf_pool) |
| 7050 | goto out_free_sg_dma_buf; |
| 7051 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 7052 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7053 | |
| 7054 | /* Verify OAS is supported */ |
| 7055 | lpfc_sli4_oas_verify(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 7056 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 7057 | /* Verify RAS support on adapter */ |
| 7058 | lpfc_sli4_ras_init(phba); |
| 7059 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 7060 | /* Verify all the SLI4 queues */ |
| 7061 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7062 | if (rc) |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 7063 | goto out_free_cmd_rsp_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7064 | |
| 7065 | /* Create driver internal CQE event pool */ |
| 7066 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 7067 | if (rc) |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 7068 | goto out_free_cmd_rsp_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7069 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7070 | /* Initialize sgl lists per host */ |
| 7071 | lpfc_init_sgl_list(phba); |
| 7072 | |
| 7073 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7074 | rc = lpfc_init_active_sgl_array(phba); |
| 7075 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7076 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7077 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7078 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7079 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7080 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 7081 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7082 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7083 | "1432 Failed to initialize rpi headers.\n"); |
| 7084 | goto out_free_active_sgl; |
| 7085 | } |
| 7086 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 7087 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7088 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7089 | phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7090 | GFP_KERNEL); |
| 7091 | if (!phba->fcf.fcf_rr_bmask) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7092 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7093 | "2759 Failed allocate memory for FCF round " |
| 7094 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7095 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7096 | goto out_remove_rpi_hdrs; |
| 7097 | } |
| 7098 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 7099 | phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 7100 | sizeof(struct lpfc_hba_eq_hdl), |
| 7101 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7102 | if (!phba->sli4_hba.hba_eq_hdl) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7103 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7104 | "2572 Failed allocate memory for " |
| 7105 | "fast-path per-EQ handle array\n"); |
| 7106 | rc = -ENOMEM; |
| 7107 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7108 | } |
| 7109 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 7110 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7111 | sizeof(struct lpfc_vector_map_info), |
| 7112 | GFP_KERNEL); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7113 | if (!phba->sli4_hba.cpu_map) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7114 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7115 | "3327 Failed allocate memory for msi-x " |
| 7116 | "interrupt vector mapping\n"); |
| 7117 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7118 | goto out_free_hba_eq_hdl; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7119 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 7120 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7121 | phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info); |
| 7122 | if (!phba->sli4_hba.eq_info) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7123 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7124 | "3321 Failed allocation for per_cpu stats\n"); |
| 7125 | rc = -ENOMEM; |
| 7126 | goto out_free_hba_cpu_map; |
| 7127 | } |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7128 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7129 | phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu, |
| 7130 | sizeof(*phba->sli4_hba.idle_stat), |
| 7131 | GFP_KERNEL); |
| 7132 | if (!phba->sli4_hba.idle_stat) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7133 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7134 | "3390 Failed allocation for idle_stat\n"); |
| 7135 | rc = -ENOMEM; |
| 7136 | goto out_free_hba_eq_info; |
| 7137 | } |
| 7138 | |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7139 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 7140 | phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat); |
| 7141 | if (!phba->sli4_hba.c_stat) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7142 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7143 | "3332 Failed allocating per cpu hdwq stats\n"); |
| 7144 | rc = -ENOMEM; |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7145 | goto out_free_hba_idle_stat; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7146 | } |
| 7147 | #endif |
| 7148 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7149 | /* |
| 7150 | * Enable sr-iov virtual functions if supported and configured |
| 7151 | * through the module parameter. |
| 7152 | */ |
| 7153 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 7154 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 7155 | phba->cfg_sriov_nr_virtfn); |
| 7156 | if (rc) { |
| 7157 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7158 | "3020 Requested number of SR-IOV " |
| 7159 | "virtual functions (%d) is not " |
| 7160 | "supported\n", |
| 7161 | phba->cfg_sriov_nr_virtfn); |
| 7162 | phba->cfg_sriov_nr_virtfn = 0; |
| 7163 | } |
| 7164 | } |
| 7165 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 7166 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7167 | |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7168 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7169 | out_free_hba_idle_stat: |
| 7170 | kfree(phba->sli4_hba.idle_stat); |
| 7171 | #endif |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7172 | out_free_hba_eq_info: |
| 7173 | free_percpu(phba->sli4_hba.eq_info); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7174 | out_free_hba_cpu_map: |
| 7175 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7176 | out_free_hba_eq_hdl: |
| 7177 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7178 | out_free_fcf_rr_bmask: |
| 7179 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7180 | out_remove_rpi_hdrs: |
| 7181 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 7182 | out_free_active_sgl: |
| 7183 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7184 | out_destroy_cq_event_pool: |
| 7185 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 7186 | out_free_cmd_rsp_buf: |
| 7187 | dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool); |
| 7188 | phba->lpfc_cmd_rsp_buf_pool = NULL; |
| 7189 | out_free_sg_dma_buf: |
| 7190 | dma_pool_destroy(phba->lpfc_sg_dma_buf_pool); |
| 7191 | phba->lpfc_sg_dma_buf_pool = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7192 | out_free_bsmbx: |
| 7193 | lpfc_destroy_bootstrap_mbox(phba); |
| 7194 | out_free_mem: |
| 7195 | lpfc_mem_free(phba); |
| 7196 | return rc; |
| 7197 | } |
| 7198 | |
| 7199 | /** |
| 7200 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 7201 | * @phba: pointer to lpfc hba data structure. |
| 7202 | * |
| 7203 | * This routine is invoked to unset the driver internal resources set up |
| 7204 | * specific for supporting the SLI-4 HBA device it attached to. |
| 7205 | **/ |
| 7206 | static void |
| 7207 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 7208 | { |
| 7209 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 7210 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7211 | free_percpu(phba->sli4_hba.eq_info); |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7212 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 7213 | free_percpu(phba->sli4_hba.c_stat); |
| 7214 | #endif |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7215 | kfree(phba->sli4_hba.idle_stat); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7216 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7217 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 7218 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 7219 | phba->sli4_hba.num_possible_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7220 | phba->sli4_hba.num_present_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 7221 | phba->sli4_hba.curr_disp_cpu = 0; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 7222 | cpumask_clear(&phba->sli4_hba.irq_aff_mask); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7223 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7224 | /* Free memory allocated for fast-path work queue handles */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7225 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7226 | |
| 7227 | /* Free the allocated rpi headers. */ |
| 7228 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 7229 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7230 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7231 | /* Free eligible FCF index bmask */ |
| 7232 | kfree(phba->fcf.fcf_rr_bmask); |
| 7233 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7234 | /* Free the ELS sgl list */ |
| 7235 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7236 | lpfc_free_els_sgl_list(phba); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7237 | lpfc_free_nvmet_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7238 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7239 | /* Free the completion queue EQ event pool */ |
| 7240 | lpfc_sli4_cq_event_release_all(phba); |
| 7241 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7242 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7243 | /* Release resource identifiers. */ |
| 7244 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 7245 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7246 | /* Free the bsmbx region. */ |
| 7247 | lpfc_destroy_bootstrap_mbox(phba); |
| 7248 | |
| 7249 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 7250 | lpfc_mem_free_all(phba); |
| 7251 | |
| 7252 | /* Free the current connect table */ |
| 7253 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7254 | &phba->fcf_conn_rec_list, list) { |
| 7255 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7256 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7257 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7258 | |
| 7259 | return; |
| 7260 | } |
| 7261 | |
| 7262 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7263 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7264 | * @phba: The hba struct for which this call is being executed. |
| 7265 | * @dev_grp: The HBA PCI-Device group number. |
| 7266 | * |
| 7267 | * This routine sets up the device INIT interface API function jump table |
| 7268 | * in @phba struct. |
| 7269 | * |
| 7270 | * Returns: 0 - success, -ENODEV - failure. |
| 7271 | **/ |
| 7272 | int |
| 7273 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7274 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 7275 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 7276 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 7277 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7278 | switch (dev_grp) { |
| 7279 | case LPFC_PCI_DEV_LP: |
| 7280 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 7281 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 7282 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 7283 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7284 | case LPFC_PCI_DEV_OC: |
| 7285 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 7286 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 7287 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 7288 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7289 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7290 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7291 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 7292 | dev_grp); |
| 7293 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7294 | } |
| 7295 | return 0; |
| 7296 | } |
| 7297 | |
| 7298 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7299 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 7300 | * @phba: pointer to lpfc hba data structure. |
| 7301 | * |
| 7302 | * This routine is invoked to set up the driver internal resources after the |
| 7303 | * device specific resource setup to support the HBA device it attached to. |
| 7304 | * |
| 7305 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7306 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7307 | * other values - error |
| 7308 | **/ |
| 7309 | static int |
| 7310 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 7311 | { |
| 7312 | int error; |
| 7313 | |
| 7314 | /* Startup the kernel thread for this host adapter. */ |
| 7315 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 7316 | "lpfc_worker_%d", phba->brd_no); |
| 7317 | if (IS_ERR(phba->worker_thread)) { |
| 7318 | error = PTR_ERR(phba->worker_thread); |
| 7319 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7320 | } |
| 7321 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7322 | return 0; |
| 7323 | } |
| 7324 | |
| 7325 | /** |
| 7326 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 7327 | * @phba: pointer to lpfc hba data structure. |
| 7328 | * |
| 7329 | * This routine is invoked to unset the driver internal resources set up after |
| 7330 | * the device specific resource setup for supporting the HBA device it |
| 7331 | * attached to. |
| 7332 | **/ |
| 7333 | static void |
| 7334 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 7335 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 7336 | if (phba->wq) { |
| 7337 | flush_workqueue(phba->wq); |
| 7338 | destroy_workqueue(phba->wq); |
| 7339 | phba->wq = NULL; |
| 7340 | } |
| 7341 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7342 | /* Stop kernel worker thread */ |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 7343 | if (phba->worker_thread) |
| 7344 | kthread_stop(phba->worker_thread); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7345 | } |
| 7346 | |
| 7347 | /** |
| 7348 | * lpfc_free_iocb_list - Free iocb list. |
| 7349 | * @phba: pointer to lpfc hba data structure. |
| 7350 | * |
| 7351 | * This routine is invoked to free the driver's IOCB list and memory. |
| 7352 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7353 | void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7354 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 7355 | { |
| 7356 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 7357 | |
| 7358 | spin_lock_irq(&phba->hbalock); |
| 7359 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 7360 | &phba->lpfc_iocb_list, list) { |
| 7361 | list_del(&iocbq_entry->list); |
| 7362 | kfree(iocbq_entry); |
| 7363 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7364 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7365 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7366 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7367 | return; |
| 7368 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7369 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7370 | /** |
| 7371 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 7372 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 7373 | * @iocb_count: number of requested iocbs |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7374 | * |
| 7375 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 7376 | * list and set up the IOCB tag array accordingly. |
| 7377 | * |
| 7378 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7379 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7380 | * other values - error |
| 7381 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7382 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7383 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 7384 | { |
| 7385 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 7386 | uint16_t iotag; |
| 7387 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7388 | |
| 7389 | /* Initialize and populate the iocb list per host. */ |
| 7390 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7391 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 7392 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7393 | if (iocbq_entry == NULL) { |
| 7394 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 7395 | "expected %d count. Unloading driver.\n", |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7396 | __func__, i, iocb_count); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7397 | goto out_free_iocbq; |
| 7398 | } |
| 7399 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7400 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 7401 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7402 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7403 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7404 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7405 | goto out_free_iocbq; |
| 7406 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7407 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7408 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7409 | |
| 7410 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7411 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 7412 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7413 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7414 | } |
| 7415 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7416 | return 0; |
| 7417 | |
| 7418 | out_free_iocbq: |
| 7419 | lpfc_free_iocb_list(phba); |
| 7420 | |
| 7421 | return -ENOMEM; |
| 7422 | } |
| 7423 | |
| 7424 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7425 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7426 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7427 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7428 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7429 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7430 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7431 | void |
| 7432 | 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] | 7433 | { |
| 7434 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7435 | |
| 7436 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 7437 | list_del(&sglq_entry->list); |
| 7438 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7439 | kfree(sglq_entry); |
| 7440 | } |
| 7441 | } |
| 7442 | |
| 7443 | /** |
| 7444 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 7445 | * @phba: pointer to lpfc hba data structure. |
| 7446 | * |
| 7447 | * This routine is invoked to free the driver's els sgl list and memory. |
| 7448 | **/ |
| 7449 | static void |
| 7450 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 7451 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7452 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7453 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7454 | /* Retrieve all els sgls from driver list */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 7455 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7456 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 7457 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7458 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7459 | /* Now free the sgl list */ |
| 7460 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7461 | } |
| 7462 | |
| 7463 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7464 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. |
| 7465 | * @phba: pointer to lpfc hba data structure. |
| 7466 | * |
| 7467 | * This routine is invoked to free the driver's nvmet sgl list and memory. |
| 7468 | **/ |
| 7469 | static void |
| 7470 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) |
| 7471 | { |
| 7472 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7473 | LIST_HEAD(sglq_list); |
| 7474 | |
| 7475 | /* Retrieve all nvmet sgls from driver list */ |
| 7476 | spin_lock_irq(&phba->hbalock); |
| 7477 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7478 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); |
| 7479 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 7480 | spin_unlock_irq(&phba->hbalock); |
| 7481 | |
| 7482 | /* Now free the sgl list */ |
| 7483 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { |
| 7484 | list_del(&sglq_entry->list); |
| 7485 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7486 | kfree(sglq_entry); |
| 7487 | } |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 7488 | |
| 7489 | /* Update the nvmet_xri_cnt to reflect no current sgls. |
| 7490 | * The next initialization cycle sets the count and allocates |
| 7491 | * the sgls over again. |
| 7492 | */ |
| 7493 | phba->sli4_hba.nvmet_xri_cnt = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7494 | } |
| 7495 | |
| 7496 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7497 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 7498 | * @phba: pointer to lpfc hba data structure. |
| 7499 | * |
| 7500 | * This routine is invoked to allocate the driver's active sgl memory. |
| 7501 | * This array will hold the sglq_entry's for active IOs. |
| 7502 | **/ |
| 7503 | static int |
| 7504 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 7505 | { |
| 7506 | int size; |
| 7507 | size = sizeof(struct lpfc_sglq *); |
| 7508 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 7509 | |
| 7510 | phba->sli4_hba.lpfc_sglq_active_list = |
| 7511 | kzalloc(size, GFP_KERNEL); |
| 7512 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 7513 | return -ENOMEM; |
| 7514 | return 0; |
| 7515 | } |
| 7516 | |
| 7517 | /** |
| 7518 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 7519 | * @phba: pointer to lpfc hba data structure. |
| 7520 | * |
| 7521 | * This routine is invoked to walk through the array of active sglq entries |
| 7522 | * and free all of the resources. |
| 7523 | * This is just a place holder for now. |
| 7524 | **/ |
| 7525 | static void |
| 7526 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 7527 | { |
| 7528 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 7529 | } |
| 7530 | |
| 7531 | /** |
| 7532 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 7533 | * @phba: pointer to lpfc hba data structure. |
| 7534 | * |
| 7535 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 7536 | * list and set up the sgl xritag tag array accordingly. |
| 7537 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7538 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7539 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7540 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 7541 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7542 | /* Initialize and populate the sglq list per host/VF. */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7543 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7544 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7545 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 7546 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7547 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7548 | /* els xri-sgl book keeping */ |
| 7549 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7550 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7551 | /* nvme xri-buffer book keeping */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7552 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7553 | } |
| 7554 | |
| 7555 | /** |
| 7556 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 7557 | * @phba: pointer to lpfc hba data structure. |
| 7558 | * |
| 7559 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7560 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7561 | * 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] | 7562 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 7563 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7564 | * |
| 7565 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7566 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7567 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7568 | **/ |
| 7569 | int |
| 7570 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 7571 | { |
| 7572 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7573 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7574 | |
| 7575 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7576 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7577 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7578 | if (phba->sli4_hba.extents_in_use) |
| 7579 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7580 | |
| 7581 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 7582 | if (!rpi_hdr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7583 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7584 | "0391 Error during rpi post operation\n"); |
| 7585 | lpfc_sli4_remove_rpis(phba); |
| 7586 | rc = -ENODEV; |
| 7587 | } |
| 7588 | |
| 7589 | return rc; |
| 7590 | } |
| 7591 | |
| 7592 | /** |
| 7593 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 7594 | * @phba: pointer to lpfc hba data structure. |
| 7595 | * |
| 7596 | * This routine is invoked to allocate a single 4KB memory region to |
| 7597 | * support rpis and stores them in the phba. This single region |
| 7598 | * provides support for up to 64 rpis. The region is used globally |
| 7599 | * by the device. |
| 7600 | * |
| 7601 | * Returns: |
| 7602 | * A valid rpi hdr on success. |
| 7603 | * A NULL pointer on any failure. |
| 7604 | **/ |
| 7605 | struct lpfc_rpi_hdr * |
| 7606 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 7607 | { |
| 7608 | uint16_t rpi_limit, curr_rpi_range; |
| 7609 | struct lpfc_dmabuf *dmabuf; |
| 7610 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7611 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7612 | /* |
| 7613 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 7614 | * required. Set the expected maximum count and let the actual value |
| 7615 | * get set when extents are fully allocated. |
| 7616 | */ |
| 7617 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7618 | return NULL; |
| 7619 | if (phba->sli4_hba.extents_in_use) |
| 7620 | return NULL; |
| 7621 | |
| 7622 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7623 | rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7624 | |
| 7625 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7626 | /* |
| 7627 | * Establish the starting RPI in this header block. The starting |
| 7628 | * rpi is normalized to a zero base because the physical rpi is |
| 7629 | * port based. |
| 7630 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7631 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7632 | spin_unlock_irq(&phba->hbalock); |
| 7633 | |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7634 | /* Reached full RPI range */ |
| 7635 | if (curr_rpi_range == rpi_limit) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7636 | return NULL; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7637 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7638 | /* |
| 7639 | * First allocate the protocol header region for the port. The |
| 7640 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 7641 | */ |
| 7642 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 7643 | if (!dmabuf) |
| 7644 | return NULL; |
| 7645 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7646 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 7647 | LPFC_HDR_TEMPLATE_SIZE, |
| 7648 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7649 | if (!dmabuf->virt) { |
| 7650 | rpi_hdr = NULL; |
| 7651 | goto err_free_dmabuf; |
| 7652 | } |
| 7653 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7654 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 7655 | rpi_hdr = NULL; |
| 7656 | goto err_free_coherent; |
| 7657 | } |
| 7658 | |
| 7659 | /* Save the rpi header data for cleanup later. */ |
| 7660 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 7661 | if (!rpi_hdr) |
| 7662 | goto err_free_coherent; |
| 7663 | |
| 7664 | rpi_hdr->dmabuf = dmabuf; |
| 7665 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 7666 | rpi_hdr->page_count = 1; |
| 7667 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7668 | |
| 7669 | /* The rpi_hdr stores the logical index only. */ |
| 7670 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7671 | 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] | 7672 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 7673 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7674 | spin_unlock_irq(&phba->hbalock); |
| 7675 | return rpi_hdr; |
| 7676 | |
| 7677 | err_free_coherent: |
| 7678 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 7679 | dmabuf->virt, dmabuf->phys); |
| 7680 | err_free_dmabuf: |
| 7681 | kfree(dmabuf); |
| 7682 | return NULL; |
| 7683 | } |
| 7684 | |
| 7685 | /** |
| 7686 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 7687 | * @phba: pointer to lpfc hba data structure. |
| 7688 | * |
| 7689 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7690 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 7691 | * presumes the caller has released all rpis consumed by fabric or port |
| 7692 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7693 | **/ |
| 7694 | void |
| 7695 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 7696 | { |
| 7697 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 7698 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7699 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7700 | goto exit; |
| 7701 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7702 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 7703 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 7704 | list_del(&rpi_hdr->list); |
| 7705 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 7706 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 7707 | kfree(rpi_hdr->dmabuf); |
| 7708 | kfree(rpi_hdr); |
| 7709 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7710 | exit: |
| 7711 | /* There are no rpis available to the port now. */ |
| 7712 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7713 | } |
| 7714 | |
| 7715 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7716 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 7717 | * @pdev: pointer to pci device data structure. |
| 7718 | * |
| 7719 | * This routine is invoked to allocate the driver hba data structure for an |
| 7720 | * HBA device. If the allocation is successful, the phba reference to the |
| 7721 | * PCI device data structure is set. |
| 7722 | * |
| 7723 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7724 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7725 | * NULL - error |
| 7726 | **/ |
| 7727 | static struct lpfc_hba * |
| 7728 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 7729 | { |
| 7730 | struct lpfc_hba *phba; |
| 7731 | |
| 7732 | /* Allocate memory for HBA structure */ |
| 7733 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 7734 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 7735 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7736 | return NULL; |
| 7737 | } |
| 7738 | |
| 7739 | /* Set reference to PCI device in HBA structure */ |
| 7740 | phba->pcidev = pdev; |
| 7741 | |
| 7742 | /* Assign an unused board number */ |
| 7743 | phba->brd_no = lpfc_get_instance(); |
| 7744 | if (phba->brd_no < 0) { |
| 7745 | kfree(phba); |
| 7746 | return NULL; |
| 7747 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7748 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7749 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 7750 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 7751 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 7752 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7753 | return phba; |
| 7754 | } |
| 7755 | |
| 7756 | /** |
| 7757 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 7758 | * @phba: pointer to lpfc hba data structure. |
| 7759 | * |
| 7760 | * This routine is invoked to free the driver hba data structure with an |
| 7761 | * HBA device. |
| 7762 | **/ |
| 7763 | static void |
| 7764 | lpfc_hba_free(struct lpfc_hba *phba) |
| 7765 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7766 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7767 | kfree(phba->sli4_hba.hdwq); |
| 7768 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7769 | /* Release the driver assigned board number */ |
| 7770 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 7771 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7772 | /* Free memory allocated with sli3 rings */ |
| 7773 | kfree(phba->sli.sli3_ring); |
| 7774 | phba->sli.sli3_ring = NULL; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7775 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7776 | kfree(phba); |
| 7777 | return; |
| 7778 | } |
| 7779 | |
| 7780 | /** |
| 7781 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 7782 | * @phba: pointer to lpfc hba data structure. |
| 7783 | * |
| 7784 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 7785 | * host with it. |
| 7786 | * |
| 7787 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7788 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7789 | * other values - error |
| 7790 | **/ |
| 7791 | static int |
| 7792 | lpfc_create_shost(struct lpfc_hba *phba) |
| 7793 | { |
| 7794 | struct lpfc_vport *vport; |
| 7795 | struct Scsi_Host *shost; |
| 7796 | |
| 7797 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7798 | phba->fc_edtov = FF_DEF_EDTOV; |
| 7799 | phba->fc_ratov = FF_DEF_RATOV; |
| 7800 | phba->fc_altov = FF_DEF_ALTOV; |
| 7801 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 7802 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7803 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 7804 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7805 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7806 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7807 | |
| 7808 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7809 | phba->pport = vport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7810 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7811 | if (phba->nvmet_support) { |
| 7812 | /* Only 1 vport (pport) will support NVME target */ |
James Smart | ea85a20 | 2019-10-18 14:18:25 -0700 | [diff] [blame] | 7813 | phba->targetport = NULL; |
| 7814 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; |
| 7815 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC, |
| 7816 | "6076 NVME Target Found\n"); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7817 | } |
| 7818 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7819 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7820 | /* Put reference to SCSI host to driver's device private data */ |
| 7821 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7822 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7823 | /* |
| 7824 | * At this point we are fully registered with PSA. In addition, |
| 7825 | * any initial discovery should be completed. |
| 7826 | */ |
| 7827 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7828 | if (phba->cfg_enable_SmartSAN || |
| 7829 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7830 | |
| 7831 | /* Setup appropriate attribute masks */ |
| 7832 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7833 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7834 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 7835 | else |
| 7836 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 7837 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7838 | return 0; |
| 7839 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7840 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7841 | /** |
| 7842 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 7843 | * @phba: pointer to lpfc hba data structure. |
| 7844 | * |
| 7845 | * This routine is invoked to destroy HBA physical port and the associated |
| 7846 | * SCSI host. |
| 7847 | **/ |
| 7848 | static void |
| 7849 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 7850 | { |
| 7851 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7852 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7853 | /* Destroy physical port that associated with the SCSI host */ |
| 7854 | destroy_port(vport); |
| 7855 | |
| 7856 | return; |
| 7857 | } |
| 7858 | |
| 7859 | /** |
| 7860 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 7861 | * @phba: pointer to lpfc hba data structure. |
| 7862 | * @shost: the shost to be used to detect Block guard settings. |
| 7863 | * |
| 7864 | * This routine sets up the local Block guard protocol settings for @shost. |
| 7865 | * This routine also allocates memory for debugging bg buffers. |
| 7866 | **/ |
| 7867 | static void |
| 7868 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 7869 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7870 | uint32_t old_mask; |
| 7871 | uint32_t old_guard; |
| 7872 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7873 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7874 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7875 | "1478 Registering BlockGuard with the " |
| 7876 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7877 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7878 | old_mask = phba->cfg_prot_mask; |
| 7879 | old_guard = phba->cfg_prot_guard; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7880 | |
| 7881 | /* Only allow supported values */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7882 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7883 | SHOST_DIX_TYPE0_PROTECTION | |
| 7884 | SHOST_DIX_TYPE1_PROTECTION); |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7885 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
| 7886 | SHOST_DIX_GUARD_CRC); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7887 | |
| 7888 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7889 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 7890 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7891 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7892 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
| 7893 | if ((old_mask != phba->cfg_prot_mask) || |
| 7894 | (old_guard != phba->cfg_prot_guard)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7895 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7896 | "1475 Registering BlockGuard with the " |
| 7897 | "SCSI layer: mask %d guard %d\n", |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7898 | phba->cfg_prot_mask, |
| 7899 | phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7900 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7901 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
| 7902 | scsi_host_set_guard(shost, phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7903 | } else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7904 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7905 | "1479 Not Registering BlockGuard with the SCSI " |
| 7906 | "layer, Bad protection parameters: %d %d\n", |
| 7907 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7908 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7909 | } |
| 7910 | |
| 7911 | /** |
| 7912 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 7913 | * @phba: pointer to lpfc hba data structure. |
| 7914 | * |
| 7915 | * This routine is invoked to perform all the necessary post initialization |
| 7916 | * setup for the device. |
| 7917 | **/ |
| 7918 | static void |
| 7919 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 7920 | { |
| 7921 | struct Scsi_Host *shost; |
| 7922 | struct lpfc_adapter_event_header adapter_event; |
| 7923 | |
| 7924 | /* Get the default values for Model Name and Description */ |
| 7925 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 7926 | |
| 7927 | /* |
| 7928 | * hba setup may have changed the hba_queue_depth so we need to |
| 7929 | * adjust the value of can_queue. |
| 7930 | */ |
| 7931 | shost = pci_get_drvdata(phba->pcidev); |
| 7932 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7933 | |
| 7934 | lpfc_host_attrib_init(shost); |
| 7935 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7936 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 7937 | spin_lock_irq(shost->host_lock); |
| 7938 | lpfc_poll_start_timer(phba); |
| 7939 | spin_unlock_irq(shost->host_lock); |
| 7940 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 7941 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7942 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7943 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7944 | /* Send board arrival event to upper layer */ |
| 7945 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 7946 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 7947 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7948 | sizeof(adapter_event), |
| 7949 | (char *) &adapter_event, |
| 7950 | LPFC_NL_VENDOR_ID); |
| 7951 | return; |
| 7952 | } |
| 7953 | |
| 7954 | /** |
| 7955 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 7956 | * @phba: pointer to lpfc hba data structure. |
| 7957 | * |
| 7958 | * This routine is invoked to set up the PCI device memory space for device |
| 7959 | * with SLI-3 interface spec. |
| 7960 | * |
| 7961 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7962 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7963 | * other values - error |
| 7964 | **/ |
| 7965 | static int |
| 7966 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 7967 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7968 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7969 | unsigned long bar0map_len, bar2map_len; |
| 7970 | int i, hbq_count; |
| 7971 | void *ptr; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7972 | int error; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7973 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7974 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7975 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7976 | |
| 7977 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7978 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 7979 | if (error) |
| 7980 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 7981 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7982 | return error; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7983 | error = -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7984 | |
| 7985 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 7986 | * required by each mapping. |
| 7987 | */ |
| 7988 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7989 | bar0map_len = pci_resource_len(pdev, 0); |
| 7990 | |
| 7991 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 7992 | bar2map_len = pci_resource_len(pdev, 2); |
| 7993 | |
| 7994 | /* Map HBA SLIM to a kernel virtual address. */ |
| 7995 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 7996 | if (!phba->slim_memmap_p) { |
| 7997 | dev_printk(KERN_ERR, &pdev->dev, |
| 7998 | "ioremap failed for SLIM memory.\n"); |
| 7999 | goto out; |
| 8000 | } |
| 8001 | |
| 8002 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 8003 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 8004 | if (!phba->ctrl_regs_memmap_p) { |
| 8005 | dev_printk(KERN_ERR, &pdev->dev, |
| 8006 | "ioremap failed for HBA control registers.\n"); |
| 8007 | goto out_iounmap_slim; |
| 8008 | } |
| 8009 | |
| 8010 | /* Allocate memory for SLI-2 structures */ |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 8011 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 8012 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8013 | if (!phba->slim2p.virt) |
| 8014 | goto out_iounmap; |
| 8015 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8016 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 8017 | phba->mbox_ext = (phba->slim2p.virt + |
| 8018 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8019 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 8020 | phba->IOCBs = (phba->slim2p.virt + |
| 8021 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 8022 | |
| 8023 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 8024 | lpfc_sli_hbq_size(), |
| 8025 | &phba->hbqslimp.phys, |
| 8026 | GFP_KERNEL); |
| 8027 | if (!phba->hbqslimp.virt) |
| 8028 | goto out_free_slim; |
| 8029 | |
| 8030 | hbq_count = lpfc_sli_hbq_count(); |
| 8031 | ptr = phba->hbqslimp.virt; |
| 8032 | for (i = 0; i < hbq_count; ++i) { |
| 8033 | phba->hbqs[i].hbq_virt = ptr; |
| 8034 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 8035 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 8036 | sizeof(struct lpfc_hbq_entry)); |
| 8037 | } |
| 8038 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 8039 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 8040 | |
| 8041 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 8042 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8043 | phba->MBslimaddr = phba->slim_memmap_p; |
| 8044 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 8045 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 8046 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 8047 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 8048 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8049 | return 0; |
| 8050 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8051 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 8052 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 8053 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8054 | out_iounmap: |
| 8055 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 8056 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8057 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8058 | out: |
| 8059 | return error; |
| 8060 | } |
| 8061 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 8062 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8063 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 8064 | * @phba: pointer to lpfc hba data structure. |
| 8065 | * |
| 8066 | * This routine is invoked to unset the PCI device memory space for device |
| 8067 | * with SLI-3 interface spec. |
| 8068 | **/ |
| 8069 | static void |
| 8070 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 8071 | { |
| 8072 | struct pci_dev *pdev; |
| 8073 | |
| 8074 | /* Obtain PCI device reference */ |
| 8075 | if (!phba->pcidev) |
| 8076 | return; |
| 8077 | else |
| 8078 | pdev = phba->pcidev; |
| 8079 | |
| 8080 | /* Free coherent DMA memory allocated */ |
| 8081 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 8082 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 8083 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 8084 | phba->slim2p.virt, phba->slim2p.phys); |
| 8085 | |
| 8086 | /* I/O memory unmap */ |
| 8087 | iounmap(phba->ctrl_regs_memmap_p); |
| 8088 | iounmap(phba->slim_memmap_p); |
| 8089 | |
| 8090 | return; |
| 8091 | } |
| 8092 | |
| 8093 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8094 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 8095 | * @phba: pointer to lpfc hba data structure. |
| 8096 | * |
| 8097 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 8098 | * done and check status. |
| 8099 | * |
| 8100 | * Return 0 if successful, otherwise -ENODEV. |
| 8101 | **/ |
| 8102 | int |
| 8103 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 8104 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8105 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 8106 | struct lpfc_register reg_data; |
| 8107 | int i, port_error = 0; |
| 8108 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8109 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8110 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 8111 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8112 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8113 | return -ENODEV; |
| 8114 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8115 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 8116 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8117 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 8118 | &portsmphr_reg.word0) || |
| 8119 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8120 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8121 | port_error = -ENODEV; |
| 8122 | break; |
| 8123 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8124 | if (LPFC_POST_STAGE_PORT_READY == |
| 8125 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8126 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8127 | msleep(10); |
| 8128 | } |
| 8129 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8130 | /* |
| 8131 | * If there was a port error during POST, then don't proceed with |
| 8132 | * other register reads as the data may not be valid. Just exit. |
| 8133 | */ |
| 8134 | if (port_error) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8135 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8136 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 8137 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 8138 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 8139 | portsmphr_reg.word0, |
| 8140 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 8141 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 8142 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 8143 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 8144 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 8145 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 8146 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 8147 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 8148 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8149 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8150 | "2534 Device Info: SLIFamily=0x%x, " |
| 8151 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 8152 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8153 | bf_get(lpfc_sli_intf_sli_family, |
| 8154 | &phba->sli4_hba.sli_intf), |
| 8155 | bf_get(lpfc_sli_intf_slirev, |
| 8156 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 8157 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8158 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 8159 | bf_get(lpfc_sli_intf_sli_hint1, |
| 8160 | &phba->sli4_hba.sli_intf), |
| 8161 | bf_get(lpfc_sli_intf_sli_hint2, |
| 8162 | &phba->sli4_hba.sli_intf), |
| 8163 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8164 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8165 | /* |
| 8166 | * Check for other Port errors during the initialization |
| 8167 | * process. Fail the load if the port did not come up |
| 8168 | * correctly. |
| 8169 | */ |
| 8170 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8171 | &phba->sli4_hba.sli_intf); |
| 8172 | switch (if_type) { |
| 8173 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8174 | phba->sli4_hba.ue_mask_lo = |
| 8175 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 8176 | phba->sli4_hba.ue_mask_hi = |
| 8177 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 8178 | uerrlo_reg.word0 = |
| 8179 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 8180 | uerrhi_reg.word0 = |
| 8181 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 8182 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 8183 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8184 | lpfc_printf_log(phba, KERN_ERR, |
| 8185 | LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8186 | "1422 Unrecoverable Error " |
| 8187 | "Detected during POST " |
| 8188 | "uerr_lo_reg=0x%x, " |
| 8189 | "uerr_hi_reg=0x%x, " |
| 8190 | "ue_mask_lo_reg=0x%x, " |
| 8191 | "ue_mask_hi_reg=0x%x\n", |
| 8192 | uerrlo_reg.word0, |
| 8193 | uerrhi_reg.word0, |
| 8194 | phba->sli4_hba.ue_mask_lo, |
| 8195 | phba->sli4_hba.ue_mask_hi); |
| 8196 | port_error = -ENODEV; |
| 8197 | } |
| 8198 | break; |
| 8199 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8200 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8201 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8202 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 8203 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8204 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 8205 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8206 | phba->work_status[0] = |
| 8207 | readl(phba->sli4_hba.u.if_type2. |
| 8208 | ERR1regaddr); |
| 8209 | phba->work_status[1] = |
| 8210 | readl(phba->sli4_hba.u.if_type2. |
| 8211 | ERR2regaddr); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8212 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 8213 | "2888 Unrecoverable port error " |
| 8214 | "following POST: port status reg " |
| 8215 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8216 | "error 1=0x%x, error 2=0x%x\n", |
| 8217 | reg_data.word0, |
| 8218 | portsmphr_reg.word0, |
| 8219 | phba->work_status[0], |
| 8220 | phba->work_status[1]); |
| 8221 | port_error = -ENODEV; |
| 8222 | } |
| 8223 | break; |
| 8224 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8225 | default: |
| 8226 | break; |
| 8227 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8228 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8229 | return port_error; |
| 8230 | } |
| 8231 | |
| 8232 | /** |
| 8233 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 8234 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8235 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8236 | * |
| 8237 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 8238 | * memory map. |
| 8239 | **/ |
| 8240 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8241 | 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] | 8242 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8243 | switch (if_type) { |
| 8244 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8245 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 8246 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 8247 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 8248 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 8249 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 8250 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 8251 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 8252 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 8253 | phba->sli4_hba.SLIINTFregaddr = |
| 8254 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8255 | break; |
| 8256 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 8257 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8258 | phba->sli4_hba.conf_regs_memmap_p + |
| 8259 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8260 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8261 | phba->sli4_hba.conf_regs_memmap_p + |
| 8262 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8263 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8264 | phba->sli4_hba.conf_regs_memmap_p + |
| 8265 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8266 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8267 | phba->sli4_hba.conf_regs_memmap_p + |
| 8268 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8269 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8270 | phba->sli4_hba.conf_regs_memmap_p + |
| 8271 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8272 | phba->sli4_hba.SLIINTFregaddr = |
| 8273 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8274 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8275 | phba->sli4_hba.conf_regs_memmap_p + |
| 8276 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8277 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8278 | phba->sli4_hba.conf_regs_memmap_p + |
| 8279 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8280 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8281 | phba->sli4_hba.conf_regs_memmap_p + |
| 8282 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8283 | phba->sli4_hba.CQDBregaddr = |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8284 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8285 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8286 | phba->sli4_hba.MQDBregaddr = |
| 8287 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 8288 | phba->sli4_hba.BMBXregaddr = |
| 8289 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8290 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8291 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8292 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8293 | phba->sli4_hba.conf_regs_memmap_p + |
| 8294 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
| 8295 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
| 8296 | phba->sli4_hba.conf_regs_memmap_p + |
| 8297 | LPFC_CTL_PORT_ER1_OFFSET; |
| 8298 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
| 8299 | phba->sli4_hba.conf_regs_memmap_p + |
| 8300 | LPFC_CTL_PORT_ER2_OFFSET; |
| 8301 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
| 8302 | phba->sli4_hba.conf_regs_memmap_p + |
| 8303 | LPFC_CTL_PORT_CTL_OFFSET; |
| 8304 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
| 8305 | phba->sli4_hba.conf_regs_memmap_p + |
| 8306 | LPFC_CTL_PORT_STA_OFFSET; |
| 8307 | phba->sli4_hba.PSMPHRregaddr = |
| 8308 | phba->sli4_hba.conf_regs_memmap_p + |
| 8309 | LPFC_CTL_PORT_SEM_OFFSET; |
| 8310 | phba->sli4_hba.BMBXregaddr = |
| 8311 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8312 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8313 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8314 | default: |
| 8315 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8316 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8317 | if_type); |
| 8318 | break; |
| 8319 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8320 | } |
| 8321 | |
| 8322 | /** |
| 8323 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 8324 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 8325 | * @if_type: sli if type to operate on. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8326 | * |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8327 | * This routine is invoked to set up SLI4 BAR1 register memory map. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8328 | **/ |
| 8329 | static void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8330 | 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] | 8331 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8332 | switch (if_type) { |
| 8333 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8334 | phba->sli4_hba.PSMPHRregaddr = |
| 8335 | phba->sli4_hba.ctrl_regs_memmap_p + |
| 8336 | LPFC_SLIPORT_IF0_SMPHR; |
| 8337 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8338 | LPFC_HST_ISR0; |
| 8339 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8340 | LPFC_HST_IMR0; |
| 8341 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8342 | LPFC_HST_ISCR0; |
| 8343 | break; |
| 8344 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8345 | phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8346 | LPFC_IF6_RQ_DOORBELL; |
| 8347 | phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8348 | LPFC_IF6_WQ_DOORBELL; |
| 8349 | phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8350 | LPFC_IF6_CQ_DOORBELL; |
| 8351 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8352 | LPFC_IF6_EQ_DOORBELL; |
| 8353 | phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8354 | LPFC_IF6_MQ_DOORBELL; |
| 8355 | break; |
| 8356 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8357 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8358 | default: |
| 8359 | dev_err(&phba->pcidev->dev, |
| 8360 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8361 | if_type); |
| 8362 | break; |
| 8363 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8364 | } |
| 8365 | |
| 8366 | /** |
| 8367 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 8368 | * @phba: pointer to lpfc hba data structure. |
| 8369 | * @vf: virtual function number |
| 8370 | * |
| 8371 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 8372 | * based on the given viftual function number, @vf. |
| 8373 | * |
| 8374 | * Return 0 if successful, otherwise -ENODEV. |
| 8375 | **/ |
| 8376 | static int |
| 8377 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 8378 | { |
| 8379 | if (vf > LPFC_VIR_FUNC_MAX) |
| 8380 | return -ENODEV; |
| 8381 | |
| 8382 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8383 | vf * LPFC_VFR_PAGE_SIZE + |
| 8384 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8385 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8386 | vf * LPFC_VFR_PAGE_SIZE + |
| 8387 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8388 | phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8389 | vf * LPFC_VFR_PAGE_SIZE + |
| 8390 | LPFC_EQCQ_DOORBELL); |
| 8391 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8392 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8393 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 8394 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8395 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 8396 | return 0; |
| 8397 | } |
| 8398 | |
| 8399 | /** |
| 8400 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 8401 | * @phba: pointer to lpfc hba data structure. |
| 8402 | * |
| 8403 | * This routine is invoked to create the bootstrap mailbox |
| 8404 | * region consistent with the SLI-4 interface spec. This |
| 8405 | * routine allocates all memory necessary to communicate |
| 8406 | * mailbox commands to the port and sets up all alignment |
| 8407 | * needs. No locks are expected to be held when calling |
| 8408 | * this routine. |
| 8409 | * |
| 8410 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8411 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8412 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8413 | **/ |
| 8414 | static int |
| 8415 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 8416 | { |
| 8417 | uint32_t bmbx_size; |
| 8418 | struct lpfc_dmabuf *dmabuf; |
| 8419 | struct dma_address *dma_address; |
| 8420 | uint32_t pa_addr; |
| 8421 | uint64_t phys_addr; |
| 8422 | |
| 8423 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 8424 | if (!dmabuf) |
| 8425 | return -ENOMEM; |
| 8426 | |
| 8427 | /* |
| 8428 | * The bootstrap mailbox region is comprised of 2 parts |
| 8429 | * plus an alignment restriction of 16 bytes. |
| 8430 | */ |
| 8431 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 8432 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 8433 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8434 | if (!dmabuf->virt) { |
| 8435 | kfree(dmabuf); |
| 8436 | return -ENOMEM; |
| 8437 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8438 | |
| 8439 | /* |
| 8440 | * Initialize the bootstrap mailbox pointers now so that the register |
| 8441 | * operations are simple later. The mailbox dma address is required |
| 8442 | * to be 16-byte aligned. Also align the virtual memory as each |
| 8443 | * maibox is copied into the bmbx mailbox region before issuing the |
| 8444 | * command to the port. |
| 8445 | */ |
| 8446 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 8447 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 8448 | |
| 8449 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 8450 | LPFC_ALIGN_16_BYTE); |
| 8451 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 8452 | LPFC_ALIGN_16_BYTE); |
| 8453 | |
| 8454 | /* |
| 8455 | * Set the high and low physical addresses now. The SLI4 alignment |
| 8456 | * requirement is 16 bytes and the mailbox is posted to the port |
| 8457 | * as two 30-bit addresses. The other data is a bit marking whether |
| 8458 | * the 30-bit address is the high or low address. |
| 8459 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 8460 | * clean on 32 bit machines. |
| 8461 | */ |
| 8462 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8463 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 8464 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 8465 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 8466 | LPFC_BMBX_BIT1_ADDR_HI); |
| 8467 | |
| 8468 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 8469 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 8470 | LPFC_BMBX_BIT1_ADDR_LO); |
| 8471 | return 0; |
| 8472 | } |
| 8473 | |
| 8474 | /** |
| 8475 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 8476 | * @phba: pointer to lpfc hba data structure. |
| 8477 | * |
| 8478 | * This routine is invoked to teardown the bootstrap mailbox |
| 8479 | * region and release all host resources. This routine requires |
| 8480 | * the caller to ensure all mailbox commands recovered, no |
| 8481 | * additional mailbox comands are sent, and interrupts are disabled |
| 8482 | * before calling this routine. |
| 8483 | * |
| 8484 | **/ |
| 8485 | static void |
| 8486 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 8487 | { |
| 8488 | dma_free_coherent(&phba->pcidev->dev, |
| 8489 | phba->sli4_hba.bmbx.bmbx_size, |
| 8490 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 8491 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 8492 | |
| 8493 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 8494 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 8495 | } |
| 8496 | |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8497 | static const char * const lpfc_topo_to_str[] = { |
| 8498 | "Loop then P2P", |
| 8499 | "Loopback", |
| 8500 | "P2P Only", |
| 8501 | "Unsupported", |
| 8502 | "Loop Only", |
| 8503 | "Unsupported", |
| 8504 | "P2P then Loop", |
| 8505 | }; |
| 8506 | |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 8507 | #define LINK_FLAGS_DEF 0x0 |
| 8508 | #define LINK_FLAGS_P2P 0x1 |
| 8509 | #define LINK_FLAGS_LOOP 0x2 |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8510 | /** |
| 8511 | * lpfc_map_topology - Map the topology read from READ_CONFIG |
| 8512 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 8513 | * @rd_config: pointer to read config data |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8514 | * |
| 8515 | * This routine is invoked to map the topology values as read |
| 8516 | * from the read config mailbox command. If the persistent |
| 8517 | * topology feature is supported, the firmware will provide the |
| 8518 | * saved topology information to be used in INIT_LINK |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8519 | **/ |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8520 | static void |
| 8521 | lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config) |
| 8522 | { |
| 8523 | u8 ptv, tf, pt; |
| 8524 | |
| 8525 | ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config); |
| 8526 | tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config); |
| 8527 | pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config); |
| 8528 | |
| 8529 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8530 | "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x", |
| 8531 | ptv, tf, pt); |
| 8532 | if (!ptv) { |
| 8533 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8534 | "2019 FW does not support persistent topology " |
| 8535 | "Using driver parameter defined value [%s]", |
| 8536 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8537 | return; |
| 8538 | } |
| 8539 | /* FW supports persistent topology - override module parameter value */ |
| 8540 | phba->hba_flag |= HBA_PERSISTENT_TOPO; |
| 8541 | switch (phba->pcidev->device) { |
| 8542 | case PCI_DEVICE_ID_LANCER_G7_FC: |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8543 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 8544 | if (!tf) { |
| 8545 | phba->cfg_topology = ((pt == LINK_FLAGS_LOOP) |
| 8546 | ? FLAGS_TOPOLOGY_MODE_LOOP |
| 8547 | : FLAGS_TOPOLOGY_MODE_PT_PT); |
| 8548 | } else { |
| 8549 | phba->hba_flag &= ~HBA_PERSISTENT_TOPO; |
| 8550 | } |
| 8551 | break; |
| 8552 | default: /* G5 */ |
| 8553 | if (tf) { |
| 8554 | /* If topology failover set - pt is '0' or '1' */ |
| 8555 | phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP : |
| 8556 | FLAGS_TOPOLOGY_MODE_LOOP_PT); |
| 8557 | } else { |
| 8558 | phba->cfg_topology = ((pt == LINK_FLAGS_P2P) |
| 8559 | ? FLAGS_TOPOLOGY_MODE_PT_PT |
| 8560 | : FLAGS_TOPOLOGY_MODE_LOOP); |
| 8561 | } |
| 8562 | break; |
| 8563 | } |
| 8564 | if (phba->hba_flag & HBA_PERSISTENT_TOPO) { |
| 8565 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8566 | "2020 Using persistent topology value [%s]", |
| 8567 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8568 | } else { |
| 8569 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8570 | "2021 Invalid topology values from FW " |
| 8571 | "Using driver parameter defined value [%s]", |
| 8572 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8573 | } |
| 8574 | } |
| 8575 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8576 | /** |
| 8577 | * lpfc_sli4_read_config - Get the config parameters. |
| 8578 | * @phba: pointer to lpfc hba data structure. |
| 8579 | * |
| 8580 | * This routine is invoked to read the configuration parameters from the HBA. |
| 8581 | * The configuration parameters are used to set the base and maximum values |
| 8582 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 8583 | * allocation for the port. |
| 8584 | * |
| 8585 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8586 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8587 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8588 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8589 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8590 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8591 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 8592 | { |
| 8593 | LPFC_MBOXQ_t *pmb; |
| 8594 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8595 | union lpfc_sli4_cfg_shdr *shdr; |
| 8596 | uint32_t shdr_status, shdr_add_status; |
| 8597 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 8598 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8599 | char *pdesc_0; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8600 | uint16_t forced_link_speed; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8601 | uint32_t if_type, qmin; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8602 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8603 | |
| 8604 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8605 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8606 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8607 | "2011 Unable to allocate memory for issuing " |
| 8608 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 8609 | return -ENOMEM; |
| 8610 | } |
| 8611 | |
| 8612 | lpfc_read_config(phba, pmb); |
| 8613 | |
| 8614 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8615 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8616 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 8617 | "2012 Mailbox failed , mbxCmd x%x " |
| 8618 | "READ_CONFIG, mbxStatus x%x\n", |
| 8619 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8620 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8621 | rc = -EIO; |
| 8622 | } else { |
| 8623 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8624 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 8625 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 8626 | phba->sli4_hba.lnk_info.lnk_tp = |
| 8627 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 8628 | phba->sli4_hba.lnk_info.lnk_no = |
| 8629 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 8630 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8631 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 8632 | phba->sli4_hba.lnk_info.lnk_tp, |
| 8633 | phba->sli4_hba.lnk_info.lnk_no); |
| 8634 | } else |
| 8635 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8636 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 8637 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 8638 | if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) { |
| 8639 | phba->bbcredit_support = 1; |
| 8640 | phba->sli4_hba.bbscn_params.word0 = rd_config->word8; |
| 8641 | } |
| 8642 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8643 | phba->sli4_hba.conf_trunk = |
| 8644 | bf_get(lpfc_mbx_rd_conf_trunk, rd_config); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8645 | phba->sli4_hba.extents_in_use = |
| 8646 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8647 | phba->sli4_hba.max_cfg_param.max_xri = |
| 8648 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
James Smart | 31f06d2 | 2019-08-14 16:56:31 -0700 | [diff] [blame] | 8649 | /* Reduce resource usage in kdump environment */ |
| 8650 | if (is_kdump_kernel() && |
| 8651 | phba->sli4_hba.max_cfg_param.max_xri > 512) |
| 8652 | phba->sli4_hba.max_cfg_param.max_xri = 512; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8653 | phba->sli4_hba.max_cfg_param.xri_base = |
| 8654 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 8655 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 8656 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
James Smart | 8b47ae6 | 2018-11-29 16:09:33 -0800 | [diff] [blame] | 8657 | /* Limit the max we support */ |
| 8658 | if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS) |
| 8659 | phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8660 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 8661 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 8662 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 8663 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 8664 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 8665 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 8666 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 8667 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 8668 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 8669 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 8670 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 8671 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8672 | phba->sli4_hba.max_cfg_param.max_eq = |
| 8673 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 8674 | phba->sli4_hba.max_cfg_param.max_rq = |
| 8675 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 8676 | phba->sli4_hba.max_cfg_param.max_wq = |
| 8677 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 8678 | phba->sli4_hba.max_cfg_param.max_cq = |
| 8679 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 8680 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 8681 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 8682 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 8683 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8684 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 8685 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8686 | phba->max_vports = phba->max_vpi; |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8687 | lpfc_map_topology(phba, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8688 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8689 | "2003 cfg params Extents? %d " |
| 8690 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8691 | "VPI(B:%d M:%d) " |
| 8692 | "VFI(B:%d M:%d) " |
| 8693 | "RPI(B:%d M:%d) " |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 8694 | "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d lmt:x%x\n", |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8695 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8696 | phba->sli4_hba.max_cfg_param.xri_base, |
| 8697 | phba->sli4_hba.max_cfg_param.max_xri, |
| 8698 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 8699 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 8700 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 8701 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 8702 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 8703 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8704 | phba->sli4_hba.max_cfg_param.max_fcfi, |
| 8705 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8706 | phba->sli4_hba.max_cfg_param.max_cq, |
| 8707 | phba->sli4_hba.max_cfg_param.max_wq, |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 8708 | phba->sli4_hba.max_cfg_param.max_rq, |
| 8709 | phba->lmt); |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8710 | |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8711 | /* |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8712 | * Calculate queue resources based on how |
| 8713 | * many WQ/CQ/EQs are available. |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8714 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8715 | qmin = phba->sli4_hba.max_cfg_param.max_wq; |
| 8716 | if (phba->sli4_hba.max_cfg_param.max_cq < qmin) |
| 8717 | qmin = phba->sli4_hba.max_cfg_param.max_cq; |
| 8718 | if (phba->sli4_hba.max_cfg_param.max_eq < qmin) |
| 8719 | qmin = phba->sli4_hba.max_cfg_param.max_eq; |
| 8720 | /* |
| 8721 | * Whats left after this can go toward NVME / FCP. |
| 8722 | * The minus 4 accounts for ELS, NVME LS, MBOX |
| 8723 | * plus one extra. When configured for |
| 8724 | * NVMET, FCP io channel WQs are not created. |
| 8725 | */ |
| 8726 | qmin -= 4; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8727 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8728 | /* Check to see if there is enough for NVME */ |
| 8729 | if ((phba->cfg_irq_chann > qmin) || |
| 8730 | (phba->cfg_hdw_queue > qmin)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8731 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 9e3e365 | 2020-08-03 14:02:23 -0700 | [diff] [blame] | 8732 | "2005 Reducing Queues - " |
| 8733 | "FW resource limitation: " |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8734 | "WQ %d CQ %d EQ %d: min %d: " |
| 8735 | "IRQ %d HDWQ %d\n", |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8736 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8737 | phba->sli4_hba.max_cfg_param.max_cq, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8738 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8739 | qmin, phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8740 | phba->cfg_hdw_queue); |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8741 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8742 | if (phba->cfg_irq_chann > qmin) |
| 8743 | phba->cfg_irq_chann = qmin; |
| 8744 | if (phba->cfg_hdw_queue > qmin) |
| 8745 | phba->cfg_hdw_queue = qmin; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8746 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8747 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8748 | |
| 8749 | if (rc) |
| 8750 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8751 | |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8752 | /* Update link speed if forced link speed is supported */ |
| 8753 | 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] | 8754 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8755 | forced_link_speed = |
| 8756 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); |
| 8757 | if (forced_link_speed) { |
| 8758 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; |
| 8759 | |
| 8760 | switch (forced_link_speed) { |
| 8761 | case LINK_SPEED_1G: |
| 8762 | phba->cfg_link_speed = |
| 8763 | LPFC_USER_LINK_SPEED_1G; |
| 8764 | break; |
| 8765 | case LINK_SPEED_2G: |
| 8766 | phba->cfg_link_speed = |
| 8767 | LPFC_USER_LINK_SPEED_2G; |
| 8768 | break; |
| 8769 | case LINK_SPEED_4G: |
| 8770 | phba->cfg_link_speed = |
| 8771 | LPFC_USER_LINK_SPEED_4G; |
| 8772 | break; |
| 8773 | case LINK_SPEED_8G: |
| 8774 | phba->cfg_link_speed = |
| 8775 | LPFC_USER_LINK_SPEED_8G; |
| 8776 | break; |
| 8777 | case LINK_SPEED_10G: |
| 8778 | phba->cfg_link_speed = |
| 8779 | LPFC_USER_LINK_SPEED_10G; |
| 8780 | break; |
| 8781 | case LINK_SPEED_16G: |
| 8782 | phba->cfg_link_speed = |
| 8783 | LPFC_USER_LINK_SPEED_16G; |
| 8784 | break; |
| 8785 | case LINK_SPEED_32G: |
| 8786 | phba->cfg_link_speed = |
| 8787 | LPFC_USER_LINK_SPEED_32G; |
| 8788 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 8789 | case LINK_SPEED_64G: |
| 8790 | phba->cfg_link_speed = |
| 8791 | LPFC_USER_LINK_SPEED_64G; |
| 8792 | break; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8793 | case 0xffff: |
| 8794 | phba->cfg_link_speed = |
| 8795 | LPFC_USER_LINK_SPEED_AUTO; |
| 8796 | break; |
| 8797 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8798 | lpfc_printf_log(phba, KERN_ERR, |
| 8799 | LOG_TRACE_EVENT, |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8800 | "0047 Unrecognized link " |
| 8801 | "speed : %d\n", |
| 8802 | forced_link_speed); |
| 8803 | phba->cfg_link_speed = |
| 8804 | LPFC_USER_LINK_SPEED_AUTO; |
| 8805 | } |
| 8806 | } |
| 8807 | } |
| 8808 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8809 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 8810 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 8811 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 8812 | if (phba->cfg_hba_queue_depth > length) { |
| 8813 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8814 | "3361 HBA queue depth changed from %d to %d\n", |
| 8815 | phba->cfg_hba_queue_depth, length); |
| 8816 | phba->cfg_hba_queue_depth = length; |
| 8817 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8818 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8819 | 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] | 8820 | LPFC_SLI_INTF_IF_TYPE_2) |
| 8821 | goto read_cfg_out; |
| 8822 | |
| 8823 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 8824 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 8825 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8826 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8827 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 8828 | length, LPFC_SLI4_MBX_EMBED); |
| 8829 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8830 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8831 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8832 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8833 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8834 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8835 | if (rc2 || shdr_status || shdr_add_status) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8836 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8837 | "3026 Mailbox failed , mbxCmd x%x " |
| 8838 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 8839 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8840 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8841 | goto read_cfg_out; |
| 8842 | } |
| 8843 | |
| 8844 | /* search for fc_fcoe resrouce descriptor */ |
| 8845 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8846 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8847 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 8848 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 8849 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 8850 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 8851 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 8852 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 8853 | goto read_cfg_out; |
| 8854 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8855 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8856 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8857 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8858 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8859 | phba->sli4_hba.iov.pf_number = |
| 8860 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 8861 | phba->sli4_hba.iov.vf_number = |
| 8862 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 8863 | break; |
| 8864 | } |
| 8865 | } |
| 8866 | |
| 8867 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 8868 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8869 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 8870 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 8871 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8872 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8873 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8874 | "3028 GET_FUNCTION_CONFIG: failed to find " |
Colin Ian King | c4dba18 | 2018-10-16 18:28:53 +0100 | [diff] [blame] | 8875 | "Resource Descriptor:x%x\n", |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8876 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8877 | |
| 8878 | read_cfg_out: |
| 8879 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8880 | return rc; |
| 8881 | } |
| 8882 | |
| 8883 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8884 | * 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] | 8885 | * @phba: pointer to lpfc hba data structure. |
| 8886 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8887 | * This routine is invoked to setup the port-side endian order when |
| 8888 | * the port if_type is 0. This routine has no function for other |
| 8889 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8890 | * |
| 8891 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8892 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8893 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8894 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8895 | **/ |
| 8896 | static int |
| 8897 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 8898 | { |
| 8899 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8900 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8901 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 8902 | HOST_ENDIAN_HIGH_WORD1}; |
| 8903 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8904 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8905 | switch (if_type) { |
| 8906 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8907 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 8908 | GFP_KERNEL); |
| 8909 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8910 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8911 | "0492 Unable to allocate memory for " |
| 8912 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 8913 | "command\n"); |
| 8914 | return -ENOMEM; |
| 8915 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8916 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8917 | /* |
| 8918 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 8919 | * two words to contain special data values and no other data. |
| 8920 | */ |
| 8921 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 8922 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 8923 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8924 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8925 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8926 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 8927 | "failed with status x%x\n", |
| 8928 | rc); |
| 8929 | rc = -EIO; |
| 8930 | } |
| 8931 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8932 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8933 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8934 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8935 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8936 | default: |
| 8937 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8938 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8939 | return rc; |
| 8940 | } |
| 8941 | |
| 8942 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8943 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8944 | * @phba: pointer to lpfc hba data structure. |
| 8945 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8946 | * This routine is invoked to check the user settable queue counts for EQs. |
| 8947 | * 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] | 8948 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 8949 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8950 | * |
| 8951 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8952 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8953 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8954 | **/ |
| 8955 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8956 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8957 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8958 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8959 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8960 | * device parameters |
| 8961 | */ |
| 8962 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8963 | if (phba->nvmet_support) { |
James Smart | 97a9ed3 | 2019-10-18 14:18:17 -0700 | [diff] [blame] | 8964 | if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq) |
| 8965 | phba->cfg_nvmet_mrq = phba->cfg_hdw_queue; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 8966 | if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) |
| 8967 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8968 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8969 | |
| 8970 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8971 | "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n", |
| 8972 | phba->cfg_hdw_queue, phba->cfg_irq_chann, |
| 8973 | phba->cfg_nvmet_mrq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8974 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8975 | /* Get EQ depth from module parameter, fake the default for now */ |
| 8976 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8977 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8978 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8979 | /* Get CQ depth from module parameter, fake the default for now */ |
| 8980 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8981 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8982 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8983 | } |
| 8984 | |
| 8985 | static int |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8986 | lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8987 | { |
| 8988 | struct lpfc_queue *qdesc; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8989 | u32 wqesize; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8990 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8991 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8992 | cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ); |
| 8993 | /* Create Fast Path IO CQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8994 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8995 | /* Increase the CQ size when WQEs contain an embedded cdb */ |
| 8996 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8997 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8998 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8999 | |
| 9000 | else |
| 9001 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9002 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9003 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9004 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9005 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 9006 | "0499 Failed allocate fast-path IO CQ (%d)\n", |
| 9007 | idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9008 | return 1; |
| 9009 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9010 | qdesc->qe_valid = 1; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9011 | qdesc->hdwq = idx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9012 | qdesc->chann = cpu; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9013 | phba->sli4_hba.hdwq[idx].io_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9014 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9015 | /* Create Fast Path IO WQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 9016 | if (phba->enab_exp_wqcq_pages) { |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 9017 | /* Increase the WQ size when WQEs contain an embedded cdb */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 9018 | wqesize = (phba->fcp_embed_io) ? |
| 9019 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 9020 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 9021 | wqesize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9022 | LPFC_WQE_EXP_COUNT, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 9023 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 9024 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9025 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9026 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 9027 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9028 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9029 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9030 | "0503 Failed allocate fast-path IO WQ (%d)\n", |
| 9031 | idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9032 | return 1; |
| 9033 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9034 | qdesc->hdwq = idx; |
| 9035 | qdesc->chann = cpu; |
| 9036 | phba->sli4_hba.hdwq[idx].io_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9037 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9038 | return 0; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9039 | } |
| 9040 | |
| 9041 | /** |
| 9042 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 9043 | * @phba: pointer to lpfc hba data structure. |
| 9044 | * |
| 9045 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 9046 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 9047 | * count (queue depth) shall be taken from the module parameter. For now, |
| 9048 | * we just use some constant number as place holder. |
| 9049 | * |
| 9050 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 9051 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9052 | * -ENOMEM - No availble memory |
| 9053 | * -EIO - The mailbox failed to complete successfully. |
| 9054 | **/ |
| 9055 | int |
| 9056 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 9057 | { |
| 9058 | struct lpfc_queue *qdesc; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9059 | int idx, cpu, eqcpu; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9060 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9061 | struct lpfc_vector_map_info *cpup; |
| 9062 | struct lpfc_vector_map_info *eqcpup; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 9063 | struct lpfc_eq_intr_info *eqi; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9064 | |
| 9065 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9066 | * Create HBA Record arrays. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9067 | * Both NVME and FCP will share that same vectors / EQs |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9068 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9069 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 9070 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 9071 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 9072 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 9073 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 9074 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9075 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 9076 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 9077 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 9078 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9079 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9080 | if (!phba->sli4_hba.hdwq) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9081 | phba->sli4_hba.hdwq = kcalloc( |
| 9082 | phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue), |
| 9083 | GFP_KERNEL); |
| 9084 | if (!phba->sli4_hba.hdwq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9085 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9086 | "6427 Failed allocate memory for " |
| 9087 | "fast-path Hardware Queue array\n"); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9088 | goto out_error; |
| 9089 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9090 | /* Prepare hardware queues to take IO buffers */ |
| 9091 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9092 | qp = &phba->sli4_hba.hdwq[idx]; |
| 9093 | spin_lock_init(&qp->io_buf_list_get_lock); |
| 9094 | spin_lock_init(&qp->io_buf_list_put_lock); |
| 9095 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 9096 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 9097 | qp->get_io_bufs = 0; |
| 9098 | qp->put_io_bufs = 0; |
| 9099 | qp->total_io_bufs = 0; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9100 | spin_lock_init(&qp->abts_io_buf_list_lock); |
| 9101 | INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9102 | qp->abts_scsi_io_bufs = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9103 | qp->abts_nvme_io_bufs = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 9104 | INIT_LIST_HEAD(&qp->sgl_list); |
| 9105 | INIT_LIST_HEAD(&qp->cmd_rsp_buf_list); |
| 9106 | spin_lock_init(&qp->hdwq_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9107 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9108 | } |
| 9109 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9110 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9111 | if (phba->nvmet_support) { |
| 9112 | phba->sli4_hba.nvmet_cqset = kcalloc( |
| 9113 | phba->cfg_nvmet_mrq, |
| 9114 | sizeof(struct lpfc_queue *), |
| 9115 | GFP_KERNEL); |
| 9116 | if (!phba->sli4_hba.nvmet_cqset) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9117 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9118 | "3121 Fail allocate memory for " |
| 9119 | "fast-path CQ set array\n"); |
| 9120 | goto out_error; |
| 9121 | } |
| 9122 | phba->sli4_hba.nvmet_mrq_hdr = kcalloc( |
| 9123 | phba->cfg_nvmet_mrq, |
| 9124 | sizeof(struct lpfc_queue *), |
| 9125 | GFP_KERNEL); |
| 9126 | if (!phba->sli4_hba.nvmet_mrq_hdr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9127 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9128 | "3122 Fail allocate memory for " |
| 9129 | "fast-path RQ set hdr array\n"); |
| 9130 | goto out_error; |
| 9131 | } |
| 9132 | phba->sli4_hba.nvmet_mrq_data = kcalloc( |
| 9133 | phba->cfg_nvmet_mrq, |
| 9134 | sizeof(struct lpfc_queue *), |
| 9135 | GFP_KERNEL); |
| 9136 | if (!phba->sli4_hba.nvmet_mrq_data) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9137 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9138 | "3124 Fail allocate memory for " |
| 9139 | "fast-path RQ set data array\n"); |
| 9140 | goto out_error; |
| 9141 | } |
| 9142 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9143 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9144 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9145 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9146 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9147 | /* Create HBA Event Queues (EQs) */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9148 | for_each_present_cpu(cpu) { |
| 9149 | /* We only want to create 1 EQ per vector, even though |
| 9150 | * multiple CPUs might be using that vector. so only |
| 9151 | * selects the CPUs that are LPFC_CPU_FIRST_IRQ. |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9152 | */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9153 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9154 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9155 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9156 | |
| 9157 | /* Get a ptr to the Hardware Queue associated with this CPU */ |
| 9158 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 9159 | |
| 9160 | /* Allocate an EQ */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9161 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9162 | phba->sli4_hba.eq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9163 | phba->sli4_hba.eq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9164 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9165 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9166 | "0497 Failed allocate EQ (%d)\n", |
| 9167 | cpup->hdwq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9168 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9169 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9170 | qdesc->qe_valid = 1; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9171 | qdesc->hdwq = cpup->hdwq; |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 9172 | qdesc->chann = cpu; /* First CPU this EQ is affinitized to */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 9173 | qdesc->last_cpu = qdesc->chann; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9174 | |
| 9175 | /* Save the allocated EQ in the Hardware Queue */ |
| 9176 | qp->hba_eq = qdesc; |
| 9177 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 9178 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu); |
| 9179 | list_add(&qdesc->cpu_list, &eqi->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9180 | } |
| 9181 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9182 | /* Now we need to populate the other Hardware Queues, that share |
| 9183 | * an IRQ vector, with the associated EQ ptr. |
| 9184 | */ |
| 9185 | for_each_present_cpu(cpu) { |
| 9186 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9187 | |
| 9188 | /* Check for EQ already allocated in previous loop */ |
| 9189 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 9190 | continue; |
| 9191 | |
| 9192 | /* Check for multiple CPUs per hdwq */ |
| 9193 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 9194 | if (qp->hba_eq) |
| 9195 | continue; |
| 9196 | |
| 9197 | /* We need to share an EQ for this hdwq */ |
| 9198 | eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ); |
| 9199 | eqcpup = &phba->sli4_hba.cpu_map[eqcpu]; |
| 9200 | qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq; |
| 9201 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9202 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9203 | /* Allocate IO Path SLI4 CQ/WQs */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9204 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9205 | if (lpfc_alloc_io_wq_cq(phba, idx)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9206 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9207 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9208 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9209 | if (phba->nvmet_support) { |
| 9210 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
| 9211 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 9212 | LPFC_FIND_BY_HDWQ); |
| 9213 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9214 | LPFC_DEFAULT_PAGE_SIZE, |
| 9215 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9216 | phba->sli4_hba.cq_ecount, |
| 9217 | cpu); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9218 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9219 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9220 | "3142 Failed allocate NVME " |
| 9221 | "CQ Set (%d)\n", idx); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9222 | goto out_error; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9223 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9224 | qdesc->qe_valid = 1; |
| 9225 | qdesc->hdwq = idx; |
| 9226 | qdesc->chann = cpu; |
| 9227 | phba->sli4_hba.nvmet_cqset[idx] = qdesc; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9228 | } |
| 9229 | } |
| 9230 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9231 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9232 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9233 | */ |
| 9234 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9235 | cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9236 | /* Create slow-path Mailbox Command Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9237 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9238 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9239 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9240 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9241 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9242 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9243 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9244 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9245 | qdesc->qe_valid = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9246 | phba->sli4_hba.mbx_cq = qdesc; |
| 9247 | |
| 9248 | /* Create slow-path ELS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9249 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9250 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9251 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9252 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9253 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9254 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9255 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9256 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9257 | qdesc->qe_valid = 1; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9258 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9259 | phba->sli4_hba.els_cq = qdesc; |
| 9260 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9261 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9262 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9263 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9264 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9265 | |
| 9266 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9267 | |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9268 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9269 | phba->sli4_hba.mq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9270 | phba->sli4_hba.mq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9271 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9272 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9273 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9274 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9275 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9276 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9277 | phba->sli4_hba.mbx_wq = qdesc; |
| 9278 | |
| 9279 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9280 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9281 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9282 | |
| 9283 | /* Create slow-path ELS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9284 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9285 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9286 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9287 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9288 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9289 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9290 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9291 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9292 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9293 | phba->sli4_hba.els_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9294 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9295 | |
| 9296 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9297 | /* Create NVME LS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9298 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9299 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9300 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9301 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9302 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9303 | "6079 Failed allocate NVME LS CQ\n"); |
| 9304 | goto out_error; |
| 9305 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9306 | qdesc->chann = cpu; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9307 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9308 | phba->sli4_hba.nvmels_cq = qdesc; |
| 9309 | |
| 9310 | /* Create NVME LS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9311 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9312 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9313 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9314 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9315 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9316 | "6080 Failed allocate NVME LS WQ\n"); |
| 9317 | goto out_error; |
| 9318 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9319 | qdesc->chann = cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9320 | phba->sli4_hba.nvmels_wq = qdesc; |
| 9321 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9322 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9323 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9324 | /* |
| 9325 | * Create Receive Queue (RQ) |
| 9326 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9327 | |
| 9328 | /* Create Receive Queue for header */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9329 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9330 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9331 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9332 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9333 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9334 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9335 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9336 | } |
| 9337 | phba->sli4_hba.hdr_rq = qdesc; |
| 9338 | |
| 9339 | /* Create Receive Queue for data */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9340 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9341 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9342 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9343 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9344 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9345 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9346 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9347 | } |
| 9348 | phba->sli4_hba.dat_rq = qdesc; |
| 9349 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9350 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 9351 | phba->nvmet_support) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9352 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9353 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 9354 | LPFC_FIND_BY_HDWQ); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9355 | /* Create NVMET Receive Queue for header */ |
| 9356 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9357 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9358 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9359 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9360 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9361 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9362 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9363 | "3146 Failed allocate " |
| 9364 | "receive HRQ\n"); |
| 9365 | goto out_error; |
| 9366 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9367 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9368 | phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc; |
| 9369 | |
| 9370 | /* Only needed for header of RQ pair */ |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9371 | qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp), |
| 9372 | GFP_KERNEL, |
| 9373 | cpu_to_node(cpu)); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9374 | if (qdesc->rqbp == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9375 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9376 | "6131 Failed allocate " |
| 9377 | "Header RQBP\n"); |
| 9378 | goto out_error; |
| 9379 | } |
| 9380 | |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 9381 | /* Put list in known state in case driver load fails. */ |
| 9382 | INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list); |
| 9383 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9384 | /* Create NVMET Receive Queue for data */ |
| 9385 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9386 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9387 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9388 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9389 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9390 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9391 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9392 | "3156 Failed allocate " |
| 9393 | "receive DRQ\n"); |
| 9394 | goto out_error; |
| 9395 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9396 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9397 | phba->sli4_hba.nvmet_mrq_data[idx] = qdesc; |
| 9398 | } |
| 9399 | } |
| 9400 | |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9401 | /* Clear NVME stats */ |
| 9402 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9403 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9404 | memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0, |
| 9405 | sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat)); |
| 9406 | } |
| 9407 | } |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9408 | |
| 9409 | /* Clear SCSI stats */ |
| 9410 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 9411 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9412 | memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0, |
| 9413 | sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat)); |
| 9414 | } |
| 9415 | } |
| 9416 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9417 | return 0; |
| 9418 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9419 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9420 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9421 | return -ENOMEM; |
| 9422 | } |
| 9423 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9424 | static inline void |
| 9425 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) |
| 9426 | { |
| 9427 | if (*qp != NULL) { |
| 9428 | lpfc_sli4_queue_free(*qp); |
| 9429 | *qp = NULL; |
| 9430 | } |
| 9431 | } |
| 9432 | |
| 9433 | static inline void |
| 9434 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) |
| 9435 | { |
| 9436 | int idx; |
| 9437 | |
| 9438 | if (*qs == NULL) |
| 9439 | return; |
| 9440 | |
| 9441 | for (idx = 0; idx < max; idx++) |
| 9442 | __lpfc_sli4_release_queue(&(*qs)[idx]); |
| 9443 | |
| 9444 | kfree(*qs); |
| 9445 | *qs = NULL; |
| 9446 | } |
| 9447 | |
| 9448 | static inline void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9449 | lpfc_sli4_release_hdwq(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9450 | { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9451 | struct lpfc_sli4_hdw_queue *hdwq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9452 | struct lpfc_queue *eq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9453 | uint32_t idx; |
| 9454 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9455 | hdwq = phba->sli4_hba.hdwq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9456 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9457 | /* Loop thru all Hardware Queues */ |
| 9458 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9459 | /* Free the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9460 | lpfc_sli4_queue_free(hdwq[idx].io_cq); |
| 9461 | lpfc_sli4_queue_free(hdwq[idx].io_wq); |
James Smart | 821bc88 | 2020-01-27 16:23:05 -0800 | [diff] [blame] | 9462 | hdwq[idx].hba_eq = NULL; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9463 | hdwq[idx].io_cq = NULL; |
| 9464 | hdwq[idx].io_wq = NULL; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 9465 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 9466 | lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]); |
| 9467 | lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9468 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9469 | /* Loop thru all IRQ vectors */ |
| 9470 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 9471 | /* Free the EQ corresponding to the IRQ vector */ |
| 9472 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 9473 | lpfc_sli4_queue_free(eq); |
| 9474 | phba->sli4_hba.hba_eq_hdl[idx].eq = NULL; |
| 9475 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9476 | } |
| 9477 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9478 | /** |
| 9479 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 9480 | * @phba: pointer to lpfc hba data structure. |
| 9481 | * |
| 9482 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 9483 | * operation. |
| 9484 | * |
| 9485 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9486 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9487 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9488 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9489 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9490 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9491 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 9492 | { |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9493 | /* |
| 9494 | * Set FREE_INIT before beginning to free the queues. |
| 9495 | * Wait until the users of queues to acknowledge to |
| 9496 | * release queues by clearing FREE_WAIT. |
| 9497 | */ |
| 9498 | spin_lock_irq(&phba->hbalock); |
| 9499 | phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT; |
| 9500 | while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) { |
| 9501 | spin_unlock_irq(&phba->hbalock); |
| 9502 | msleep(20); |
| 9503 | spin_lock_irq(&phba->hbalock); |
| 9504 | } |
| 9505 | spin_unlock_irq(&phba->hbalock); |
| 9506 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 9507 | lpfc_sli4_cleanup_poll_list(phba); |
| 9508 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9509 | /* Release HBA eqs */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9510 | if (phba->sli4_hba.hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9511 | lpfc_sli4_release_hdwq(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9512 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9513 | if (phba->nvmet_support) { |
| 9514 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset, |
| 9515 | phba->cfg_nvmet_mrq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9516 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9517 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr, |
| 9518 | phba->cfg_nvmet_mrq); |
| 9519 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data, |
| 9520 | phba->cfg_nvmet_mrq); |
| 9521 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9522 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9523 | /* Release mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9524 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9525 | |
| 9526 | /* Release ELS work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9527 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); |
| 9528 | |
| 9529 | /* Release ELS work queue */ |
| 9530 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9531 | |
| 9532 | /* Release unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9533 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); |
| 9534 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9535 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9536 | /* Release ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9537 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); |
| 9538 | |
| 9539 | /* Release NVME LS complete queue */ |
| 9540 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9541 | |
| 9542 | /* Release mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9543 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); |
| 9544 | |
| 9545 | /* Everything on this list has been freed */ |
| 9546 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9547 | |
| 9548 | /* Done with freeing the queues */ |
| 9549 | spin_lock_irq(&phba->hbalock); |
| 9550 | phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT; |
| 9551 | spin_unlock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9552 | } |
| 9553 | |
| 9554 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9555 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) |
| 9556 | { |
| 9557 | struct lpfc_rqb *rqbp; |
| 9558 | struct lpfc_dmabuf *h_buf; |
| 9559 | struct rqb_dmabuf *rqb_buffer; |
| 9560 | |
| 9561 | rqbp = rq->rqbp; |
| 9562 | while (!list_empty(&rqbp->rqb_buffer_list)) { |
| 9563 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 9564 | struct lpfc_dmabuf, list); |
| 9565 | |
| 9566 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 9567 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); |
| 9568 | rqbp->buffer_count--; |
| 9569 | } |
| 9570 | return 1; |
| 9571 | } |
| 9572 | |
| 9573 | static int |
| 9574 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 9575 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, |
| 9576 | int qidx, uint32_t qtype) |
| 9577 | { |
| 9578 | struct lpfc_sli_ring *pring; |
| 9579 | int rc; |
| 9580 | |
| 9581 | if (!eq || !cq || !wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9582 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9583 | "6085 Fast-path %s (%d) not allocated\n", |
| 9584 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); |
| 9585 | return -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9586 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9587 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9588 | /* create the Cq first */ |
| 9589 | rc = lpfc_cq_create(phba, cq, eq, |
| 9590 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); |
| 9591 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9592 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 9593 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", |
| 9594 | qidx, (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9595 | return rc; |
| 9596 | } |
| 9597 | |
| 9598 | if (qtype != LPFC_MBOX) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9599 | /* Setup cq_map for fast lookup */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9600 | if (cq_map) |
| 9601 | *cq_map = cq->queue_id; |
| 9602 | |
| 9603 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9604 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", |
| 9605 | qidx, cq->queue_id, qidx, eq->queue_id); |
| 9606 | |
| 9607 | /* create the wq */ |
| 9608 | rc = lpfc_wq_create(phba, wq, cq, qtype); |
| 9609 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9610 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c835c08 | 2019-03-12 16:30:30 -0700 | [diff] [blame] | 9611 | "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9612 | qidx, (uint32_t)rc); |
| 9613 | /* no need to tear down cq - caller will do so */ |
| 9614 | return rc; |
| 9615 | } |
| 9616 | |
| 9617 | /* Bind this CQ/WQ to the NVME ring */ |
| 9618 | pring = wq->pring; |
| 9619 | pring->sli.sli4.wqp = (void *)wq; |
| 9620 | cq->pring = pring; |
| 9621 | |
| 9622 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9623 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", |
| 9624 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); |
| 9625 | } else { |
| 9626 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); |
| 9627 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9628 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 9629 | "0539 Failed setup of slow-path MQ: " |
| 9630 | "rc = 0x%x\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9631 | /* no need to tear down cq - caller will do so */ |
| 9632 | return rc; |
| 9633 | } |
| 9634 | |
| 9635 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9636 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9637 | phba->sli4_hba.mbx_wq->queue_id, |
| 9638 | phba->sli4_hba.mbx_cq->queue_id); |
| 9639 | } |
| 9640 | |
| 9641 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9642 | } |
| 9643 | |
| 9644 | /** |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9645 | * lpfc_setup_cq_lookup - Setup the CQ lookup table |
| 9646 | * @phba: pointer to lpfc hba data structure. |
| 9647 | * |
| 9648 | * This routine will populate the cq_lookup table by all |
| 9649 | * available CQ queue_id's. |
| 9650 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 9651 | static void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9652 | lpfc_setup_cq_lookup(struct lpfc_hba *phba) |
| 9653 | { |
| 9654 | struct lpfc_queue *eq, *childq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9655 | int qidx; |
| 9656 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9657 | memset(phba->sli4_hba.cq_lookup, 0, |
| 9658 | (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1))); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9659 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9660 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9661 | /* Get the EQ corresponding to the IRQ vector */ |
| 9662 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9663 | if (!eq) |
| 9664 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9665 | /* Loop through all CQs associated with that EQ */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9666 | list_for_each_entry(childq, &eq->child_list, list) { |
| 9667 | if (childq->queue_id > phba->sli4_hba.cq_max) |
| 9668 | continue; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9669 | if (childq->subtype == LPFC_IO) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9670 | phba->sli4_hba.cq_lookup[childq->queue_id] = |
| 9671 | childq; |
| 9672 | } |
| 9673 | } |
| 9674 | } |
| 9675 | |
| 9676 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9677 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 9678 | * @phba: pointer to lpfc hba data structure. |
| 9679 | * |
| 9680 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 9681 | * operation. |
| 9682 | * |
| 9683 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9684 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9685 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9686 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9687 | **/ |
| 9688 | int |
| 9689 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 9690 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9691 | uint32_t shdr_status, shdr_add_status; |
| 9692 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9693 | struct lpfc_vector_map_info *cpup; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9694 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9695 | LPFC_MBOXQ_t *mboxq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9696 | int qidx, cpu; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9697 | uint32_t length, usdelay; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9698 | int rc = -ENOMEM; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9699 | |
| 9700 | /* Check for dual-ULP support */ |
| 9701 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9702 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9703 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9704 | "3249 Unable to allocate memory for " |
| 9705 | "QUERY_FW_CFG mailbox command\n"); |
| 9706 | return -ENOMEM; |
| 9707 | } |
| 9708 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 9709 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9710 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9711 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 9712 | length, LPFC_SLI4_MBX_EMBED); |
| 9713 | |
| 9714 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9715 | |
| 9716 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 9717 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 9718 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 9719 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 9720 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9721 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9722 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 9723 | "x%x add_status x%x, mbx status x%x\n", |
| 9724 | shdr_status, shdr_add_status, rc); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 9725 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9726 | rc = -ENXIO; |
| 9727 | goto out_error; |
| 9728 | } |
| 9729 | |
| 9730 | phba->sli4_hba.fw_func_mode = |
| 9731 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 9732 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 9733 | 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] | 9734 | phba->sli4_hba.physical_port = |
| 9735 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9736 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9737 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 9738 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 9739 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 9740 | |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 9741 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9742 | |
| 9743 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9744 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9745 | */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9746 | qp = phba->sli4_hba.hdwq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9747 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9748 | /* Set up HBA event queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9749 | if (!qp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9750 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9751 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9752 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9753 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9754 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9755 | |
| 9756 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9757 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9758 | /* Create HBA Event Queues (EQs) in order */ |
| 9759 | for_each_present_cpu(cpu) { |
| 9760 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9761 | |
| 9762 | /* Look for the CPU thats using that vector with |
| 9763 | * LPFC_CPU_FIRST_IRQ set. |
| 9764 | */ |
| 9765 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 9766 | continue; |
| 9767 | if (qidx != cpup->eq) |
| 9768 | continue; |
| 9769 | |
| 9770 | /* Create an EQ for that vector */ |
| 9771 | rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq, |
| 9772 | phba->cfg_fcp_imax); |
| 9773 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9774 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9775 | "0523 Failed setup of fast-path" |
| 9776 | " EQ (%d), rc = 0x%x\n", |
| 9777 | cpup->eq, (uint32_t)rc); |
| 9778 | goto out_destroy; |
| 9779 | } |
| 9780 | |
| 9781 | /* Save the EQ for that vector in the hba_eq_hdl */ |
| 9782 | phba->sli4_hba.hba_eq_hdl[cpup->eq].eq = |
| 9783 | qp[cpup->hdwq].hba_eq; |
| 9784 | |
| 9785 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9786 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
| 9787 | cpup->eq, |
| 9788 | qp[cpup->hdwq].hba_eq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9789 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9790 | } |
| 9791 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9792 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9793 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9794 | cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ); |
| 9795 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9796 | |
| 9797 | /* Create the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9798 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9799 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9800 | qp[qidx].io_cq, |
| 9801 | qp[qidx].io_wq, |
| 9802 | &phba->sli4_hba.hdwq[qidx].io_cq_map, |
| 9803 | qidx, |
| 9804 | LPFC_IO); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9805 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9806 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9807 | "0535 Failed to setup fastpath " |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9808 | "IO WQ/CQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9809 | qidx, (uint32_t)rc); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9810 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9811 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9812 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9813 | |
| 9814 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9815 | * Set up Slow Path Complete Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9816 | */ |
| 9817 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9818 | /* Set up slow-path MBOX CQ/MQ */ |
| 9819 | |
| 9820 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9821 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9822 | "0528 %s not allocated\n", |
| 9823 | phba->sli4_hba.mbx_cq ? |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9824 | "Mailbox WQ" : "Mailbox CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9825 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9826 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9827 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9828 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9829 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9830 | phba->sli4_hba.mbx_cq, |
| 9831 | phba->sli4_hba.mbx_wq, |
| 9832 | NULL, 0, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9833 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9834 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9835 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
| 9836 | (uint32_t)rc); |
| 9837 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9838 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9839 | if (phba->nvmet_support) { |
| 9840 | if (!phba->sli4_hba.nvmet_cqset) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9841 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9842 | "3165 Fast-path NVME CQ Set " |
| 9843 | "array not allocated\n"); |
| 9844 | rc = -ENOMEM; |
| 9845 | goto out_destroy; |
| 9846 | } |
| 9847 | if (phba->cfg_nvmet_mrq > 1) { |
| 9848 | rc = lpfc_cq_create_set(phba, |
| 9849 | phba->sli4_hba.nvmet_cqset, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9850 | qp, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9851 | LPFC_WCQ, LPFC_NVMET); |
| 9852 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9853 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9854 | "3164 Failed setup of NVME CQ " |
| 9855 | "Set, rc = 0x%x\n", |
| 9856 | (uint32_t)rc); |
| 9857 | goto out_destroy; |
| 9858 | } |
| 9859 | } else { |
| 9860 | /* Set up NVMET Receive Complete Queue */ |
| 9861 | rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0], |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9862 | qp[0].hba_eq, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9863 | LPFC_WCQ, LPFC_NVMET); |
| 9864 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9865 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9866 | "6089 Failed setup NVMET CQ: " |
| 9867 | "rc = 0x%x\n", (uint32_t)rc); |
| 9868 | goto out_destroy; |
| 9869 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9870 | phba->sli4_hba.nvmet_cqset[0]->chann = 0; |
| 9871 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9872 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9873 | "6090 NVMET CQ setup: cq-id=%d, " |
| 9874 | "parent eq-id=%d\n", |
| 9875 | phba->sli4_hba.nvmet_cqset[0]->queue_id, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9876 | qp[0].hba_eq->queue_id); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9877 | } |
| 9878 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9879 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9880 | /* Set up slow-path ELS WQ/CQ */ |
| 9881 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9882 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9883 | "0530 ELS %s not allocated\n", |
| 9884 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9885 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9886 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9887 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9888 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9889 | phba->sli4_hba.els_cq, |
| 9890 | phba->sli4_hba.els_wq, |
| 9891 | NULL, 0, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9892 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9893 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9894 | "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
| 9895 | (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9896 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9897 | } |
| 9898 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9899 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9900 | phba->sli4_hba.els_wq->queue_id, |
| 9901 | phba->sli4_hba.els_cq->queue_id); |
| 9902 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9903 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9904 | /* Set up NVME LS Complete Queue */ |
| 9905 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9906 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9907 | "6091 LS %s not allocated\n", |
| 9908 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); |
| 9909 | rc = -ENOMEM; |
| 9910 | goto out_destroy; |
| 9911 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9912 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9913 | phba->sli4_hba.nvmels_cq, |
| 9914 | phba->sli4_hba.nvmels_wq, |
| 9915 | NULL, 0, LPFC_NVME_LS); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9916 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9917 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9918 | "0526 Failed setup of NVVME LS WQ/CQ: " |
| 9919 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9920 | goto out_destroy; |
| 9921 | } |
| 9922 | |
| 9923 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9924 | "6096 ELS WQ setup: wq-id=%d, " |
| 9925 | "parent cq-id=%d\n", |
| 9926 | phba->sli4_hba.nvmels_wq->queue_id, |
| 9927 | phba->sli4_hba.nvmels_cq->queue_id); |
| 9928 | } |
| 9929 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9930 | /* |
| 9931 | * Create NVMET Receive Queue (RQ) |
| 9932 | */ |
| 9933 | if (phba->nvmet_support) { |
| 9934 | if ((!phba->sli4_hba.nvmet_cqset) || |
| 9935 | (!phba->sli4_hba.nvmet_mrq_hdr) || |
| 9936 | (!phba->sli4_hba.nvmet_mrq_data)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9937 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9938 | "6130 MRQ CQ Queues not " |
| 9939 | "allocated\n"); |
| 9940 | rc = -ENOMEM; |
| 9941 | goto out_destroy; |
| 9942 | } |
| 9943 | if (phba->cfg_nvmet_mrq > 1) { |
| 9944 | rc = lpfc_mrq_create(phba, |
| 9945 | phba->sli4_hba.nvmet_mrq_hdr, |
| 9946 | phba->sli4_hba.nvmet_mrq_data, |
| 9947 | phba->sli4_hba.nvmet_cqset, |
| 9948 | LPFC_NVMET); |
| 9949 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9950 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9951 | "6098 Failed setup of NVMET " |
| 9952 | "MRQ: rc = 0x%x\n", |
| 9953 | (uint32_t)rc); |
| 9954 | goto out_destroy; |
| 9955 | } |
| 9956 | |
| 9957 | } else { |
| 9958 | rc = lpfc_rq_create(phba, |
| 9959 | phba->sli4_hba.nvmet_mrq_hdr[0], |
| 9960 | phba->sli4_hba.nvmet_mrq_data[0], |
| 9961 | phba->sli4_hba.nvmet_cqset[0], |
| 9962 | LPFC_NVMET); |
| 9963 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9964 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9965 | "6057 Failed setup of NVMET " |
| 9966 | "Receive Queue: rc = 0x%x\n", |
| 9967 | (uint32_t)rc); |
| 9968 | goto out_destroy; |
| 9969 | } |
| 9970 | |
| 9971 | lpfc_printf_log( |
| 9972 | phba, KERN_INFO, LOG_INIT, |
| 9973 | "6099 NVMET RQ setup: hdr-rq-id=%d, " |
| 9974 | "dat-rq-id=%d parent cq-id=%d\n", |
| 9975 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id, |
| 9976 | phba->sli4_hba.nvmet_mrq_data[0]->queue_id, |
| 9977 | phba->sli4_hba.nvmet_cqset[0]->queue_id); |
| 9978 | |
| 9979 | } |
| 9980 | } |
| 9981 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9982 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9983 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9984 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9985 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9986 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9987 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9988 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9989 | 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] | 9990 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9991 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9992 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9993 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9994 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9995 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9996 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9997 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9998 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9999 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 10000 | "parent cq-id=%d\n", |
| 10001 | phba->sli4_hba.hdr_rq->queue_id, |
| 10002 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 10003 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10004 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 10005 | if (phba->cfg_fcp_imax) |
| 10006 | usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax; |
| 10007 | else |
| 10008 | usdelay = 0; |
| 10009 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10010 | for (qidx = 0; qidx < phba->cfg_irq_chann; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10011 | qidx += LPFC_MAX_EQ_DELAY_EQID_CNT) |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 10012 | lpfc_modify_hba_eq_delay(phba, qidx, LPFC_MAX_EQ_DELAY_EQID_CNT, |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 10013 | usdelay); |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 10014 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10015 | if (phba->sli4_hba.cq_max) { |
| 10016 | kfree(phba->sli4_hba.cq_lookup); |
| 10017 | phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1), |
| 10018 | sizeof(struct lpfc_queue *), GFP_KERNEL); |
| 10019 | if (!phba->sli4_hba.cq_lookup) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10020 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10021 | "0549 Failed setup of CQ Lookup table: " |
| 10022 | "size 0x%x\n", phba->sli4_hba.cq_max); |
Dan Carpenter | fad28e3 | 2019-02-11 21:43:00 +0300 | [diff] [blame] | 10023 | rc = -ENOMEM; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10024 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10025 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10026 | lpfc_setup_cq_lookup(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 10027 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10028 | return 0; |
| 10029 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10030 | out_destroy: |
| 10031 | lpfc_sli4_queue_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10032 | out_error: |
| 10033 | return rc; |
| 10034 | } |
| 10035 | |
| 10036 | /** |
| 10037 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 10038 | * @phba: pointer to lpfc hba data structure. |
| 10039 | * |
| 10040 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 10041 | * operation. |
| 10042 | * |
| 10043 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10044 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10045 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10046 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10047 | **/ |
| 10048 | void |
| 10049 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 10050 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10051 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10052 | struct lpfc_queue *eq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10053 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10054 | |
| 10055 | /* Unset mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10056 | if (phba->sli4_hba.mbx_wq) |
| 10057 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 10058 | |
| 10059 | /* Unset NVME LS work queue */ |
| 10060 | if (phba->sli4_hba.nvmels_wq) |
| 10061 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); |
| 10062 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10063 | /* Unset ELS work queue */ |
Colin Ian King | 019c0d6 | 2017-05-06 23:13:55 +0100 | [diff] [blame] | 10064 | if (phba->sli4_hba.els_wq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10065 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 10066 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10067 | /* Unset unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10068 | if (phba->sli4_hba.hdr_rq) |
| 10069 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, |
| 10070 | phba->sli4_hba.dat_rq); |
| 10071 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10072 | /* Unset mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10073 | if (phba->sli4_hba.mbx_cq) |
| 10074 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 10075 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10076 | /* Unset ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10077 | if (phba->sli4_hba.els_cq) |
| 10078 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 10079 | |
| 10080 | /* Unset NVME LS complete queue */ |
| 10081 | if (phba->sli4_hba.nvmels_cq) |
| 10082 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); |
| 10083 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 10084 | if (phba->nvmet_support) { |
| 10085 | /* Unset NVMET MRQ queue */ |
| 10086 | if (phba->sli4_hba.nvmet_mrq_hdr) { |
| 10087 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 10088 | lpfc_rq_destroy( |
| 10089 | phba, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10090 | phba->sli4_hba.nvmet_mrq_hdr[qidx], |
| 10091 | phba->sli4_hba.nvmet_mrq_data[qidx]); |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 10092 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10093 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 10094 | /* Unset NVMET CQ Set complete queue */ |
| 10095 | if (phba->sli4_hba.nvmet_cqset) { |
| 10096 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 10097 | lpfc_cq_destroy( |
| 10098 | phba, phba->sli4_hba.nvmet_cqset[qidx]); |
| 10099 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10100 | } |
| 10101 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10102 | /* Unset fast-path SLI4 queues */ |
| 10103 | if (phba->sli4_hba.hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10104 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10105 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10106 | /* Destroy the CQ/WQ corresponding to Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10107 | qp = &phba->sli4_hba.hdwq[qidx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10108 | lpfc_wq_destroy(phba, qp->io_wq); |
| 10109 | lpfc_cq_destroy(phba, qp->io_cq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10110 | } |
| 10111 | /* Loop thru all IRQ vectors */ |
| 10112 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 10113 | /* Destroy the EQ corresponding to the IRQ vector */ |
| 10114 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
| 10115 | lpfc_eq_destroy(phba, eq); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10116 | } |
| 10117 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10118 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10119 | kfree(phba->sli4_hba.cq_lookup); |
| 10120 | phba->sli4_hba.cq_lookup = NULL; |
| 10121 | phba->sli4_hba.cq_max = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10122 | } |
| 10123 | |
| 10124 | /** |
| 10125 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 10126 | * @phba: pointer to lpfc hba data structure. |
| 10127 | * |
| 10128 | * This routine is invoked to allocate and set up a pool of completion queue |
| 10129 | * events. The body of the completion queue event is a completion queue entry |
| 10130 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 10131 | * the following HBA completion queue events for the worker thread to process: |
| 10132 | * - Mailbox asynchronous events |
| 10133 | * - Receive queue completion unsolicited events |
| 10134 | * Later, this can be used for all the slow-path events. |
| 10135 | * |
| 10136 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10137 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10138 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10139 | **/ |
| 10140 | static int |
| 10141 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 10142 | { |
| 10143 | struct lpfc_cq_event *cq_event; |
| 10144 | int i; |
| 10145 | |
| 10146 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 10147 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 10148 | if (!cq_event) |
| 10149 | goto out_pool_create_fail; |
| 10150 | list_add_tail(&cq_event->list, |
| 10151 | &phba->sli4_hba.sp_cqe_event_pool); |
| 10152 | } |
| 10153 | return 0; |
| 10154 | |
| 10155 | out_pool_create_fail: |
| 10156 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 10157 | return -ENOMEM; |
| 10158 | } |
| 10159 | |
| 10160 | /** |
| 10161 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 10162 | * @phba: pointer to lpfc hba data structure. |
| 10163 | * |
| 10164 | * This routine is invoked to free the pool of completion queue events at |
| 10165 | * driver unload time. Note that, it is the responsibility of the driver |
| 10166 | * cleanup routine to free all the outstanding completion-queue events |
| 10167 | * allocated from this pool back into the pool before invoking this routine |
| 10168 | * to destroy the pool. |
| 10169 | **/ |
| 10170 | static void |
| 10171 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 10172 | { |
| 10173 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 10174 | |
| 10175 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 10176 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 10177 | list_del(&cq_event->list); |
| 10178 | kfree(cq_event); |
| 10179 | } |
| 10180 | } |
| 10181 | |
| 10182 | /** |
| 10183 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 10184 | * @phba: pointer to lpfc hba data structure. |
| 10185 | * |
| 10186 | * This routine is the lock free version of the API invoked to allocate a |
| 10187 | * completion-queue event from the free pool. |
| 10188 | * |
| 10189 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 10190 | * NULL otherwise. |
| 10191 | **/ |
| 10192 | struct lpfc_cq_event * |
| 10193 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 10194 | { |
| 10195 | struct lpfc_cq_event *cq_event = NULL; |
| 10196 | |
| 10197 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 10198 | struct lpfc_cq_event, list); |
| 10199 | return cq_event; |
| 10200 | } |
| 10201 | |
| 10202 | /** |
| 10203 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 10204 | * @phba: pointer to lpfc hba data structure. |
| 10205 | * |
| 10206 | * This routine is the lock version of the API invoked to allocate a |
| 10207 | * completion-queue event from the free pool. |
| 10208 | * |
| 10209 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 10210 | * NULL otherwise. |
| 10211 | **/ |
| 10212 | struct lpfc_cq_event * |
| 10213 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 10214 | { |
| 10215 | struct lpfc_cq_event *cq_event; |
| 10216 | unsigned long iflags; |
| 10217 | |
| 10218 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10219 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 10220 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10221 | return cq_event; |
| 10222 | } |
| 10223 | |
| 10224 | /** |
| 10225 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 10226 | * @phba: pointer to lpfc hba data structure. |
| 10227 | * @cq_event: pointer to the completion queue event to be freed. |
| 10228 | * |
| 10229 | * This routine is the lock free version of the API invoked to release a |
| 10230 | * completion-queue event back into the free pool. |
| 10231 | **/ |
| 10232 | void |
| 10233 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 10234 | struct lpfc_cq_event *cq_event) |
| 10235 | { |
| 10236 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 10237 | } |
| 10238 | |
| 10239 | /** |
| 10240 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 10241 | * @phba: pointer to lpfc hba data structure. |
| 10242 | * @cq_event: pointer to the completion queue event to be freed. |
| 10243 | * |
| 10244 | * This routine is the lock version of the API invoked to release a |
| 10245 | * completion-queue event back into the free pool. |
| 10246 | **/ |
| 10247 | void |
| 10248 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 10249 | struct lpfc_cq_event *cq_event) |
| 10250 | { |
| 10251 | unsigned long iflags; |
| 10252 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10253 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 10254 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10255 | } |
| 10256 | |
| 10257 | /** |
| 10258 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 10259 | * @phba: pointer to lpfc hba data structure. |
| 10260 | * |
| 10261 | * This routine is to free all the pending completion-queue events to the |
| 10262 | * back into the free pool for device reset. |
| 10263 | **/ |
| 10264 | static void |
| 10265 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 10266 | { |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 10267 | LIST_HEAD(cq_event_list); |
| 10268 | struct lpfc_cq_event *cq_event; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10269 | unsigned long iflags; |
| 10270 | |
| 10271 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10272 | |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 10273 | /* Pending ELS XRI abort events */ |
| 10274 | spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
| 10275 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10276 | &cq_event_list); |
| 10277 | spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
| 10278 | |
| 10279 | /* Pending asynnc events */ |
| 10280 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
| 10281 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 10282 | &cq_event_list); |
| 10283 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags); |
| 10284 | |
| 10285 | while (!list_empty(&cq_event_list)) { |
| 10286 | list_remove_head(&cq_event_list, cq_event, |
| 10287 | struct lpfc_cq_event, list); |
| 10288 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10289 | } |
| 10290 | } |
| 10291 | |
| 10292 | /** |
| 10293 | * lpfc_pci_function_reset - Reset pci function. |
| 10294 | * @phba: pointer to lpfc hba data structure. |
| 10295 | * |
| 10296 | * This routine is invoked to request a PCI function reset. It will destroys |
| 10297 | * all resources assigned to the PCI function which originates this request. |
| 10298 | * |
| 10299 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10300 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10301 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10302 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10303 | **/ |
| 10304 | int |
| 10305 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 10306 | { |
| 10307 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10308 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10309 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10310 | uint32_t rdy_chk; |
| 10311 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10312 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10313 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10314 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10315 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10316 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10317 | switch (if_type) { |
| 10318 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10319 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 10320 | GFP_KERNEL); |
| 10321 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10322 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10323 | "0494 Unable to allocate memory for " |
| 10324 | "issuing SLI_FUNCTION_RESET mailbox " |
| 10325 | "command\n"); |
| 10326 | return -ENOMEM; |
| 10327 | } |
| 10328 | |
| 10329 | /* Setup PCI function reset mailbox-ioctl command */ |
| 10330 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10331 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 10332 | LPFC_SLI4_MBX_EMBED); |
| 10333 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10334 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 10335 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 10336 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 10337 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 10338 | &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 10339 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10340 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10341 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10342 | "0495 SLI_FUNCTION_RESET mailbox " |
| 10343 | "failed with status x%x add_status x%x," |
| 10344 | " mbx status x%x\n", |
| 10345 | shdr_status, shdr_add_status, rc); |
| 10346 | rc = -ENXIO; |
| 10347 | } |
| 10348 | break; |
| 10349 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10350 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10351 | wait: |
| 10352 | /* |
| 10353 | * Poll the Port Status Register and wait for RDY for |
| 10354 | * up to 30 seconds. If the port doesn't respond, treat |
| 10355 | * it as an error. |
| 10356 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 10357 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10358 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 10359 | STATUSregaddr, ®_data.word0)) { |
| 10360 | rc = -ENODEV; |
| 10361 | goto out; |
| 10362 | } |
| 10363 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 10364 | break; |
| 10365 | msleep(20); |
| 10366 | } |
| 10367 | |
| 10368 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 10369 | phba->work_status[0] = readl( |
| 10370 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10371 | phba->work_status[1] = readl( |
| 10372 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10373 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10374 | "2890 Port not ready, port status reg " |
| 10375 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 10376 | reg_data.word0, |
| 10377 | phba->work_status[0], |
| 10378 | phba->work_status[1]); |
| 10379 | rc = -ENODEV; |
| 10380 | goto out; |
| 10381 | } |
| 10382 | |
| 10383 | if (!port_reset) { |
| 10384 | /* |
| 10385 | * Reset the port now |
| 10386 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10387 | reg_data.word0 = 0; |
| 10388 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 10389 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 10390 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 10391 | LPFC_SLIPORT_INIT_PORT); |
| 10392 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 10393 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 10394 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10395 | pci_read_config_word(phba->pcidev, |
| 10396 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10397 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10398 | port_reset = 1; |
| 10399 | msleep(20); |
| 10400 | goto wait; |
| 10401 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 10402 | rc = -ENODEV; |
| 10403 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10404 | } |
| 10405 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10406 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10407 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10408 | default: |
| 10409 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10410 | } |
| 10411 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 10412 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10413 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10414 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10415 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10416 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10417 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10418 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10419 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10420 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10421 | return rc; |
| 10422 | } |
| 10423 | |
| 10424 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10425 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 10426 | * @phba: pointer to lpfc hba data structure. |
| 10427 | * |
| 10428 | * This routine is invoked to set up the PCI device memory space for device |
| 10429 | * with SLI-4 interface spec. |
| 10430 | * |
| 10431 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10432 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10433 | * other values - error |
| 10434 | **/ |
| 10435 | static int |
| 10436 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 10437 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10438 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10439 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10440 | int error; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10441 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10442 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10443 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10444 | return -ENODEV; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10445 | |
| 10446 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10447 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 10448 | if (error) |
| 10449 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10450 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10451 | return error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10452 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10453 | /* |
| 10454 | * The BARs and register set definitions and offset locations are |
| 10455 | * dependent on the if_type. |
| 10456 | */ |
| 10457 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 10458 | &phba->sli4_hba.sli_intf.word0)) { |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10459 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10460 | } |
| 10461 | |
| 10462 | /* There is no SLI3 failback for SLI4 devices. */ |
| 10463 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 10464 | LPFC_SLI_INTF_VALID) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10465 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10466 | "2894 SLI_INTF reg contents invalid " |
| 10467 | "sli_intf reg 0x%x\n", |
| 10468 | phba->sli4_hba.sli_intf.word0); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10469 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10470 | } |
| 10471 | |
| 10472 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10473 | /* |
| 10474 | * Get the bus address of SLI4 device Bar regions and the |
| 10475 | * number of bytes required by each mapping. The mapping of the |
| 10476 | * particular PCI BARs regions is dependent on the type of |
| 10477 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10478 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10479 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 10480 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 10481 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10482 | |
| 10483 | /* |
| 10484 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 10485 | * addr |
| 10486 | */ |
| 10487 | phba->sli4_hba.conf_regs_memmap_p = |
| 10488 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 10489 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10490 | dev_printk(KERN_ERR, &pdev->dev, |
| 10491 | "ioremap failed for SLI4 PCI config " |
| 10492 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10493 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10494 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10495 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10496 | /* Set up BAR0 PCI config space register memory map */ |
| 10497 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10498 | } else { |
| 10499 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 10500 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10501 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10502 | dev_printk(KERN_ERR, &pdev->dev, |
| 10503 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10504 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10505 | } |
| 10506 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10507 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10508 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10509 | dev_printk(KERN_ERR, &pdev->dev, |
| 10510 | "ioremap failed for SLI4 PCI config " |
| 10511 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10512 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10513 | } |
| 10514 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10515 | } |
| 10516 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10517 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10518 | if (pci_resource_start(pdev, PCI_64BIT_BAR2)) { |
| 10519 | /* |
| 10520 | * Map SLI4 if type 0 HBA Control Register base to a |
| 10521 | * kernel virtual address and setup the registers. |
| 10522 | */ |
| 10523 | phba->pci_bar1_map = pci_resource_start(pdev, |
| 10524 | PCI_64BIT_BAR2); |
| 10525 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10526 | phba->sli4_hba.ctrl_regs_memmap_p = |
| 10527 | ioremap(phba->pci_bar1_map, |
| 10528 | bar1map_len); |
| 10529 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 10530 | dev_err(&pdev->dev, |
| 10531 | "ioremap failed for SLI4 HBA " |
| 10532 | "control registers.\n"); |
| 10533 | error = -ENOMEM; |
| 10534 | goto out_iounmap_conf; |
| 10535 | } |
| 10536 | phba->pci_bar2_memmap_p = |
| 10537 | phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10538 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10539 | } else { |
| 10540 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10541 | goto out_iounmap_conf; |
| 10542 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10543 | } |
| 10544 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10545 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) && |
| 10546 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
| 10547 | /* |
| 10548 | * Map SLI4 if type 6 HBA Doorbell Register base to a kernel |
| 10549 | * virtual address and setup the registers. |
| 10550 | */ |
| 10551 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 10552 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10553 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10554 | ioremap(phba->pci_bar1_map, bar1map_len); |
| 10555 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10556 | dev_err(&pdev->dev, |
| 10557 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10558 | error = -ENOMEM; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10559 | goto out_iounmap_conf; |
| 10560 | } |
| 10561 | phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
| 10562 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
| 10563 | } |
| 10564 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10565 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10566 | if (pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10567 | /* |
| 10568 | * Map SLI4 if type 0 HBA Doorbell Register base to |
| 10569 | * a kernel virtual address and setup the registers. |
| 10570 | */ |
| 10571 | phba->pci_bar2_map = pci_resource_start(pdev, |
| 10572 | PCI_64BIT_BAR4); |
| 10573 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10574 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10575 | ioremap(phba->pci_bar2_map, |
| 10576 | bar2map_len); |
| 10577 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10578 | dev_err(&pdev->dev, |
| 10579 | "ioremap failed for SLI4 HBA" |
| 10580 | " doorbell registers.\n"); |
| 10581 | error = -ENOMEM; |
| 10582 | goto out_iounmap_ctrl; |
| 10583 | } |
| 10584 | phba->pci_bar4_memmap_p = |
| 10585 | phba->sli4_hba.drbl_regs_memmap_p; |
| 10586 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 10587 | if (error) |
| 10588 | goto out_iounmap_all; |
| 10589 | } else { |
| 10590 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10591 | goto out_iounmap_all; |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10592 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10593 | } |
| 10594 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10595 | if (if_type == LPFC_SLI_INTF_IF_TYPE_6 && |
| 10596 | pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10597 | /* |
| 10598 | * Map SLI4 if type 6 HBA DPP Register base to a kernel |
| 10599 | * virtual address and setup the registers. |
| 10600 | */ |
| 10601 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 10602 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10603 | phba->sli4_hba.dpp_regs_memmap_p = |
| 10604 | ioremap(phba->pci_bar2_map, bar2map_len); |
| 10605 | if (!phba->sli4_hba.dpp_regs_memmap_p) { |
| 10606 | dev_err(&pdev->dev, |
| 10607 | "ioremap failed for SLI4 HBA dpp registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10608 | error = -ENOMEM; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10609 | goto out_iounmap_ctrl; |
| 10610 | } |
| 10611 | phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; |
| 10612 | } |
| 10613 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10614 | /* Set up the EQ/CQ register handeling functions now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10615 | switch (if_type) { |
| 10616 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10617 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10618 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10619 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db; |
| 10620 | phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10621 | break; |
| 10622 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10623 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_if6_eq_clr_intr; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10624 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db; |
| 10625 | phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_if6_write_cq_db; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10626 | break; |
| 10627 | default: |
| 10628 | break; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10629 | } |
| 10630 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10631 | return 0; |
| 10632 | |
| 10633 | out_iounmap_all: |
| 10634 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10635 | out_iounmap_ctrl: |
| 10636 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10637 | out_iounmap_conf: |
| 10638 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10639 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10640 | return error; |
| 10641 | } |
| 10642 | |
| 10643 | /** |
| 10644 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 10645 | * @phba: pointer to lpfc hba data structure. |
| 10646 | * |
| 10647 | * This routine is invoked to unset the PCI device memory space for device |
| 10648 | * with SLI-4 interface spec. |
| 10649 | **/ |
| 10650 | static void |
| 10651 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 10652 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10653 | uint32_t if_type; |
| 10654 | 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] | 10655 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10656 | switch (if_type) { |
| 10657 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10658 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10659 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10660 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10661 | break; |
| 10662 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 10663 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10664 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10665 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10666 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10667 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
James Smart | 0b43919 | 2019-12-18 15:58:05 -0800 | [diff] [blame] | 10668 | if (phba->sli4_hba.dpp_regs_memmap_p) |
| 10669 | iounmap(phba->sli4_hba.dpp_regs_memmap_p); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10670 | break; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10671 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10672 | default: |
| 10673 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 10674 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 10675 | if_type); |
| 10676 | break; |
| 10677 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10678 | } |
| 10679 | |
| 10680 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10681 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 10682 | * @phba: pointer to lpfc hba data structure. |
| 10683 | * |
| 10684 | * 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] | 10685 | * with SLI-3 interface specs. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10686 | * |
| 10687 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10688 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10689 | * other values - error |
| 10690 | **/ |
| 10691 | static int |
| 10692 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 10693 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10694 | int rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10695 | LPFC_MBOXQ_t *pmb; |
| 10696 | |
| 10697 | /* Set up MSI-X multi-message vectors */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10698 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 10699 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); |
| 10700 | if (rc < 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10701 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10702 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10703 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10704 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10705 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10706 | /* |
| 10707 | * Assign MSI-X vectors to interrupt handlers |
| 10708 | */ |
| 10709 | |
| 10710 | /* vector-0 is associated to slow-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10711 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10712 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10713 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 10714 | if (rc) { |
| 10715 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10716 | "0421 MSI-X slow-path request_irq failed " |
| 10717 | "(%d)\n", rc); |
| 10718 | goto msi_fail_out; |
| 10719 | } |
| 10720 | |
| 10721 | /* vector-1 is associated to fast-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10722 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10723 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10724 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 10725 | |
| 10726 | if (rc) { |
| 10727 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10728 | "0429 MSI-X fast-path request_irq failed " |
| 10729 | "(%d)\n", rc); |
| 10730 | goto irq_fail_out; |
| 10731 | } |
| 10732 | |
| 10733 | /* |
| 10734 | * Configure HBA MSI-X attention conditions to messages |
| 10735 | */ |
| 10736 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 10737 | |
| 10738 | if (!pmb) { |
| 10739 | rc = -ENOMEM; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10740 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10741 | "0474 Unable to allocate memory for issuing " |
| 10742 | "MBOX_CONFIG_MSI command\n"); |
| 10743 | goto mem_fail_out; |
| 10744 | } |
| 10745 | rc = lpfc_config_msi(phba, pmb); |
| 10746 | if (rc) |
| 10747 | goto mbx_fail_out; |
| 10748 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 10749 | if (rc != MBX_SUCCESS) { |
| 10750 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 10751 | "0351 Config MSI mailbox command failed, " |
| 10752 | "mbxCmd x%x, mbxStatus x%x\n", |
| 10753 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 10754 | goto mbx_fail_out; |
| 10755 | } |
| 10756 | |
| 10757 | /* Free memory allocated for mailbox command */ |
| 10758 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10759 | return rc; |
| 10760 | |
| 10761 | mbx_fail_out: |
| 10762 | /* Free memory allocated for mailbox command */ |
| 10763 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10764 | |
| 10765 | mem_fail_out: |
| 10766 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10767 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10768 | |
| 10769 | irq_fail_out: |
| 10770 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10771 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10772 | |
| 10773 | msi_fail_out: |
| 10774 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10775 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10776 | |
| 10777 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10778 | return rc; |
| 10779 | } |
| 10780 | |
| 10781 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10782 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 10783 | * @phba: pointer to lpfc hba data structure. |
| 10784 | * |
| 10785 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 10786 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 10787 | * enable the MSI vector. The device driver is responsible for calling the |
| 10788 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 10789 | * is done in this function. |
| 10790 | * |
| 10791 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10792 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10793 | * other values - error |
| 10794 | */ |
| 10795 | static int |
| 10796 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 10797 | { |
| 10798 | int rc; |
| 10799 | |
| 10800 | rc = pci_enable_msi(phba->pcidev); |
| 10801 | if (!rc) |
| 10802 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10803 | "0462 PCI enable MSI mode success.\n"); |
| 10804 | else { |
| 10805 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10806 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 10807 | return rc; |
| 10808 | } |
| 10809 | |
| 10810 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10811 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10812 | if (rc) { |
| 10813 | pci_disable_msi(phba->pcidev); |
| 10814 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10815 | "0478 MSI request_irq failed (%d)\n", rc); |
| 10816 | } |
| 10817 | return rc; |
| 10818 | } |
| 10819 | |
| 10820 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10821 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 10822 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 10823 | * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X). |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10824 | * |
| 10825 | * This routine is invoked to enable device interrupt and associate driver's |
| 10826 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 10827 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 10828 | * will try to fallback from the configured interrupt mode to an interrupt |
| 10829 | * mode which is supported by the platform, kernel, and device in the order |
| 10830 | * of: |
| 10831 | * MSI-X -> MSI -> IRQ. |
| 10832 | * |
| 10833 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10834 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10835 | * other values - error |
| 10836 | **/ |
| 10837 | static uint32_t |
| 10838 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 10839 | { |
| 10840 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 10841 | int retval; |
| 10842 | |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 10843 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 10844 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 10845 | if (retval) |
| 10846 | return intr_mode; |
| 10847 | phba->hba_flag &= ~HBA_NEEDS_CFG_PORT; |
| 10848 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10849 | if (cfg_mode == 2) { |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 10850 | /* Now, try to enable MSI-X interrupt mode */ |
| 10851 | retval = lpfc_sli_enable_msix(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10852 | if (!retval) { |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 10853 | /* Indicate initialization to MSI-X mode */ |
| 10854 | phba->intr_type = MSIX; |
| 10855 | intr_mode = 2; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10856 | } |
| 10857 | } |
| 10858 | |
| 10859 | /* Fallback to MSI if MSI-X initialization failed */ |
| 10860 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 10861 | retval = lpfc_sli_enable_msi(phba); |
| 10862 | if (!retval) { |
| 10863 | /* Indicate initialization to MSI mode */ |
| 10864 | phba->intr_type = MSI; |
| 10865 | intr_mode = 1; |
| 10866 | } |
| 10867 | } |
| 10868 | |
| 10869 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 10870 | if (phba->intr_type == NONE) { |
| 10871 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 10872 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 10873 | if (!retval) { |
| 10874 | /* Indicate initialization to INTx mode */ |
| 10875 | phba->intr_type = INTx; |
| 10876 | intr_mode = 0; |
| 10877 | } |
| 10878 | } |
| 10879 | return intr_mode; |
| 10880 | } |
| 10881 | |
| 10882 | /** |
| 10883 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 10884 | * @phba: pointer to lpfc hba data structure. |
| 10885 | * |
| 10886 | * This routine is invoked to disable device interrupt and disassociate the |
| 10887 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 10888 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 10889 | * release the interrupt vector(s) for the message signaled interrupt. |
| 10890 | **/ |
| 10891 | static void |
| 10892 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 10893 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10894 | int nr_irqs, i; |
| 10895 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10896 | if (phba->intr_type == MSIX) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10897 | nr_irqs = LPFC_MSIX_VECTORS; |
| 10898 | else |
| 10899 | nr_irqs = 1; |
| 10900 | |
| 10901 | for (i = 0; i < nr_irqs; i++) |
| 10902 | free_irq(pci_irq_vector(phba->pcidev, i), phba); |
| 10903 | pci_free_irq_vectors(phba->pcidev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10904 | |
| 10905 | /* Reset interrupt management states */ |
| 10906 | phba->intr_type = NONE; |
| 10907 | phba->sli.slistat.sli_intr = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10908 | } |
| 10909 | |
| 10910 | /** |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10911 | * lpfc_find_cpu_handle - Find the CPU that corresponds to the specified Queue |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10912 | * @phba: pointer to lpfc hba data structure. |
| 10913 | * @id: EQ vector index or Hardware Queue index |
| 10914 | * @match: LPFC_FIND_BY_EQ = match by EQ |
| 10915 | * LPFC_FIND_BY_HDWQ = match by Hardware Queue |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10916 | * Return the CPU that matches the selection criteria |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10917 | */ |
| 10918 | static uint16_t |
| 10919 | lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match) |
| 10920 | { |
| 10921 | struct lpfc_vector_map_info *cpup; |
| 10922 | int cpu; |
| 10923 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10924 | /* Loop through all CPUs */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10925 | for_each_present_cpu(cpu) { |
| 10926 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10927 | |
| 10928 | /* If we are matching by EQ, there may be multiple CPUs using |
| 10929 | * using the same vector, so select the one with |
| 10930 | * LPFC_CPU_FIRST_IRQ set. |
| 10931 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10932 | if ((match == LPFC_FIND_BY_EQ) && |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10933 | (cpup->flag & LPFC_CPU_FIRST_IRQ) && |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10934 | (cpup->eq == id)) |
| 10935 | return cpu; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10936 | |
| 10937 | /* If matching by HDWQ, select the first CPU that matches */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10938 | if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id)) |
| 10939 | return cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10940 | } |
| 10941 | return 0; |
| 10942 | } |
| 10943 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10944 | #ifdef CONFIG_X86 |
| 10945 | /** |
| 10946 | * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded |
| 10947 | * @phba: pointer to lpfc hba data structure. |
| 10948 | * @cpu: CPU map index |
| 10949 | * @phys_id: CPU package physical id |
| 10950 | * @core_id: CPU core id |
| 10951 | */ |
| 10952 | static int |
| 10953 | lpfc_find_hyper(struct lpfc_hba *phba, int cpu, |
| 10954 | uint16_t phys_id, uint16_t core_id) |
| 10955 | { |
| 10956 | struct lpfc_vector_map_info *cpup; |
| 10957 | int idx; |
| 10958 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10959 | for_each_present_cpu(idx) { |
| 10960 | cpup = &phba->sli4_hba.cpu_map[idx]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10961 | /* Does the cpup match the one we are looking for */ |
| 10962 | if ((cpup->phys_id == phys_id) && |
| 10963 | (cpup->core_id == core_id) && |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10964 | (cpu != idx)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10965 | return 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10966 | } |
| 10967 | return 0; |
| 10968 | } |
| 10969 | #endif |
| 10970 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10971 | /* |
| 10972 | * lpfc_assign_eq_map_info - Assigns eq for vector_map structure |
| 10973 | * @phba: pointer to lpfc hba data structure. |
| 10974 | * @eqidx: index for eq and irq vector |
| 10975 | * @flag: flags to set for vector_map structure |
| 10976 | * @cpu: cpu used to index vector_map structure |
| 10977 | * |
| 10978 | * The routine assigns eq info into vector_map structure |
| 10979 | */ |
| 10980 | static inline void |
| 10981 | lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag, |
| 10982 | unsigned int cpu) |
| 10983 | { |
| 10984 | struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10985 | struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx); |
| 10986 | |
| 10987 | cpup->eq = eqidx; |
| 10988 | cpup->flag |= flag; |
| 10989 | |
| 10990 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10991 | "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n", |
| 10992 | cpu, eqhdl->irq, cpup->eq, cpup->flag); |
| 10993 | } |
| 10994 | |
| 10995 | /** |
| 10996 | * lpfc_cpu_map_array_init - Initialize cpu_map structure |
| 10997 | * @phba: pointer to lpfc hba data structure. |
| 10998 | * |
| 10999 | * The routine initializes the cpu_map array structure |
| 11000 | */ |
| 11001 | static void |
| 11002 | lpfc_cpu_map_array_init(struct lpfc_hba *phba) |
| 11003 | { |
| 11004 | struct lpfc_vector_map_info *cpup; |
| 11005 | struct lpfc_eq_intr_info *eqi; |
| 11006 | int cpu; |
| 11007 | |
| 11008 | for_each_possible_cpu(cpu) { |
| 11009 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11010 | cpup->phys_id = LPFC_VECTOR_MAP_EMPTY; |
| 11011 | cpup->core_id = LPFC_VECTOR_MAP_EMPTY; |
| 11012 | cpup->hdwq = LPFC_VECTOR_MAP_EMPTY; |
| 11013 | cpup->eq = LPFC_VECTOR_MAP_EMPTY; |
| 11014 | cpup->flag = 0; |
| 11015 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu); |
| 11016 | INIT_LIST_HEAD(&eqi->list); |
| 11017 | eqi->icnt = 0; |
| 11018 | } |
| 11019 | } |
| 11020 | |
| 11021 | /** |
| 11022 | * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure |
| 11023 | * @phba: pointer to lpfc hba data structure. |
| 11024 | * |
| 11025 | * The routine initializes the hba_eq_hdl array structure |
| 11026 | */ |
| 11027 | static void |
| 11028 | lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba) |
| 11029 | { |
| 11030 | struct lpfc_hba_eq_hdl *eqhdl; |
| 11031 | int i; |
| 11032 | |
| 11033 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 11034 | eqhdl = lpfc_get_eq_hdl(i); |
| 11035 | eqhdl->irq = LPFC_VECTOR_MAP_EMPTY; |
| 11036 | eqhdl->phba = phba; |
| 11037 | } |
| 11038 | } |
| 11039 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11040 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11041 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11042 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11043 | * @vectors: number of msix vectors allocated. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11044 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11045 | * The routine will figure out the CPU affinity assignment for every |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11046 | * MSI-X vector allocated for the HBA. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11047 | * In addition, the CPU to IO channel mapping will be calculated |
| 11048 | * and the phba->sli4_hba.cpu_map array will reflect this. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11049 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11050 | static void |
| 11051 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11052 | { |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11053 | int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11054 | int max_phys_id, min_phys_id; |
| 11055 | int max_core_id, min_core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11056 | struct lpfc_vector_map_info *cpup; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11057 | struct lpfc_vector_map_info *new_cpup; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11058 | #ifdef CONFIG_X86 |
| 11059 | struct cpuinfo_x86 *cpuinfo; |
| 11060 | #endif |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 11061 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 11062 | struct lpfc_hdwq_stat *c_stat; |
| 11063 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11064 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11065 | max_phys_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11066 | min_phys_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11067 | max_core_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11068 | min_core_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11069 | |
| 11070 | /* Update CPU map with physical id and core id of each CPU */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 11071 | for_each_present_cpu(cpu) { |
| 11072 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11073 | #ifdef CONFIG_X86 |
| 11074 | cpuinfo = &cpu_data(cpu); |
| 11075 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 11076 | cpup->core_id = cpuinfo->cpu_core_id; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11077 | if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) |
| 11078 | cpup->flag |= LPFC_CPU_MAP_HYPER; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11079 | #else |
| 11080 | /* No distinction between CPUs for other platforms */ |
| 11081 | cpup->phys_id = 0; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11082 | cpup->core_id = cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11083 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11084 | |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11085 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11086 | "3328 CPU %d physid %d coreid %d flag x%x\n", |
| 11087 | cpu, cpup->phys_id, cpup->core_id, cpup->flag); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11088 | |
| 11089 | if (cpup->phys_id > max_phys_id) |
| 11090 | max_phys_id = cpup->phys_id; |
| 11091 | if (cpup->phys_id < min_phys_id) |
| 11092 | min_phys_id = cpup->phys_id; |
| 11093 | |
| 11094 | if (cpup->core_id > max_core_id) |
| 11095 | max_core_id = cpup->core_id; |
| 11096 | if (cpup->core_id < min_core_id) |
| 11097 | min_core_id = cpup->core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11098 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11099 | |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11100 | /* After looking at each irq vector assigned to this pcidev, its |
| 11101 | * possible to see that not ALL CPUs have been accounted for. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11102 | * Next we will set any unassigned (unaffinitized) cpu map |
| 11103 | * entries to a IRQ on the same phys_id. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11104 | */ |
| 11105 | first_cpu = cpumask_first(cpu_present_mask); |
| 11106 | start_cpu = first_cpu; |
| 11107 | |
| 11108 | for_each_present_cpu(cpu) { |
| 11109 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11110 | |
| 11111 | /* Is this CPU entry unassigned */ |
| 11112 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 11113 | /* Mark CPU as IRQ not assigned by the kernel */ |
| 11114 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 11115 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11116 | /* If so, find a new_cpup thats on the the SAME |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11117 | * phys_id as cpup. start_cpu will start where we |
| 11118 | * left off so all unassigned entries don't get assgined |
| 11119 | * the IRQ of the first entry. |
| 11120 | */ |
| 11121 | new_cpu = start_cpu; |
| 11122 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11123 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11124 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11125 | (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) && |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11126 | (new_cpup->phys_id == cpup->phys_id)) |
| 11127 | goto found_same; |
| 11128 | new_cpu = cpumask_next( |
| 11129 | new_cpu, cpu_present_mask); |
| 11130 | if (new_cpu == nr_cpumask_bits) |
| 11131 | new_cpu = first_cpu; |
| 11132 | } |
| 11133 | /* At this point, we leave the CPU as unassigned */ |
| 11134 | continue; |
| 11135 | found_same: |
| 11136 | /* We found a matching phys_id, so copy the IRQ info */ |
| 11137 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11138 | |
| 11139 | /* Bump start_cpu to the next slot to minmize the |
| 11140 | * chance of having multiple unassigned CPU entries |
| 11141 | * selecting the same IRQ. |
| 11142 | */ |
| 11143 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11144 | if (start_cpu == nr_cpumask_bits) |
| 11145 | start_cpu = first_cpu; |
| 11146 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11147 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11148 | "3337 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11149 | "eq %d from peer cpu %d same " |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11150 | "phys_id (%d)\n", |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11151 | cpu, cpup->eq, new_cpu, |
| 11152 | cpup->phys_id); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11153 | } |
| 11154 | } |
| 11155 | |
| 11156 | /* Set any unassigned cpu map entries to a IRQ on any phys_id */ |
| 11157 | start_cpu = first_cpu; |
| 11158 | |
| 11159 | for_each_present_cpu(cpu) { |
| 11160 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11161 | |
| 11162 | /* Is this entry unassigned */ |
| 11163 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 11164 | /* Mark it as IRQ not assigned by the kernel */ |
| 11165 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 11166 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11167 | /* If so, find a new_cpup thats on ANY phys_id |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11168 | * as the cpup. start_cpu will start where we |
| 11169 | * left off so all unassigned entries don't get |
| 11170 | * assigned the IRQ of the first entry. |
| 11171 | */ |
| 11172 | new_cpu = start_cpu; |
| 11173 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11174 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11175 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11176 | (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY)) |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11177 | goto found_any; |
| 11178 | new_cpu = cpumask_next( |
| 11179 | new_cpu, cpu_present_mask); |
| 11180 | if (new_cpu == nr_cpumask_bits) |
| 11181 | new_cpu = first_cpu; |
| 11182 | } |
| 11183 | /* We should never leave an entry unassigned */ |
| 11184 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11185 | "3339 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11186 | "eq %d UNASSIGNED\n", |
| 11187 | cpup->hdwq, cpup->eq); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11188 | continue; |
| 11189 | found_any: |
| 11190 | /* We found an available entry, copy the IRQ info */ |
| 11191 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11192 | |
| 11193 | /* Bump start_cpu to the next slot to minmize the |
| 11194 | * chance of having multiple unassigned CPU entries |
| 11195 | * selecting the same IRQ. |
| 11196 | */ |
| 11197 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11198 | if (start_cpu == nr_cpumask_bits) |
| 11199 | start_cpu = first_cpu; |
| 11200 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11201 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11202 | "3338 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11203 | "eq %d from peer cpu %d (%d/%d)\n", |
| 11204 | cpu, cpup->eq, new_cpu, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11205 | new_cpup->phys_id, new_cpup->core_id); |
| 11206 | } |
| 11207 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11208 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11209 | /* Assign hdwq indices that are unique across all cpus in the map |
| 11210 | * that are also FIRST_CPUs. |
| 11211 | */ |
| 11212 | idx = 0; |
| 11213 | for_each_present_cpu(cpu) { |
| 11214 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11215 | |
| 11216 | /* Only FIRST IRQs get a hdwq index assignment. */ |
| 11217 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 11218 | continue; |
| 11219 | |
| 11220 | /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */ |
| 11221 | cpup->hdwq = idx; |
| 11222 | idx++; |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 11223 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11224 | "3333 Set Affinity: CPU %d (phys %d core %d): " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11225 | "hdwq %d eq %d flg x%x\n", |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11226 | cpu, cpup->phys_id, cpup->core_id, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11227 | cpup->hdwq, cpup->eq, cpup->flag); |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11228 | } |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11229 | /* Associate a hdwq with each cpu_map entry |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11230 | * This will be 1 to 1 - hdwq to cpu, unless there are less |
| 11231 | * hardware queues then CPUs. For that case we will just round-robin |
| 11232 | * the available hardware queues as they get assigned to CPUs. |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11233 | * The next_idx is the idx from the FIRST_CPU loop above to account |
| 11234 | * for irq_chann < hdwq. The idx is used for round-robin assignments |
| 11235 | * and needs to start at 0. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11236 | */ |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11237 | next_idx = idx; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11238 | start_cpu = 0; |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11239 | idx = 0; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11240 | for_each_present_cpu(cpu) { |
| 11241 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11242 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11243 | /* FIRST cpus are already mapped. */ |
| 11244 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 11245 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11246 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11247 | /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq |
| 11248 | * of the unassigned cpus to the next idx so that all |
| 11249 | * hdw queues are fully utilized. |
| 11250 | */ |
| 11251 | if (next_idx < phba->cfg_hdw_queue) { |
| 11252 | cpup->hdwq = next_idx; |
| 11253 | next_idx++; |
| 11254 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11255 | } |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11256 | |
| 11257 | /* Not a First CPU and all hdw_queues are used. Reuse a |
| 11258 | * Hardware Queue for another CPU, so be smart about it |
| 11259 | * and pick one that has its IRQ/EQ mapped to the same phys_id |
| 11260 | * (CPU package) and core_id. |
| 11261 | */ |
| 11262 | new_cpu = start_cpu; |
| 11263 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11264 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11265 | if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && |
| 11266 | new_cpup->phys_id == cpup->phys_id && |
| 11267 | new_cpup->core_id == cpup->core_id) { |
| 11268 | goto found_hdwq; |
| 11269 | } |
| 11270 | new_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11271 | if (new_cpu == nr_cpumask_bits) |
| 11272 | new_cpu = first_cpu; |
| 11273 | } |
| 11274 | |
| 11275 | /* If we can't match both phys_id and core_id, |
| 11276 | * settle for just a phys_id match. |
| 11277 | */ |
| 11278 | new_cpu = start_cpu; |
| 11279 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11280 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11281 | if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && |
| 11282 | new_cpup->phys_id == cpup->phys_id) |
| 11283 | goto found_hdwq; |
| 11284 | |
| 11285 | new_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11286 | if (new_cpu == nr_cpumask_bits) |
| 11287 | new_cpu = first_cpu; |
| 11288 | } |
| 11289 | |
| 11290 | /* Otherwise just round robin on cfg_hdw_queue */ |
| 11291 | cpup->hdwq = idx % phba->cfg_hdw_queue; |
| 11292 | idx++; |
| 11293 | goto logit; |
| 11294 | found_hdwq: |
| 11295 | /* We found an available entry, copy the IRQ info */ |
| 11296 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11297 | if (start_cpu == nr_cpumask_bits) |
| 11298 | start_cpu = first_cpu; |
| 11299 | cpup->hdwq = new_cpup->hdwq; |
| 11300 | logit: |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 11301 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11302 | "3335 Set Affinity: CPU %d (phys %d core %d): " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11303 | "hdwq %d eq %d flg x%x\n", |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11304 | cpu, cpup->phys_id, cpup->core_id, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11305 | cpup->hdwq, cpup->eq, cpup->flag); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11306 | } |
| 11307 | |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11308 | /* |
| 11309 | * Initialize the cpu_map slots for not-present cpus in case |
| 11310 | * a cpu is hot-added. Perform a simple hdwq round robin assignment. |
| 11311 | */ |
| 11312 | idx = 0; |
| 11313 | for_each_possible_cpu(cpu) { |
| 11314 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 11315 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 11316 | c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu); |
| 11317 | c_stat->hdwq_no = cpup->hdwq; |
| 11318 | #endif |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11319 | if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) |
| 11320 | continue; |
| 11321 | |
| 11322 | cpup->hdwq = idx++ % phba->cfg_hdw_queue; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 11323 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 11324 | c_stat->hdwq_no = cpup->hdwq; |
| 11325 | #endif |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11326 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11327 | "3340 Set Affinity: not present " |
| 11328 | "CPU %d hdwq %d\n", |
| 11329 | cpu, cpup->hdwq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11330 | } |
| 11331 | |
| 11332 | /* The cpu_map array will be used later during initialization |
| 11333 | * when EQ / CQ / WQs are allocated and configured. |
| 11334 | */ |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11335 | return; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11336 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11337 | |
| 11338 | /** |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11339 | * lpfc_cpuhp_get_eq |
| 11340 | * |
| 11341 | * @phba: pointer to lpfc hba data structure. |
| 11342 | * @cpu: cpu going offline |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 11343 | * @eqlist: eq list to append to |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11344 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11345 | static int |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11346 | lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu, |
| 11347 | struct list_head *eqlist) |
| 11348 | { |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11349 | const struct cpumask *maskp; |
| 11350 | struct lpfc_queue *eq; |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11351 | struct cpumask *tmp; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11352 | u16 idx; |
| 11353 | |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11354 | tmp = kzalloc(cpumask_size(), GFP_KERNEL); |
| 11355 | if (!tmp) |
| 11356 | return -ENOMEM; |
| 11357 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11358 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 11359 | maskp = pci_irq_get_affinity(phba->pcidev, idx); |
| 11360 | if (!maskp) |
| 11361 | continue; |
| 11362 | /* |
| 11363 | * if irq is not affinitized to the cpu going |
| 11364 | * then we don't need to poll the eq attached |
| 11365 | * to it. |
| 11366 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11367 | if (!cpumask_and(tmp, maskp, cpumask_of(cpu))) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11368 | continue; |
| 11369 | /* get the cpus that are online and are affini- |
| 11370 | * tized to this irq vector. If the count is |
| 11371 | * more than 1 then cpuhp is not going to shut- |
| 11372 | * down this vector. Since this cpu has not |
| 11373 | * gone offline yet, we need >1. |
| 11374 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11375 | cpumask_and(tmp, maskp, cpu_online_mask); |
| 11376 | if (cpumask_weight(tmp) > 1) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11377 | continue; |
| 11378 | |
| 11379 | /* Now that we have an irq to shutdown, get the eq |
| 11380 | * mapped to this irq. Note: multiple hdwq's in |
| 11381 | * the software can share an eq, but eventually |
| 11382 | * only eq will be mapped to this vector |
| 11383 | */ |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11384 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 11385 | list_add(&eq->_poll_list, eqlist); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11386 | } |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11387 | kfree(tmp); |
| 11388 | return 0; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11389 | } |
| 11390 | |
| 11391 | static void __lpfc_cpuhp_remove(struct lpfc_hba *phba) |
| 11392 | { |
| 11393 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 11394 | return; |
| 11395 | |
| 11396 | cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state, |
| 11397 | &phba->cpuhp); |
| 11398 | /* |
| 11399 | * unregistering the instance doesn't stop the polling |
| 11400 | * timer. Wait for the poll timer to retire. |
| 11401 | */ |
| 11402 | synchronize_rcu(); |
| 11403 | del_timer_sync(&phba->cpuhp_poll_timer); |
| 11404 | } |
| 11405 | |
| 11406 | static void lpfc_cpuhp_remove(struct lpfc_hba *phba) |
| 11407 | { |
| 11408 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 11409 | return; |
| 11410 | |
| 11411 | __lpfc_cpuhp_remove(phba); |
| 11412 | } |
| 11413 | |
| 11414 | static void lpfc_cpuhp_add(struct lpfc_hba *phba) |
| 11415 | { |
| 11416 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 11417 | return; |
| 11418 | |
| 11419 | rcu_read_lock(); |
| 11420 | |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 11421 | if (!list_empty(&phba->poll_list)) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11422 | mod_timer(&phba->cpuhp_poll_timer, |
| 11423 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11424 | |
| 11425 | rcu_read_unlock(); |
| 11426 | |
| 11427 | cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, |
| 11428 | &phba->cpuhp); |
| 11429 | } |
| 11430 | |
| 11431 | static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval) |
| 11432 | { |
| 11433 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 11434 | *retval = -EAGAIN; |
| 11435 | return true; |
| 11436 | } |
| 11437 | |
| 11438 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11439 | *retval = 0; |
| 11440 | return true; |
| 11441 | } |
| 11442 | |
| 11443 | /* proceed with the hotplug */ |
| 11444 | return false; |
| 11445 | } |
| 11446 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11447 | /** |
| 11448 | * lpfc_irq_set_aff - set IRQ affinity |
| 11449 | * @eqhdl: EQ handle |
| 11450 | * @cpu: cpu to set affinity |
| 11451 | * |
| 11452 | **/ |
| 11453 | static inline void |
| 11454 | lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu) |
| 11455 | { |
| 11456 | cpumask_clear(&eqhdl->aff_mask); |
| 11457 | cpumask_set_cpu(cpu, &eqhdl->aff_mask); |
| 11458 | irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING); |
| 11459 | irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask); |
| 11460 | } |
| 11461 | |
| 11462 | /** |
| 11463 | * lpfc_irq_clear_aff - clear IRQ affinity |
| 11464 | * @eqhdl: EQ handle |
| 11465 | * |
| 11466 | **/ |
| 11467 | static inline void |
| 11468 | lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl) |
| 11469 | { |
| 11470 | cpumask_clear(&eqhdl->aff_mask); |
| 11471 | irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11472 | } |
| 11473 | |
| 11474 | /** |
| 11475 | * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event |
| 11476 | * @phba: pointer to HBA context object. |
| 11477 | * @cpu: cpu going offline/online |
| 11478 | * @offline: true, cpu is going offline. false, cpu is coming online. |
| 11479 | * |
| 11480 | * If cpu is going offline, we'll try our best effort to find the next |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11481 | * online cpu on the phba's original_mask and migrate all offlining IRQ |
| 11482 | * affinities. |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11483 | * |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11484 | * If cpu is coming online, reaffinitize the IRQ back to the onlining cpu. |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11485 | * |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11486 | * Note: Call only if NUMA or NHT mode is enabled, otherwise rely on |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11487 | * PCI_IRQ_AFFINITY to auto-manage IRQ affinity. |
| 11488 | * |
| 11489 | **/ |
| 11490 | static void |
| 11491 | lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline) |
| 11492 | { |
| 11493 | struct lpfc_vector_map_info *cpup; |
| 11494 | struct cpumask *aff_mask; |
| 11495 | unsigned int cpu_select, cpu_next, idx; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11496 | const struct cpumask *orig_mask; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11497 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11498 | if (phba->irq_chann_mode == NORMAL_MODE) |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11499 | return; |
| 11500 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11501 | orig_mask = &phba->sli4_hba.irq_aff_mask; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11502 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11503 | if (!cpumask_test_cpu(cpu, orig_mask)) |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11504 | return; |
| 11505 | |
| 11506 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11507 | |
| 11508 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 11509 | return; |
| 11510 | |
| 11511 | if (offline) { |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11512 | /* Find next online CPU on original mask */ |
| 11513 | cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true); |
| 11514 | cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11515 | |
| 11516 | /* Found a valid CPU */ |
| 11517 | if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) { |
| 11518 | /* Go through each eqhdl and ensure offlining |
| 11519 | * cpu aff_mask is migrated |
| 11520 | */ |
| 11521 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 11522 | aff_mask = lpfc_get_aff_mask(idx); |
| 11523 | |
| 11524 | /* Migrate affinity */ |
| 11525 | if (cpumask_test_cpu(cpu, aff_mask)) |
| 11526 | lpfc_irq_set_aff(lpfc_get_eq_hdl(idx), |
| 11527 | cpu_select); |
| 11528 | } |
| 11529 | } else { |
| 11530 | /* Rely on irqbalance if no online CPUs left on NUMA */ |
| 11531 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) |
| 11532 | lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx)); |
| 11533 | } |
| 11534 | } else { |
| 11535 | /* Migrate affinity back to this CPU */ |
| 11536 | lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu); |
| 11537 | } |
| 11538 | } |
| 11539 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11540 | static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node) |
| 11541 | { |
| 11542 | struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp); |
| 11543 | struct lpfc_queue *eq, *next; |
| 11544 | LIST_HEAD(eqlist); |
| 11545 | int retval; |
| 11546 | |
| 11547 | if (!phba) { |
| 11548 | WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id()); |
| 11549 | return 0; |
| 11550 | } |
| 11551 | |
| 11552 | if (__lpfc_cpuhp_checks(phba, &retval)) |
| 11553 | return retval; |
| 11554 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11555 | lpfc_irq_rebalance(phba, cpu, true); |
| 11556 | |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11557 | retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist); |
| 11558 | if (retval) |
| 11559 | return retval; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11560 | |
| 11561 | /* start polling on these eq's */ |
| 11562 | list_for_each_entry_safe(eq, next, &eqlist, _poll_list) { |
| 11563 | list_del_init(&eq->_poll_list); |
| 11564 | lpfc_sli4_start_polling(eq); |
| 11565 | } |
| 11566 | |
| 11567 | return 0; |
| 11568 | } |
| 11569 | |
| 11570 | static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node) |
| 11571 | { |
| 11572 | struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp); |
| 11573 | struct lpfc_queue *eq, *next; |
| 11574 | unsigned int n; |
| 11575 | int retval; |
| 11576 | |
| 11577 | if (!phba) { |
| 11578 | WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id()); |
| 11579 | return 0; |
| 11580 | } |
| 11581 | |
| 11582 | if (__lpfc_cpuhp_checks(phba, &retval)) |
| 11583 | return retval; |
| 11584 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11585 | lpfc_irq_rebalance(phba, cpu, false); |
| 11586 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11587 | list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) { |
| 11588 | n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ); |
| 11589 | if (n == cpu) |
| 11590 | lpfc_sli4_stop_polling(eq); |
| 11591 | } |
| 11592 | |
| 11593 | return 0; |
| 11594 | } |
| 11595 | |
| 11596 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11597 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 11598 | * @phba: pointer to lpfc hba data structure. |
| 11599 | * |
| 11600 | * This routine is invoked to enable the MSI-X interrupt vectors to device |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11601 | * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them |
| 11602 | * to cpus on the system. |
| 11603 | * |
| 11604 | * When cfg_irq_numa is enabled, the adapter will only allocate vectors for |
| 11605 | * the number of cpus on the same numa node as this adapter. The vectors are |
| 11606 | * allocated without requesting OS affinity mapping. A vector will be |
| 11607 | * allocated and assigned to each online and offline cpu. If the cpu is |
| 11608 | * online, then affinity will be set to that cpu. If the cpu is offline, then |
| 11609 | * affinity will be set to the nearest peer cpu within the numa node that is |
| 11610 | * online. If there are no online cpus within the numa node, affinity is not |
| 11611 | * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping |
| 11612 | * is consistent with the way cpu online/offline is handled when cfg_irq_numa is |
| 11613 | * configured. |
| 11614 | * |
| 11615 | * If numa mode is not enabled and there is more than 1 vector allocated, then |
| 11616 | * the driver relies on the managed irq interface where the OS assigns vector to |
| 11617 | * cpu affinity. The driver will then use that affinity mapping to setup its |
| 11618 | * cpu mapping table. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11619 | * |
| 11620 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11621 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11622 | * other values - error |
| 11623 | **/ |
| 11624 | static int |
| 11625 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 11626 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11627 | int vectors, rc, index; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11628 | char *name; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11629 | const struct cpumask *aff_mask = NULL; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11630 | unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids; |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11631 | struct lpfc_vector_map_info *cpup; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11632 | struct lpfc_hba_eq_hdl *eqhdl; |
| 11633 | const struct cpumask *maskp; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11634 | unsigned int flags = PCI_IRQ_MSIX; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11635 | |
| 11636 | /* Set up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11637 | vectors = phba->cfg_irq_chann; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11638 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11639 | if (phba->irq_chann_mode != NORMAL_MODE) |
| 11640 | aff_mask = &phba->sli4_hba.irq_aff_mask; |
| 11641 | |
| 11642 | if (aff_mask) { |
| 11643 | cpu_cnt = cpumask_weight(aff_mask); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11644 | vectors = min(phba->cfg_irq_chann, cpu_cnt); |
| 11645 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11646 | /* cpu: iterates over aff_mask including offline or online |
| 11647 | * cpu_select: iterates over online aff_mask to set affinity |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11648 | */ |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11649 | cpu = cpumask_first(aff_mask); |
| 11650 | cpu_select = lpfc_next_online_cpu(aff_mask, cpu); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11651 | } else { |
| 11652 | flags |= PCI_IRQ_AFFINITY; |
| 11653 | } |
| 11654 | |
| 11655 | rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags); |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11656 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11657 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11658 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11659 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11660 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11661 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11662 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11663 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11664 | for (index = 0; index < vectors; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11665 | eqhdl = lpfc_get_eq_hdl(index); |
| 11666 | name = eqhdl->handler_name; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11667 | memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ); |
| 11668 | snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 11669 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11670 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11671 | eqhdl->idx = index; |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 11672 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
| 11673 | &lpfc_sli4_hba_intr_handler, 0, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11674 | name, eqhdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11675 | if (rc) { |
| 11676 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11677 | "0486 MSI-X fast-path (%d) " |
| 11678 | "request_irq failed (%d)\n", index, rc); |
| 11679 | goto cfg_fail_out; |
| 11680 | } |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11681 | |
| 11682 | eqhdl->irq = pci_irq_vector(phba->pcidev, index); |
| 11683 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11684 | if (aff_mask) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11685 | /* If found a neighboring online cpu, set affinity */ |
| 11686 | if (cpu_select < nr_cpu_ids) |
| 11687 | lpfc_irq_set_aff(eqhdl, cpu_select); |
| 11688 | |
| 11689 | /* Assign EQ to cpu_map */ |
| 11690 | lpfc_assign_eq_map_info(phba, index, |
| 11691 | LPFC_CPU_FIRST_IRQ, |
| 11692 | cpu); |
| 11693 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11694 | /* Iterate to next offline or online cpu in aff_mask */ |
| 11695 | cpu = cpumask_next(cpu, aff_mask); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11696 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11697 | /* Find next online cpu in aff_mask to set affinity */ |
| 11698 | cpu_select = lpfc_next_online_cpu(aff_mask, cpu); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11699 | } else if (vectors == 1) { |
| 11700 | cpu = cpumask_first(cpu_present_mask); |
| 11701 | lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ, |
| 11702 | cpu); |
| 11703 | } else { |
| 11704 | maskp = pci_irq_get_affinity(phba->pcidev, index); |
| 11705 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11706 | /* Loop through all CPUs associated with vector index */ |
| 11707 | for_each_cpu_and(cpu, maskp, cpu_present_mask) { |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11708 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11709 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11710 | /* If this is the first CPU thats assigned to |
| 11711 | * this vector, set LPFC_CPU_FIRST_IRQ. |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11712 | * |
| 11713 | * With certain platforms its possible that irq |
| 11714 | * vectors are affinitized to all the cpu's. |
| 11715 | * This can result in each cpu_map.eq to be set |
| 11716 | * to the last vector, resulting in overwrite |
| 11717 | * of all the previous cpu_map.eq. Ensure that |
| 11718 | * each vector receives a place in cpu_map. |
| 11719 | * Later call to lpfc_cpu_affinity_check will |
| 11720 | * ensure we are nicely balanced out. |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11721 | */ |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11722 | if (cpup->eq != LPFC_VECTOR_MAP_EMPTY) |
| 11723 | continue; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11724 | lpfc_assign_eq_map_info(phba, index, |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11725 | LPFC_CPU_FIRST_IRQ, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11726 | cpu); |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11727 | break; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11728 | } |
| 11729 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11730 | } |
| 11731 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11732 | if (vectors != phba->cfg_irq_chann) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11733 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11734 | "3238 Reducing IO channels to match number of " |
| 11735 | "MSI-X vectors, requested %d got %d\n", |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11736 | phba->cfg_irq_chann, vectors); |
| 11737 | if (phba->cfg_irq_chann > vectors) |
| 11738 | phba->cfg_irq_chann = vectors; |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11739 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11740 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11741 | return rc; |
| 11742 | |
| 11743 | cfg_fail_out: |
| 11744 | /* free the irq already requested */ |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11745 | for (--index; index >= 0; index--) { |
| 11746 | eqhdl = lpfc_get_eq_hdl(index); |
| 11747 | lpfc_irq_clear_aff(eqhdl); |
| 11748 | irq_set_affinity_hint(eqhdl->irq, NULL); |
| 11749 | free_irq(eqhdl->irq, eqhdl); |
| 11750 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11751 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11752 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11753 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11754 | |
| 11755 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11756 | return rc; |
| 11757 | } |
| 11758 | |
| 11759 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11760 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 11761 | * @phba: pointer to lpfc hba data structure. |
| 11762 | * |
| 11763 | * This routine is invoked to enable the MSI interrupt mode to device with |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11764 | * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is |
| 11765 | * called to enable the MSI vector. The device driver is responsible for |
| 11766 | * calling the request_irq() to register MSI vector with a interrupt the |
| 11767 | * handler, which is done in this function. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11768 | * |
| 11769 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11770 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11771 | * other values - error |
| 11772 | **/ |
| 11773 | static int |
| 11774 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 11775 | { |
| 11776 | int rc, index; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11777 | unsigned int cpu; |
| 11778 | struct lpfc_hba_eq_hdl *eqhdl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11779 | |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11780 | rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1, |
| 11781 | PCI_IRQ_MSI | PCI_IRQ_AFFINITY); |
| 11782 | if (rc > 0) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11783 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11784 | "0487 PCI enable MSI mode success.\n"); |
| 11785 | else { |
| 11786 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11787 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11788 | return rc ? rc : -1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11789 | } |
| 11790 | |
| 11791 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 11792 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11793 | if (rc) { |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11794 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11795 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11796 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11797 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11798 | } |
| 11799 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11800 | eqhdl = lpfc_get_eq_hdl(0); |
| 11801 | eqhdl->irq = pci_irq_vector(phba->pcidev, 0); |
| 11802 | |
| 11803 | cpu = cpumask_first(cpu_present_mask); |
| 11804 | lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu); |
| 11805 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11806 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11807 | eqhdl = lpfc_get_eq_hdl(index); |
| 11808 | eqhdl->idx = index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11809 | } |
| 11810 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11811 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11812 | } |
| 11813 | |
| 11814 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11815 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 11816 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 11817 | * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X). |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11818 | * |
| 11819 | * This routine is invoked to enable device interrupt and associate driver's |
| 11820 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 11821 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 11822 | * the driver will try to fallback from the configured interrupt mode to an |
| 11823 | * interrupt mode which is supported by the platform, kernel, and device in |
| 11824 | * the order of: |
| 11825 | * MSI-X -> MSI -> IRQ. |
| 11826 | * |
| 11827 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11828 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11829 | * other values - error |
| 11830 | **/ |
| 11831 | static uint32_t |
| 11832 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 11833 | { |
| 11834 | uint32_t intr_mode = LPFC_INTR_ERROR; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11835 | int retval, idx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11836 | |
| 11837 | if (cfg_mode == 2) { |
| 11838 | /* Preparation before conf_msi mbox cmd */ |
| 11839 | retval = 0; |
| 11840 | if (!retval) { |
| 11841 | /* Now, try to enable MSI-X interrupt mode */ |
| 11842 | retval = lpfc_sli4_enable_msix(phba); |
| 11843 | if (!retval) { |
| 11844 | /* Indicate initialization to MSI-X mode */ |
| 11845 | phba->intr_type = MSIX; |
| 11846 | intr_mode = 2; |
| 11847 | } |
| 11848 | } |
| 11849 | } |
| 11850 | |
| 11851 | /* Fallback to MSI if MSI-X initialization failed */ |
| 11852 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 11853 | retval = lpfc_sli4_enable_msi(phba); |
| 11854 | if (!retval) { |
| 11855 | /* Indicate initialization to MSI mode */ |
| 11856 | phba->intr_type = MSI; |
| 11857 | intr_mode = 1; |
| 11858 | } |
| 11859 | } |
| 11860 | |
| 11861 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 11862 | if (phba->intr_type == NONE) { |
| 11863 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 11864 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 11865 | if (!retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11866 | struct lpfc_hba_eq_hdl *eqhdl; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11867 | unsigned int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11868 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11869 | /* Indicate initialization to INTx mode */ |
| 11870 | phba->intr_type = INTx; |
| 11871 | intr_mode = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11872 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11873 | eqhdl = lpfc_get_eq_hdl(0); |
| 11874 | eqhdl->irq = pci_irq_vector(phba->pcidev, 0); |
| 11875 | |
| 11876 | cpu = cpumask_first(cpu_present_mask); |
| 11877 | lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, |
| 11878 | cpu); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11879 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11880 | eqhdl = lpfc_get_eq_hdl(idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11881 | eqhdl->idx = idx; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11882 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11883 | } |
| 11884 | } |
| 11885 | return intr_mode; |
| 11886 | } |
| 11887 | |
| 11888 | /** |
| 11889 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 11890 | * @phba: pointer to lpfc hba data structure. |
| 11891 | * |
| 11892 | * This routine is invoked to disable device interrupt and disassociate |
| 11893 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 11894 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 11895 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 11896 | **/ |
| 11897 | static void |
| 11898 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 11899 | { |
| 11900 | /* Disable the currently initialized interrupt mode */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11901 | if (phba->intr_type == MSIX) { |
| 11902 | int index; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11903 | struct lpfc_hba_eq_hdl *eqhdl; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11904 | |
| 11905 | /* Free up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11906 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11907 | eqhdl = lpfc_get_eq_hdl(index); |
| 11908 | lpfc_irq_clear_aff(eqhdl); |
| 11909 | irq_set_affinity_hint(eqhdl->irq, NULL); |
| 11910 | free_irq(eqhdl->irq, eqhdl); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11911 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11912 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11913 | free_irq(phba->pcidev->irq, phba); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11914 | } |
| 11915 | |
| 11916 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11917 | |
| 11918 | /* Reset interrupt management states */ |
| 11919 | phba->intr_type = NONE; |
| 11920 | phba->sli.slistat.sli_intr = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11921 | } |
| 11922 | |
| 11923 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11924 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 11925 | * @phba: pointer to lpfc hba data structure. |
| 11926 | * |
| 11927 | * This routine is invoked to unset the HBA device initialization steps to |
| 11928 | * a device with SLI-3 interface spec. |
| 11929 | **/ |
| 11930 | static void |
| 11931 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 11932 | { |
| 11933 | struct lpfc_vport *vport = phba->pport; |
| 11934 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 11935 | |
| 11936 | spin_lock_irq(shost->host_lock); |
| 11937 | vport->load_flag |= FC_UNLOADING; |
| 11938 | spin_unlock_irq(shost->host_lock); |
| 11939 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 11940 | kfree(phba->vpi_bmask); |
| 11941 | kfree(phba->vpi_ids); |
| 11942 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11943 | lpfc_stop_hba_timers(phba); |
| 11944 | |
| 11945 | phba->pport->work_port_events = 0; |
| 11946 | |
| 11947 | lpfc_sli_hba_down(phba); |
| 11948 | |
| 11949 | lpfc_sli_brdrestart(phba); |
| 11950 | |
| 11951 | lpfc_sli_disable_intr(phba); |
| 11952 | |
| 11953 | return; |
| 11954 | } |
| 11955 | |
| 11956 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11957 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 11958 | * @phba: Pointer to HBA context object. |
| 11959 | * |
| 11960 | * This function is called in the SLI4 code path to wait for completion |
| 11961 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 11962 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 11963 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 11964 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 11965 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 11966 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 11967 | * the rest of the driver unload resource release. |
| 11968 | **/ |
| 11969 | static void |
| 11970 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 11971 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11972 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11973 | int idx, ccnt; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11974 | int wait_time = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11975 | int io_xri_cmpl = 1; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11976 | int nvmet_xri_cmpl = 1; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11977 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 11978 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11979 | /* Driver just aborted IOs during the hba_unset process. Pause |
| 11980 | * here to give the HBA time to complete the IO and get entries |
| 11981 | * into the abts lists. |
| 11982 | */ |
| 11983 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5); |
| 11984 | |
| 11985 | /* Wait for NVME pending IO to flush back to transport. */ |
| 11986 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11987 | lpfc_nvme_wait_for_io_drain(phba); |
| 11988 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11989 | ccnt = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11990 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11991 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11992 | io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list); |
| 11993 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11994 | ccnt++; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11995 | } |
| 11996 | if (ccnt) |
| 11997 | io_xri_cmpl = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11998 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11999 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 12000 | nvmet_xri_cmpl = |
| 12001 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 12002 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12003 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12004 | while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 12005 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 12006 | if (!nvmet_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12007 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 12008 | "6424 NVMET XRI exchange busy " |
| 12009 | "wait time: %d seconds.\n", |
| 12010 | wait_time/1000); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12011 | if (!io_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12012 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12013 | "6100 IO XRI exchange busy " |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 12014 | "wait time: %d seconds.\n", |
| 12015 | wait_time/1000); |
| 12016 | if (!els_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12017 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 12018 | "2878 ELS XRI exchange busy " |
| 12019 | "wait time: %d seconds.\n", |
| 12020 | wait_time/1000); |
| 12021 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 12022 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 12023 | } else { |
| 12024 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 12025 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 12026 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12027 | |
| 12028 | ccnt = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12029 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 12030 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12031 | io_xri_cmpl = list_empty( |
| 12032 | &qp->lpfc_abts_io_buf_list); |
| 12033 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 12034 | ccnt++; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12035 | } |
| 12036 | if (ccnt) |
| 12037 | io_xri_cmpl = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 12038 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 12039 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 12040 | nvmet_xri_cmpl = list_empty( |
| 12041 | &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 12042 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 12043 | els_xri_cmpl = |
| 12044 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12045 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 12046 | } |
| 12047 | } |
| 12048 | |
| 12049 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12050 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 12051 | * @phba: Pointer to HBA context object. |
| 12052 | * |
| 12053 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 12054 | * function. The caller is not required to hold any lock. This routine |
| 12055 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 12056 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 12057 | * free any pending commands. |
| 12058 | **/ |
| 12059 | static void |
| 12060 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 12061 | { |
| 12062 | int wait_cnt = 0; |
| 12063 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 12064 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12065 | |
| 12066 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 12067 | if (phba->pport) |
| 12068 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12069 | |
| 12070 | /* |
| 12071 | * Gracefully wait out the potential current outstanding asynchronous |
| 12072 | * mailbox command. |
| 12073 | */ |
| 12074 | |
| 12075 | /* First, block any pending async mailbox command from posted */ |
| 12076 | spin_lock_irq(&phba->hbalock); |
| 12077 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 12078 | spin_unlock_irq(&phba->hbalock); |
| 12079 | /* Now, trying to wait it out if we can */ |
| 12080 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 12081 | msleep(10); |
| 12082 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 12083 | break; |
| 12084 | } |
| 12085 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 12086 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 12087 | spin_lock_irq(&phba->hbalock); |
| 12088 | mboxq = phba->sli.mbox_active; |
| 12089 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 12090 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 12091 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 12092 | phba->sli.mbox_active = NULL; |
| 12093 | spin_unlock_irq(&phba->hbalock); |
| 12094 | } |
| 12095 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 12096 | /* Abort all iocbs associated with the hba */ |
| 12097 | lpfc_sli_hba_iocb_abort(phba); |
| 12098 | |
| 12099 | /* Wait for completion of device XRI exchange busy */ |
| 12100 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 12101 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12102 | /* per-phba callback de-registration for hotplug event */ |
SeongJae Park | 46da547 | 2020-06-23 10:41:22 +0200 | [diff] [blame] | 12103 | if (phba->pport) |
| 12104 | lpfc_cpuhp_remove(phba); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12105 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12106 | /* Disable PCI subsystem interrupt */ |
| 12107 | lpfc_sli4_disable_intr(phba); |
| 12108 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 12109 | /* Disable SR-IOV if enabled */ |
| 12110 | if (phba->cfg_sriov_nr_virtfn) |
| 12111 | pci_disable_sriov(pdev); |
| 12112 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12113 | /* Stop kthread signal shall trigger work_done one more time */ |
| 12114 | kthread_stop(phba->worker_thread); |
| 12115 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12116 | /* Disable FW logging to host memory */ |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 12117 | lpfc_ras_stop_fwlog(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12118 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 12119 | /* Unset the queues shared with the hardware then release all |
| 12120 | * allocated resources. |
| 12121 | */ |
| 12122 | lpfc_sli4_queue_unset(phba); |
| 12123 | lpfc_sli4_queue_destroy(phba); |
| 12124 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 12125 | /* Reset SLI4 HBA FCoE function */ |
| 12126 | lpfc_pci_function_reset(phba); |
| 12127 | |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 12128 | /* Free RAS DMA memory */ |
| 12129 | if (phba->ras_fwlog.ras_enabled) |
| 12130 | lpfc_sli4_ras_dma_free(phba); |
| 12131 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12132 | /* Stop the SLI4 device port */ |
James Smart | 1ffdd2c | 2019-03-04 15:27:51 -0800 | [diff] [blame] | 12133 | if (phba->pport) |
| 12134 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12135 | } |
| 12136 | |
| 12137 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12138 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 12139 | * @phba: Pointer to HBA context object. |
| 12140 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 12141 | * |
| 12142 | * This function is called in the SLI4 code path to read the port's |
| 12143 | * sli4 capabilities. |
| 12144 | * |
| 12145 | * This function may be be called from any context that can block-wait |
| 12146 | * for the completion. The expectation is that this routine is called |
| 12147 | * typically from probe_one or from the online routine. |
| 12148 | **/ |
| 12149 | int |
| 12150 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 12151 | { |
| 12152 | int rc; |
| 12153 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 12154 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12155 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12156 | int length; |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12157 | bool exp_wqcq_pages = true; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12158 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 12159 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 12160 | /* |
| 12161 | * By default, the driver assumes the SLI4 port requires RPI |
| 12162 | * header postings. The SLI4_PARAM response will correct this |
| 12163 | * assumption. |
| 12164 | */ |
| 12165 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 12166 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12167 | /* Read the port's SLI4 Config Parameters */ |
| 12168 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 12169 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12170 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12171 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 12172 | length, LPFC_SLI4_MBX_EMBED); |
| 12173 | if (!phba->sli4_hba.intr_enable) |
| 12174 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12175 | else { |
| 12176 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 12177 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 12178 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12179 | if (unlikely(rc)) |
| 12180 | return rc; |
| 12181 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 12182 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 12183 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 12184 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 12185 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 12186 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 12187 | mbx_sli4_parameters); |
| 12188 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 12189 | mbx_sli4_parameters); |
| 12190 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 12191 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 12192 | else |
| 12193 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 12194 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
James Smart | b62232b | 2021-04-11 18:31:22 -0700 | [diff] [blame] | 12195 | sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope, |
| 12196 | mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12197 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12198 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 12199 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 12200 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 12201 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 12202 | sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters); |
| 12203 | sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 12204 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 12205 | sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters); |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 12206 | sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12207 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 12208 | mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12209 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12210 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 12211 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 12212 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 12213 | 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] | 12214 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 12215 | /* Check for Extended Pre-Registered SGL support */ |
| 12216 | phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters); |
| 12217 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12218 | /* Check for firmware nvme support */ |
| 12219 | rc = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
| 12220 | bf_get(cfg_xib, mbx_sli4_parameters)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12221 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12222 | if (rc) { |
| 12223 | /* Save this to indicate the Firmware supports NVME */ |
| 12224 | sli4_params->nvme = 1; |
| 12225 | |
| 12226 | /* Firmware NVME support, check driver FC4 NVME support */ |
| 12227 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) { |
| 12228 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
| 12229 | "6133 Disabling NVME support: " |
| 12230 | "FC4 type not supported: x%x\n", |
| 12231 | phba->cfg_enable_fc4_type); |
| 12232 | goto fcponly; |
| 12233 | } |
| 12234 | } else { |
| 12235 | /* No firmware NVME support, check driver FC4 NVME support */ |
| 12236 | sli4_params->nvme = 0; |
| 12237 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 12238 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, |
| 12239 | "6101 Disabling NVME support: Not " |
| 12240 | "supported by firmware (%d %d) x%x\n", |
| 12241 | bf_get(cfg_nvme, mbx_sli4_parameters), |
| 12242 | bf_get(cfg_xib, mbx_sli4_parameters), |
| 12243 | phba->cfg_enable_fc4_type); |
| 12244 | fcponly: |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12245 | phba->nvmet_support = 0; |
| 12246 | phba->cfg_nvmet_mrq = 0; |
James Smart | 6a224b4 | 2019-08-14 16:56:57 -0700 | [diff] [blame] | 12247 | phba->cfg_nvme_seg_cnt = 0; |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12248 | |
| 12249 | /* If no FC4 type support, move to just SCSI support */ |
| 12250 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 12251 | return -ENODEV; |
| 12252 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; |
| 12253 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12254 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12255 | |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12256 | /* If the NVME FC4 type is enabled, scale the sg_seg_cnt to |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 12257 | * accommodate 512K and 1M IOs in a single nvme buf. |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12258 | */ |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 12259 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12260 | phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12261 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12262 | /* Only embed PBDE for if_type 6, PBDE support requires xib be set */ |
| 12263 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 12264 | LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters))) |
| 12265 | phba->cfg_enable_pbde = 0; |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12266 | |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 12267 | /* |
| 12268 | * To support Suppress Response feature we must satisfy 3 conditions. |
| 12269 | * lpfc_suppress_rsp module parameter must be set (default). |
| 12270 | * In SLI4-Parameters Descriptor: |
| 12271 | * Extended Inline Buffers (XIB) must be supported. |
| 12272 | * Suppress Response IU Not Supported (SRIUNS) must NOT be supported |
| 12273 | * (double negative). |
| 12274 | */ |
| 12275 | if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) && |
| 12276 | !(bf_get(cfg_nosr, mbx_sli4_parameters))) |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12277 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 12278 | else |
| 12279 | phba->cfg_suppress_rsp = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12280 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 12281 | if (bf_get(cfg_eqdr, mbx_sli4_parameters)) |
| 12282 | phba->sli.sli_flag |= LPFC_SLI_USE_EQDR; |
| 12283 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12284 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 12285 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 12286 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 12287 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 12288 | /* |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12289 | * Check whether the adapter supports an embedded copy of the |
| 12290 | * FCP CMD IU within the WQE for FCP_Ixxx commands. In order |
| 12291 | * to use this option, 128-byte WQEs must be used. |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 12292 | */ |
| 12293 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 12294 | phba->fcp_embed_io = 1; |
| 12295 | else |
| 12296 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 12297 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12298 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12299 | "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n", |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12300 | bf_get(cfg_xib, mbx_sli4_parameters), |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12301 | phba->cfg_enable_pbde, |
James Smart | ae463b6 | 2021-07-07 11:43:32 -0700 | [diff] [blame] | 12302 | phba->fcp_embed_io, sli4_params->nvme, |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 12303 | phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp); |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12304 | |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12305 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 12306 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 12307 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
James Smart | c221768 | 2018-05-24 21:09:00 -0700 | [diff] [blame] | 12308 | LPFC_SLI_INTF_FAMILY_LNCR_A0)) |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12309 | exp_wqcq_pages = false; |
| 12310 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12311 | if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) && |
| 12312 | (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) && |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12313 | exp_wqcq_pages && |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12314 | (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT)) |
| 12315 | phba->enab_exp_wqcq_pages = 1; |
| 12316 | else |
| 12317 | phba->enab_exp_wqcq_pages = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 12318 | /* |
| 12319 | * Check if the SLI port supports MDS Diagnostics |
| 12320 | */ |
| 12321 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 12322 | phba->mds_diags_support = 1; |
| 12323 | else |
| 12324 | phba->mds_diags_support = 0; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12325 | |
James Smart | 0d8af09 | 2019-08-14 16:57:10 -0700 | [diff] [blame] | 12326 | /* |
| 12327 | * Check if the SLI port supports NSLER |
| 12328 | */ |
| 12329 | if (bf_get(cfg_nsler, mbx_sli4_parameters)) |
| 12330 | phba->nsler = 1; |
| 12331 | else |
| 12332 | phba->nsler = 0; |
| 12333 | |
James Smart | 8aaa7bc | 2020-10-20 13:27:17 -0700 | [diff] [blame] | 12334 | /* Save PB info for use during HBA setup */ |
| 12335 | sli4_params->mi_ver = bf_get(cfg_mi_ver, mbx_sli4_parameters); |
| 12336 | sli4_params->mib_bde_cnt = bf_get(cfg_mib_bde_cnt, mbx_sli4_parameters); |
| 12337 | sli4_params->mib_size = mbx_sli4_parameters->mib_size; |
| 12338 | sli4_params->mi_value = LPFC_DFLT_MIB_VAL; |
| 12339 | |
| 12340 | /* Next we check for Vendor MIB support */ |
| 12341 | if (sli4_params->mi_ver && phba->cfg_enable_mi) |
| 12342 | phba->cfg_fdmi_on = LPFC_FDMI_SUPPORT; |
| 12343 | |
| 12344 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12345 | "6461 MIB attr %d enable %d FDMI %d buf %d:%d\n", |
| 12346 | sli4_params->mi_ver, phba->cfg_enable_mi, |
| 12347 | sli4_params->mi_value, sli4_params->mib_bde_cnt, |
| 12348 | sli4_params->mib_size); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12349 | return 0; |
| 12350 | } |
| 12351 | |
| 12352 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12353 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 12354 | * @pdev: pointer to PCI device |
| 12355 | * @pid: pointer to PCI device identifier |
| 12356 | * |
| 12357 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 12358 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 12359 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 12360 | * information of the device and driver to see if the driver state that it can |
| 12361 | * support this kind of device. If the match is successful, the driver core |
| 12362 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 12363 | * does all the initialization that it needs to do to handle the HBA properly. |
| 12364 | * |
| 12365 | * Return code |
| 12366 | * 0 - driver can claim the device |
| 12367 | * negative value - driver can not claim the device |
| 12368 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12369 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12370 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 12371 | { |
| 12372 | struct lpfc_hba *phba; |
| 12373 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12374 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12375 | int error; |
| 12376 | uint32_t cfg_mode, intr_mode; |
| 12377 | |
| 12378 | /* Allocate memory for HBA structure */ |
| 12379 | phba = lpfc_hba_alloc(pdev); |
| 12380 | if (!phba) |
| 12381 | return -ENOMEM; |
| 12382 | |
| 12383 | /* Perform generic PCI device enabling operation */ |
| 12384 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12385 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12386 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12387 | |
| 12388 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 12389 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 12390 | if (error) |
| 12391 | goto out_disable_pci_dev; |
| 12392 | |
| 12393 | /* Set up SLI-3 specific device PCI memory space */ |
| 12394 | error = lpfc_sli_pci_mem_setup(phba); |
| 12395 | if (error) { |
| 12396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12397 | "1402 Failed to set up pci memory space.\n"); |
| 12398 | goto out_disable_pci_dev; |
| 12399 | } |
| 12400 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12401 | /* Set up SLI-3 specific device driver resources */ |
| 12402 | error = lpfc_sli_driver_resource_setup(phba); |
| 12403 | if (error) { |
| 12404 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12405 | "1404 Failed to set up driver resource.\n"); |
| 12406 | goto out_unset_pci_mem_s3; |
| 12407 | } |
| 12408 | |
| 12409 | /* Initialize and populate the iocb list per host */ |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 12410 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12411 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 12412 | if (error) { |
| 12413 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12414 | "1405 Failed to initialize iocb list.\n"); |
| 12415 | goto out_unset_driver_resource_s3; |
| 12416 | } |
| 12417 | |
| 12418 | /* Set up common device driver resources */ |
| 12419 | error = lpfc_setup_driver_resource_phase2(phba); |
| 12420 | if (error) { |
| 12421 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12422 | "1406 Failed to set up driver resource.\n"); |
| 12423 | goto out_free_iocb_list; |
| 12424 | } |
| 12425 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12426 | /* Get the default values for Model Name and Description */ |
| 12427 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 12428 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12429 | /* Create SCSI host to the physical port */ |
| 12430 | error = lpfc_create_shost(phba); |
| 12431 | if (error) { |
| 12432 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12433 | "1407 Failed to create scsi host.\n"); |
| 12434 | goto out_unset_driver_resource; |
| 12435 | } |
| 12436 | |
| 12437 | /* Configure sysfs attributes */ |
| 12438 | vport = phba->pport; |
| 12439 | error = lpfc_alloc_sysfs_attr(vport); |
| 12440 | if (error) { |
| 12441 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12442 | "1476 Failed to allocate sysfs attr\n"); |
| 12443 | goto out_destroy_shost; |
| 12444 | } |
| 12445 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12446 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12447 | /* Now, trying to enable interrupt and bring up the device */ |
| 12448 | cfg_mode = phba->cfg_use_msi; |
| 12449 | while (true) { |
| 12450 | /* Put device to a known state before enabling interrupt */ |
| 12451 | lpfc_stop_port(phba); |
| 12452 | /* Configure and enable interrupt */ |
| 12453 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 12454 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12455 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12456 | "0431 Failed to enable interrupt.\n"); |
| 12457 | error = -ENODEV; |
| 12458 | goto out_free_sysfs_attr; |
| 12459 | } |
| 12460 | /* SLI-3 HBA setup */ |
| 12461 | if (lpfc_sli_hba_setup(phba)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12462 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12463 | "1477 Failed to set up hba\n"); |
| 12464 | error = -ENODEV; |
| 12465 | goto out_remove_device; |
| 12466 | } |
| 12467 | |
| 12468 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 12469 | msleep(50); |
| 12470 | /* Check active interrupts on message signaled interrupts */ |
| 12471 | if (intr_mode == 0 || |
| 12472 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 12473 | /* Log the current active interrupt mode */ |
| 12474 | phba->intr_mode = intr_mode; |
| 12475 | lpfc_log_intr_mode(phba, intr_mode); |
| 12476 | break; |
| 12477 | } else { |
| 12478 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12479 | "0447 Configure interrupt mode (%d) " |
| 12480 | "failed active interrupt test.\n", |
| 12481 | intr_mode); |
| 12482 | /* Disable the current interrupt mode */ |
| 12483 | lpfc_sli_disable_intr(phba); |
| 12484 | /* Try next level of interrupt mode */ |
| 12485 | cfg_mode = --intr_mode; |
| 12486 | } |
| 12487 | } |
| 12488 | |
| 12489 | /* Perform post initialization setup */ |
| 12490 | lpfc_post_init_setup(phba); |
| 12491 | |
| 12492 | /* Check if there are static vports to be created. */ |
| 12493 | lpfc_create_static_vport(phba); |
| 12494 | |
| 12495 | return 0; |
| 12496 | |
| 12497 | out_remove_device: |
| 12498 | lpfc_unset_hba(phba); |
| 12499 | out_free_sysfs_attr: |
| 12500 | lpfc_free_sysfs_attr(vport); |
| 12501 | out_destroy_shost: |
| 12502 | lpfc_destroy_shost(phba); |
| 12503 | out_unset_driver_resource: |
| 12504 | lpfc_unset_driver_resource_phase2(phba); |
| 12505 | out_free_iocb_list: |
| 12506 | lpfc_free_iocb_list(phba); |
| 12507 | out_unset_driver_resource_s3: |
| 12508 | lpfc_sli_driver_resource_unset(phba); |
| 12509 | out_unset_pci_mem_s3: |
| 12510 | lpfc_sli_pci_mem_unset(phba); |
| 12511 | out_disable_pci_dev: |
| 12512 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12513 | if (shost) |
| 12514 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12515 | out_free_phba: |
| 12516 | lpfc_hba_free(phba); |
| 12517 | return error; |
| 12518 | } |
| 12519 | |
| 12520 | /** |
| 12521 | * 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] | 12522 | * @pdev: pointer to PCI device |
| 12523 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12524 | * This routine is to be called to disattach a device with SLI-3 interface |
| 12525 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 12526 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 12527 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12528 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12529 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12530 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12531 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12532 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12533 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12534 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12535 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12536 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 12537 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 12538 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12539 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 12540 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12541 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12542 | lpfc_free_sysfs_attr(vport); |
| 12543 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12544 | /* Release all the vports against this physical port */ |
| 12545 | vports = lpfc_create_vport_work_array(phba); |
| 12546 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12547 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 12548 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 12549 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12550 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12551 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12552 | lpfc_destroy_vport_work_array(phba, vports); |
| 12553 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 12554 | /* Remove FC host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12555 | fc_remove_host(shost); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 12556 | scsi_remove_host(shost); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 12557 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 12558 | /* Clean up all nodes, mailboxes and IOs. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 12559 | lpfc_cleanup(vport); |
| 12560 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12561 | /* |
| 12562 | * Bring down the SLI Layer. This step disable all interrupts, |
| 12563 | * clears the rings, discards all mailbox commands, and resets |
| 12564 | * the HBA. |
| 12565 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12566 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 12567 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12568 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12569 | /* Stop kthread signal shall trigger work_done one more time */ |
| 12570 | kthread_stop(phba->worker_thread); |
| 12571 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12572 | lpfc_sli_brdrestart(phba); |
| 12573 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 12574 | kfree(phba->vpi_bmask); |
| 12575 | kfree(phba->vpi_ids); |
| 12576 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12577 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12578 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12579 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12580 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12581 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12582 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12583 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 12584 | /* Disable SR-IOV if enabled */ |
| 12585 | if (phba->cfg_sriov_nr_virtfn) |
| 12586 | pci_disable_sriov(pdev); |
| 12587 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12588 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12589 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12590 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12591 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12592 | |
| 12593 | /* |
| 12594 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 12595 | * corresponding pools here. |
| 12596 | */ |
| 12597 | lpfc_scsi_free(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 12598 | lpfc_free_iocb_list(phba); |
| 12599 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12600 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12601 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12602 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 12603 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12604 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12605 | /* Free resources associated with SLI2 interface */ |
| 12606 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12607 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12608 | |
| 12609 | /* unmap adapter SLIM and Control Registers */ |
| 12610 | iounmap(phba->ctrl_regs_memmap_p); |
| 12611 | iounmap(phba->slim_memmap_p); |
| 12612 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12613 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12614 | |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 12615 | pci_release_mem_regions(pdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12616 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12617 | } |
| 12618 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12619 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12620 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12621 | * @dev_d: pointer to device |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12622 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12623 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12624 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 12625 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 12626 | * worker thread for the device, turning off device's interrupt and DMA, |
| 12627 | * and bring the device offline. Note that as the driver implements the |
| 12628 | * minimum PM requirements to a power-aware driver's PM support for the |
| 12629 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 12630 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 12631 | * fully reinitialize its device during resume() method call, the driver will |
| 12632 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 12633 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12634 | * |
| 12635 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12636 | * 0 - driver suspended the device |
| 12637 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12638 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12639 | static int __maybe_unused |
| 12640 | lpfc_pci_suspend_one_s3(struct device *dev_d) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12641 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12642 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12643 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12644 | |
| 12645 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12646 | "0473 PCI device Power Management suspend.\n"); |
| 12647 | |
| 12648 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12649 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12650 | lpfc_offline(phba); |
| 12651 | kthread_stop(phba->worker_thread); |
| 12652 | |
| 12653 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12654 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12655 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12656 | return 0; |
| 12657 | } |
| 12658 | |
| 12659 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12660 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12661 | * @dev_d: pointer to device |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12662 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12663 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12664 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 12665 | * invokes this method, it restores the device's PCI config space state and |
| 12666 | * fully reinitializes the device and brings it online. Note that as the |
| 12667 | * driver implements the minimum PM requirements to a power-aware driver's |
| 12668 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 12669 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 12670 | * driver will fully reinitialize its device during resume() method call, |
| 12671 | * the device will be set to PCI_D0 directly in PCI config space before |
| 12672 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12673 | * |
| 12674 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12675 | * 0 - driver suspended the device |
| 12676 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12677 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12678 | static int __maybe_unused |
| 12679 | lpfc_pci_resume_one_s3(struct device *dev_d) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12680 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12681 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12682 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12683 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12684 | int error; |
| 12685 | |
| 12686 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12687 | "0452 PCI device Power Management resume.\n"); |
| 12688 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12689 | /* Startup the kernel thread for this host adapter. */ |
| 12690 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 12691 | "lpfc_worker_%d", phba->brd_no); |
| 12692 | if (IS_ERR(phba->worker_thread)) { |
| 12693 | error = PTR_ERR(phba->worker_thread); |
| 12694 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12695 | "0434 PM resume failed to start worker " |
| 12696 | "thread: error=x%x.\n", error); |
| 12697 | return error; |
| 12698 | } |
| 12699 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12700 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12701 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12702 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12703 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12704 | "0430 PM resume Failed to enable interrupt\n"); |
| 12705 | return -EIO; |
| 12706 | } else |
| 12707 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12708 | |
| 12709 | /* Restart HBA and bring it online */ |
| 12710 | lpfc_sli_brdrestart(phba); |
| 12711 | lpfc_online(phba); |
| 12712 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12713 | /* Log the current active interrupt mode */ |
| 12714 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12715 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12716 | return 0; |
| 12717 | } |
| 12718 | |
| 12719 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12720 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 12721 | * @phba: pointer to lpfc hba data structure. |
| 12722 | * |
| 12723 | * 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] | 12724 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12725 | **/ |
| 12726 | static void |
| 12727 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 12728 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12729 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12730 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12731 | |
| 12732 | /* |
| 12733 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 12734 | * and let the SCSI mid-layer to retry them to recover. |
| 12735 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12736 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12737 | } |
| 12738 | |
| 12739 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12740 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 12741 | * @phba: pointer to lpfc hba data structure. |
| 12742 | * |
| 12743 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 12744 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 12745 | * pending I/Os. |
| 12746 | **/ |
| 12747 | static void |
| 12748 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 12749 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12750 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12751 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12752 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12753 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12754 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12755 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12756 | /* Block all SCSI devices' I/Os on the host */ |
| 12757 | lpfc_scsi_dev_block(phba); |
| 12758 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12759 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12760 | lpfc_sli_flush_io_rings(phba); |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12761 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12762 | /* stop all timers */ |
| 12763 | lpfc_stop_hba_timers(phba); |
| 12764 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12765 | /* Disable interrupt and pci device */ |
| 12766 | lpfc_sli_disable_intr(phba); |
| 12767 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12768 | } |
| 12769 | |
| 12770 | /** |
| 12771 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 12772 | * @phba: pointer to lpfc hba data structure. |
| 12773 | * |
| 12774 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 12775 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 12776 | * pending I/Os. |
| 12777 | **/ |
| 12778 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12779 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12780 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12781 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12782 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12783 | /* Block all SCSI devices' I/Os on the host */ |
| 12784 | lpfc_scsi_dev_block(phba); |
| 12785 | |
| 12786 | /* stop all timers */ |
| 12787 | lpfc_stop_hba_timers(phba); |
| 12788 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12789 | /* Clean up all driver's outstanding SCSI I/Os */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12790 | lpfc_sli_flush_io_rings(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12791 | } |
| 12792 | |
| 12793 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12794 | * 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] | 12795 | * @pdev: pointer to PCI device. |
| 12796 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12797 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12798 | * This routine is called from the PCI subsystem for I/O error handling to |
| 12799 | * device with SLI-3 interface spec. This function is called by the PCI |
| 12800 | * subsystem after a PCI bus error affecting this device has been detected. |
| 12801 | * When this function is invoked, it will need to stop all the I/Os and |
| 12802 | * interrupt(s) to the device. Once that is done, it will return |
| 12803 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 12804 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12805 | * |
| 12806 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12807 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12808 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12809 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12810 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12811 | static pci_ers_result_t |
| 12812 | 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] | 12813 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12814 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12815 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12816 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12817 | switch (state) { |
| 12818 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12819 | /* Non-fatal error, prepare for recovery */ |
| 12820 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12821 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 12822 | case pci_channel_io_frozen: |
| 12823 | /* Fatal error, prepare for slot reset */ |
| 12824 | lpfc_sli_prep_dev_for_reset(phba); |
| 12825 | return PCI_ERS_RESULT_NEED_RESET; |
| 12826 | case pci_channel_io_perm_failure: |
| 12827 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12828 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12829 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12830 | default: |
| 12831 | /* Unknown state, prepare and request slot reset */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12832 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12833 | "0472 Unknown PCI error state: x%x\n", state); |
| 12834 | lpfc_sli_prep_dev_for_reset(phba); |
| 12835 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 12836 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12837 | } |
| 12838 | |
| 12839 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12840 | * 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] | 12841 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12842 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12843 | * This routine is called from the PCI subsystem for error handling to |
| 12844 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 12845 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 12846 | * During the PCI subsystem error recovery, after driver returns |
| 12847 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 12848 | * recovery and then call this routine before calling the .resume method |
| 12849 | * to recover the device. This function will initialize the HBA device, |
| 12850 | * enable the interrupt, but it will just put the HBA to offline state |
| 12851 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12852 | * |
| 12853 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12854 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 12855 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12856 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12857 | static pci_ers_result_t |
| 12858 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12859 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12860 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12861 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12862 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12863 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12864 | |
| 12865 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 12866 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12867 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 12868 | "PCI device after reset.\n"); |
| 12869 | return PCI_ERS_RESULT_DISCONNECT; |
| 12870 | } |
| 12871 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12872 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12873 | |
| 12874 | /* |
| 12875 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12876 | * device saved_state flag, need to save the restored state again. |
| 12877 | */ |
| 12878 | pci_save_state(pdev); |
| 12879 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12880 | if (pdev->is_busmaster) |
| 12881 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12882 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12883 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12884 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12885 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12886 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12887 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12888 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12889 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12890 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12891 | "0427 Cannot re-enable interrupt after " |
| 12892 | "slot reset.\n"); |
| 12893 | return PCI_ERS_RESULT_DISCONNECT; |
| 12894 | } else |
| 12895 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12896 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12897 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12898 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12899 | lpfc_offline(phba); |
| 12900 | lpfc_sli_brdrestart(phba); |
| 12901 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12902 | /* Log the current active interrupt mode */ |
| 12903 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12904 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12905 | return PCI_ERS_RESULT_RECOVERED; |
| 12906 | } |
| 12907 | |
| 12908 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12909 | * 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] | 12910 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12911 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12912 | * This routine is called from the PCI subsystem for error handling to device |
| 12913 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 12914 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 12915 | * error recovery. After this call, traffic can start to flow from this device |
| 12916 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12917 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12918 | static void |
| 12919 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12920 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12921 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12922 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12923 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12924 | /* 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] | 12925 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12926 | } |
| 12927 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12928 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12929 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 12930 | * @phba: pointer to lpfc hba data structure. |
| 12931 | * |
| 12932 | * returns the number of ELS/CT IOCBs to reserve |
| 12933 | **/ |
| 12934 | int |
| 12935 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 12936 | { |
| 12937 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 12938 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12939 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 12940 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12941 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12942 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12943 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12944 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12945 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12946 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12947 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12948 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12949 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12950 | else if (max_xri <= 2048) |
| 12951 | return 200; |
| 12952 | else |
| 12953 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12954 | } else |
| 12955 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12956 | } |
| 12957 | |
| 12958 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12959 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve |
| 12960 | * @phba: pointer to lpfc hba data structure. |
| 12961 | * |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12962 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12963 | **/ |
| 12964 | int |
| 12965 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) |
| 12966 | { |
| 12967 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); |
| 12968 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12969 | if (phba->nvmet_support) |
| 12970 | max_xri += LPFC_NVMET_BUF_POST; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12971 | return max_xri; |
| 12972 | } |
| 12973 | |
| 12974 | |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12975 | static int |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12976 | lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset, |
| 12977 | uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize, |
| 12978 | const struct firmware *fw) |
| 12979 | { |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12980 | int rc; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12981 | |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12982 | /* Three cases: (1) FW was not supported on the detected adapter. |
| 12983 | * (2) FW update has been locked out administratively. |
| 12984 | * (3) Some other error during FW update. |
| 12985 | * In each case, an unmaskable message is written to the console |
| 12986 | * for admin diagnosis. |
| 12987 | */ |
| 12988 | if (offset == ADD_STATUS_FW_NOT_SUPPORTED || |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12989 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
James Smart | 5792a0e | 2019-10-25 11:43:42 -0700 | [diff] [blame] | 12990 | magic_number != MAGIC_NUMBER_G6) || |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12991 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC && |
James Smart | 5792a0e | 2019-10-25 11:43:42 -0700 | [diff] [blame] | 12992 | magic_number != MAGIC_NUMBER_G7)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12993 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12994 | "3030 This firmware version is not supported on" |
| 12995 | " this HBA model. Device:%x Magic:%x Type:%x " |
| 12996 | "ID:%x Size %d %zd\n", |
| 12997 | phba->pcidev->device, magic_number, ftype, fid, |
| 12998 | fsize, fw->size); |
| 12999 | rc = -EINVAL; |
| 13000 | } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13001 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13002 | "3021 Firmware downloads have been prohibited " |
| 13003 | "by a system configuration setting on " |
| 13004 | "Device:%x Magic:%x Type:%x ID:%x Size %d " |
| 13005 | "%zd\n", |
| 13006 | phba->pcidev->device, magic_number, ftype, fid, |
| 13007 | fsize, fw->size); |
| 13008 | rc = -EACCES; |
| 13009 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13010 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13011 | "3022 FW Download failed. Add Status x%x " |
| 13012 | "Device:%x Magic:%x Type:%x ID:%x Size %d " |
| 13013 | "%zd\n", |
| 13014 | offset, phba->pcidev->device, magic_number, |
| 13015 | ftype, fid, fsize, fw->size); |
| 13016 | rc = -EIO; |
| 13017 | } |
| 13018 | return rc; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13019 | } |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13020 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13021 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13022 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13023 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13024 | * @context: pointer to firmware image returned from request_firmware. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13025 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13026 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13027 | static void |
| 13028 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13029 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13030 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 13031 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13032 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13033 | struct list_head dma_buffer_list; |
| 13034 | int i, rc = 0; |
| 13035 | struct lpfc_dmabuf *dmabuf, *next; |
| 13036 | uint32_t offset = 0, temp_offset = 0; |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 13037 | uint32_t magic_number, ftype, fid, fsize; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13038 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13039 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13040 | if (!fw) { |
| 13041 | rc = -ENXIO; |
| 13042 | goto out; |
| 13043 | } |
| 13044 | image = (struct lpfc_grp_hdr *)fw->data; |
| 13045 | |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 13046 | magic_number = be32_to_cpu(image->magic_number); |
| 13047 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13048 | fid = bf_get_be32(lpfc_grp_hdr_id, image); |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 13049 | fsize = be32_to_cpu(image->size); |
| 13050 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13051 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13052 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13053 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13054 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13055 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13056 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13057 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13058 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 13059 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 13060 | GFP_KERNEL); |
| 13061 | if (!dmabuf) { |
| 13062 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13063 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13064 | } |
| 13065 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 13066 | SLI4_PAGE_SIZE, |
| 13067 | &dmabuf->phys, |
| 13068 | GFP_KERNEL); |
| 13069 | if (!dmabuf->virt) { |
| 13070 | kfree(dmabuf); |
| 13071 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13072 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13073 | } |
| 13074 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 13075 | } |
| 13076 | while (offset < fw->size) { |
| 13077 | temp_offset = offset; |
| 13078 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13079 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13080 | memcpy(dmabuf->virt, |
| 13081 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13082 | fw->size - temp_offset); |
| 13083 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13084 | break; |
| 13085 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13086 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 13087 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13088 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13089 | } |
| 13090 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 13091 | (fw->size - offset), &offset); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13092 | if (rc) { |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13093 | rc = lpfc_log_write_firmware_error(phba, offset, |
| 13094 | magic_number, |
| 13095 | ftype, |
| 13096 | fid, |
| 13097 | fsize, |
| 13098 | fw); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13099 | goto release_out; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13100 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13101 | } |
| 13102 | rc = offset; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13103 | } else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13104 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13105 | "3029 Skipped Firmware update, Current " |
| 13106 | "Version:%s New Version:%s\n", |
| 13107 | fwrev, image->revision); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13108 | |
| 13109 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13110 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 13111 | list_del(&dmabuf->list); |
| 13112 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 13113 | dmabuf->virt, dmabuf->phys); |
| 13114 | kfree(dmabuf); |
| 13115 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13116 | release_firmware(fw); |
| 13117 | out: |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13118 | if (rc < 0) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13119 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13120 | "3062 Firmware update error, status %d.\n", rc); |
| 13121 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13122 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13123 | "3024 Firmware update success: size %d.\n", rc); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13124 | } |
| 13125 | |
| 13126 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13127 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 13128 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 13129 | * @fw_upgrade: which firmware to update. |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13130 | * |
| 13131 | * This routine is called to perform Linux generic firmware upgrade on device |
| 13132 | * that supports such feature. |
| 13133 | **/ |
| 13134 | int |
| 13135 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 13136 | { |
| 13137 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 13138 | int ret; |
| 13139 | const struct firmware *fw; |
| 13140 | |
| 13141 | /* Only supported on SLI4 interface type 2 for now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 13142 | 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] | 13143 | LPFC_SLI_INTF_IF_TYPE_2) |
| 13144 | return -EPERM; |
| 13145 | |
| 13146 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 13147 | |
| 13148 | if (fw_upgrade == INT_FW_UPGRADE) { |
Shawn Guo | 0733d83 | 2021-04-25 10:00:24 +0800 | [diff] [blame] | 13149 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13150 | file_name, &phba->pcidev->dev, |
| 13151 | GFP_KERNEL, (void *)phba, |
| 13152 | lpfc_write_firmware); |
| 13153 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 13154 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 13155 | if (!ret) |
| 13156 | lpfc_write_firmware(fw, (void *)phba); |
| 13157 | } else { |
| 13158 | ret = -EINVAL; |
| 13159 | } |
| 13160 | |
| 13161 | return ret; |
| 13162 | } |
| 13163 | |
| 13164 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13165 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 13166 | * @pdev: pointer to PCI device |
| 13167 | * @pid: pointer to PCI device identifier |
| 13168 | * |
| 13169 | * This routine is called from the kernel's PCI subsystem to device with |
| 13170 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 13171 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 13172 | * information of the device and driver to see if the driver state that it |
| 13173 | * can support this kind of device. If the match is successful, the driver |
| 13174 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 13175 | * it does all the initialization that it needs to do to handle the HBA |
| 13176 | * properly. |
| 13177 | * |
| 13178 | * Return code |
| 13179 | * 0 - driver can claim the device |
| 13180 | * negative value - driver can not claim the device |
| 13181 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13182 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13183 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13184 | { |
| 13185 | struct lpfc_hba *phba; |
| 13186 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13187 | struct Scsi_Host *shost = NULL; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 13188 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13189 | uint32_t cfg_mode, intr_mode; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13190 | |
| 13191 | /* Allocate memory for HBA structure */ |
| 13192 | phba = lpfc_hba_alloc(pdev); |
| 13193 | if (!phba) |
| 13194 | return -ENOMEM; |
| 13195 | |
| 13196 | /* Perform generic PCI device enabling operation */ |
| 13197 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13198 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13199 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13200 | |
| 13201 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 13202 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 13203 | if (error) |
| 13204 | goto out_disable_pci_dev; |
| 13205 | |
| 13206 | /* Set up SLI-4 specific device PCI memory space */ |
| 13207 | error = lpfc_sli4_pci_mem_setup(phba); |
| 13208 | if (error) { |
| 13209 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13210 | "1410 Failed to set up pci memory space.\n"); |
| 13211 | goto out_disable_pci_dev; |
| 13212 | } |
| 13213 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13214 | /* Set up SLI-4 Specific device driver resources */ |
| 13215 | error = lpfc_sli4_driver_resource_setup(phba); |
| 13216 | if (error) { |
| 13217 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13218 | "1412 Failed to set up driver resource.\n"); |
| 13219 | goto out_unset_pci_mem_s4; |
| 13220 | } |
| 13221 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 13222 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 13223 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 13224 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13225 | /* Set up common device driver resources */ |
| 13226 | error = lpfc_setup_driver_resource_phase2(phba); |
| 13227 | if (error) { |
| 13228 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13229 | "1414 Failed to set up driver resource.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 13230 | goto out_unset_driver_resource_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13231 | } |
| 13232 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13233 | /* Get the default values for Model Name and Description */ |
| 13234 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 13235 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13236 | /* Now, trying to enable interrupt and bring up the device */ |
| 13237 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13238 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13239 | /* Put device to a known state before enabling interrupt */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13240 | phba->pport = NULL; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13241 | lpfc_stop_port(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13242 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 13243 | /* Init cpu_map array */ |
| 13244 | lpfc_cpu_map_array_init(phba); |
| 13245 | |
| 13246 | /* Init hba_eq_hdl array */ |
| 13247 | lpfc_hba_eq_hdl_array_init(phba); |
| 13248 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13249 | /* Configure and enable interrupt */ |
| 13250 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 13251 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13252 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13253 | "0426 Failed to enable interrupt.\n"); |
| 13254 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13255 | goto out_unset_driver_resource; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13256 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13257 | /* Default to single EQ for non-MSI-X */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13258 | if (phba->intr_type != MSIX) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13259 | phba->cfg_irq_chann = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13260 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13261 | if (phba->nvmet_support) |
| 13262 | phba->cfg_nvmet_mrq = 1; |
| 13263 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13264 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13265 | lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13266 | |
| 13267 | /* Create SCSI host to the physical port */ |
| 13268 | error = lpfc_create_shost(phba); |
| 13269 | if (error) { |
| 13270 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13271 | "1415 Failed to create scsi host.\n"); |
| 13272 | goto out_disable_intr; |
| 13273 | } |
| 13274 | vport = phba->pport; |
| 13275 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
| 13276 | |
| 13277 | /* Configure sysfs attributes */ |
| 13278 | error = lpfc_alloc_sysfs_attr(vport); |
| 13279 | if (error) { |
| 13280 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13281 | "1416 Failed to allocate sysfs attr\n"); |
| 13282 | goto out_destroy_shost; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13283 | } |
| 13284 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13285 | /* Set up SLI-4 HBA */ |
| 13286 | if (lpfc_sli4_hba_setup(phba)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13287 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13288 | "1421 Failed to set up hba\n"); |
| 13289 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13290 | goto out_free_sysfs_attr; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13291 | } |
| 13292 | |
| 13293 | /* Log the current active interrupt mode */ |
| 13294 | phba->intr_mode = intr_mode; |
| 13295 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13296 | |
| 13297 | /* Perform post initialization setup */ |
| 13298 | lpfc_post_init_setup(phba); |
| 13299 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13300 | /* NVME support in FW earlier in the driver load corrects the |
| 13301 | * FC4 type making a check for nvme_support unnecessary. |
| 13302 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 13303 | if (phba->nvmet_support == 0) { |
| 13304 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13305 | /* Create NVME binding with nvme_fc_transport. This |
| 13306 | * ensures the vport is initialized. If the localport |
| 13307 | * create fails, it should not unload the driver to |
| 13308 | * support field issues. |
| 13309 | */ |
| 13310 | error = lpfc_nvme_create_localport(vport); |
| 13311 | if (error) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13312 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 13313 | "6004 NVME registration " |
| 13314 | "failed, error x%x\n", |
| 13315 | error); |
| 13316 | } |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13317 | } |
| 13318 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13319 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13320 | /* check for firmware upgrade or downgrade */ |
| 13321 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 13322 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13323 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 13324 | /* Check if there are static vports to be created. */ |
| 13325 | lpfc_create_static_vport(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13326 | |
| 13327 | /* Enable RAS FW log support */ |
| 13328 | lpfc_sli4_ras_setup(phba); |
| 13329 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13330 | INIT_LIST_HEAD(&phba->poll_list); |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 13331 | timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13332 | cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp); |
| 13333 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13334 | return 0; |
| 13335 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13336 | out_free_sysfs_attr: |
| 13337 | lpfc_free_sysfs_attr(vport); |
| 13338 | out_destroy_shost: |
| 13339 | lpfc_destroy_shost(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13340 | out_disable_intr: |
| 13341 | lpfc_sli4_disable_intr(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13342 | out_unset_driver_resource: |
| 13343 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13344 | out_unset_driver_resource_s4: |
| 13345 | lpfc_sli4_driver_resource_unset(phba); |
| 13346 | out_unset_pci_mem_s4: |
| 13347 | lpfc_sli4_pci_mem_unset(phba); |
| 13348 | out_disable_pci_dev: |
| 13349 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13350 | if (shost) |
| 13351 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13352 | out_free_phba: |
| 13353 | lpfc_hba_free(phba); |
| 13354 | return error; |
| 13355 | } |
| 13356 | |
| 13357 | /** |
| 13358 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 13359 | * @pdev: pointer to PCI device |
| 13360 | * |
| 13361 | * This routine is called from the kernel's PCI subsystem to device with |
| 13362 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 13363 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 13364 | * device to be removed from the PCI subsystem properly. |
| 13365 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13366 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13367 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 13368 | { |
| 13369 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13370 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 13371 | struct lpfc_vport **vports; |
| 13372 | struct lpfc_hba *phba = vport->phba; |
| 13373 | int i; |
| 13374 | |
| 13375 | /* Mark the device unloading flag */ |
| 13376 | spin_lock_irq(&phba->hbalock); |
| 13377 | vport->load_flag |= FC_UNLOADING; |
| 13378 | spin_unlock_irq(&phba->hbalock); |
| 13379 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13380 | lpfc_free_sysfs_attr(vport); |
| 13381 | |
| 13382 | /* Release all the vports against this physical port */ |
| 13383 | vports = lpfc_create_vport_work_array(phba); |
| 13384 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 13385 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 13386 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 13387 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13388 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 13389 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13390 | lpfc_destroy_vport_work_array(phba, vports); |
| 13391 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 13392 | /* Remove FC host with the physical port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13393 | fc_remove_host(shost); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 13394 | scsi_remove_host(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13395 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13396 | /* Perform ndlp cleanup on the physical port. The nvme and nvmet |
| 13397 | * localports are destroyed after to cleanup all transport memory. |
| 13398 | */ |
| 13399 | lpfc_cleanup(vport); |
| 13400 | lpfc_nvmet_destroy_targetport(phba); |
| 13401 | lpfc_nvme_destroy_localport(vport); |
| 13402 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 13403 | /* De-allocate multi-XRI pools */ |
| 13404 | if (phba->cfg_xri_rebalancing) |
| 13405 | lpfc_destroy_multixri_pools(phba); |
| 13406 | |
James Smart | 281d619 | 2018-01-30 15:58:47 -0800 | [diff] [blame] | 13407 | /* |
| 13408 | * Bring down the SLI Layer. This step disables all interrupts, |
| 13409 | * clears the rings, discards all mailbox commands, and resets |
| 13410 | * the HBA FCoE function. |
| 13411 | */ |
| 13412 | lpfc_debugfs_terminate(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13413 | |
Dick Kennedy | 1901762 | 2017-09-29 17:34:27 -0700 | [diff] [blame] | 13414 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13415 | spin_lock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13416 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13417 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13418 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 13419 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13420 | * buffers are released to their corresponding pools here. |
| 13421 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13422 | lpfc_io_free(phba); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13423 | lpfc_free_iocb_list(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13424 | lpfc_sli4_hba_unset(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13425 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 13426 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13427 | lpfc_sli4_driver_resource_unset(phba); |
| 13428 | |
| 13429 | /* Unmap adapter Control and Doorbell registers */ |
| 13430 | lpfc_sli4_pci_mem_unset(phba); |
| 13431 | |
| 13432 | /* Release PCI resources and disable device's PCI function */ |
| 13433 | scsi_host_put(shost); |
| 13434 | lpfc_disable_pci_dev(phba); |
| 13435 | |
| 13436 | /* Finally, free the driver's device data structure */ |
| 13437 | lpfc_hba_free(phba); |
| 13438 | |
| 13439 | return; |
| 13440 | } |
| 13441 | |
| 13442 | /** |
| 13443 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13444 | * @dev_d: pointer to device |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13445 | * |
| 13446 | * This routine is called from the kernel's PCI subsystem to support system |
| 13447 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 13448 | * this method, it quiesces the device by stopping the driver's worker |
| 13449 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 13450 | * the device offline. Note that as the driver implements the minimum PM |
| 13451 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 13452 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 13453 | * method call will be treated as SUSPEND and the driver will fully |
| 13454 | * reinitialize its device during resume() method call, the driver will set |
| 13455 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 13456 | * according to the @msg provided by the PM. |
| 13457 | * |
| 13458 | * Return code |
| 13459 | * 0 - driver suspended the device |
| 13460 | * Error otherwise |
| 13461 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13462 | static int __maybe_unused |
| 13463 | lpfc_pci_suspend_one_s4(struct device *dev_d) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13464 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13465 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13466 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13467 | |
| 13468 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13469 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13470 | |
| 13471 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13472 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13473 | lpfc_offline(phba); |
| 13474 | kthread_stop(phba->worker_thread); |
| 13475 | |
| 13476 | /* Disable interrupt from device */ |
| 13477 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13478 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13479 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13480 | return 0; |
| 13481 | } |
| 13482 | |
| 13483 | /** |
| 13484 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13485 | * @dev_d: pointer to device |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13486 | * |
| 13487 | * This routine is called from the kernel's PCI subsystem to support system |
| 13488 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 13489 | * this method, it restores the device's PCI config space state and fully |
| 13490 | * reinitializes the device and brings it online. Note that as the driver |
| 13491 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 13492 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 13493 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 13494 | * will fully reinitialize its device during resume() method call, the device |
| 13495 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 13496 | * state. |
| 13497 | * |
| 13498 | * Return code |
| 13499 | * 0 - driver suspended the device |
| 13500 | * Error otherwise |
| 13501 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13502 | static int __maybe_unused |
| 13503 | lpfc_pci_resume_one_s4(struct device *dev_d) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13504 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13505 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13506 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13507 | uint32_t intr_mode; |
| 13508 | int error; |
| 13509 | |
| 13510 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13511 | "0292 PCI device Power Management resume.\n"); |
| 13512 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13513 | /* Startup the kernel thread for this host adapter. */ |
| 13514 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 13515 | "lpfc_worker_%d", phba->brd_no); |
| 13516 | if (IS_ERR(phba->worker_thread)) { |
| 13517 | error = PTR_ERR(phba->worker_thread); |
| 13518 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13519 | "0293 PM resume failed to start worker " |
| 13520 | "thread: error=x%x.\n", error); |
| 13521 | return error; |
| 13522 | } |
| 13523 | |
| 13524 | /* Configure and enable interrupt */ |
| 13525 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13526 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13527 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13528 | "0294 PM resume Failed to enable interrupt\n"); |
| 13529 | return -EIO; |
| 13530 | } else |
| 13531 | phba->intr_mode = intr_mode; |
| 13532 | |
| 13533 | /* Restart HBA and bring it online */ |
| 13534 | lpfc_sli_brdrestart(phba); |
| 13535 | lpfc_online(phba); |
| 13536 | |
| 13537 | /* Log the current active interrupt mode */ |
| 13538 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13539 | |
| 13540 | return 0; |
| 13541 | } |
| 13542 | |
| 13543 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13544 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 13545 | * @phba: pointer to lpfc hba data structure. |
| 13546 | * |
| 13547 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 13548 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 13549 | **/ |
| 13550 | static void |
| 13551 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 13552 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13553 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13554 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 13555 | /* |
| 13556 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 13557 | * and let the SCSI mid-layer to retry them to recover. |
| 13558 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 13559 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13560 | } |
| 13561 | |
| 13562 | /** |
| 13563 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 13564 | * @phba: pointer to lpfc hba data structure. |
| 13565 | * |
| 13566 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 13567 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 13568 | * pending I/Os. |
| 13569 | **/ |
| 13570 | static void |
| 13571 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 13572 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13573 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13574 | "2826 PCI channel disable preparing for reset\n"); |
| 13575 | |
| 13576 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13577 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13578 | |
| 13579 | /* Block all SCSI devices' I/Os on the host */ |
| 13580 | lpfc_scsi_dev_block(phba); |
| 13581 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13582 | /* Flush all driver's outstanding I/Os as we are to reset */ |
| 13583 | lpfc_sli_flush_io_rings(phba); |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 13584 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13585 | /* stop all timers */ |
| 13586 | lpfc_stop_hba_timers(phba); |
| 13587 | |
| 13588 | /* Disable interrupt and pci device */ |
| 13589 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13590 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13591 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13592 | } |
| 13593 | |
| 13594 | /** |
| 13595 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 13596 | * @phba: pointer to lpfc hba data structure. |
| 13597 | * |
| 13598 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 13599 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 13600 | * pending I/Os. |
| 13601 | **/ |
| 13602 | static void |
| 13603 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 13604 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13605 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13606 | "2827 PCI channel permanent disable for failure\n"); |
| 13607 | |
| 13608 | /* Block all SCSI devices' I/Os on the host */ |
| 13609 | lpfc_scsi_dev_block(phba); |
| 13610 | |
| 13611 | /* stop all timers */ |
| 13612 | lpfc_stop_hba_timers(phba); |
| 13613 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13614 | /* Clean up all driver's outstanding I/Os */ |
| 13615 | lpfc_sli_flush_io_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13616 | } |
| 13617 | |
| 13618 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13619 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 13620 | * @pdev: pointer to PCI device. |
| 13621 | * @state: the current PCI connection state. |
| 13622 | * |
| 13623 | * This routine is called from the PCI subsystem for error handling to device |
| 13624 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 13625 | * after a PCI bus error affecting this device has been detected. When this |
| 13626 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 13627 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 13628 | * for the PCI subsystem to perform proper recovery as desired. |
| 13629 | * |
| 13630 | * Return codes |
| 13631 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13632 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13633 | **/ |
| 13634 | static pci_ers_result_t |
| 13635 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 13636 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13637 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13638 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13639 | |
| 13640 | switch (state) { |
| 13641 | case pci_channel_io_normal: |
| 13642 | /* Non-fatal error, prepare for recovery */ |
| 13643 | lpfc_sli4_prep_dev_for_recover(phba); |
| 13644 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 13645 | case pci_channel_io_frozen: |
| 13646 | /* Fatal error, prepare for slot reset */ |
| 13647 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13648 | return PCI_ERS_RESULT_NEED_RESET; |
| 13649 | case pci_channel_io_perm_failure: |
| 13650 | /* Permanent failure, prepare for device down */ |
| 13651 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 13652 | return PCI_ERS_RESULT_DISCONNECT; |
| 13653 | default: |
| 13654 | /* Unknown state, prepare and request slot reset */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13655 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13656 | "2825 Unknown PCI error state: x%x\n", state); |
| 13657 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13658 | return PCI_ERS_RESULT_NEED_RESET; |
| 13659 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13660 | } |
| 13661 | |
| 13662 | /** |
| 13663 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 13664 | * @pdev: pointer to PCI device. |
| 13665 | * |
| 13666 | * This routine is called from the PCI subsystem for error handling to device |
| 13667 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 13668 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 13669 | * PCI subsystem error recovery, after the driver returns |
| 13670 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 13671 | * recovery and then call this routine before calling the .resume method to |
| 13672 | * recover the device. This function will initialize the HBA device, enable |
| 13673 | * the interrupt, but it will just put the HBA to offline state without |
| 13674 | * passing any I/O traffic. |
| 13675 | * |
| 13676 | * Return codes |
| 13677 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13678 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13679 | */ |
| 13680 | static pci_ers_result_t |
| 13681 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 13682 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13683 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13684 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13685 | struct lpfc_sli *psli = &phba->sli; |
| 13686 | uint32_t intr_mode; |
| 13687 | |
| 13688 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 13689 | if (pci_enable_device_mem(pdev)) { |
| 13690 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 13691 | "PCI device after reset.\n"); |
| 13692 | return PCI_ERS_RESULT_DISCONNECT; |
| 13693 | } |
| 13694 | |
| 13695 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 13696 | |
| 13697 | /* |
| 13698 | * As the new kernel behavior of pci_restore_state() API call clears |
| 13699 | * device saved_state flag, need to save the restored state again. |
| 13700 | */ |
| 13701 | pci_save_state(pdev); |
| 13702 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13703 | if (pdev->is_busmaster) |
| 13704 | pci_set_master(pdev); |
| 13705 | |
| 13706 | spin_lock_irq(&phba->hbalock); |
| 13707 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 13708 | spin_unlock_irq(&phba->hbalock); |
| 13709 | |
| 13710 | /* Configure and enable interrupt */ |
| 13711 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13712 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13713 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13714 | "2824 Cannot re-enable interrupt after " |
| 13715 | "slot reset.\n"); |
| 13716 | return PCI_ERS_RESULT_DISCONNECT; |
| 13717 | } else |
| 13718 | phba->intr_mode = intr_mode; |
| 13719 | |
| 13720 | /* Log the current active interrupt mode */ |
| 13721 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13722 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13723 | return PCI_ERS_RESULT_RECOVERED; |
| 13724 | } |
| 13725 | |
| 13726 | /** |
| 13727 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 13728 | * @pdev: pointer to PCI device |
| 13729 | * |
| 13730 | * This routine is called from the PCI subsystem for error handling to device |
| 13731 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 13732 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 13733 | * error recovery. After this call, traffic can start to flow from this device |
| 13734 | * again. |
| 13735 | **/ |
| 13736 | static void |
| 13737 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 13738 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13739 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13740 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13741 | |
| 13742 | /* |
| 13743 | * In case of slot reset, as function reset is performed through |
| 13744 | * mailbox command which needs DMA to be enabled, this operation |
| 13745 | * has to be moved to the io resume phase. Taking device offline |
| 13746 | * will perform the necessary cleanup. |
| 13747 | */ |
| 13748 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 13749 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13750 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13751 | lpfc_offline(phba); |
| 13752 | lpfc_sli_brdrestart(phba); |
| 13753 | /* Bring the device back online */ |
| 13754 | lpfc_online(phba); |
| 13755 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13756 | } |
| 13757 | |
| 13758 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13759 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 13760 | * @pdev: pointer to PCI device |
| 13761 | * @pid: pointer to PCI device identifier |
| 13762 | * |
| 13763 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13764 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 13765 | * at PCI device-specific information of the device and driver to see if the |
| 13766 | * driver state that it can support this kind of device. If the match is |
| 13767 | * successful, the driver core invokes this routine. This routine dispatches |
| 13768 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 13769 | * do all the initialization that it needs to do to handle the HBA device |
| 13770 | * properly. |
| 13771 | * |
| 13772 | * Return code |
| 13773 | * 0 - driver can claim the device |
| 13774 | * negative value - driver can not claim the device |
| 13775 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13776 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13777 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13778 | { |
| 13779 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13780 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13781 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13782 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13783 | return -ENODEV; |
| 13784 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13785 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13786 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13787 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13788 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13789 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13790 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13791 | return rc; |
| 13792 | } |
| 13793 | |
| 13794 | /** |
| 13795 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 13796 | * @pdev: pointer to PCI device |
| 13797 | * |
| 13798 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13799 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 13800 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 13801 | * remove routine, which will perform all the necessary cleanup for the |
| 13802 | * device to be removed from the PCI subsystem properly. |
| 13803 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13804 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13805 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 13806 | { |
| 13807 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13808 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13809 | |
| 13810 | switch (phba->pci_dev_grp) { |
| 13811 | case LPFC_PCI_DEV_LP: |
| 13812 | lpfc_pci_remove_one_s3(pdev); |
| 13813 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13814 | case LPFC_PCI_DEV_OC: |
| 13815 | lpfc_pci_remove_one_s4(pdev); |
| 13816 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13817 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13818 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13819 | "1424 Invalid PCI device group: 0x%x\n", |
| 13820 | phba->pci_dev_grp); |
| 13821 | break; |
| 13822 | } |
| 13823 | return; |
| 13824 | } |
| 13825 | |
| 13826 | /** |
| 13827 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13828 | * @dev: pointer to device |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13829 | * |
| 13830 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13831 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13832 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 13833 | * suspend the device. |
| 13834 | * |
| 13835 | * Return code |
| 13836 | * 0 - driver suspended the device |
| 13837 | * Error otherwise |
| 13838 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13839 | static int __maybe_unused |
| 13840 | lpfc_pci_suspend_one(struct device *dev) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13841 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13842 | struct Scsi_Host *shost = dev_get_drvdata(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13843 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13844 | int rc = -ENODEV; |
| 13845 | |
| 13846 | switch (phba->pci_dev_grp) { |
| 13847 | case LPFC_PCI_DEV_LP: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13848 | rc = lpfc_pci_suspend_one_s3(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13849 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13850 | case LPFC_PCI_DEV_OC: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13851 | rc = lpfc_pci_suspend_one_s4(dev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13852 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13853 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13854 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13855 | "1425 Invalid PCI device group: 0x%x\n", |
| 13856 | phba->pci_dev_grp); |
| 13857 | break; |
| 13858 | } |
| 13859 | return rc; |
| 13860 | } |
| 13861 | |
| 13862 | /** |
| 13863 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13864 | * @dev: pointer to device |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13865 | * |
| 13866 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13867 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13868 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 13869 | * resume the device. |
| 13870 | * |
| 13871 | * Return code |
| 13872 | * 0 - driver suspended the device |
| 13873 | * Error otherwise |
| 13874 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13875 | static int __maybe_unused |
| 13876 | lpfc_pci_resume_one(struct device *dev) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13877 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13878 | struct Scsi_Host *shost = dev_get_drvdata(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13879 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13880 | int rc = -ENODEV; |
| 13881 | |
| 13882 | switch (phba->pci_dev_grp) { |
| 13883 | case LPFC_PCI_DEV_LP: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13884 | rc = lpfc_pci_resume_one_s3(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13885 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13886 | case LPFC_PCI_DEV_OC: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13887 | rc = lpfc_pci_resume_one_s4(dev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13888 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13889 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13890 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13891 | "1426 Invalid PCI device group: 0x%x\n", |
| 13892 | phba->pci_dev_grp); |
| 13893 | break; |
| 13894 | } |
| 13895 | return rc; |
| 13896 | } |
| 13897 | |
| 13898 | /** |
| 13899 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 13900 | * @pdev: pointer to PCI device. |
| 13901 | * @state: the current PCI connection state. |
| 13902 | * |
| 13903 | * This routine is registered to the PCI subsystem for error handling. This |
| 13904 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 13905 | * this device has been detected. When this routine is invoked, it dispatches |
| 13906 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 13907 | * routine, which will perform the proper error detected operation. |
| 13908 | * |
| 13909 | * Return codes |
| 13910 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13911 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13912 | **/ |
| 13913 | static pci_ers_result_t |
| 13914 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 13915 | { |
| 13916 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13917 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13918 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13919 | |
| 13920 | switch (phba->pci_dev_grp) { |
| 13921 | case LPFC_PCI_DEV_LP: |
| 13922 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 13923 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13924 | case LPFC_PCI_DEV_OC: |
| 13925 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 13926 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13927 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13928 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13929 | "1427 Invalid PCI device group: 0x%x\n", |
| 13930 | phba->pci_dev_grp); |
| 13931 | break; |
| 13932 | } |
| 13933 | return rc; |
| 13934 | } |
| 13935 | |
| 13936 | /** |
| 13937 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 13938 | * @pdev: pointer to PCI device. |
| 13939 | * |
| 13940 | * This routine is registered to the PCI subsystem for error handling. This |
| 13941 | * function is called after PCI bus has been reset to restart the PCI card |
| 13942 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 13943 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 13944 | * routine, which will perform the proper device reset. |
| 13945 | * |
| 13946 | * Return codes |
| 13947 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13948 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13949 | **/ |
| 13950 | static pci_ers_result_t |
| 13951 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 13952 | { |
| 13953 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13954 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13955 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13956 | |
| 13957 | switch (phba->pci_dev_grp) { |
| 13958 | case LPFC_PCI_DEV_LP: |
| 13959 | rc = lpfc_io_slot_reset_s3(pdev); |
| 13960 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13961 | case LPFC_PCI_DEV_OC: |
| 13962 | rc = lpfc_io_slot_reset_s4(pdev); |
| 13963 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13964 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13965 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13966 | "1428 Invalid PCI device group: 0x%x\n", |
| 13967 | phba->pci_dev_grp); |
| 13968 | break; |
| 13969 | } |
| 13970 | return rc; |
| 13971 | } |
| 13972 | |
| 13973 | /** |
| 13974 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 13975 | * @pdev: pointer to PCI device |
| 13976 | * |
| 13977 | * This routine is registered to the PCI subsystem for error handling. It |
| 13978 | * is called when kernel error recovery tells the lpfc driver that it is |
| 13979 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 13980 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 13981 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 13982 | **/ |
| 13983 | static void |
| 13984 | lpfc_io_resume(struct pci_dev *pdev) |
| 13985 | { |
| 13986 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13987 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13988 | |
| 13989 | switch (phba->pci_dev_grp) { |
| 13990 | case LPFC_PCI_DEV_LP: |
| 13991 | lpfc_io_resume_s3(pdev); |
| 13992 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13993 | case LPFC_PCI_DEV_OC: |
| 13994 | lpfc_io_resume_s4(pdev); |
| 13995 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13996 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13997 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13998 | "1429 Invalid PCI device group: 0x%x\n", |
| 13999 | phba->pci_dev_grp); |
| 14000 | break; |
| 14001 | } |
| 14002 | return; |
| 14003 | } |
| 14004 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14005 | /** |
| 14006 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 14007 | * @phba: pointer to lpfc hba data structure. |
| 14008 | * |
| 14009 | * This routine checks to see if OAS is supported for this adapter. If |
| 14010 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 14011 | * the enable oas flag is cleared and the pool created for OAS device data |
| 14012 | * is destroyed. |
| 14013 | * |
| 14014 | **/ |
YueHaibing | c709297 | 2019-04-17 23:05:54 +0800 | [diff] [blame] | 14015 | static void |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14016 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 14017 | { |
| 14018 | |
| 14019 | if (!phba->cfg_EnableXLane) |
| 14020 | return; |
| 14021 | |
| 14022 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 14023 | phba->cfg_fof = 1; |
| 14024 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 14025 | phba->cfg_fof = 0; |
Saurav Girepunje | c3e5aac | 2019-10-27 01:17:17 +0530 | [diff] [blame] | 14026 | mempool_destroy(phba->device_data_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14027 | phba->device_data_mem_pool = NULL; |
| 14028 | } |
| 14029 | |
| 14030 | return; |
| 14031 | } |
| 14032 | |
| 14033 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 14034 | * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter |
| 14035 | * @phba: pointer to lpfc hba data structure. |
| 14036 | * |
| 14037 | * This routine checks to see if RAS is supported by the adapter. Check the |
| 14038 | * function through which RAS support enablement is to be done. |
| 14039 | **/ |
| 14040 | void |
| 14041 | lpfc_sli4_ras_init(struct lpfc_hba *phba) |
| 14042 | { |
| 14043 | switch (phba->pcidev->device) { |
| 14044 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 14045 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 14046 | phba->ras_fwlog.ras_hwsupport = true; |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 14047 | if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) && |
| 14048 | phba->cfg_ras_fwlog_buffsize) |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 14049 | phba->ras_fwlog.ras_enabled = true; |
| 14050 | else |
| 14051 | phba->ras_fwlog.ras_enabled = false; |
| 14052 | break; |
| 14053 | default: |
| 14054 | phba->ras_fwlog.ras_hwsupport = false; |
| 14055 | } |
| 14056 | } |
| 14057 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14058 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14059 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 14060 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 14061 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14062 | .error_detected = lpfc_io_error_detected, |
| 14063 | .slot_reset = lpfc_io_slot_reset, |
| 14064 | .resume = lpfc_io_resume, |
| 14065 | }; |
| 14066 | |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14067 | static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one, |
| 14068 | lpfc_pci_suspend_one, |
| 14069 | lpfc_pci_resume_one); |
| 14070 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14071 | static struct pci_driver lpfc_driver = { |
| 14072 | .name = LPFC_DRIVER_NAME, |
| 14073 | .id_table = lpfc_id_table, |
| 14074 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 14075 | .remove = lpfc_pci_remove_one, |
Anton Blanchard | 85e8a23 | 2017-02-13 08:49:20 +1100 | [diff] [blame] | 14076 | .shutdown = lpfc_pci_remove_one, |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14077 | .driver.pm = &lpfc_pci_pm_ops_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 14078 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14079 | }; |
| 14080 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14081 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 14082 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14083 | }; |
| 14084 | |
| 14085 | static struct miscdevice lpfc_mgmt_dev = { |
| 14086 | .minor = MISC_DYNAMIC_MINOR, |
| 14087 | .name = "lpfcmgmt", |
| 14088 | .fops = &lpfc_mgmt_fop, |
| 14089 | }; |
| 14090 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14091 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 14092 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14093 | * |
| 14094 | * This routine is to be invoked when the lpfc module is loaded into the |
| 14095 | * kernel. The special kernel macro module_init() is used to indicate the |
| 14096 | * role of this routine to the kernel as lpfc module entry point. |
| 14097 | * |
| 14098 | * Return codes |
| 14099 | * 0 - successful |
| 14100 | * -ENOMEM - FC attach transport failed |
| 14101 | * all others - failed |
| 14102 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14103 | static int __init |
| 14104 | lpfc_init(void) |
| 14105 | { |
| 14106 | int error = 0; |
| 14107 | |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 14108 | pr_info(LPFC_MODULE_DESC "\n"); |
| 14109 | pr_info(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14110 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14111 | error = misc_register(&lpfc_mgmt_dev); |
| 14112 | if (error) |
| 14113 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 14114 | "misc_register returned with status %d", error); |
| 14115 | |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14116 | error = -ENOMEM; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 14117 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 14118 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14119 | lpfc_transport_template = |
| 14120 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 14121 | if (lpfc_transport_template == NULL) |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14122 | goto unregister; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 14123 | lpfc_vport_transport_template = |
| 14124 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 14125 | if (lpfc_vport_transport_template == NULL) { |
| 14126 | fc_release_transport(lpfc_transport_template); |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14127 | goto unregister; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 14128 | } |
James Smart | 840a470 | 2020-11-15 11:26:40 -0800 | [diff] [blame] | 14129 | lpfc_wqe_cmd_template(); |
James Smart | bd3061b | 2018-03-05 12:04:05 -0800 | [diff] [blame] | 14130 | lpfc_nvmet_cmd_template(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 14131 | |
| 14132 | /* Initialize in case vector mapping is needed */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14133 | lpfc_present_cpu = num_present_cpus(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 14134 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14135 | error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, |
| 14136 | "lpfc/sli4:online", |
| 14137 | lpfc_cpu_online, lpfc_cpu_offline); |
| 14138 | if (error < 0) |
| 14139 | goto cpuhp_failure; |
| 14140 | lpfc_cpuhp_state = error; |
| 14141 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14142 | error = pci_register_driver(&lpfc_driver); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14143 | if (error) |
| 14144 | goto unwind; |
| 14145 | |
| 14146 | return error; |
| 14147 | |
| 14148 | unwind: |
| 14149 | cpuhp_remove_multi_state(lpfc_cpuhp_state); |
| 14150 | cpuhp_failure: |
| 14151 | fc_release_transport(lpfc_transport_template); |
| 14152 | fc_release_transport(lpfc_vport_transport_template); |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14153 | unregister: |
| 14154 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14155 | |
| 14156 | return error; |
| 14157 | } |
| 14158 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14159 | void lpfc_dmp_dbg(struct lpfc_hba *phba) |
| 14160 | { |
| 14161 | unsigned int start_idx; |
| 14162 | unsigned int dbg_cnt; |
| 14163 | unsigned int temp_idx; |
| 14164 | int i; |
| 14165 | int j = 0; |
James Smart | e861308 | 2021-07-07 11:43:33 -0700 | [diff] [blame] | 14166 | unsigned long rem_nsec, iflags; |
| 14167 | bool log_verbose = false; |
| 14168 | struct lpfc_vport *port_iterator; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14169 | |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 14170 | /* Don't dump messages if we explicitly set log_verbose for the |
| 14171 | * physical port or any vport. |
| 14172 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14173 | if (phba->cfg_log_verbose) |
| 14174 | return; |
| 14175 | |
James Smart | e861308 | 2021-07-07 11:43:33 -0700 | [diff] [blame] | 14176 | spin_lock_irqsave(&phba->port_list_lock, iflags); |
| 14177 | list_for_each_entry(port_iterator, &phba->port_list, listentry) { |
| 14178 | if (port_iterator->load_flag & FC_UNLOADING) |
| 14179 | continue; |
| 14180 | if (scsi_host_get(lpfc_shost_from_vport(port_iterator))) { |
| 14181 | if (port_iterator->cfg_log_verbose) |
| 14182 | log_verbose = true; |
| 14183 | |
| 14184 | scsi_host_put(lpfc_shost_from_vport(port_iterator)); |
| 14185 | |
| 14186 | if (log_verbose) { |
| 14187 | spin_unlock_irqrestore(&phba->port_list_lock, |
| 14188 | iflags); |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 14189 | return; |
| 14190 | } |
| 14191 | } |
| 14192 | } |
James Smart | e861308 | 2021-07-07 11:43:33 -0700 | [diff] [blame] | 14193 | spin_unlock_irqrestore(&phba->port_list_lock, iflags); |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 14194 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14195 | if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0) |
| 14196 | return; |
| 14197 | |
| 14198 | start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ; |
| 14199 | dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt); |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 14200 | if (!dbg_cnt) |
| 14201 | goto out; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14202 | temp_idx = start_idx; |
| 14203 | if (dbg_cnt >= DBG_LOG_SZ) { |
| 14204 | dbg_cnt = DBG_LOG_SZ; |
| 14205 | temp_idx -= 1; |
| 14206 | } else { |
| 14207 | if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) { |
| 14208 | temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ; |
| 14209 | } else { |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 14210 | if (start_idx < dbg_cnt) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14211 | start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx); |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 14212 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14213 | start_idx -= dbg_cnt; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14214 | } |
| 14215 | } |
| 14216 | dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n", |
| 14217 | start_idx, temp_idx, dbg_cnt); |
| 14218 | |
| 14219 | for (i = 0; i < dbg_cnt; i++) { |
| 14220 | if ((start_idx + i) < DBG_LOG_SZ) |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 14221 | temp_idx = (start_idx + i) % DBG_LOG_SZ; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14222 | else |
| 14223 | temp_idx = j++; |
| 14224 | rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC); |
| 14225 | dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s", |
| 14226 | temp_idx, |
| 14227 | (unsigned long)phba->dbg_log[temp_idx].t_ns, |
| 14228 | rem_nsec / 1000, |
| 14229 | phba->dbg_log[temp_idx].log); |
| 14230 | } |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 14231 | out: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14232 | atomic_set(&phba->dbg_log_cnt, 0); |
| 14233 | atomic_set(&phba->dbg_log_dmping, 0); |
| 14234 | } |
| 14235 | |
Lee Jones | 7fa03c7 | 2020-07-23 13:24:21 +0100 | [diff] [blame] | 14236 | __printf(2, 3) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14237 | void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...) |
| 14238 | { |
| 14239 | unsigned int idx; |
| 14240 | va_list args; |
| 14241 | int dbg_dmping = atomic_read(&phba->dbg_log_dmping); |
| 14242 | struct va_format vaf; |
| 14243 | |
| 14244 | |
| 14245 | va_start(args, fmt); |
| 14246 | if (unlikely(dbg_dmping)) { |
| 14247 | vaf.fmt = fmt; |
| 14248 | vaf.va = &args; |
| 14249 | dev_info(&phba->pcidev->dev, "%pV", &vaf); |
| 14250 | va_end(args); |
| 14251 | return; |
| 14252 | } |
| 14253 | idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) % |
| 14254 | DBG_LOG_SZ; |
| 14255 | |
| 14256 | atomic_inc(&phba->dbg_log_cnt); |
| 14257 | |
| 14258 | vscnprintf(phba->dbg_log[idx].log, |
| 14259 | sizeof(phba->dbg_log[idx].log), fmt, args); |
| 14260 | va_end(args); |
| 14261 | |
| 14262 | phba->dbg_log[idx].t_ns = local_clock(); |
| 14263 | } |
| 14264 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14265 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 14266 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14267 | * |
| 14268 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 14269 | * The special kernel macro module_exit() is used to indicate the role of |
| 14270 | * this routine to the kernel as lpfc module exit point. |
| 14271 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14272 | static void __exit |
| 14273 | lpfc_exit(void) |
| 14274 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14275 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14276 | pci_unregister_driver(&lpfc_driver); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14277 | cpuhp_remove_multi_state(lpfc_cpuhp_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14278 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 14279 | fc_release_transport(lpfc_vport_transport_template); |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 14280 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14281 | } |
| 14282 | |
| 14283 | module_init(lpfc_init); |
| 14284 | module_exit(lpfc_exit); |
| 14285 | MODULE_LICENSE("GPL"); |
| 14286 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 14287 | MODULE_AUTHOR("Broadcom"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14288 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |