| 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 |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 101 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 102 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 103 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 104 | * @phba: pointer to lpfc hba data structure. |
| 105 | * |
| 106 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 107 | * mailbox command. It retrieves the revision information from the HBA and |
| 108 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 109 | * configuration of the HBA. |
| 110 | * |
| 111 | * Return codes: |
| 112 | * 0 - success. |
| 113 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 114 | * Any other value - indicates an error. |
| 115 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 117 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | { |
| 119 | lpfc_vpd_t *vp = &phba->vpd; |
| 120 | int i = 0, rc; |
| 121 | LPFC_MBOXQ_t *pmb; |
| 122 | MAILBOX_t *mb; |
| 123 | char *lpfc_vpd_data = NULL; |
| 124 | uint16_t offset = 0; |
| 125 | static char licensed[56] = |
| 126 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 127 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 128 | |
| 129 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 130 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 131 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 132 | return -ENOMEM; |
| 133 | } |
| 134 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 135 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 136 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 137 | |
| 138 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 139 | if (init_key) { |
| 140 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 141 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 142 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 143 | *ptext = cpu_to_be32(*ptext); |
| 144 | init_key = 0; |
| 145 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 146 | |
| 147 | lpfc_read_nv(phba, pmb); |
| 148 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 149 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 150 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 151 | sizeof (licensed)); |
| 152 | |
| 153 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 154 | |
| 155 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 156 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 157 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 | "error, mbxCmd x%x READ_NVPARM, " |
| 159 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | mb->mbxCommand, mb->mbxStatus); |
| 161 | mempool_free(pmb, phba->mbox_mem_pool); |
| 162 | return -ERESTART; |
| 163 | } |
| 164 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 165 | sizeof(phba->wwnn)); |
| 166 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 167 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 168 | } |
| 169 | |
Martin Wilck | dfb7513 | 2018-11-12 09:58:37 +0100 | [diff] [blame] | 170 | /* |
| 171 | * Clear all option bits except LPFC_SLI3_BG_ENABLED, |
| 172 | * which was already set in lpfc_get_cfgparam() |
| 173 | */ |
| 174 | phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 175 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 176 | /* Setup and issue mailbox READ REV command */ |
| 177 | lpfc_read_rev(phba, pmb); |
| 178 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 179 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 180 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 181 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 182 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 183 | mb->mbxCommand, mb->mbxStatus); |
| 184 | mempool_free( pmb, phba->mbox_mem_pool); |
| 185 | return -ERESTART; |
| 186 | } |
| 187 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 188 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 189 | /* |
| 190 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 191 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 192 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 193 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 194 | vp->rev.rBit = 0; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 195 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 196 | "0440 Adapter failed to init, READ_REV has " |
| 197 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 198 | mempool_free(pmb, phba->mbox_mem_pool); |
| 199 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 200 | } |
| 201 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 202 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 203 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 204 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 205 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 206 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 208 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 209 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 210 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 211 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 212 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 213 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 214 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 215 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 216 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 217 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 218 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 219 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 220 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 221 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 222 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 223 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 224 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 225 | /* If the sli feature level is less then 9, we must |
| 226 | * tear down all RPIs and VPIs on link down if NPIV |
| 227 | * is enabled. |
| 228 | */ |
| 229 | if (vp->rev.feaLevelHigh < 9) |
| 230 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 231 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 232 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 233 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 234 | sizeof (phba->RandomData)); |
| 235 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 236 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 238 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 239 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 240 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 241 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 242 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 243 | |
| 244 | if (rc != MBX_SUCCESS) { |
| 245 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 246 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 247 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 249 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 250 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 251 | /* dump mem may return a zero when finished or we got a |
| 252 | * mailbox error, either way we are done. |
| 253 | */ |
| 254 | if (mb->un.varDmp.word_cnt == 0) |
| 255 | break; |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 256 | |
| 257 | i = mb->un.varDmp.word_cnt * sizeof(uint32_t); |
| 258 | if (offset + i > DMP_VPD_SIZE) |
| 259 | i = 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, |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 261 | lpfc_vpd_data + offset, i); |
| 262 | offset += i; |
| 263 | } while (offset < DMP_VPD_SIZE); |
| 264 | |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 265 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 266 | |
| 267 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 268 | out_free_mbox: |
| 269 | mempool_free(pmb, phba->mbox_mem_pool); |
| 270 | return 0; |
| 271 | } |
| 272 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 273 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 274 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 275 | * @phba: pointer to lpfc hba data structure. |
| 276 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 277 | * |
| 278 | * This is the completion handler for driver's configuring asynchronous event |
| 279 | * mailbox command to the device. If the mailbox command returns successfully, |
| 280 | * it will set internal async event support flag to 1; otherwise, it will |
| 281 | * set internal async event support flag to 0. |
| 282 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 283 | static void |
| 284 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 285 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 286 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 287 | phba->temp_sensor_support = 1; |
| 288 | else |
| 289 | phba->temp_sensor_support = 0; |
| 290 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 291 | return; |
| 292 | } |
| 293 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 294 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 295 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 296 | * @phba: pointer to lpfc hba data structure. |
| 297 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 298 | * |
| 299 | * This is the completion handler for dump mailbox command for getting |
| 300 | * wake up parameters. When this command complete, the response contain |
| 301 | * Option rom version of the HBA. This function translate the version number |
| 302 | * into a human readable string and store it in OptionROMVersion. |
| 303 | **/ |
| 304 | static void |
| 305 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 306 | { |
| 307 | struct prog_id *prg; |
| 308 | uint32_t prog_id_word; |
| 309 | char dist = ' '; |
| 310 | /* character array used for decoding dist type. */ |
| 311 | char dist_char[] = "nabx"; |
| 312 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 313 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 314 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 315 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 316 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 317 | |
| 318 | prg = (struct prog_id *) &prog_id_word; |
| 319 | |
| 320 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 321 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 322 | |
| 323 | /* Decode the Option rom version word to a readable string */ |
| 324 | if (prg->dist < 4) |
| 325 | dist = dist_char[prg->dist]; |
| 326 | |
| 327 | if ((prg->dist == 3) && (prg->num == 0)) |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 328 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 329 | prg->ver, prg->rev, prg->lev); |
| 330 | else |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 331 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 332 | prg->ver, prg->rev, prg->lev, |
| 333 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 334 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 335 | return; |
| 336 | } |
| 337 | |
| 338 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 339 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 340 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 341 | * @vport: pointer to lpfc vport data structure. |
| 342 | * |
| 343 | * |
| 344 | * Return codes |
| 345 | * None. |
| 346 | **/ |
| 347 | void |
| 348 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 349 | { |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 350 | uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level; |
| 351 | u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0]; |
| 352 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 353 | /* If the soft name exists then update it using the service params */ |
| 354 | if (vport->phba->cfg_soft_wwnn) |
| 355 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 356 | vport->fc_sparam.nodeName.u.wwn); |
| 357 | if (vport->phba->cfg_soft_wwpn) |
| 358 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 359 | vport->fc_sparam.portName.u.wwn); |
| 360 | |
| 361 | /* |
| 362 | * If the name is empty or there exists a soft name |
| 363 | * then copy the service params name, otherwise use the fc name |
| 364 | */ |
| 365 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 366 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 367 | sizeof(struct lpfc_name)); |
| 368 | else |
| 369 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 370 | sizeof(struct lpfc_name)); |
| 371 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 372 | /* |
| 373 | * If the port name has changed, then set the Param changes flag |
| 374 | * to unreg the login |
| 375 | */ |
| 376 | if (vport->fc_portname.u.wwn[0] != 0 && |
| 377 | memcmp(&vport->fc_portname, &vport->fc_sparam.portName, |
| 378 | sizeof(struct lpfc_name))) |
| 379 | vport->vport_flag |= FAWWPN_PARAM_CHG; |
| 380 | |
| 381 | if (vport->fc_portname.u.wwn[0] == 0 || |
| 382 | vport->phba->cfg_soft_wwpn || |
| 383 | (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) || |
| 384 | vport->vport_flag & FAWWPN_SET) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 385 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 386 | sizeof(struct lpfc_name)); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 387 | vport->vport_flag &= ~FAWWPN_SET; |
| 388 | if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) |
| 389 | vport->vport_flag |= FAWWPN_SET; |
| 390 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 391 | else |
| 392 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 393 | sizeof(struct lpfc_name)); |
| 394 | } |
| 395 | |
| 396 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 397 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 398 | * @phba: pointer to lpfc hba data structure. |
| 399 | * |
| 400 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 401 | * command call. It performs all internal resource and state setups on the |
| 402 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 403 | * ELS ring timers, etc. |
| 404 | * |
| 405 | * Return codes |
| 406 | * 0 - success. |
| 407 | * Any other value - error. |
| 408 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 409 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 410 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 412 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 413 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | LPFC_MBOXQ_t *pmb; |
| 415 | MAILBOX_t *mb; |
| 416 | struct lpfc_dmabuf *mp; |
| 417 | struct lpfc_sli *psli = &phba->sli; |
| 418 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 419 | int i, j; |
| 420 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 421 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 422 | spin_lock_irq(&phba->hbalock); |
| 423 | /* |
| 424 | * If the Config port completed correctly the HBA is not |
| 425 | * over heated any more. |
| 426 | */ |
| 427 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 428 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 429 | spin_unlock_irq(&phba->hbalock); |
| 430 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 431 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 432 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 433 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 434 | return -ENOMEM; |
| 435 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 436 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 437 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 438 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 439 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 440 | if (rc) { |
| 441 | mempool_free(pmb, phba->mbox_mem_pool); |
| 442 | return -ENOMEM; |
| 443 | } |
| 444 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 445 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 446 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 447 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 448 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 449 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 450 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 451 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 452 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 453 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 454 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 455 | kfree(mp); |
| 456 | return -EIO; |
| 457 | } |
| 458 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 459 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 461 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 462 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 463 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 464 | pmb->ctx_buf = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 465 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 466 | |
| 467 | /* Update the fc_host data structures with new wwn. */ |
| 468 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 469 | 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] | 470 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 471 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 472 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 473 | /* This should be consolidated into parse_vpd ? - mr */ |
| 474 | if (phba->SerialNumber[0] == 0) { |
| 475 | uint8_t *outptr; |
| 476 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 477 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 478 | for (i = 0; i < 12; i++) { |
| 479 | status = *outptr++; |
| 480 | j = ((status & 0xf0) >> 4); |
| 481 | if (j <= 9) |
| 482 | phba->SerialNumber[i] = |
| 483 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 484 | else |
| 485 | phba->SerialNumber[i] = |
| 486 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 487 | i++; |
| 488 | j = (status & 0xf); |
| 489 | if (j <= 9) |
| 490 | phba->SerialNumber[i] = |
| 491 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 492 | else |
| 493 | phba->SerialNumber[i] = |
| 494 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 495 | } |
| 496 | } |
| 497 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 498 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 499 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 500 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 501 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 502 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 503 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 505 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | mempool_free( pmb, phba->mbox_mem_pool); |
| 507 | return -EIO; |
| 508 | } |
| 509 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 510 | /* Check if the port is disabled */ |
| 511 | lpfc_sli_read_link_ste(phba); |
| 512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | f6770e7 | 2020-01-27 16:23:09 -0800 | [diff] [blame] | 514 | if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) { |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 515 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 516 | "3359 HBA queue depth changed from %d to %d\n", |
James Smart | f6770e7 | 2020-01-27 16:23:09 -0800 | [diff] [blame] | 517 | phba->cfg_hba_queue_depth, |
| 518 | mb->un.varRdConfig.max_xri); |
| 519 | phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri; |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 520 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 521 | |
| 522 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 523 | |
| 524 | /* Get the default values for Model Name and Description */ |
| 525 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 526 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 527 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 528 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 529 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 530 | if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr) |
| 531 | psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 532 | if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr) |
| 533 | psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 534 | |
| 535 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 536 | if (phba->sli_rev != 3) |
| 537 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 538 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 539 | /* |
| 540 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 541 | */ |
| 542 | if (phba->intr_type == MSIX) { |
| 543 | rc = lpfc_config_msi(phba, pmb); |
| 544 | if (rc) { |
| 545 | mempool_free(pmb, phba->mbox_mem_pool); |
| 546 | return -EIO; |
| 547 | } |
| 548 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 549 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 550 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 551 | "0352 Config MSI mailbox command " |
| 552 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 553 | pmb->u.mb.mbxCommand, |
| 554 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 555 | mempool_free(pmb, phba->mbox_mem_pool); |
| 556 | return -EIO; |
| 557 | } |
| 558 | } |
| 559 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 560 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 561 | /* Initialize ERATT handling flag */ |
| 562 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 563 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 564 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 565 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 566 | spin_unlock_irq(&phba->hbalock); |
| 567 | return -EIO; |
| 568 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 569 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 570 | if (psli->num_rings > 0) |
| 571 | status |= HC_R0INT_ENA; |
| 572 | if (psli->num_rings > 1) |
| 573 | status |= HC_R1INT_ENA; |
| 574 | if (psli->num_rings > 2) |
| 575 | status |= HC_R2INT_ENA; |
| 576 | if (psli->num_rings > 3) |
| 577 | status |= HC_R3INT_ENA; |
| 578 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 579 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 580 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 581 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 582 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 583 | writel(status, phba->HCregaddr); |
| 584 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 585 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 586 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 587 | /* Set up ring-0 (ELS) timer */ |
| 588 | timeout = phba->fc_ratov * 2; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 589 | mod_timer(&vport->els_tmofunc, |
| 590 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 591 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 592 | mod_timer(&phba->hb_tmofunc, |
| 593 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 594 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 595 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 596 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 597 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 598 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 600 | if (phba->hba_flag & LINK_DISABLED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 601 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 602 | "2598 Adapter Link is disabled.\n"); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 603 | lpfc_down_link(phba, pmb); |
| 604 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 605 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 606 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 607 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 608 | "2599 Adapter failed to issue DOWN_LINK" |
| 609 | " mbox command rc 0x%x\n", rc); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 610 | |
| 611 | mempool_free(pmb, phba->mbox_mem_pool); |
| 612 | return -EIO; |
| 613 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 614 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 615 | mempool_free(pmb, phba->mbox_mem_pool); |
| 616 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 617 | if (rc) |
| 618 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | } |
| 620 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 621 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 622 | if (!pmb) { |
| 623 | phba->link_state = LPFC_HBA_ERROR; |
| 624 | return -ENOMEM; |
| 625 | } |
| 626 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 627 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 628 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 629 | pmb->vport = phba->pport; |
| 630 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 632 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 633 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 634 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 635 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 636 | rc); |
| 637 | mempool_free(pmb, phba->mbox_mem_pool); |
| 638 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 639 | |
| 640 | /* Get Option rom version */ |
| 641 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 642 | if (!pmb) { |
| 643 | phba->link_state = LPFC_HBA_ERROR; |
| 644 | return -ENOMEM; |
| 645 | } |
| 646 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 647 | lpfc_dump_wakeup_param(phba, pmb); |
| 648 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 649 | pmb->vport = phba->pport; |
| 650 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 651 | |
| 652 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 653 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 654 | "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 655 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 656 | mempool_free(pmb, phba->mbox_mem_pool); |
| 657 | } |
| 658 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 659 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 660 | } |
| 661 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 662 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 663 | * lpfc_hba_init_link - Initialize the FC link |
| 664 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 665 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 666 | * |
| 667 | * This routine will issue the INIT_LINK mailbox command call. |
| 668 | * It is available to other drivers through the lpfc_hba data |
| 669 | * structure for use as a delayed link up mechanism with the |
| 670 | * module parameter lpfc_suppress_link_up. |
| 671 | * |
| 672 | * Return code |
| 673 | * 0 - success |
| 674 | * Any other value - error |
| 675 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 676 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 677 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 678 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 679 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 684 | * @phba: pointer to lpfc hba data structure. |
| 685 | * @fc_topology: desired fc topology. |
| 686 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 687 | * |
| 688 | * This routine will issue the INIT_LINK mailbox command call. |
| 689 | * It is available to other drivers through the lpfc_hba data |
| 690 | * structure for use as a delayed link up mechanism with the |
| 691 | * module parameter lpfc_suppress_link_up. |
| 692 | * |
| 693 | * Return code |
| 694 | * 0 - success |
| 695 | * Any other value - error |
| 696 | **/ |
| 697 | int |
| 698 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 699 | uint32_t flag) |
| 700 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 701 | struct lpfc_vport *vport = phba->pport; |
| 702 | LPFC_MBOXQ_t *pmb; |
| 703 | MAILBOX_t *mb; |
| 704 | int rc; |
| 705 | |
| 706 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 707 | if (!pmb) { |
| 708 | phba->link_state = LPFC_HBA_ERROR; |
| 709 | return -ENOMEM; |
| 710 | } |
| 711 | mb = &pmb->u.mb; |
| 712 | pmb->vport = vport; |
| 713 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 714 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 715 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 716 | !(phba->lmt & LMT_1Gb)) || |
| 717 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 718 | !(phba->lmt & LMT_2Gb)) || |
| 719 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 720 | !(phba->lmt & LMT_4Gb)) || |
| 721 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 722 | !(phba->lmt & LMT_8Gb)) || |
| 723 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 724 | !(phba->lmt & LMT_10Gb)) || |
| 725 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 726 | !(phba->lmt & LMT_16Gb)) || |
| 727 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) && |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 728 | !(phba->lmt & LMT_32Gb)) || |
| 729 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) && |
| 730 | !(phba->lmt & LMT_64Gb))) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 731 | /* Reset link speed to auto */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 732 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 733 | "1302 Invalid speed for this board:%d " |
| 734 | "Reset link speed to auto.\n", |
| 735 | phba->cfg_link_speed); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 736 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 737 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 738 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 739 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 740 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 741 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 742 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 743 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 744 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 745 | "0498 Adapter failed to init, mbxCmd x%x " |
| 746 | "INIT_LINK, mbxStatus x%x\n", |
| 747 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 748 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 749 | /* Clear all interrupt enable conditions */ |
| 750 | writel(0, phba->HCregaddr); |
| 751 | readl(phba->HCregaddr); /* flush */ |
| 752 | /* Clear all pending interrupts */ |
| 753 | writel(0xffffffff, phba->HAregaddr); |
| 754 | readl(phba->HAregaddr); /* flush */ |
| 755 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 756 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 757 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 758 | mempool_free(pmb, phba->mbox_mem_pool); |
| 759 | return -EIO; |
| 760 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 761 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 762 | if (flag == MBX_POLL) |
| 763 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 764 | |
| 765 | return 0; |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 770 | * @phba: pointer to lpfc hba data structure. |
| 771 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 772 | * |
| 773 | * This routine will issue the DOWN_LINK mailbox command call. |
| 774 | * It is available to other drivers through the lpfc_hba data |
| 775 | * structure for use to stop the link. |
| 776 | * |
| 777 | * Return code |
| 778 | * 0 - success |
| 779 | * Any other value - error |
| 780 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 781 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 782 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 783 | { |
| 784 | LPFC_MBOXQ_t *pmb; |
| 785 | int rc; |
| 786 | |
| 787 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 788 | if (!pmb) { |
| 789 | phba->link_state = LPFC_HBA_ERROR; |
| 790 | return -ENOMEM; |
| 791 | } |
| 792 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 793 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 794 | "0491 Adapter Link is disabled.\n"); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 795 | lpfc_down_link(phba, pmb); |
| 796 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 797 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 798 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 799 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 800 | "2522 Adapter failed to issue DOWN_LINK" |
| 801 | " mbox command rc 0x%x\n", rc); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 802 | |
| 803 | mempool_free(pmb, phba->mbox_mem_pool); |
| 804 | return -EIO; |
| 805 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 806 | if (flag == MBX_POLL) |
| 807 | mempool_free(pmb, phba->mbox_mem_pool); |
| 808 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 813 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 814 | * @phba: pointer to lpfc HBA data structure. |
| 815 | * |
| 816 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 817 | * bringing down the SLI Layer. |
| 818 | * |
| 819 | * Return codes |
| 820 | * 0 - success. |
| 821 | * Any other value - error. |
| 822 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 823 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 824 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 825 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 826 | struct lpfc_vport **vports; |
| 827 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 828 | |
| 829 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 830 | /* Disable interrupts */ |
| 831 | writel(0, phba->HCregaddr); |
| 832 | readl(phba->HCregaddr); /* flush */ |
| 833 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 834 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 835 | if (phba->pport->load_flag & FC_UNLOADING) |
| 836 | lpfc_cleanup_discovery_resources(phba->pport); |
| 837 | else { |
| 838 | vports = lpfc_create_vport_work_array(phba); |
| 839 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 840 | for (i = 0; i <= phba->max_vports && |
| 841 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 842 | lpfc_cleanup_discovery_resources(vports[i]); |
| 843 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 844 | } |
| 845 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | } |
| 847 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 848 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 849 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 850 | * rspiocb which got deferred |
| 851 | * |
| 852 | * @phba: pointer to lpfc HBA data structure. |
| 853 | * |
| 854 | * This routine will cleanup completed slow path events after HBA is reset |
| 855 | * when bringing down the SLI Layer. |
| 856 | * |
| 857 | * |
| 858 | * Return codes |
| 859 | * void. |
| 860 | **/ |
| 861 | static void |
| 862 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 863 | { |
| 864 | struct lpfc_iocbq *rspiocbq; |
| 865 | struct hbq_dmabuf *dmabuf; |
| 866 | struct lpfc_cq_event *cq_event; |
| 867 | |
| 868 | spin_lock_irq(&phba->hbalock); |
| 869 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 870 | spin_unlock_irq(&phba->hbalock); |
| 871 | |
| 872 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 873 | /* Get the response iocb from the head of work queue */ |
| 874 | spin_lock_irq(&phba->hbalock); |
| 875 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 876 | cq_event, struct lpfc_cq_event, list); |
| 877 | spin_unlock_irq(&phba->hbalock); |
| 878 | |
| 879 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 880 | case CQE_CODE_COMPL_WQE: |
| 881 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 882 | cq_event); |
| 883 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 884 | break; |
| 885 | case CQE_CODE_RECEIVE: |
| 886 | case CQE_CODE_RECEIVE_V1: |
| 887 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 888 | cq_event); |
| 889 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 895 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 896 | * @phba: pointer to lpfc HBA data structure. |
| 897 | * |
| 898 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 899 | * when bringing down the SLI Layer. |
| 900 | * |
| 901 | * |
| 902 | * Return codes |
| 903 | * void. |
| 904 | **/ |
| 905 | static void |
| 906 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 907 | { |
| 908 | struct lpfc_sli *psli = &phba->sli; |
| 909 | struct lpfc_sli_ring *pring; |
| 910 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 911 | LIST_HEAD(buflist); |
| 912 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 913 | |
| 914 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 915 | lpfc_sli_hbqbuf_free_all(phba); |
| 916 | else { |
| 917 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 918 | pring = &psli->sli3_ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 919 | spin_lock_irq(&phba->hbalock); |
| 920 | list_splice_init(&pring->postbufq, &buflist); |
| 921 | spin_unlock_irq(&phba->hbalock); |
| 922 | |
| 923 | count = 0; |
| 924 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 925 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 926 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 927 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 928 | kfree(mp); |
| 929 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 930 | |
| 931 | spin_lock_irq(&phba->hbalock); |
| 932 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 933 | spin_unlock_irq(&phba->hbalock); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | /** |
| 938 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 939 | * @phba: pointer to lpfc HBA data structure. |
| 940 | * |
| 941 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 942 | * down the SLI Layer. |
| 943 | * |
| 944 | * Return codes |
| 945 | * void |
| 946 | **/ |
| 947 | static void |
| 948 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 949 | { |
| 950 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 951 | struct lpfc_queue *qp = NULL; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 952 | struct lpfc_sli_ring *pring; |
| 953 | LIST_HEAD(completions); |
| 954 | int i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 955 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 956 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 957 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 958 | for (i = 0; i < psli->num_rings; i++) { |
| 959 | pring = &psli->sli3_ring[i]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 960 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 961 | /* At this point in time the HBA is either reset or DOA |
| 962 | * Nothing should be on txcmplq as it will |
| 963 | * NEVER complete. |
| 964 | */ |
| 965 | list_splice_init(&pring->txcmplq, &completions); |
| 966 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 967 | spin_unlock_irq(&phba->hbalock); |
| 968 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 969 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 970 | } |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 971 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 972 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 973 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
| 974 | return; |
| 975 | } |
| 976 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 977 | pring = qp->pring; |
| 978 | if (!pring) |
| 979 | continue; |
| 980 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 981 | list_for_each_entry_safe(piocb, next_iocb, |
| 982 | &pring->txcmplq, list) |
| 983 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 984 | list_splice_init(&pring->txcmplq, &completions); |
| 985 | pring->txcmplq_cnt = 0; |
| 986 | spin_unlock_irq(&pring->ring_lock); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 987 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 988 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 989 | /* Cancel all the IOCBs from the completions list */ |
| 990 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 991 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 995 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 996 | * @phba: pointer to lpfc HBA data structure. |
| 997 | * |
| 998 | * This routine will do uninitialization after the HBA is reset when bring |
| 999 | * down the SLI Layer. |
| 1000 | * |
| 1001 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1002 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1003 | * Any other value - error. |
| 1004 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1005 | static int |
| 1006 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1007 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1008 | lpfc_hba_free_post_buf(phba); |
| 1009 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1010 | return 0; |
| 1011 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 1012 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1013 | /** |
| 1014 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 1015 | * @phba: pointer to lpfc HBA data structure. |
| 1016 | * |
| 1017 | * This routine will do uninitialization after the HBA is reset when bring |
| 1018 | * down the SLI Layer. |
| 1019 | * |
| 1020 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1021 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1022 | * Any other value - error. |
| 1023 | **/ |
| 1024 | static int |
| 1025 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 1026 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1027 | struct lpfc_io_buf *psb, *psb_next; |
James Smart | 7cacae2 | 2020-03-31 09:50:03 -0700 | [diff] [blame] | 1028 | struct lpfc_async_xchg_ctx *ctxp, *ctxp_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1029 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1030 | LIST_HEAD(aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1031 | LIST_HEAD(nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1032 | LIST_HEAD(nvmet_aborts); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1033 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1034 | int cnt, idx; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1035 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1036 | |
| 1037 | lpfc_sli_hbqbuf_free_all(phba); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1038 | lpfc_hba_clean_txcmplq(phba); |
| 1039 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1040 | /* At this point in time the HBA is either reset or DOA. Either |
| 1041 | * 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] | 1042 | * 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] | 1043 | * driver is unloading or reposted if the driver is restarting |
| 1044 | * the port. |
| 1045 | */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1046 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1047 | /* sgl_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1048 | * list. |
| 1049 | */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1050 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1051 | list_for_each_entry(sglq_entry, |
| 1052 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1053 | sglq_entry->state = SGL_FREED; |
| 1054 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1055 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1056 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1057 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1058 | |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1059 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1060 | |
| 1061 | /* abts_xxxx_buf_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1062 | * list. |
| 1063 | */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1064 | spin_lock_irq(&phba->hbalock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1065 | cnt = 0; |
| 1066 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 1067 | qp = &phba->sli4_hba.hdwq[idx]; |
| 1068 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1069 | spin_lock(&qp->abts_io_buf_list_lock); |
| 1070 | list_splice_init(&qp->lpfc_abts_io_buf_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1071 | &aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1072 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 1073 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1074 | psb->pCmd = NULL; |
| 1075 | psb->status = IOSTAT_SUCCESS; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1076 | cnt++; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1077 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1078 | spin_lock(&qp->io_buf_list_put_lock); |
| 1079 | list_splice_init(&aborts, &qp->lpfc_io_buf_list_put); |
| 1080 | qp->put_io_bufs += qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1081 | qp->put_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1082 | qp->abts_scsi_io_bufs = 0; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1083 | qp->abts_nvme_io_bufs = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1084 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1085 | spin_unlock(&qp->abts_io_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1086 | } |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1087 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1088 | |
| 1089 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1090 | spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1091 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list, |
| 1092 | &nvmet_aborts); |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1093 | spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1094 | list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) { |
James Smart | 7b7f551 | 2020-03-31 09:50:04 -0700 | [diff] [blame] | 1095 | ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 1096 | lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1097 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1098 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1099 | |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1100 | lpfc_sli4_free_sp_events(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1101 | return cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | /** |
| 1105 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1106 | * @phba: pointer to lpfc HBA data structure. |
| 1107 | * |
| 1108 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1109 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1110 | * |
| 1111 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1112 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1113 | * Any other value - error. |
| 1114 | **/ |
| 1115 | int |
| 1116 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1117 | { |
| 1118 | return (*phba->lpfc_hba_down_post)(phba); |
| 1119 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1120 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1121 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1122 | * lpfc_hb_timeout - The HBA-timer timeout handler |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1123 | * @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] | 1124 | * |
| 1125 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1126 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1127 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1128 | * event will be used by the worker thread to invoke the actual timeout |
| 1129 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1130 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1131 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1132 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1133 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1134 | lpfc_hb_timeout(struct timer_list *t) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1135 | { |
| 1136 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1137 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1138 | unsigned long iflag; |
| 1139 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1140 | phba = from_timer(phba, t, hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1141 | |
| 1142 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1143 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1144 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1145 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1146 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1147 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1148 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1149 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1150 | if (!tmo_posted) |
| 1151 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1152 | return; |
| 1153 | } |
| 1154 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1155 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1156 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1157 | * @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] | 1158 | * |
| 1159 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1160 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1161 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1162 | * event will be used by the worker thread to invoke the actual timeout |
| 1163 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1164 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1165 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1166 | **/ |
| 1167 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1168 | lpfc_rrq_timeout(struct timer_list *t) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1169 | { |
| 1170 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1171 | unsigned long iflag; |
| 1172 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1173 | phba = from_timer(phba, t, rrq_tmr); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1174 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1175 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1176 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1177 | else |
| 1178 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1179 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1180 | |
| 1181 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1182 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1186 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1187 | * @phba: pointer to lpfc hba data structure. |
| 1188 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1189 | * |
| 1190 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1191 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1192 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1193 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1194 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1195 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1196 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1197 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1198 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1199 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1200 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1201 | static void |
| 1202 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1203 | { |
| 1204 | unsigned long drvr_flag; |
| 1205 | |
| 1206 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1207 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1208 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1209 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1210 | /* Check and reset heart-beat timer if necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1211 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1212 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1213 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1214 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1215 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1216 | jiffies + |
| 1217 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1218 | return; |
| 1219 | } |
| 1220 | |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1221 | /* |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 1222 | * lpfc_idle_stat_delay_work - idle_stat tracking |
| 1223 | * |
| 1224 | * This routine tracks per-cq idle_stat and determines polling decisions. |
| 1225 | * |
| 1226 | * Return codes: |
| 1227 | * None |
| 1228 | **/ |
| 1229 | static void |
| 1230 | lpfc_idle_stat_delay_work(struct work_struct *work) |
| 1231 | { |
| 1232 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1233 | struct lpfc_hba, |
| 1234 | idle_stat_delay_work); |
| 1235 | struct lpfc_queue *cq; |
| 1236 | struct lpfc_sli4_hdw_queue *hdwq; |
| 1237 | struct lpfc_idle_stat *idle_stat; |
| 1238 | u32 i, idle_percent; |
| 1239 | u64 wall, wall_idle, diff_wall, diff_idle, busy_time; |
| 1240 | |
| 1241 | if (phba->pport->load_flag & FC_UNLOADING) |
| 1242 | return; |
| 1243 | |
| 1244 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1245 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1246 | goto requeue; |
| 1247 | |
| 1248 | for_each_present_cpu(i) { |
| 1249 | hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq]; |
| 1250 | cq = hdwq->io_cq; |
| 1251 | |
| 1252 | /* Skip if we've already handled this cq's primary CPU */ |
| 1253 | if (cq->chann != i) |
| 1254 | continue; |
| 1255 | |
| 1256 | idle_stat = &phba->sli4_hba.idle_stat[i]; |
| 1257 | |
| 1258 | /* get_cpu_idle_time returns values as running counters. Thus, |
| 1259 | * to know the amount for this period, the prior counter values |
| 1260 | * need to be subtracted from the current counter values. |
| 1261 | * From there, the idle time stat can be calculated as a |
| 1262 | * percentage of 100 - the sum of the other consumption times. |
| 1263 | */ |
| 1264 | wall_idle = get_cpu_idle_time(i, &wall, 1); |
| 1265 | diff_idle = wall_idle - idle_stat->prev_idle; |
| 1266 | diff_wall = wall - idle_stat->prev_wall; |
| 1267 | |
| 1268 | if (diff_wall <= diff_idle) |
| 1269 | busy_time = 0; |
| 1270 | else |
| 1271 | busy_time = diff_wall - diff_idle; |
| 1272 | |
| 1273 | idle_percent = div64_u64(100 * busy_time, diff_wall); |
| 1274 | idle_percent = 100 - idle_percent; |
| 1275 | |
| 1276 | if (idle_percent < 15) |
| 1277 | cq->poll_mode = LPFC_QUEUE_WORK; |
| 1278 | else |
| 1279 | cq->poll_mode = LPFC_IRQ_POLL; |
| 1280 | |
| 1281 | idle_stat->prev_idle = wall_idle; |
| 1282 | idle_stat->prev_wall = wall; |
| 1283 | } |
| 1284 | |
| 1285 | requeue: |
| 1286 | schedule_delayed_work(&phba->idle_stat_delay_work, |
| 1287 | msecs_to_jiffies(LPFC_IDLE_STAT_DELAY)); |
| 1288 | } |
| 1289 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1290 | static void |
| 1291 | lpfc_hb_eq_delay_work(struct work_struct *work) |
| 1292 | { |
| 1293 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1294 | struct lpfc_hba, eq_delay_work); |
| 1295 | struct lpfc_eq_intr_info *eqi, *eqi_new; |
| 1296 | struct lpfc_queue *eq, *eq_next; |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1297 | unsigned char *ena_delay = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1298 | uint32_t usdelay; |
| 1299 | int i; |
| 1300 | |
| 1301 | if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING) |
| 1302 | return; |
| 1303 | |
| 1304 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1305 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1306 | goto requeue; |
| 1307 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1308 | ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay), |
| 1309 | GFP_KERNEL); |
| 1310 | if (!ena_delay) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1311 | goto requeue; |
| 1312 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1313 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 1314 | /* Get the EQ corresponding to the IRQ vector */ |
| 1315 | eq = phba->sli4_hba.hba_eq_hdl[i].eq; |
| 1316 | if (!eq) |
| 1317 | continue; |
| 1318 | if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) { |
| 1319 | eq->q_flag &= ~HBA_EQ_DELAY_CHK; |
| 1320 | ena_delay[eq->last_cpu] = 1; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame] | 1321 | } |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1322 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1323 | |
| 1324 | for_each_present_cpu(i) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1325 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i); |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1326 | if (ena_delay[i]) { |
| 1327 | usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP; |
| 1328 | if (usdelay > LPFC_MAX_AUTO_EQ_DELAY) |
| 1329 | usdelay = LPFC_MAX_AUTO_EQ_DELAY; |
| 1330 | } else { |
| 1331 | usdelay = 0; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame] | 1332 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1333 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1334 | eqi->icnt = 0; |
| 1335 | |
| 1336 | list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) { |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1337 | if (unlikely(eq->last_cpu != i)) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1338 | eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info, |
| 1339 | eq->last_cpu); |
| 1340 | list_move_tail(&eq->cpu_list, &eqi_new->list); |
| 1341 | continue; |
| 1342 | } |
| 1343 | if (usdelay != eq->q_mode) |
| 1344 | lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1, |
| 1345 | usdelay); |
| 1346 | } |
| 1347 | } |
| 1348 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1349 | kfree(ena_delay); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1350 | |
| 1351 | requeue: |
| 1352 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 1353 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 1354 | } |
| 1355 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1356 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1357 | * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution |
| 1358 | * @phba: pointer to lpfc hba data structure. |
| 1359 | * |
| 1360 | * For each heartbeat, this routine does some heuristic methods to adjust |
| 1361 | * XRI distribution. The goal is to fully utilize free XRIs. |
| 1362 | **/ |
| 1363 | static void lpfc_hb_mxp_handler(struct lpfc_hba *phba) |
| 1364 | { |
| 1365 | u32 i; |
| 1366 | u32 hwq_count; |
| 1367 | |
| 1368 | hwq_count = phba->cfg_hdw_queue; |
| 1369 | for (i = 0; i < hwq_count; i++) { |
| 1370 | /* Adjust XRIs in private pool */ |
| 1371 | lpfc_adjust_pvt_pool_count(phba, i); |
| 1372 | |
| 1373 | /* Adjust high watermark */ |
| 1374 | lpfc_adjust_high_watermark(phba, i); |
| 1375 | |
| 1376 | #ifdef LPFC_MXP_STAT |
| 1377 | /* Snapshot pbl, pvt and busy count */ |
| 1378 | lpfc_snapshot_mxp(phba, i); |
| 1379 | #endif |
| 1380 | } |
| 1381 | } |
| 1382 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1383 | /** |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1384 | * lpfc_issue_hb_mbox - Issues heart-beat mailbox command |
| 1385 | * @phba: pointer to lpfc hba data structure. |
| 1386 | * |
| 1387 | * If a HB mbox is not already in progrees, this routine will allocate |
| 1388 | * a LPFC_MBOXQ_t, populate it with a MBX_HEARTBEAT (0x31) command, |
| 1389 | * and issue it. The HBA_HBEAT_INP flag means the command is in progress. |
| 1390 | **/ |
| 1391 | int |
| 1392 | lpfc_issue_hb_mbox(struct lpfc_hba *phba) |
| 1393 | { |
| 1394 | LPFC_MBOXQ_t *pmboxq; |
| 1395 | int retval; |
| 1396 | |
| 1397 | /* Is a Heartbeat mbox already in progress */ |
| 1398 | if (phba->hba_flag & HBA_HBEAT_INP) |
| 1399 | return 0; |
| 1400 | |
| 1401 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1402 | if (!pmboxq) |
| 1403 | return -ENOMEM; |
| 1404 | |
| 1405 | lpfc_heart_beat(phba, pmboxq); |
| 1406 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1407 | pmboxq->vport = phba->pport; |
| 1408 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 1409 | |
| 1410 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { |
| 1411 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1412 | return -ENXIO; |
| 1413 | } |
| 1414 | phba->hba_flag |= HBA_HBEAT_INP; |
| 1415 | |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
| 1419 | /** |
| 1420 | * lpfc_issue_hb_tmo - Signals heartbeat timer to issue mbox command |
| 1421 | * @phba: pointer to lpfc hba data structure. |
| 1422 | * |
| 1423 | * The heartbeat timer (every 5 sec) will fire. If the HBA_HBEAT_TMO |
| 1424 | * flag is set, it will force a MBX_HEARTBEAT mbox command, regardless |
| 1425 | * of the value of lpfc_enable_hba_heartbeat. |
| 1426 | * If lpfc_enable_hba_heartbeat is set, the timeout routine will always |
| 1427 | * try to issue a MBX_HEARTBEAT mbox command. |
| 1428 | **/ |
| 1429 | void |
| 1430 | lpfc_issue_hb_tmo(struct lpfc_hba *phba) |
| 1431 | { |
| 1432 | if (phba->cfg_enable_hba_heartbeat) |
| 1433 | return; |
| 1434 | phba->hba_flag |= HBA_HBEAT_TMO; |
| 1435 | } |
| 1436 | |
| 1437 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1438 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1439 | * @phba: pointer to lpfc hba data structure. |
| 1440 | * |
| 1441 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1442 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1443 | * handler performs any periodic operations needed for the device. If such |
| 1444 | * periodic event has already been attended to either in the interrupt handler |
| 1445 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1446 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1447 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1448 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1449 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1450 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1451 | * to offline. |
| 1452 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1453 | void |
| 1454 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1455 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1456 | struct lpfc_vport **vports; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1457 | struct lpfc_dmabuf *buf_ptr; |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1458 | int retval = 0; |
| 1459 | int i, tmo; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1460 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1461 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1462 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1463 | if (phba->cfg_xri_rebalancing) { |
| 1464 | /* Multi-XRI pools handler */ |
| 1465 | lpfc_hb_mxp_handler(phba); |
| 1466 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1467 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1468 | vports = lpfc_create_vport_work_array(phba); |
| 1469 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1470 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1471 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | e3ba04c | 2019-12-18 15:58:02 -0800 | [diff] [blame] | 1472 | lpfc_fdmi_change_check(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1473 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1474 | lpfc_destroy_vport_work_array(phba, vports); |
| 1475 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1476 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1477 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1478 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1479 | return; |
| 1480 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1481 | if (phba->elsbuf_cnt && |
| 1482 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1483 | spin_lock_irq(&phba->hbalock); |
| 1484 | list_splice_init(&phba->elsbuf, &completions); |
| 1485 | phba->elsbuf_cnt = 0; |
| 1486 | phba->elsbuf_prev_cnt = 0; |
| 1487 | spin_unlock_irq(&phba->hbalock); |
| 1488 | |
| 1489 | while (!list_empty(&completions)) { |
| 1490 | list_remove_head(&completions, buf_ptr, |
| 1491 | struct lpfc_dmabuf, list); |
| 1492 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1493 | kfree(buf_ptr); |
| 1494 | } |
| 1495 | } |
| 1496 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1497 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1498 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1499 | if (phba->cfg_enable_hba_heartbeat) { |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1500 | /* If IOs are completing, no need to issue a MBX_HEARTBEAT */ |
| 1501 | spin_lock_irq(&phba->pport->work_port_lock); |
| 1502 | if (time_after(phba->last_completion_time + |
| 1503 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1504 | jiffies)) { |
| 1505 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1506 | if (phba->hba_flag & HBA_HBEAT_INP) |
| 1507 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1508 | else |
| 1509 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
| 1510 | goto out; |
| 1511 | } |
| 1512 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1513 | |
| 1514 | /* Check if a MBX_HEARTBEAT is already in progress */ |
| 1515 | if (phba->hba_flag & HBA_HBEAT_INP) { |
| 1516 | /* |
| 1517 | * If heart beat timeout called with HBA_HBEAT_INP set |
| 1518 | * we need to give the hb mailbox cmd a chance to |
| 1519 | * complete or TMO. |
| 1520 | */ |
| 1521 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1522 | "0459 Adapter heartbeat still outstanding: " |
| 1523 | "last compl time was %d ms.\n", |
| 1524 | jiffies_to_msecs(jiffies |
| 1525 | - phba->last_completion_time)); |
| 1526 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1527 | } else { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1528 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1529 | (list_empty(&psli->mboxq))) { |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1530 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1531 | retval = lpfc_issue_hb_mbox(phba); |
| 1532 | if (retval) { |
| 1533 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
| 1534 | goto out; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1535 | } |
| 1536 | phba->skipped_hb = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1537 | } else if (time_before_eq(phba->last_completion_time, |
| 1538 | phba->skipped_hb)) { |
| 1539 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1540 | "2857 Last completion time not " |
| 1541 | " updated in %d ms\n", |
| 1542 | jiffies_to_msecs(jiffies |
| 1543 | - phba->last_completion_time)); |
| 1544 | } else |
| 1545 | phba->skipped_hb = jiffies; |
| 1546 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1547 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1548 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1549 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1550 | } else { |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1551 | /* Check to see if we want to force a MBX_HEARTBEAT */ |
| 1552 | if (phba->hba_flag & HBA_HBEAT_TMO) { |
| 1553 | retval = lpfc_issue_hb_mbox(phba); |
| 1554 | if (retval) |
| 1555 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
| 1556 | else |
| 1557 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1558 | goto out; |
| 1559 | } |
| 1560 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1561 | } |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1562 | out: |
| 1563 | mod_timer(&phba->hb_tmofunc, jiffies + msecs_to_jiffies(tmo)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1564 | } |
| 1565 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1566 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1567 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1568 | * @phba: pointer to lpfc hba data structure. |
| 1569 | * |
| 1570 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1571 | * other than Port Error 6 has been detected. |
| 1572 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1573 | static void |
| 1574 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1575 | { |
| 1576 | struct lpfc_sli *psli = &phba->sli; |
| 1577 | |
| 1578 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1579 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1580 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1581 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1582 | |
| 1583 | lpfc_offline(phba); |
| 1584 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1585 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1586 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1587 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1588 | lpfc_hba_down_post(phba); |
| 1589 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1590 | lpfc_unblock_mgmt_io(phba); |
| 1591 | phba->link_state = LPFC_HBA_ERROR; |
| 1592 | return; |
| 1593 | } |
| 1594 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1595 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1596 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1597 | * @phba: pointer to lpfc hba data structure. |
| 1598 | * |
| 1599 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1600 | * other than Port Error 6 has been detected. |
| 1601 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1602 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1603 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1604 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1605 | spin_lock_irq(&phba->hbalock); |
| 1606 | phba->link_state = LPFC_HBA_ERROR; |
| 1607 | spin_unlock_irq(&phba->hbalock); |
| 1608 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1609 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1610 | lpfc_sli_flush_io_rings(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1611 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1612 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1613 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1617 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1618 | * @phba: pointer to lpfc hba data structure. |
| 1619 | * |
| 1620 | * This routine is invoked to handle the deferred HBA hardware error |
| 1621 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1622 | * and another ER bit in the host status register. The driver will |
| 1623 | * wait until the ER1 bit clears before handling the error condition. |
| 1624 | **/ |
| 1625 | static void |
| 1626 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1627 | { |
| 1628 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1629 | struct lpfc_sli *psli = &phba->sli; |
| 1630 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1631 | /* If the pci channel is offline, ignore possible errors, |
| 1632 | * since we cannot communicate with the pci card anyway. |
| 1633 | */ |
| 1634 | if (pci_channel_offline(phba->pcidev)) { |
| 1635 | spin_lock_irq(&phba->hbalock); |
| 1636 | phba->hba_flag &= ~DEFER_ERATT; |
| 1637 | spin_unlock_irq(&phba->hbalock); |
| 1638 | return; |
| 1639 | } |
| 1640 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1641 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 1642 | "0479 Deferred Adapter Hardware Error " |
| 1643 | "Data: x%x x%x x%x\n", |
| 1644 | phba->work_hs, phba->work_status[0], |
| 1645 | phba->work_status[1]); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1646 | |
| 1647 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1648 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1649 | spin_unlock_irq(&phba->hbalock); |
| 1650 | |
| 1651 | |
| 1652 | /* |
| 1653 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1654 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1655 | * SCSI layer retry it after re-establishing link. |
| 1656 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1657 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1658 | |
| 1659 | /* |
| 1660 | * There was a firmware error. Take the hba offline and then |
| 1661 | * attempt to restart it. |
| 1662 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1663 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1664 | lpfc_offline(phba); |
| 1665 | |
| 1666 | /* Wait for the ER1 bit to clear.*/ |
| 1667 | while (phba->work_hs & HS_FFER1) { |
| 1668 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1669 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1670 | phba->work_hs = UNPLUG_ERR ; |
| 1671 | break; |
| 1672 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1673 | /* If driver is unloading let the worker thread continue */ |
| 1674 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1675 | phba->work_hs = 0; |
| 1676 | break; |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | /* |
| 1681 | * This is to ptrotect against a race condition in which |
| 1682 | * first write to the host attention register clear the |
| 1683 | * host status register. |
| 1684 | */ |
| 1685 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1686 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1687 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1688 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1689 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1690 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1691 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1692 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1693 | } |
| 1694 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1695 | static void |
| 1696 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1697 | { |
| 1698 | struct lpfc_board_event_header board_event; |
| 1699 | struct Scsi_Host *shost; |
| 1700 | |
| 1701 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1702 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1703 | shost = lpfc_shost_from_vport(phba->pport); |
| 1704 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1705 | sizeof(board_event), |
| 1706 | (char *) &board_event, |
| 1707 | LPFC_NL_VENDOR_ID); |
| 1708 | } |
| 1709 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1710 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1711 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1712 | * @phba: pointer to lpfc hba data structure. |
| 1713 | * |
| 1714 | * This routine is invoked to handle the following HBA hardware error |
| 1715 | * conditions: |
| 1716 | * 1 - HBA error attention interrupt |
| 1717 | * 2 - DMA ring index out of range |
| 1718 | * 3 - Mailbox command came back as unknown |
| 1719 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1720 | static void |
| 1721 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1722 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1723 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1724 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1725 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1726 | unsigned long temperature; |
| 1727 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1728 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1729 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1730 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1731 | * since we cannot communicate with the pci card anyway. |
| 1732 | */ |
| 1733 | if (pci_channel_offline(phba->pcidev)) { |
| 1734 | spin_lock_irq(&phba->hbalock); |
| 1735 | phba->hba_flag &= ~DEFER_ERATT; |
| 1736 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1737 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1738 | } |
| 1739 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1740 | /* If resets are disabled then leave the HBA alone and return */ |
| 1741 | if (!phba->cfg_enable_hba_reset) |
| 1742 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1743 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1744 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1745 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1746 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1747 | if (phba->hba_flag & DEFER_ERATT) |
| 1748 | lpfc_handle_deferred_eratt(phba); |
| 1749 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1750 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1751 | if (phba->work_hs & HS_FFER6) |
| 1752 | /* Re-establishing Link */ |
| 1753 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1754 | "1301 Re-establishing Link " |
| 1755 | "Data: x%x x%x x%x\n", |
| 1756 | phba->work_hs, phba->work_status[0], |
| 1757 | phba->work_status[1]); |
| 1758 | if (phba->work_hs & HS_FFER8) |
| 1759 | /* Device Zeroization */ |
| 1760 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1761 | "2861 Host Authentication device " |
| 1762 | "zeroization Data:x%x x%x x%x\n", |
| 1763 | phba->work_hs, phba->work_status[0], |
| 1764 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1765 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1766 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1767 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1768 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1769 | |
| 1770 | /* |
| 1771 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1772 | * That could cause the I/Os dropped by the firmware. |
| 1773 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1774 | * retry it after re-establishing link. |
| 1775 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1776 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1777 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1778 | /* |
| 1779 | * There was a firmware error. Take the hba offline and then |
| 1780 | * attempt to restart it. |
| 1781 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1782 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1783 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1784 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1785 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1786 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1787 | return; |
| 1788 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1789 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1790 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1791 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1792 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1793 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1794 | temp_event_data.data = (uint32_t)temperature; |
| 1795 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1796 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1797 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1798 | "(%ld), taking this port offline " |
| 1799 | "Data: x%x x%x x%x\n", |
| 1800 | temperature, phba->work_hs, |
| 1801 | phba->work_status[0], phba->work_status[1]); |
| 1802 | |
| 1803 | shost = lpfc_shost_from_vport(phba->pport); |
| 1804 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1805 | sizeof(temp_event_data), |
| 1806 | (char *) &temp_event_data, |
| 1807 | SCSI_NL_VID_TYPE_PCI |
| 1808 | | PCI_VENDOR_ID_EMULEX); |
| 1809 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1810 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1811 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1812 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1813 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1814 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1815 | } else { |
| 1816 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1817 | * failure is a value other than FFER6. Do not call the offline |
| 1818 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1819 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1820 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1821 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1822 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1823 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1824 | phba->work_status[0], phba->work_status[1]); |
| 1825 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1826 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1827 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1828 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1829 | sizeof(event_data), (char *) &event_data, |
| 1830 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1831 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1832 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1833 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1834 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1835 | } |
| 1836 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1837 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1838 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1839 | * @phba: pointer to lpfc hba data structure. |
| 1840 | * @mbx_action: flag for mailbox shutdown action. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1841 | * @en_rn_msg: send reset/port recovery message. |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1842 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1843 | * response to port status register polling attention. It waits for port |
| 1844 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1845 | * During this process, interrupt vectors are freed and later requested |
| 1846 | * for handling possible port resource change. |
| 1847 | **/ |
| 1848 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1849 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1850 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1851 | { |
| 1852 | int rc; |
| 1853 | uint32_t intr_mode; |
| 1854 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1855 | 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] | 1856 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1857 | /* |
| 1858 | * On error status condition, driver need to wait for port |
| 1859 | * ready before performing reset. |
| 1860 | */ |
| 1861 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1862 | if (rc) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1863 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1864 | } |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1865 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1866 | /* need reset: attempt for port recovery */ |
| 1867 | if (en_rn_msg) |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 1868 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1869 | "2887 Reset Needed: Attempting Port " |
| 1870 | "Recovery...\n"); |
James Smart | 3ba6216 | 2021-01-04 10:02:31 -0800 | [diff] [blame] | 1871 | |
| 1872 | /* If we are no wait, the HBA has been reset and is not |
| 1873 | * functional, thus we should clear LPFC_SLI_ACTIVE flag. |
| 1874 | */ |
| 1875 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 1876 | spin_lock_irq(&phba->hbalock); |
| 1877 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
| 1878 | spin_unlock_irq(&phba->hbalock); |
| 1879 | } |
| 1880 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1881 | lpfc_offline_prep(phba, mbx_action); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1882 | lpfc_sli_flush_io_rings(phba); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1883 | lpfc_offline(phba); |
| 1884 | /* release interrupt for possible resource change */ |
| 1885 | lpfc_sli4_disable_intr(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1886 | rc = lpfc_sli_brdrestart(phba); |
| 1887 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1888 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1889 | "6309 Failed to restart board\n"); |
| 1890 | return rc; |
| 1891 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1892 | /* request and enable interrupt */ |
| 1893 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1894 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1895 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1896 | "3175 Failed to enable interrupt\n"); |
| 1897 | return -EIO; |
| 1898 | } |
| 1899 | phba->intr_mode = intr_mode; |
| 1900 | rc = lpfc_online(phba); |
| 1901 | if (rc == 0) |
| 1902 | lpfc_unblock_mgmt_io(phba); |
| 1903 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1904 | return rc; |
| 1905 | } |
| 1906 | |
| 1907 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1908 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1909 | * @phba: pointer to lpfc hba data structure. |
| 1910 | * |
| 1911 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1912 | * conditions. |
| 1913 | **/ |
| 1914 | static void |
| 1915 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1916 | { |
| 1917 | struct lpfc_vport *vport = phba->pport; |
| 1918 | uint32_t event_data; |
| 1919 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1920 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1921 | struct lpfc_register portstat_reg = {0}; |
| 1922 | uint32_t reg_err1, reg_err2; |
| 1923 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1924 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1925 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1926 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1927 | struct lpfc_register portsmphr_reg; |
| 1928 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1929 | |
| 1930 | /* If the pci channel is offline, ignore possible errors, since |
| 1931 | * we cannot communicate with the pci card anyway. |
| 1932 | */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1933 | if (pci_channel_offline(phba->pcidev)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1934 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1935 | "3166 pci channel is offline\n"); |
| 1936 | lpfc_sli4_offline_eratt(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1937 | return; |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1938 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1939 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1940 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1941 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1942 | switch (if_type) { |
| 1943 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1944 | pci_rd_rc1 = lpfc_readl( |
| 1945 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1946 | &uerrlo_reg); |
| 1947 | pci_rd_rc2 = lpfc_readl( |
| 1948 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1949 | &uemasklo_reg); |
| 1950 | /* consider PCI bus read error as pci_channel_offline */ |
| 1951 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1952 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1953 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1954 | lpfc_sli4_offline_eratt(phba); |
| 1955 | return; |
| 1956 | } |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1957 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1958 | "7623 Checking UE recoverable"); |
| 1959 | |
| 1960 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1961 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1962 | &portsmphr_reg.word0)) |
| 1963 | continue; |
| 1964 | |
| 1965 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1966 | &portsmphr_reg); |
| 1967 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1968 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1969 | break; |
| 1970 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1971 | msleep(1000); |
| 1972 | } |
| 1973 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1974 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1975 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1976 | smphr_port_status, i); |
| 1977 | |
| 1978 | /* Recoverable UE, reset the HBA device */ |
| 1979 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1980 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1981 | for (i = 0; i < 20; i++) { |
| 1982 | msleep(1000); |
| 1983 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1984 | &portsmphr_reg.word0) && |
| 1985 | (LPFC_POST_STAGE_PORT_READY == |
| 1986 | bf_get(lpfc_port_smphr_port_status, |
| 1987 | &portsmphr_reg))) { |
| 1988 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 1989 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 1990 | if (rc == 0) |
| 1991 | return; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1992 | lpfc_printf_log(phba, KERN_ERR, |
| 1993 | LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1994 | "4215 Failed to recover UE"); |
| 1995 | break; |
| 1996 | } |
| 1997 | } |
| 1998 | } |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1999 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 2000 | "7624 Firmware not ready: Failing UE recovery," |
| 2001 | " waited %dSec", i); |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 2002 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2003 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2004 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2005 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2006 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2007 | pci_rd_rc1 = lpfc_readl( |
| 2008 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 2009 | &portstat_reg.word0); |
| 2010 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2011 | if (pci_rd_rc1 == -EIO) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2012 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2013 | "3151 PCI bus read access failure: x%x\n", |
| 2014 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 2015 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2016 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2017 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2018 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 2019 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2020 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2021 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 2022 | "2889 Port Overtemperature event, " |
| 2023 | "taking port offline Data: x%x x%x\n", |
| 2024 | reg_err1, reg_err2); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2025 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 2026 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2027 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 2028 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 2029 | temp_event_data.data = 0xFFFFFFFF; |
| 2030 | |
| 2031 | shost = lpfc_shost_from_vport(phba->pport); |
| 2032 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2033 | sizeof(temp_event_data), |
| 2034 | (char *)&temp_event_data, |
| 2035 | SCSI_NL_VID_TYPE_PCI |
| 2036 | | PCI_VENDOR_ID_EMULEX); |
| 2037 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2038 | spin_lock_irq(&phba->hbalock); |
| 2039 | phba->over_temp_state = HBA_OVER_TEMP; |
| 2040 | spin_unlock_irq(&phba->hbalock); |
| 2041 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2042 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2043 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2044 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2045 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2046 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2047 | "3143 Port Down: Firmware Update " |
| 2048 | "Detected\n"); |
| 2049 | en_rn_msg = false; |
| 2050 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2051 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2052 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2053 | "3144 Port Down: Debug Dump\n"); |
| 2054 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 2055 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2056 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2057 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2058 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2059 | /* If resets are disabled then leave the HBA alone and return */ |
| 2060 | if (!phba->cfg_enable_hba_reset) |
| 2061 | return; |
| 2062 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2063 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2064 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 2065 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2066 | if (rc == 0) { |
| 2067 | /* don't report event on forced debug dump */ |
| 2068 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 2069 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 2070 | return; |
| 2071 | else |
| 2072 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2073 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2074 | /* fall through for not able to recover */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2075 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 2076 | "3152 Unrecoverable error\n"); |
| 2077 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2078 | break; |
| 2079 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 2080 | default: |
| 2081 | break; |
| 2082 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2083 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2084 | "3123 Report dump event to upper layer\n"); |
| 2085 | /* Send an internal error event to mgmt application */ |
| 2086 | lpfc_board_errevt_to_mgmt(phba); |
| 2087 | |
| 2088 | event_data = FC_REG_DUMP_EVENT; |
| 2089 | shost = lpfc_shost_from_vport(vport); |
| 2090 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2091 | sizeof(event_data), (char *) &event_data, |
| 2092 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | /** |
| 2096 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 2097 | * @phba: pointer to lpfc HBA data structure. |
| 2098 | * |
| 2099 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 2100 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 2101 | * |
| 2102 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2103 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2104 | * Any other value - error. |
| 2105 | **/ |
| 2106 | void |
| 2107 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 2108 | { |
| 2109 | (*phba->lpfc_handle_eratt)(phba); |
| 2110 | } |
| 2111 | |
| 2112 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2113 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2114 | * @phba: pointer to lpfc hba data structure. |
| 2115 | * |
| 2116 | * 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] | 2117 | * attention link event. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2118 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2120 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2121 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2122 | struct lpfc_vport *vport = phba->pport; |
| 2123 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2124 | LPFC_MBOXQ_t *pmb; |
| 2125 | volatile uint32_t control; |
| 2126 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2127 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | |
| 2129 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2130 | if (!pmb) { |
| 2131 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2132 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2133 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2134 | |
| 2135 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2136 | if (!mp) { |
| 2137 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2138 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2139 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | |
| 2141 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2142 | if (!mp->virt) { |
| 2143 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2145 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2146 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 2147 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2148 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2149 | |
| 2150 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2151 | lpfc_read_topology(phba, pmb, mp); |
| 2152 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2153 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2154 | /* Block ELS IOCBs until we have processed this mbox command */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2155 | phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2156 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2157 | if (rc == MBX_NOT_FINISHED) { |
| 2158 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2159 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2160 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2161 | |
| 2162 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2163 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2164 | writel(HA_LATT, phba->HAregaddr); |
| 2165 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2166 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2167 | |
| 2168 | return; |
| 2169 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2170 | lpfc_handle_latt_free_mbuf: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2171 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2172 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2173 | lpfc_handle_latt_free_mp: |
| 2174 | kfree(mp); |
| 2175 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2176 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | lpfc_handle_latt_err_exit: |
| 2178 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2179 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2180 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 2181 | control = readl(phba->HCregaddr); |
| 2182 | control |= HC_LAINT_ENA; |
| 2183 | writel(control, phba->HCregaddr); |
| 2184 | readl(phba->HCregaddr); /* flush */ |
| 2185 | |
| 2186 | /* Clear Link Attention in HA REG */ |
| 2187 | writel(HA_LATT, phba->HAregaddr); |
| 2188 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2189 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2190 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2191 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2192 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2193 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 2194 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2195 | |
| 2196 | return; |
| 2197 | } |
| 2198 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2199 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2200 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2201 | * @phba: pointer to lpfc hba data structure. |
| 2202 | * @vpd: pointer to the vital product data. |
| 2203 | * @len: length of the vital product data in bytes. |
| 2204 | * |
| 2205 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 2206 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 2207 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 2208 | * |
| 2209 | * Return codes |
| 2210 | * 0 - pointer to the VPD passed in is NULL |
| 2211 | * 1 - success |
| 2212 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2213 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2214 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2215 | { |
| 2216 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 2217 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2218 | int i, j; |
| 2219 | int finished = 0; |
| 2220 | int index = 0; |
| 2221 | |
| 2222 | if (!vpd) |
| 2223 | return 0; |
| 2224 | |
| 2225 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2226 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2227 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2228 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 2229 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2230 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | switch (vpd[index]) { |
| 2232 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2233 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2234 | index += 1; |
| 2235 | lenlo = vpd[index]; |
| 2236 | index += 1; |
| 2237 | lenhi = vpd[index]; |
| 2238 | index += 1; |
| 2239 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 2240 | index += i; |
| 2241 | break; |
| 2242 | case 0x90: |
| 2243 | index += 1; |
| 2244 | lenlo = vpd[index]; |
| 2245 | index += 1; |
| 2246 | lenhi = vpd[index]; |
| 2247 | index += 1; |
| 2248 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2249 | if (Length > len - index) |
| 2250 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2251 | while (Length > 0) { |
| 2252 | /* Look for Serial Number */ |
| 2253 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 2254 | index += 2; |
| 2255 | i = vpd[index]; |
| 2256 | index += 1; |
| 2257 | j = 0; |
| 2258 | Length -= (3+i); |
| 2259 | while(i--) { |
| 2260 | phba->SerialNumber[j++] = vpd[index++]; |
| 2261 | if (j == 31) |
| 2262 | break; |
| 2263 | } |
| 2264 | phba->SerialNumber[j] = 0; |
| 2265 | continue; |
| 2266 | } |
| 2267 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 2268 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 2269 | index += 2; |
| 2270 | i = vpd[index]; |
| 2271 | index += 1; |
| 2272 | j = 0; |
| 2273 | Length -= (3+i); |
| 2274 | while(i--) { |
| 2275 | phba->ModelDesc[j++] = vpd[index++]; |
| 2276 | if (j == 255) |
| 2277 | break; |
| 2278 | } |
| 2279 | phba->ModelDesc[j] = 0; |
| 2280 | continue; |
| 2281 | } |
| 2282 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 2283 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 2284 | index += 2; |
| 2285 | i = vpd[index]; |
| 2286 | index += 1; |
| 2287 | j = 0; |
| 2288 | Length -= (3+i); |
| 2289 | while(i--) { |
| 2290 | phba->ModelName[j++] = vpd[index++]; |
| 2291 | if (j == 79) |
| 2292 | break; |
| 2293 | } |
| 2294 | phba->ModelName[j] = 0; |
| 2295 | continue; |
| 2296 | } |
| 2297 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2298 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2299 | index += 2; |
| 2300 | i = vpd[index]; |
| 2301 | index += 1; |
| 2302 | j = 0; |
| 2303 | Length -= (3+i); |
| 2304 | while(i--) { |
| 2305 | phba->ProgramType[j++] = vpd[index++]; |
| 2306 | if (j == 255) |
| 2307 | break; |
| 2308 | } |
| 2309 | phba->ProgramType[j] = 0; |
| 2310 | continue; |
| 2311 | } |
| 2312 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2313 | phba->vpd_flag |= VPD_PORT; |
| 2314 | index += 2; |
| 2315 | i = vpd[index]; |
| 2316 | index += 1; |
| 2317 | j = 0; |
| 2318 | Length -= (3+i); |
| 2319 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2320 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2321 | (phba->sli4_hba.pport_name_sta == |
| 2322 | LPFC_SLI4_PPNAME_GET)) { |
| 2323 | j++; |
| 2324 | index++; |
| 2325 | } else |
| 2326 | phba->Port[j++] = vpd[index++]; |
| 2327 | if (j == 19) |
| 2328 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2329 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2330 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 2331 | (phba->sli4_hba.pport_name_sta == |
| 2332 | LPFC_SLI4_PPNAME_NON)) |
| 2333 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2334 | continue; |
| 2335 | } |
| 2336 | else { |
| 2337 | index += 2; |
| 2338 | i = vpd[index]; |
| 2339 | index += 1; |
| 2340 | index += i; |
| 2341 | Length -= (3 + i); |
| 2342 | } |
| 2343 | } |
| 2344 | finished = 0; |
| 2345 | break; |
| 2346 | case 0x78: |
| 2347 | finished = 1; |
| 2348 | break; |
| 2349 | default: |
| 2350 | index ++; |
| 2351 | break; |
| 2352 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2353 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2354 | |
| 2355 | return(1); |
| 2356 | } |
| 2357 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2358 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2359 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2360 | * @phba: pointer to lpfc hba data structure. |
| 2361 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2362 | * @descp: pointer to the data structure to hold the derived description. |
| 2363 | * |
| 2364 | * This routine retrieves HBA's description based on its registered PCI device |
| 2365 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2366 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2367 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2368 | * function returns, the @mdp will be filled with the model name. |
| 2369 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2370 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2371 | 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] | 2372 | { |
| 2373 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2374 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2375 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2376 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2377 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2378 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2379 | char *name; |
| 2380 | char *bus; |
| 2381 | char *function; |
| 2382 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2383 | |
| 2384 | if (mdp && mdp[0] != '\0' |
| 2385 | && descp && descp[0] != '\0') |
| 2386 | return; |
| 2387 | |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 2388 | if (phba->lmt & LMT_64Gb) |
| 2389 | max_speed = 64; |
| 2390 | else if (phba->lmt & LMT_32Gb) |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2391 | max_speed = 32; |
| 2392 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2393 | max_speed = 16; |
| 2394 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2395 | max_speed = 10; |
| 2396 | else if (phba->lmt & LMT_8Gb) |
| 2397 | max_speed = 8; |
| 2398 | else if (phba->lmt & LMT_4Gb) |
| 2399 | max_speed = 4; |
| 2400 | else if (phba->lmt & LMT_2Gb) |
| 2401 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2402 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2403 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2404 | else |
| 2405 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | |
| 2407 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2409 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2410 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2411 | m = (typeof(m)){"LP6000", "PCI", |
| 2412 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2413 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | case PCI_DEVICE_ID_SUPERFLY: |
| 2415 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2416 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2417 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2418 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2419 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2420 | break; |
| 2421 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2422 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2423 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | break; |
| 2425 | case PCI_DEVICE_ID_CENTAUR: |
| 2426 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2427 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2428 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2429 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2430 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2431 | break; |
| 2432 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2433 | m = (typeof(m)){"LP952", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2434 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | break; |
| 2436 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2437 | m = (typeof(m)){"LP9802", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2438 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2439 | break; |
| 2440 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2441 | m = (typeof(m)){"LP10000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2442 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2443 | break; |
| 2444 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2445 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2446 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | break; |
| 2448 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2449 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2450 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2451 | break; |
| 2452 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2453 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2454 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2455 | break; |
| 2456 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2457 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2458 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2459 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2460 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2461 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2462 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2463 | break; |
| 2464 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2465 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2466 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2467 | break; |
| 2468 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2469 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2470 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2471 | break; |
| 2472 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2473 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2474 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2475 | break; |
| 2476 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2477 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2478 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2479 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2480 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2481 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2482 | break; |
| 2483 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2484 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2485 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2486 | break; |
| 2487 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2488 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2489 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2490 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2491 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2492 | break; |
| 2493 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2494 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2495 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2496 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2497 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2498 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | break; |
| 2500 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2501 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | break; |
| 2503 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2504 | m = (typeof(m)){"LP101", "PCI-X", |
| 2505 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2506 | break; |
| 2507 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2508 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2509 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2510 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2511 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2512 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2513 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2514 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2515 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2516 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2517 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2518 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2519 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2520 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2521 | break; |
| 2522 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2523 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2524 | break; |
| 2525 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2526 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2527 | break; |
| 2528 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2529 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2530 | break; |
| 2531 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2532 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2533 | break; |
| 2534 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2535 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2536 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2537 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2538 | m = (typeof(m)){"LP21000", "PCIe", |
| 2539 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2540 | GE = 1; |
| 2541 | break; |
| 2542 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2543 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2544 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2545 | break; |
| 2546 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2547 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2548 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2549 | break; |
| 2550 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2551 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2552 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2553 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2554 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2555 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2556 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2557 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2558 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2559 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2560 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2561 | break; |
| 2562 | case PCI_DEVICE_ID_FALCON: |
| 2563 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2564 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2565 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2566 | case PCI_DEVICE_ID_BALIUS: |
| 2567 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2568 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2569 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2570 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2571 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2572 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2573 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2574 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2575 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2576 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2577 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2578 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2579 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2580 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2581 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2582 | oneConnect = 1; |
| 2583 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2584 | "Obsolete, Unsupported FCoE"}; |
| 2585 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2586 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2587 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2588 | break; |
James Smart | c238b9b | 2018-02-22 08:18:44 -0800 | [diff] [blame] | 2589 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 2590 | m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"}; |
| 2591 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2592 | case PCI_DEVICE_ID_SKYHAWK: |
| 2593 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2594 | oneConnect = 1; |
| 2595 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2596 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2597 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2598 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2599 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2600 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2601 | |
| 2602 | if (mdp && mdp[0] == '\0') |
| 2603 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2604 | /* |
| 2605 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2606 | * and we put the port number on the end |
| 2607 | */ |
| 2608 | if (descp && descp[0] == '\0') { |
| 2609 | if (oneConnect) |
| 2610 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2611 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2612 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2613 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2614 | else if (max_speed == 0) |
| 2615 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2616 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2617 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2618 | else |
| 2619 | snprintf(descp, 255, |
| 2620 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2621 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2622 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2623 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2624 | } |
| 2625 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2626 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2627 | * 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] | 2628 | * @phba: pointer to lpfc hba data structure. |
| 2629 | * @pring: pointer to a IOCB ring. |
| 2630 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2631 | * |
| 2632 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2633 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2634 | * |
| 2635 | * Return codes |
| 2636 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2637 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2638 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2639 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2640 | { |
| 2641 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2642 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | struct lpfc_dmabuf *mp1, *mp2; |
| 2644 | |
| 2645 | cnt += pring->missbufcnt; |
| 2646 | |
| 2647 | /* While there are buffers to post */ |
| 2648 | while (cnt > 0) { |
| 2649 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2650 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2651 | if (iocb == NULL) { |
| 2652 | pring->missbufcnt = cnt; |
| 2653 | return cnt; |
| 2654 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2655 | icmd = &iocb->iocb; |
| 2656 | |
| 2657 | /* 2 buffers can be posted per command */ |
| 2658 | /* Allocate buffer to post */ |
| 2659 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2660 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2661 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2662 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2663 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2664 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2665 | pring->missbufcnt = cnt; |
| 2666 | return cnt; |
| 2667 | } |
| 2668 | |
| 2669 | INIT_LIST_HEAD(&mp1->list); |
| 2670 | /* Allocate buffer to post */ |
| 2671 | if (cnt > 1) { |
| 2672 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2673 | if (mp2) |
| 2674 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2675 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2676 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2677 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2679 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2680 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2681 | pring->missbufcnt = cnt; |
| 2682 | return cnt; |
| 2683 | } |
| 2684 | |
| 2685 | INIT_LIST_HEAD(&mp2->list); |
| 2686 | } else { |
| 2687 | mp2 = NULL; |
| 2688 | } |
| 2689 | |
| 2690 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2691 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2692 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2693 | icmd->ulpBdeCount = 1; |
| 2694 | cnt--; |
| 2695 | if (mp2) { |
| 2696 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2697 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2698 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2699 | cnt--; |
| 2700 | icmd->ulpBdeCount = 2; |
| 2701 | } |
| 2702 | |
| 2703 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2704 | icmd->ulpLe = 1; |
| 2705 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2706 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2707 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2708 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2709 | kfree(mp1); |
| 2710 | cnt++; |
| 2711 | if (mp2) { |
| 2712 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2713 | kfree(mp2); |
| 2714 | cnt++; |
| 2715 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2716 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2717 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2718 | return cnt; |
| 2719 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2720 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2721 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2722 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2723 | } |
| 2724 | pring->missbufcnt = 0; |
| 2725 | return 0; |
| 2726 | } |
| 2727 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2728 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2729 | * 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] | 2730 | * @phba: pointer to lpfc hba data structure. |
| 2731 | * |
| 2732 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2733 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2734 | * set to 64 IOCBs. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2735 | * |
| 2736 | * Return codes |
| 2737 | * 0 - success (currently always success) |
| 2738 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2740 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | { |
| 2742 | struct lpfc_sli *psli = &phba->sli; |
| 2743 | |
| 2744 | /* Ring 0, ELS / CT buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2745 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2746 | /* Ring 2 - FCP no buffers needed */ |
| 2747 | |
| 2748 | return 0; |
| 2749 | } |
| 2750 | |
| 2751 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2752 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2753 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2754 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2755 | * @HashResultPointer: pointer to an array as hash table. |
| 2756 | * |
| 2757 | * This routine sets up the initial values to the array of hash table entries |
| 2758 | * for the LC HBAs. |
| 2759 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | static void |
| 2761 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2762 | { |
| 2763 | HashResultPointer[0] = 0x67452301; |
| 2764 | HashResultPointer[1] = 0xEFCDAB89; |
| 2765 | HashResultPointer[2] = 0x98BADCFE; |
| 2766 | HashResultPointer[3] = 0x10325476; |
| 2767 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2768 | } |
| 2769 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2770 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2771 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2772 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2773 | * @HashWorkingPointer: pointer to an working hash table. |
| 2774 | * |
| 2775 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2776 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2777 | * The results are putting back to the initial hash table, returned through |
| 2778 | * the @HashResultPointer as the result hash table. |
| 2779 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2780 | static void |
| 2781 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2782 | { |
| 2783 | int t; |
| 2784 | uint32_t TEMP; |
| 2785 | uint32_t A, B, C, D, E; |
| 2786 | t = 16; |
| 2787 | do { |
| 2788 | HashWorkingPointer[t] = |
| 2789 | S(1, |
| 2790 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2791 | 8] ^ |
| 2792 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2793 | } while (++t <= 79); |
| 2794 | t = 0; |
| 2795 | A = HashResultPointer[0]; |
| 2796 | B = HashResultPointer[1]; |
| 2797 | C = HashResultPointer[2]; |
| 2798 | D = HashResultPointer[3]; |
| 2799 | E = HashResultPointer[4]; |
| 2800 | |
| 2801 | do { |
| 2802 | if (t < 20) { |
| 2803 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2804 | } else if (t < 40) { |
| 2805 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2806 | } else if (t < 60) { |
| 2807 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2808 | } else { |
| 2809 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2810 | } |
| 2811 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2812 | E = D; |
| 2813 | D = C; |
| 2814 | C = S(30, B); |
| 2815 | B = A; |
| 2816 | A = TEMP; |
| 2817 | } while (++t <= 79); |
| 2818 | |
| 2819 | HashResultPointer[0] += A; |
| 2820 | HashResultPointer[1] += B; |
| 2821 | HashResultPointer[2] += C; |
| 2822 | HashResultPointer[3] += D; |
| 2823 | HashResultPointer[4] += E; |
| 2824 | |
| 2825 | } |
| 2826 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2827 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2828 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2829 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2830 | * @HashWorking: pointer to the entry of the working hash array. |
| 2831 | * |
| 2832 | * This routine calculates the working hash array referred by @HashWorking |
| 2833 | * from the challenge random numbers associated with the host, referred by |
| 2834 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2835 | * array and returned by reference through @HashWorking. |
| 2836 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2837 | static void |
| 2838 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2839 | { |
| 2840 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2841 | } |
| 2842 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2843 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2844 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2845 | * @phba: pointer to lpfc hba data structure. |
| 2846 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2847 | * |
| 2848 | * This routine performs the special handling for LC HBA initialization. |
| 2849 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2850 | void |
| 2851 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2852 | { |
| 2853 | int t; |
| 2854 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2855 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2856 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2857 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2858 | if (!HashWorking) |
| 2859 | return; |
| 2860 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2861 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2862 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2863 | |
| 2864 | for (t = 0; t < 7; t++) |
| 2865 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2866 | |
| 2867 | lpfc_sha_init(hbainit); |
| 2868 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2869 | kfree(HashWorking); |
| 2870 | } |
| 2871 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2872 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2873 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2874 | * @vport: pointer to a virtual N_Port data structure. |
| 2875 | * |
| 2876 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2877 | * It invokes the discovery state machine to perform necessary state |
| 2878 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2879 | * the physical port is treated as @vport 0. |
| 2880 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2881 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2882 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2883 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2884 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2885 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2886 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2887 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2888 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2889 | lpfc_port_link_failure(vport); |
| 2890 | |
| 2891 | 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] | 2892 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2893 | ndlp->nlp_DID == Fabric_DID) { |
| 2894 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2895 | lpfc_nlp_put(ndlp); |
| 2896 | continue; |
| 2897 | } |
| 2898 | |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 2899 | if (ndlp->nlp_DID == Fabric_Cntl_DID && |
| 2900 | ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2901 | lpfc_nlp_put(ndlp); |
| 2902 | continue; |
| 2903 | } |
| 2904 | |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2905 | /* Fabric Ports not in UNMAPPED state are cleaned up in the |
| 2906 | * DEVICE_RM event. |
| 2907 | */ |
| 2908 | if (ndlp->nlp_type & NLP_FABRIC && |
| 2909 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2910 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2911 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2912 | |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2913 | if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD))) |
| 2914 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2915 | NLP_EVT_DEVICE_RM); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2916 | } |
| 2917 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2918 | /* At this point, ALL ndlp's should be gone |
| 2919 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2920 | * Lets wait for this to happen, if needed. |
| 2921 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2922 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2923 | if (i++ > 3000) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2924 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2925 | LOG_TRACE_EVENT, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2926 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2927 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2928 | &vport->fc_nodes, nlp_listp) { |
| 2929 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2930 | LOG_TRACE_EVENT, |
| 2931 | "0282 did:x%x ndlp:x%px " |
| 2932 | "refcnt:%d xflags x%x nflag x%x\n", |
| 2933 | ndlp->nlp_DID, (void *)ndlp, |
| 2934 | kref_read(&ndlp->kref), |
| 2935 | ndlp->fc4_xpt_flags, |
| 2936 | ndlp->nlp_flag); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2937 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2938 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2939 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2940 | |
| 2941 | /* Wait for any activity on ndlps to settle */ |
| 2942 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2943 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2944 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2945 | } |
| 2946 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2947 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2948 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2949 | * @vport: pointer to a virtual N_Port data structure. |
| 2950 | * |
| 2951 | * This routine stops all the timers associated with a @vport. This function |
| 2952 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2953 | * port is treated as @vport 0. |
| 2954 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2955 | void |
| 2956 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2957 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2958 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2959 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2960 | lpfc_can_disctmo(vport); |
| 2961 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2962 | } |
| 2963 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2964 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2965 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2966 | * @phba: pointer to lpfc hba data structure. |
| 2967 | * |
| 2968 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2969 | * caller of this routine should already hold the host lock. |
| 2970 | **/ |
| 2971 | void |
| 2972 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2973 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2974 | /* Clear pending FCF rediscovery wait flag */ |
| 2975 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2976 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2977 | /* Now, try to stop the timer */ |
| 2978 | del_timer(&phba->fcf.redisc_wait); |
| 2979 | } |
| 2980 | |
| 2981 | /** |
| 2982 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2983 | * @phba: pointer to lpfc hba data structure. |
| 2984 | * |
| 2985 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2986 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2987 | * lock held before proceeding with disabling the timer and clearing the |
| 2988 | * wait timer pendig flag. |
| 2989 | **/ |
| 2990 | void |
| 2991 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2992 | { |
| 2993 | spin_lock_irq(&phba->hbalock); |
| 2994 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2995 | /* FCF rediscovery timer already fired or stopped */ |
| 2996 | spin_unlock_irq(&phba->hbalock); |
| 2997 | return; |
| 2998 | } |
| 2999 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 3000 | /* Clear failover in progress flags */ |
| 3001 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3002 | spin_unlock_irq(&phba->hbalock); |
| 3003 | } |
| 3004 | |
| 3005 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3006 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3007 | * @phba: pointer to lpfc hba data structure. |
| 3008 | * |
| 3009 | * This routine stops all the timers associated with a HBA. This function is |
| 3010 | * invoked before either putting a HBA offline or unloading the driver. |
| 3011 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3012 | void |
| 3013 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3014 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 3015 | if (phba->pport) |
| 3016 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 3017 | cancel_delayed_work_sync(&phba->eq_delay_work); |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 3018 | cancel_delayed_work_sync(&phba->idle_stat_delay_work); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3019 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3020 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3021 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3022 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3023 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3024 | del_timer_sync(&phba->rrq_tmr); |
| 3025 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 3026 | } |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 3027 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3028 | |
| 3029 | switch (phba->pci_dev_grp) { |
| 3030 | case LPFC_PCI_DEV_LP: |
| 3031 | /* Stop any LightPulse device specific driver timers */ |
| 3032 | del_timer_sync(&phba->fcp_poll_timer); |
| 3033 | break; |
| 3034 | case LPFC_PCI_DEV_OC: |
Paul Walmsley | cc0e5f1 | 2019-07-11 20:52:33 -0700 | [diff] [blame] | 3035 | /* Stop any OneConnect device specific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3036 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3037 | break; |
| 3038 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3039 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3040 | "0297 Invalid device group (x%x)\n", |
| 3041 | phba->pci_dev_grp); |
| 3042 | break; |
| 3043 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3044 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3045 | } |
| 3046 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3047 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3048 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3049 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 3050 | * @mbx_action: flag for mailbox no wait action. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3051 | * |
| 3052 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 3053 | * management interface is marked as blocked, all the user space access to |
| 3054 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 3055 | * all be blocked. The HBA is set to block the management interface when the |
| 3056 | * driver prepares the HBA interface for online or offline. |
| 3057 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3058 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3059 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3060 | { |
| 3061 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3062 | uint8_t actcmd = MBX_HEARTBEAT; |
| 3063 | unsigned long timeout; |
| 3064 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3065 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3066 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3067 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3068 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 3069 | return; |
| 3070 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 3071 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3072 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3073 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3074 | /* Determine how long we might wait for the active mailbox |
| 3075 | * command to be gracefully completed by firmware. |
| 3076 | */ |
| 3077 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3078 | phba->sli.mbox_active) * 1000) + jiffies; |
| 3079 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3080 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3081 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3082 | /* Wait for the outstnading mailbox command to complete */ |
| 3083 | while (phba->sli.mbox_active) { |
| 3084 | /* Check active mailbox complete status every 2ms */ |
| 3085 | msleep(2); |
| 3086 | if (time_after(jiffies, timeout)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3087 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 3088 | "2813 Mgmt IO is Blocked %x " |
| 3089 | "- mbox cmd %x still active\n", |
| 3090 | phba->sli.sli_flag, actcmd); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3091 | break; |
| 3092 | } |
| 3093 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3094 | } |
| 3095 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3096 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3097 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 3098 | * @phba: pointer to lpfc hba data structure. |
| 3099 | * |
| 3100 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 3101 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 3102 | * is to fixup the temporary rpi assignments. |
| 3103 | **/ |
| 3104 | void |
| 3105 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 3106 | { |
| 3107 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3108 | struct lpfc_vport **vports; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3109 | int i, rpi; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3110 | |
| 3111 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 3112 | return; |
| 3113 | |
| 3114 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3115 | if (vports == NULL) |
| 3116 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3117 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3118 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3119 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3120 | continue; |
| 3121 | |
| 3122 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3123 | &vports[i]->fc_nodes, |
| 3124 | nlp_listp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3125 | rpi = lpfc_sli4_alloc_rpi(phba); |
| 3126 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3127 | /* TODO print log? */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3128 | continue; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3129 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3130 | ndlp->nlp_rpi = rpi; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3131 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, |
| 3132 | LOG_NODE | LOG_DISCOVERY, |
| 3133 | "0009 Assign RPI x%x to ndlp x%px " |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3134 | "DID:x%06x flg:x%x\n", |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3135 | ndlp->nlp_rpi, ndlp, ndlp->nlp_DID, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3136 | ndlp->nlp_flag); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3137 | } |
| 3138 | } |
| 3139 | lpfc_destroy_vport_work_array(phba, vports); |
| 3140 | } |
| 3141 | |
| 3142 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3143 | * lpfc_create_expedite_pool - create expedite pool |
| 3144 | * @phba: pointer to lpfc hba data structure. |
| 3145 | * |
| 3146 | * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0 |
| 3147 | * to expedite pool. Mark them as expedite. |
| 3148 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3149 | static void lpfc_create_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3150 | { |
| 3151 | struct lpfc_sli4_hdw_queue *qp; |
| 3152 | struct lpfc_io_buf *lpfc_ncmd; |
| 3153 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3154 | struct lpfc_epd_pool *epd_pool; |
| 3155 | unsigned long iflag; |
| 3156 | |
| 3157 | epd_pool = &phba->epd_pool; |
| 3158 | qp = &phba->sli4_hba.hdwq[0]; |
| 3159 | |
| 3160 | spin_lock_init(&epd_pool->lock); |
| 3161 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3162 | spin_lock(&epd_pool->lock); |
| 3163 | INIT_LIST_HEAD(&epd_pool->list); |
| 3164 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3165 | &qp->lpfc_io_buf_list_put, list) { |
| 3166 | list_move_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 3167 | lpfc_ncmd->expedite = true; |
| 3168 | qp->put_io_bufs--; |
| 3169 | epd_pool->count++; |
| 3170 | if (epd_pool->count >= XRI_BATCH) |
| 3171 | break; |
| 3172 | } |
| 3173 | spin_unlock(&epd_pool->lock); |
| 3174 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3175 | } |
| 3176 | |
| 3177 | /** |
| 3178 | * lpfc_destroy_expedite_pool - destroy expedite pool |
| 3179 | * @phba: pointer to lpfc hba data structure. |
| 3180 | * |
| 3181 | * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put |
| 3182 | * of HWQ 0. Clear the mark. |
| 3183 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3184 | static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3185 | { |
| 3186 | struct lpfc_sli4_hdw_queue *qp; |
| 3187 | struct lpfc_io_buf *lpfc_ncmd; |
| 3188 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3189 | struct lpfc_epd_pool *epd_pool; |
| 3190 | unsigned long iflag; |
| 3191 | |
| 3192 | epd_pool = &phba->epd_pool; |
| 3193 | qp = &phba->sli4_hba.hdwq[0]; |
| 3194 | |
| 3195 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3196 | spin_lock(&epd_pool->lock); |
| 3197 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3198 | &epd_pool->list, list) { |
| 3199 | list_move_tail(&lpfc_ncmd->list, |
| 3200 | &qp->lpfc_io_buf_list_put); |
| 3201 | lpfc_ncmd->flags = false; |
| 3202 | qp->put_io_bufs++; |
| 3203 | epd_pool->count--; |
| 3204 | } |
| 3205 | spin_unlock(&epd_pool->lock); |
| 3206 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3207 | } |
| 3208 | |
| 3209 | /** |
| 3210 | * lpfc_create_multixri_pools - create multi-XRI pools |
| 3211 | * @phba: pointer to lpfc hba data structure. |
| 3212 | * |
| 3213 | * This routine initialize public, private per HWQ. Then, move XRIs from |
| 3214 | * lpfc_io_buf_list_put to public pool. High and low watermark are also |
| 3215 | * Initialized. |
| 3216 | **/ |
| 3217 | void lpfc_create_multixri_pools(struct lpfc_hba *phba) |
| 3218 | { |
| 3219 | u32 i, j; |
| 3220 | u32 hwq_count; |
| 3221 | u32 count_per_hwq; |
| 3222 | struct lpfc_io_buf *lpfc_ncmd; |
| 3223 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3224 | unsigned long iflag; |
| 3225 | struct lpfc_sli4_hdw_queue *qp; |
| 3226 | struct lpfc_multixri_pool *multixri_pool; |
| 3227 | struct lpfc_pbl_pool *pbl_pool; |
| 3228 | struct lpfc_pvt_pool *pvt_pool; |
| 3229 | |
| 3230 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3231 | "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n", |
| 3232 | phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu, |
| 3233 | phba->sli4_hba.io_xri_cnt); |
| 3234 | |
| 3235 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3236 | lpfc_create_expedite_pool(phba); |
| 3237 | |
| 3238 | hwq_count = phba->cfg_hdw_queue; |
| 3239 | count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count; |
| 3240 | |
| 3241 | for (i = 0; i < hwq_count; i++) { |
| 3242 | multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL); |
| 3243 | |
| 3244 | if (!multixri_pool) { |
| 3245 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3246 | "1238 Failed to allocate memory for " |
| 3247 | "multixri_pool\n"); |
| 3248 | |
| 3249 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3250 | lpfc_destroy_expedite_pool(phba); |
| 3251 | |
| 3252 | j = 0; |
| 3253 | while (j < i) { |
| 3254 | qp = &phba->sli4_hba.hdwq[j]; |
| 3255 | kfree(qp->p_multixri_pool); |
| 3256 | j++; |
| 3257 | } |
| 3258 | phba->cfg_xri_rebalancing = 0; |
| 3259 | return; |
| 3260 | } |
| 3261 | |
| 3262 | qp = &phba->sli4_hba.hdwq[i]; |
| 3263 | qp->p_multixri_pool = multixri_pool; |
| 3264 | |
| 3265 | multixri_pool->xri_limit = count_per_hwq; |
| 3266 | multixri_pool->rrb_next_hwqid = i; |
| 3267 | |
| 3268 | /* Deal with public free xri pool */ |
| 3269 | pbl_pool = &multixri_pool->pbl_pool; |
| 3270 | spin_lock_init(&pbl_pool->lock); |
| 3271 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3272 | spin_lock(&pbl_pool->lock); |
| 3273 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3274 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3275 | &qp->lpfc_io_buf_list_put, list) { |
| 3276 | list_move_tail(&lpfc_ncmd->list, &pbl_pool->list); |
| 3277 | qp->put_io_bufs--; |
| 3278 | pbl_pool->count++; |
| 3279 | } |
| 3280 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3281 | "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n", |
| 3282 | pbl_pool->count, i); |
| 3283 | spin_unlock(&pbl_pool->lock); |
| 3284 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3285 | |
| 3286 | /* Deal with private free xri pool */ |
| 3287 | pvt_pool = &multixri_pool->pvt_pool; |
| 3288 | pvt_pool->high_watermark = multixri_pool->xri_limit / 2; |
| 3289 | pvt_pool->low_watermark = XRI_BATCH; |
| 3290 | spin_lock_init(&pvt_pool->lock); |
| 3291 | spin_lock_irqsave(&pvt_pool->lock, iflag); |
| 3292 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3293 | pvt_pool->count = 0; |
| 3294 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | /** |
| 3299 | * lpfc_destroy_multixri_pools - destroy multi-XRI pools |
| 3300 | * @phba: pointer to lpfc hba data structure. |
| 3301 | * |
| 3302 | * This routine returns XRIs from public/private to lpfc_io_buf_list_put. |
| 3303 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3304 | static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3305 | { |
| 3306 | u32 i; |
| 3307 | u32 hwq_count; |
| 3308 | struct lpfc_io_buf *lpfc_ncmd; |
| 3309 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3310 | unsigned long iflag; |
| 3311 | struct lpfc_sli4_hdw_queue *qp; |
| 3312 | struct lpfc_multixri_pool *multixri_pool; |
| 3313 | struct lpfc_pbl_pool *pbl_pool; |
| 3314 | struct lpfc_pvt_pool *pvt_pool; |
| 3315 | |
| 3316 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3317 | lpfc_destroy_expedite_pool(phba); |
| 3318 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 3319 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3320 | lpfc_sli_flush_io_rings(phba); |
James Smart | c66a919 | 2019-03-12 16:30:19 -0700 | [diff] [blame] | 3321 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3322 | hwq_count = phba->cfg_hdw_queue; |
| 3323 | |
| 3324 | for (i = 0; i < hwq_count; i++) { |
| 3325 | qp = &phba->sli4_hba.hdwq[i]; |
| 3326 | multixri_pool = qp->p_multixri_pool; |
| 3327 | if (!multixri_pool) |
| 3328 | continue; |
| 3329 | |
| 3330 | qp->p_multixri_pool = NULL; |
| 3331 | |
| 3332 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3333 | |
| 3334 | /* Deal with public free xri pool */ |
| 3335 | pbl_pool = &multixri_pool->pbl_pool; |
| 3336 | spin_lock(&pbl_pool->lock); |
| 3337 | |
| 3338 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3339 | "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n", |
| 3340 | pbl_pool->count, i); |
| 3341 | |
| 3342 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3343 | &pbl_pool->list, list) { |
| 3344 | list_move_tail(&lpfc_ncmd->list, |
| 3345 | &qp->lpfc_io_buf_list_put); |
| 3346 | qp->put_io_bufs++; |
| 3347 | pbl_pool->count--; |
| 3348 | } |
| 3349 | |
| 3350 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3351 | pbl_pool->count = 0; |
| 3352 | |
| 3353 | spin_unlock(&pbl_pool->lock); |
| 3354 | |
| 3355 | /* Deal with private free xri pool */ |
| 3356 | pvt_pool = &multixri_pool->pvt_pool; |
| 3357 | spin_lock(&pvt_pool->lock); |
| 3358 | |
| 3359 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3360 | "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n", |
| 3361 | pvt_pool->count, i); |
| 3362 | |
| 3363 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3364 | &pvt_pool->list, list) { |
| 3365 | list_move_tail(&lpfc_ncmd->list, |
| 3366 | &qp->lpfc_io_buf_list_put); |
| 3367 | qp->put_io_bufs++; |
| 3368 | pvt_pool->count--; |
| 3369 | } |
| 3370 | |
| 3371 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3372 | pvt_pool->count = 0; |
| 3373 | |
| 3374 | spin_unlock(&pvt_pool->lock); |
| 3375 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3376 | |
| 3377 | kfree(multixri_pool); |
| 3378 | } |
| 3379 | } |
| 3380 | |
| 3381 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3382 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3383 | * @phba: pointer to lpfc hba data structure. |
| 3384 | * |
| 3385 | * This routine initializes the HBA and brings a HBA online. During this |
| 3386 | * process, the management interface is blocked to prevent user space access |
| 3387 | * to the HBA interfering with the driver initialization. |
| 3388 | * |
| 3389 | * Return codes |
| 3390 | * 0 - successful |
| 3391 | * 1 - failed |
| 3392 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3393 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3394 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3395 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3396 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3397 | struct lpfc_vport **vports; |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3398 | int i, error = 0; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3399 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3400 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3401 | if (!phba) |
| 3402 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3403 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3404 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3405 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3406 | return 0; |
| 3407 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3408 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3409 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3410 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3411 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3412 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3413 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3414 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 3415 | lpfc_unblock_mgmt_io(phba); |
| 3416 | return 1; |
| 3417 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3418 | spin_lock_irq(&phba->hbalock); |
| 3419 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 3420 | vpis_cleared = true; |
| 3421 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3422 | |
| 3423 | /* Reestablish the local initiator port. |
| 3424 | * The offline process destroyed the previous lport. |
| 3425 | */ |
| 3426 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
| 3427 | !phba->nvmet_support) { |
| 3428 | error = lpfc_nvme_create_localport(phba->pport); |
| 3429 | if (error) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3430 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3431 | "6132 NVME restore reg failed " |
| 3432 | "on nvmei error x%x\n", error); |
| 3433 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3434 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3435 | lpfc_sli_queue_init(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3436 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 3437 | lpfc_unblock_mgmt_io(phba); |
| 3438 | return 1; |
| 3439 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3440 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3441 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3442 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3443 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3444 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3445 | struct Scsi_Host *shost; |
| 3446 | shost = lpfc_shost_from_vport(vports[i]); |
| 3447 | spin_lock_irq(shost->host_lock); |
| 3448 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 3449 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3450 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3451 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3452 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3453 | if ((vpis_cleared) && |
| 3454 | (vports[i]->port_type != |
| 3455 | LPFC_PHYSICAL_PORT)) |
| 3456 | vports[i]->vpi = 0; |
| 3457 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3458 | spin_unlock_irq(shost->host_lock); |
| 3459 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3460 | } |
| 3461 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3462 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3463 | if (phba->cfg_xri_rebalancing) |
| 3464 | lpfc_create_multixri_pools(phba); |
| 3465 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 3466 | lpfc_cpuhp_add(phba); |
| 3467 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3468 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3469 | return 0; |
| 3470 | } |
| 3471 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3472 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3473 | * 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] | 3474 | * @phba: pointer to lpfc hba data structure. |
| 3475 | * |
| 3476 | * This routine marks a HBA's management interface as not blocked. Once the |
| 3477 | * HBA's management interface is marked as not blocked, all the user space |
| 3478 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 3479 | * interface will be allowed. The HBA is set to block the management interface |
| 3480 | * when the driver prepares the HBA interface for online or offline and then |
| 3481 | * set to unblock the management interface afterwards. |
| 3482 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3483 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3484 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 3485 | { |
| 3486 | unsigned long iflag; |
| 3487 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3488 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3489 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 3490 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3491 | } |
| 3492 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3493 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3494 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3495 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 3496 | * @mbx_action: flag for mailbox shutdown action. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3497 | * |
| 3498 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 3499 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 3500 | * queue to make it ready to be brought offline. |
| 3501 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3502 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3503 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3504 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3505 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3506 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3507 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3508 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3509 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3510 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3511 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3512 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3513 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3514 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3515 | |
| 3516 | lpfc_linkdown(phba); |
| 3517 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3518 | /* Issue an unreg_login to all nodes on all vports */ |
| 3519 | vports = lpfc_create_vport_work_array(phba); |
| 3520 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3521 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3522 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3523 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3524 | shost = lpfc_shost_from_vport(vports[i]); |
| 3525 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3526 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3527 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 3528 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3529 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3530 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3531 | shost = lpfc_shost_from_vport(vports[i]); |
| 3532 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3533 | &vports[i]->fc_nodes, |
| 3534 | nlp_listp) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3535 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3536 | /* Driver must assume RPI is invalid for |
| 3537 | * any unused or inactive node. |
| 3538 | */ |
| 3539 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3540 | continue; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3541 | } |
| 3542 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3543 | spin_lock_irq(&ndlp->lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3544 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3545 | spin_unlock_irq(&ndlp->lock); |
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 | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3561 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3562 | |
| 3563 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3564 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3565 | NULL, NLP_EVT_DEVICE_RECOVERY); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 3566 | |
| 3567 | /* Don't remove the node unless the |
| 3568 | * has been unregistered with the |
| 3569 | * transport. If so, let dev_loss |
| 3570 | * take care of the node. |
| 3571 | */ |
| 3572 | if (!(ndlp->fc4_xpt_flags & |
| 3573 | (NVME_XPT_REGD | SCSI_XPT_REGD))) |
| 3574 | lpfc_disc_state_machine |
| 3575 | (vports[i], ndlp, |
| 3576 | NULL, |
| 3577 | NLP_EVT_DEVICE_RM); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3578 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3579 | } |
| 3580 | } |
| 3581 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3582 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3583 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3584 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 3585 | |
| 3586 | if (phba->wq) |
| 3587 | flush_workqueue(phba->wq); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3588 | } |
| 3589 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3590 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3591 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3592 | * @phba: pointer to lpfc hba data structure. |
| 3593 | * |
| 3594 | * This routine actually brings a HBA offline. It stops all the timers |
| 3595 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3596 | * marks the HBA as in offline state for the upper layer protocol. |
| 3597 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3598 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3599 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3600 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3601 | struct Scsi_Host *shost; |
| 3602 | struct lpfc_vport **vports; |
| 3603 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3604 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3605 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3606 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3607 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3608 | /* stop port and all timers associated with this hba */ |
| 3609 | lpfc_stop_port(phba); |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 3610 | |
| 3611 | /* Tear down the local and target port registrations. The |
| 3612 | * nvme transports need to cleanup. |
| 3613 | */ |
| 3614 | lpfc_nvmet_destroy_targetport(phba); |
| 3615 | lpfc_nvme_destroy_localport(phba->pport); |
| 3616 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3617 | vports = lpfc_create_vport_work_array(phba); |
| 3618 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3619 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3620 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3621 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3622 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3623 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3625 | now. */ |
| 3626 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3627 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3628 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3629 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3630 | vports = lpfc_create_vport_work_array(phba); |
| 3631 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3632 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3633 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3634 | spin_lock_irq(shost->host_lock); |
| 3635 | vports[i]->work_port_events = 0; |
| 3636 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3637 | spin_unlock_irq(shost->host_lock); |
| 3638 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3639 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | f0871ab | 2021-01-04 10:02:32 -0800 | [diff] [blame] | 3640 | /* If OFFLINE flag is clear (i.e. unloading), cpuhp removal is handled |
| 3641 | * in hba_unset |
| 3642 | */ |
| 3643 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 3644 | __lpfc_cpuhp_remove(phba); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3645 | |
| 3646 | if (phba->cfg_xri_rebalancing) |
| 3647 | lpfc_destroy_multixri_pools(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3648 | } |
| 3649 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3650 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3651 | * 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] | 3652 | * @phba: pointer to lpfc hba data structure. |
| 3653 | * |
| 3654 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3655 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3656 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3657 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3658 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3659 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3660 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3661 | struct lpfc_io_buf *sb, *sb_next; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3662 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3663 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3664 | return; |
| 3665 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3666 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3667 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3668 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3669 | |
| 3670 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3671 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3672 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3673 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3674 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3675 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3676 | kfree(sb); |
| 3677 | phba->total_scsi_bufs--; |
| 3678 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3679 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3680 | |
| 3681 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3682 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3683 | list) { |
| 3684 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3685 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3686 | sb->dma_handle); |
| 3687 | kfree(sb); |
| 3688 | phba->total_scsi_bufs--; |
| 3689 | } |
| 3690 | spin_unlock(&phba->scsi_buf_list_get_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3691 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3692 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3693 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3694 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3695 | * 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] | 3696 | * @phba: pointer to lpfc hba data structure. |
| 3697 | * |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3698 | * 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] | 3699 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3700 | * the internal resources before the device is removed from the system. |
| 3701 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3702 | void |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3703 | lpfc_io_free(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3704 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3705 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3706 | struct lpfc_sli4_hdw_queue *qp; |
| 3707 | int idx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3708 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3709 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3710 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3711 | /* Release all the lpfc_nvme_bufs maintained by this host. */ |
| 3712 | spin_lock(&qp->io_buf_list_put_lock); |
| 3713 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3714 | &qp->lpfc_io_buf_list_put, |
| 3715 | list) { |
| 3716 | list_del(&lpfc_ncmd->list); |
| 3717 | qp->put_io_bufs--; |
| 3718 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3719 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3720 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 3721 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 3722 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3723 | kfree(lpfc_ncmd); |
| 3724 | qp->total_io_bufs--; |
| 3725 | } |
| 3726 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3727 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3728 | spin_lock(&qp->io_buf_list_get_lock); |
| 3729 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3730 | &qp->lpfc_io_buf_list_get, |
| 3731 | list) { |
| 3732 | list_del(&lpfc_ncmd->list); |
| 3733 | qp->get_io_bufs--; |
| 3734 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3735 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3736 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 3737 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 3738 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3739 | kfree(lpfc_ncmd); |
| 3740 | qp->total_io_bufs--; |
| 3741 | } |
| 3742 | spin_unlock(&qp->io_buf_list_get_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3743 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3744 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3745 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3746 | /** |
| 3747 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3748 | * @phba: pointer to lpfc hba data structure. |
| 3749 | * |
| 3750 | * This routine first calculates the sizes of the current els and allocated |
| 3751 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3752 | * XRIs assigned due to port function reset. During port initialization, the |
| 3753 | * current els and allocated scsi sgl lists are 0s. |
| 3754 | * |
| 3755 | * Return codes |
| 3756 | * 0 - successful (for now, it always returns 0) |
| 3757 | **/ |
| 3758 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3759 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3760 | { |
| 3761 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3762 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3763 | LIST_HEAD(els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3764 | int rc; |
| 3765 | |
| 3766 | /* |
| 3767 | * update on pci function's els xri-sgl list |
| 3768 | */ |
| 3769 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3770 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3771 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3772 | /* els xri-sgl expanded */ |
| 3773 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3774 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3775 | "3157 ELS xri-sgl count increased from " |
| 3776 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3777 | els_xri_cnt); |
| 3778 | /* allocate the additional els sgls */ |
| 3779 | for (i = 0; i < xri_cnt; i++) { |
| 3780 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3781 | GFP_KERNEL); |
| 3782 | if (sglq_entry == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3783 | lpfc_printf_log(phba, KERN_ERR, |
| 3784 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3785 | "2562 Failure to allocate an " |
| 3786 | "ELS sgl entry:%d\n", i); |
| 3787 | rc = -ENOMEM; |
| 3788 | goto out_free_mem; |
| 3789 | } |
| 3790 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3791 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3792 | &sglq_entry->phys); |
| 3793 | if (sglq_entry->virt == NULL) { |
| 3794 | kfree(sglq_entry); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3795 | lpfc_printf_log(phba, KERN_ERR, |
| 3796 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3797 | "2563 Failure to allocate an " |
| 3798 | "ELS mbuf:%d\n", i); |
| 3799 | rc = -ENOMEM; |
| 3800 | goto out_free_mem; |
| 3801 | } |
| 3802 | sglq_entry->sgl = sglq_entry->virt; |
| 3803 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3804 | sglq_entry->state = SGL_FREED; |
| 3805 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3806 | } |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3807 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3808 | list_splice_init(&els_sgl_list, |
| 3809 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3810 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3811 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3812 | /* els xri-sgl shrinked */ |
| 3813 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3814 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3815 | "3158 ELS xri-sgl count decreased from " |
| 3816 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3817 | els_xri_cnt); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3818 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3819 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, |
| 3820 | &els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3821 | /* release extra els sgls from list */ |
| 3822 | for (i = 0; i < xri_cnt; i++) { |
| 3823 | list_remove_head(&els_sgl_list, |
| 3824 | sglq_entry, struct lpfc_sglq, list); |
| 3825 | if (sglq_entry) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3826 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3827 | sglq_entry->phys); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3828 | kfree(sglq_entry); |
| 3829 | } |
| 3830 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3831 | list_splice_init(&els_sgl_list, |
| 3832 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3833 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3834 | } else |
| 3835 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3836 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3837 | els_xri_cnt); |
| 3838 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3839 | |
| 3840 | /* update xris to els sgls on the list */ |
| 3841 | sglq_entry = NULL; |
| 3842 | sglq_entry_next = NULL; |
| 3843 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3844 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3845 | lxri = lpfc_sli4_next_xritag(phba); |
| 3846 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3847 | lpfc_printf_log(phba, KERN_ERR, |
| 3848 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3849 | "2400 Failed to allocate xri for " |
| 3850 | "ELS sgl\n"); |
| 3851 | rc = -ENOMEM; |
| 3852 | goto out_free_mem; |
| 3853 | } |
| 3854 | sglq_entry->sli4_lxritag = lxri; |
| 3855 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3856 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3857 | return 0; |
| 3858 | |
| 3859 | out_free_mem: |
| 3860 | lpfc_free_els_sgl_list(phba); |
| 3861 | return rc; |
| 3862 | } |
| 3863 | |
| 3864 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3865 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping |
| 3866 | * @phba: pointer to lpfc hba data structure. |
| 3867 | * |
| 3868 | * This routine first calculates the sizes of the current els and allocated |
| 3869 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3870 | * XRIs assigned due to port function reset. During port initialization, the |
| 3871 | * current els and allocated scsi sgl lists are 0s. |
| 3872 | * |
| 3873 | * Return codes |
| 3874 | * 0 - successful (for now, it always returns 0) |
| 3875 | **/ |
| 3876 | int |
| 3877 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) |
| 3878 | { |
| 3879 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3880 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3881 | uint16_t nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3882 | LIST_HEAD(nvmet_sgl_list); |
| 3883 | int rc; |
| 3884 | |
| 3885 | /* |
| 3886 | * update on pci function's nvmet xri-sgl list |
| 3887 | */ |
| 3888 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 3889 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3890 | /* For NVMET, ALL remaining XRIs are dedicated for IO processing */ |
| 3891 | 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] | 3892 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { |
| 3893 | /* els xri-sgl expanded */ |
| 3894 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; |
| 3895 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3896 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", |
| 3897 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); |
| 3898 | /* allocate the additional nvmet sgls */ |
| 3899 | for (i = 0; i < xri_cnt; i++) { |
| 3900 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3901 | GFP_KERNEL); |
| 3902 | if (sglq_entry == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3903 | lpfc_printf_log(phba, KERN_ERR, |
| 3904 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3905 | "6303 Failure to allocate an " |
| 3906 | "NVMET sgl entry:%d\n", i); |
| 3907 | rc = -ENOMEM; |
| 3908 | goto out_free_mem; |
| 3909 | } |
| 3910 | sglq_entry->buff_type = NVMET_BUFF_TYPE; |
| 3911 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, |
| 3912 | &sglq_entry->phys); |
| 3913 | if (sglq_entry->virt == NULL) { |
| 3914 | kfree(sglq_entry); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3915 | lpfc_printf_log(phba, KERN_ERR, |
| 3916 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3917 | "6304 Failure to allocate an " |
| 3918 | "NVMET buf:%d\n", i); |
| 3919 | rc = -ENOMEM; |
| 3920 | goto out_free_mem; |
| 3921 | } |
| 3922 | sglq_entry->sgl = sglq_entry->virt; |
| 3923 | memset(sglq_entry->sgl, 0, |
| 3924 | phba->cfg_sg_dma_buf_size); |
| 3925 | sglq_entry->state = SGL_FREED; |
| 3926 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); |
| 3927 | } |
| 3928 | spin_lock_irq(&phba->hbalock); |
| 3929 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3930 | list_splice_init(&nvmet_sgl_list, |
| 3931 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3932 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3933 | spin_unlock_irq(&phba->hbalock); |
| 3934 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { |
| 3935 | /* nvmet xri-sgl shrunk */ |
| 3936 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; |
| 3937 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3938 | "6305 NVMET xri-sgl count decreased from " |
| 3939 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, |
| 3940 | nvmet_xri_cnt); |
| 3941 | spin_lock_irq(&phba->hbalock); |
| 3942 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3943 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 3944 | &nvmet_sgl_list); |
| 3945 | /* release extra nvmet sgls from list */ |
| 3946 | for (i = 0; i < xri_cnt; i++) { |
| 3947 | list_remove_head(&nvmet_sgl_list, |
| 3948 | sglq_entry, struct lpfc_sglq, list); |
| 3949 | if (sglq_entry) { |
| 3950 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, |
| 3951 | sglq_entry->phys); |
| 3952 | kfree(sglq_entry); |
| 3953 | } |
| 3954 | } |
| 3955 | list_splice_init(&nvmet_sgl_list, |
| 3956 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3957 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3958 | spin_unlock_irq(&phba->hbalock); |
| 3959 | } else |
| 3960 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3961 | "6306 NVMET xri-sgl count unchanged: %d\n", |
| 3962 | nvmet_xri_cnt); |
| 3963 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; |
| 3964 | |
| 3965 | /* update xris to nvmet sgls on the list */ |
| 3966 | sglq_entry = NULL; |
| 3967 | sglq_entry_next = NULL; |
| 3968 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3969 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { |
| 3970 | lxri = lpfc_sli4_next_xritag(phba); |
| 3971 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3972 | lpfc_printf_log(phba, KERN_ERR, |
| 3973 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3974 | "6307 Failed to allocate xri for " |
| 3975 | "NVMET sgl\n"); |
| 3976 | rc = -ENOMEM; |
| 3977 | goto out_free_mem; |
| 3978 | } |
| 3979 | sglq_entry->sli4_lxritag = lxri; |
| 3980 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3981 | } |
| 3982 | return 0; |
| 3983 | |
| 3984 | out_free_mem: |
| 3985 | lpfc_free_nvmet_sgl_list(phba); |
| 3986 | return rc; |
| 3987 | } |
| 3988 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3989 | int |
| 3990 | lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3991 | { |
| 3992 | LIST_HEAD(blist); |
| 3993 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3994 | struct lpfc_io_buf *lpfc_cmd; |
| 3995 | struct lpfc_io_buf *iobufp, *prev_iobufp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3996 | int idx, cnt, xri, inserted; |
| 3997 | |
| 3998 | cnt = 0; |
| 3999 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 4000 | qp = &phba->sli4_hba.hdwq[idx]; |
| 4001 | spin_lock_irq(&qp->io_buf_list_get_lock); |
| 4002 | spin_lock(&qp->io_buf_list_put_lock); |
| 4003 | |
| 4004 | /* Take everything off the get and put lists */ |
| 4005 | list_splice_init(&qp->lpfc_io_buf_list_get, &blist); |
| 4006 | list_splice(&qp->lpfc_io_buf_list_put, &blist); |
| 4007 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 4008 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 4009 | cnt += qp->get_io_bufs + qp->put_io_bufs; |
| 4010 | qp->get_io_bufs = 0; |
| 4011 | qp->put_io_bufs = 0; |
| 4012 | qp->total_io_bufs = 0; |
| 4013 | spin_unlock(&qp->io_buf_list_put_lock); |
| 4014 | spin_unlock_irq(&qp->io_buf_list_get_lock); |
| 4015 | } |
| 4016 | |
| 4017 | /* |
| 4018 | * Take IO buffers off blist and put on cbuf sorted by XRI. |
| 4019 | * This is because POST_SGL takes a sequential range of XRIs |
| 4020 | * to post to the firmware. |
| 4021 | */ |
| 4022 | for (idx = 0; idx < cnt; idx++) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4023 | list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4024 | if (!lpfc_cmd) |
| 4025 | return cnt; |
| 4026 | if (idx == 0) { |
| 4027 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 4028 | continue; |
| 4029 | } |
| 4030 | xri = lpfc_cmd->cur_iocbq.sli4_xritag; |
| 4031 | inserted = 0; |
| 4032 | prev_iobufp = NULL; |
| 4033 | list_for_each_entry(iobufp, cbuf, list) { |
| 4034 | if (xri < iobufp->cur_iocbq.sli4_xritag) { |
| 4035 | if (prev_iobufp) |
| 4036 | list_add(&lpfc_cmd->list, |
| 4037 | &prev_iobufp->list); |
| 4038 | else |
| 4039 | list_add(&lpfc_cmd->list, cbuf); |
| 4040 | inserted = 1; |
| 4041 | break; |
| 4042 | } |
| 4043 | prev_iobufp = iobufp; |
| 4044 | } |
| 4045 | if (!inserted) |
| 4046 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 4047 | } |
| 4048 | return cnt; |
| 4049 | } |
| 4050 | |
| 4051 | int |
| 4052 | lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf) |
| 4053 | { |
| 4054 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4055 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4056 | int idx, cnt; |
| 4057 | |
| 4058 | qp = phba->sli4_hba.hdwq; |
| 4059 | cnt = 0; |
| 4060 | while (!list_empty(cbuf)) { |
| 4061 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 4062 | list_remove_head(cbuf, lpfc_cmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4063 | struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4064 | if (!lpfc_cmd) |
| 4065 | return cnt; |
| 4066 | cnt++; |
| 4067 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 4068 | lpfc_cmd->hdwq_no = idx; |
| 4069 | lpfc_cmd->hdwq = qp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4070 | lpfc_cmd->cur_iocbq.wqe_cmpl = NULL; |
| 4071 | lpfc_cmd->cur_iocbq.iocb_cmpl = NULL; |
| 4072 | spin_lock(&qp->io_buf_list_put_lock); |
| 4073 | list_add_tail(&lpfc_cmd->list, |
| 4074 | &qp->lpfc_io_buf_list_put); |
| 4075 | qp->put_io_bufs++; |
| 4076 | qp->total_io_bufs++; |
| 4077 | spin_unlock(&qp->io_buf_list_put_lock); |
| 4078 | } |
| 4079 | } |
| 4080 | return cnt; |
| 4081 | } |
| 4082 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 4083 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4084 | * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4085 | * @phba: pointer to lpfc hba data structure. |
| 4086 | * |
| 4087 | * This routine first calculates the sizes of the current els and allocated |
| 4088 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 4089 | * XRIs assigned due to port function reset. During port initialization, the |
| 4090 | * current els and allocated scsi sgl lists are 0s. |
| 4091 | * |
| 4092 | * Return codes |
| 4093 | * 0 - successful (for now, it always returns 0) |
| 4094 | **/ |
| 4095 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4096 | lpfc_sli4_io_sgl_update(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4097 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4098 | struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4099 | uint16_t i, lxri, els_xri_cnt; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4100 | uint16_t io_xri_cnt, io_xri_max; |
| 4101 | LIST_HEAD(io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4102 | int rc, cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4103 | |
| 4104 | /* |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4105 | * update on pci function's allocated nvme xri-sgl list |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4106 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4107 | |
| 4108 | /* maximum number of xris available for nvme buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4109 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4110 | io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 4111 | phba->sli4_hba.io_xri_max = io_xri_max; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4112 | |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4113 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4114 | "6074 Current allocated XRI sgl count:%d, " |
| 4115 | "maximum XRI count:%d\n", |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4116 | phba->sli4_hba.io_xri_cnt, |
| 4117 | phba->sli4_hba.io_xri_max); |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4118 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4119 | cnt = lpfc_io_buf_flush(phba, &io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4120 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4121 | 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] | 4122 | /* max nvme xri shrunk below the allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4123 | io_xri_cnt = phba->sli4_hba.io_xri_cnt - |
| 4124 | phba->sli4_hba.io_xri_max; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4125 | /* release the extra allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4126 | for (i = 0; i < io_xri_cnt; i++) { |
| 4127 | list_remove_head(&io_sgl_list, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4128 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4129 | if (lpfc_ncmd) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 4130 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4131 | lpfc_ncmd->data, |
| 4132 | lpfc_ncmd->dma_handle); |
| 4133 | kfree(lpfc_ncmd); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 4134 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4135 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4136 | phba->sli4_hba.io_xri_cnt -= io_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4137 | } |
| 4138 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4139 | /* update xris associated to remaining allocated nvme buffers */ |
| 4140 | lpfc_ncmd = NULL; |
| 4141 | lpfc_ncmd_next = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4142 | phba->sli4_hba.io_xri_cnt = cnt; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4143 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4144 | &io_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4145 | lxri = lpfc_sli4_next_xritag(phba); |
| 4146 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4147 | lpfc_printf_log(phba, KERN_ERR, |
| 4148 | LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4149 | "6075 Failed to allocate xri for " |
| 4150 | "nvme buffer\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4151 | rc = -ENOMEM; |
| 4152 | goto out_free_mem; |
| 4153 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4154 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; |
| 4155 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4156 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4157 | cnt = lpfc_io_buf_replenish(phba, &io_sgl_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4158 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4159 | |
| 4160 | out_free_mem: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4161 | lpfc_io_free(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4162 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4163 | } |
| 4164 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4165 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4166 | * 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] | 4167 | * @phba: Pointer to lpfc hba data structure. |
| 4168 | * @num_to_alloc: The requested number of buffers to allocate. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4169 | * |
| 4170 | * This routine allocates nvme buffers for device with SLI-4 interface spec, |
| 4171 | * the nvme buffer contains all the necessary information needed to initiate |
| 4172 | * an I/O. After allocating up to @num_to_allocate IO buffers and put |
| 4173 | * them on a list, it post them to the port by using SGL block post. |
| 4174 | * |
| 4175 | * Return codes: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4176 | * int - number of IO buffers that were allocated and posted. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4177 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 4178 | **/ |
| 4179 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4180 | lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4181 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4182 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4183 | struct lpfc_iocbq *pwqeq; |
| 4184 | uint16_t iotag, lxri = 0; |
| 4185 | int bcnt, num_posted; |
| 4186 | LIST_HEAD(prep_nblist); |
| 4187 | LIST_HEAD(post_nblist); |
| 4188 | LIST_HEAD(nvme_nblist); |
| 4189 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4190 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4191 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
James Smart | 7f9989b | 2019-08-27 14:27:46 -0700 | [diff] [blame] | 4192 | lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4193 | if (!lpfc_ncmd) |
| 4194 | break; |
| 4195 | /* |
| 4196 | * Get memory from the pci pool to map the virt space to |
| 4197 | * pci bus space for an I/O. The DMA buffer includes the |
| 4198 | * number of SGE's necessary to support the sg_tablesize. |
| 4199 | */ |
Thomas Meyer | a5c990e | 2019-05-29 22:21:36 +0200 | [diff] [blame] | 4200 | lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
| 4201 | GFP_KERNEL, |
| 4202 | &lpfc_ncmd->dma_handle); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4203 | if (!lpfc_ncmd->data) { |
| 4204 | kfree(lpfc_ncmd); |
| 4205 | break; |
| 4206 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4207 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4208 | if (phba->cfg_xpsgl && !phba->nvmet_support) { |
| 4209 | INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list); |
| 4210 | } else { |
| 4211 | /* |
| 4212 | * 4K Page alignment is CRITICAL to BlockGuard, double |
| 4213 | * check to be sure. |
| 4214 | */ |
| 4215 | if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 4216 | (((unsigned long)(lpfc_ncmd->data) & |
| 4217 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4218 | lpfc_printf_log(phba, KERN_ERR, |
| 4219 | LOG_TRACE_EVENT, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4220 | "3369 Memory alignment err: " |
| 4221 | "addr=%lx\n", |
| 4222 | (unsigned long)lpfc_ncmd->data); |
| 4223 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4224 | lpfc_ncmd->data, |
| 4225 | lpfc_ncmd->dma_handle); |
| 4226 | kfree(lpfc_ncmd); |
| 4227 | break; |
| 4228 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4229 | } |
| 4230 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4231 | INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list); |
| 4232 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4233 | lxri = lpfc_sli4_next_xritag(phba); |
| 4234 | if (lxri == NO_XRI) { |
| 4235 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4236 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4237 | kfree(lpfc_ncmd); |
| 4238 | break; |
| 4239 | } |
| 4240 | pwqeq = &lpfc_ncmd->cur_iocbq; |
| 4241 | |
| 4242 | /* Allocate iotag for lpfc_ncmd->cur_iocbq. */ |
| 4243 | iotag = lpfc_sli_next_iotag(phba, pwqeq); |
| 4244 | if (iotag == 0) { |
| 4245 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4246 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4247 | kfree(lpfc_ncmd); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4248 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4249 | "6121 Failed to allocate IOTAG for" |
| 4250 | " XRI:0x%x\n", lxri); |
| 4251 | lpfc_sli4_free_xri(phba, lxri); |
| 4252 | break; |
| 4253 | } |
| 4254 | pwqeq->sli4_lxritag = lxri; |
| 4255 | pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 4256 | pwqeq->context1 = lpfc_ncmd; |
| 4257 | |
| 4258 | /* Initialize local short-hand pointers. */ |
| 4259 | lpfc_ncmd->dma_sgl = lpfc_ncmd->data; |
| 4260 | lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle; |
| 4261 | lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4262 | spin_lock_init(&lpfc_ncmd->buf_lock); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4263 | |
| 4264 | /* add the nvme buffer to a post list */ |
| 4265 | list_add_tail(&lpfc_ncmd->list, &post_nblist); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4266 | phba->sli4_hba.io_xri_cnt++; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4267 | } |
| 4268 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME, |
| 4269 | "6114 Allocate %d out of %d requested new NVME " |
| 4270 | "buffers\n", bcnt, num_to_alloc); |
| 4271 | |
| 4272 | /* post the list of nvme buffer sgls to port if available */ |
| 4273 | if (!list_empty(&post_nblist)) |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4274 | num_posted = lpfc_sli4_post_io_sgl_list( |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4275 | phba, &post_nblist, bcnt); |
| 4276 | else |
| 4277 | num_posted = 0; |
| 4278 | |
| 4279 | return num_posted; |
| 4280 | } |
| 4281 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4282 | static uint64_t |
| 4283 | lpfc_get_wwpn(struct lpfc_hba *phba) |
| 4284 | { |
| 4285 | uint64_t wwn; |
| 4286 | int rc; |
| 4287 | LPFC_MBOXQ_t *mboxq; |
| 4288 | MAILBOX_t *mb; |
| 4289 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4290 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4291 | GFP_KERNEL); |
| 4292 | if (!mboxq) |
| 4293 | return (uint64_t)-1; |
| 4294 | |
| 4295 | /* First get WWN of HBA instance */ |
| 4296 | lpfc_read_nv(phba, mboxq); |
| 4297 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4298 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4299 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4300 | "6019 Mailbox failed , mbxCmd x%x " |
| 4301 | "READ_NV, mbxStatus x%x\n", |
| 4302 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4303 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 4304 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4305 | return (uint64_t) -1; |
| 4306 | } |
| 4307 | mb = &mboxq->u.mb; |
| 4308 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t)); |
| 4309 | /* wwn is WWPN of HBA instance */ |
| 4310 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4311 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4312 | return be64_to_cpu(wwn); |
| 4313 | else |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 4314 | return rol64(wwn, 32); |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4315 | } |
| 4316 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4317 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4318 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4319 | * @phba: pointer to lpfc hba data structure. |
| 4320 | * @instance: a unique integer ID to this FC port. |
| 4321 | * @dev: pointer to the device data structure. |
| 4322 | * |
| 4323 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 4324 | * can be created on top of either a physical port or a virtual port provided |
| 4325 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 4326 | * and associates the FC port created before adding the shost into the SCSI |
| 4327 | * layer. |
| 4328 | * |
| 4329 | * Return codes |
| 4330 | * @vport - pointer to the virtual N_Port data structure. |
| 4331 | * NULL - port create failed. |
| 4332 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4333 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4334 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4335 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4336 | struct lpfc_vport *vport; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4337 | struct Scsi_Host *shost = NULL; |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4338 | struct scsi_host_template *template; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4339 | int error = 0; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4340 | int i; |
| 4341 | uint64_t wwn; |
| 4342 | bool use_no_reset_hba = false; |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4343 | int rc; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4344 | |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4345 | if (lpfc_no_hba_reset_cnt) { |
| 4346 | if (phba->sli_rev < LPFC_SLI_REV4 && |
| 4347 | dev == &phba->pcidev->dev) { |
| 4348 | /* Reset the port first */ |
| 4349 | lpfc_sli_brdrestart(phba); |
| 4350 | rc = lpfc_sli_chipset_init(phba); |
| 4351 | if (rc) |
| 4352 | return NULL; |
| 4353 | } |
| 4354 | wwn = lpfc_get_wwpn(phba); |
| 4355 | } |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4356 | |
| 4357 | for (i = 0; i < lpfc_no_hba_reset_cnt; i++) { |
| 4358 | if (wwn == lpfc_no_hba_reset[i]) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4359 | lpfc_printf_log(phba, KERN_ERR, |
| 4360 | LOG_TRACE_EVENT, |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4361 | "6020 Setting use_no_reset port=%llx\n", |
| 4362 | wwn); |
| 4363 | use_no_reset_hba = true; |
| 4364 | break; |
| 4365 | } |
| 4366 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4367 | |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4368 | /* Seed template for SCSI host registration */ |
| 4369 | if (dev == &phba->pcidev->dev) { |
| 4370 | template = &phba->port_template; |
| 4371 | |
| 4372 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 4373 | /* Seed physical port template */ |
| 4374 | memcpy(template, &lpfc_template, sizeof(*template)); |
| 4375 | |
James Smart | 7c30bb6 | 2020-10-20 13:27:16 -0700 | [diff] [blame] | 4376 | if (use_no_reset_hba) |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4377 | /* template is for a no reset SCSI Host */ |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4378 | template->eh_host_reset_handler = NULL; |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4379 | |
| 4380 | /* Template for all vports this physical port creates */ |
| 4381 | memcpy(&phba->vport_template, &lpfc_template, |
| 4382 | sizeof(*template)); |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4383 | phba->vport_template.shost_attrs = lpfc_vport_attrs; |
| 4384 | phba->vport_template.eh_bus_reset_handler = NULL; |
| 4385 | phba->vport_template.eh_host_reset_handler = NULL; |
| 4386 | phba->vport_template.vendor_id = 0; |
| 4387 | |
| 4388 | /* Initialize the host templates with updated value */ |
| 4389 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4390 | template->sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 4391 | phba->vport_template.sg_tablesize = |
| 4392 | phba->cfg_scsi_seg_cnt; |
| 4393 | } else { |
| 4394 | template->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4395 | phba->vport_template.sg_tablesize = |
| 4396 | phba->cfg_sg_seg_cnt; |
| 4397 | } |
| 4398 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4399 | } else { |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4400 | /* NVMET is for physical port only */ |
| 4401 | memcpy(template, &lpfc_template_nvme, |
| 4402 | sizeof(*template)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4403 | } |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4404 | } else { |
| 4405 | template = &phba->vport_template; |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 4406 | } |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4407 | |
| 4408 | shost = scsi_host_alloc(template, sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4409 | if (!shost) |
| 4410 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4411 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4412 | vport = (struct lpfc_vport *) shost->hostdata; |
| 4413 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4414 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4415 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4416 | vport->fc_rscn_flush = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4417 | lpfc_get_vport_cfgparam(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4418 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4419 | /* Adjust value in vport */ |
| 4420 | vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type; |
| 4421 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4422 | shost->unique_id = instance; |
| 4423 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4424 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4425 | shost->this_id = -1; |
| 4426 | shost->max_cmd_len = 16; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4427 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4428 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 77ffd34 | 2019-08-15 19:36:49 -0700 | [diff] [blame] | 4429 | if (!phba->cfg_fcp_mq_threshold || |
| 4430 | phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue) |
| 4431 | phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue; |
| 4432 | |
| 4433 | shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(), |
| 4434 | phba->cfg_fcp_mq_threshold); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4435 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4436 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4437 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4438 | |
| 4439 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 4440 | shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE; |
| 4441 | else |
| 4442 | shost->sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 4443 | } else |
| 4444 | /* SLI-3 has a limited number of hardware queues (3), |
| 4445 | * thus there is only one for FCP processing. |
| 4446 | */ |
| 4447 | shost->nr_hw_queues = 1; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 4448 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4449 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4450 | * Set initial can_queue value since 0 is no longer supported and |
| 4451 | * scsi_add_host will fail. This will be adjusted later based on the |
| 4452 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4453 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4454 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4455 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4456 | shost->transportt = lpfc_vport_transport_template; |
| 4457 | vport->port_type = LPFC_NPIV_PORT; |
| 4458 | } else { |
| 4459 | shost->transportt = lpfc_transport_template; |
| 4460 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 4461 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4462 | |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4463 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 4464 | "9081 CreatePort TMPLATE type %x TBLsize %d " |
| 4465 | "SEGcnt %d/%d\n", |
| 4466 | vport->port_type, shost->sg_tablesize, |
| 4467 | phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt); |
| 4468 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4469 | /* Initialize all internally managed lists. */ |
| 4470 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4471 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4472 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4473 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4474 | timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4475 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4476 | timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4477 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4478 | timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4479 | |
James Smart | aa6ff30 | 2019-05-21 17:49:09 -0700 | [diff] [blame] | 4480 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 4481 | lpfc_setup_bg(phba, shost); |
| 4482 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 4483 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4484 | if (error) |
| 4485 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4486 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4487 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4488 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4489 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4490 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4491 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4492 | out_put_shost: |
| 4493 | scsi_host_put(shost); |
| 4494 | out: |
| 4495 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4496 | } |
| 4497 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4498 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4499 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4500 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 4501 | * |
| 4502 | * This routine destroys a FC port from the upper layer protocol. All the |
| 4503 | * resources associated with the port are released. |
| 4504 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4505 | void |
| 4506 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4507 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4508 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4509 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4510 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4511 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4512 | fc_remove_host(shost); |
| 4513 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4514 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4515 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4516 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4517 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4518 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4519 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4520 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4521 | } |
| 4522 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4523 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4524 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4525 | * |
| 4526 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 4527 | * uses the kernel idr facility to perform the task. |
| 4528 | * |
| 4529 | * Return codes: |
| 4530 | * instance - a unique integer ID allocated as the new instance. |
| 4531 | * -1 - lpfc get instance failed. |
| 4532 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4533 | int |
| 4534 | lpfc_get_instance(void) |
| 4535 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4536 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4537 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4538 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 4539 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4540 | } |
| 4541 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4542 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4543 | * 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] | 4544 | * @shost: pointer to SCSI host data structure. |
| 4545 | * @time: elapsed time of the scan in jiffies. |
| 4546 | * |
| 4547 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 4548 | * whether the scan host is finished. |
| 4549 | * |
| 4550 | * Note: there is no scan_start function as adapter initialization will have |
| 4551 | * asynchronously kicked off the link initialization. |
| 4552 | * |
| 4553 | * Return codes |
| 4554 | * 0 - SCSI host scan is not over yet. |
| 4555 | * 1 - SCSI host scan is over. |
| 4556 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4557 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 4558 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4559 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4560 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4561 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4562 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4563 | spin_lock_irq(shost->host_lock); |
| 4564 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4565 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4566 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4567 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4568 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4569 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4570 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4571 | "0461 Scanning longer than 30 " |
| 4572 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4573 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4574 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4575 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4576 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 4577 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4578 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4579 | "0465 Link down longer than 15 " |
| 4580 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4581 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4582 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4583 | } |
| 4584 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4585 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4586 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4587 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4588 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4589 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4590 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4591 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4592 | goto finished; |
| 4593 | |
| 4594 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4595 | |
| 4596 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4597 | spin_unlock_irq(shost->host_lock); |
| 4598 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4599 | } |
| 4600 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 4601 | static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost) |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4602 | { |
| 4603 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; |
| 4604 | struct lpfc_hba *phba = vport->phba; |
| 4605 | |
| 4606 | fc_host_supported_speeds(shost) = 0; |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 4607 | /* |
| 4608 | * Avoid reporting supported link speed for FCoE as it can't be |
| 4609 | * controlled via FCoE. |
| 4610 | */ |
| 4611 | if (phba->hba_flag & HBA_FCOE_MODE) |
| 4612 | return; |
| 4613 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4614 | if (phba->lmt & LMT_128Gb) |
| 4615 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4616 | if (phba->lmt & LMT_64Gb) |
| 4617 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT; |
| 4618 | if (phba->lmt & LMT_32Gb) |
| 4619 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
| 4620 | if (phba->lmt & LMT_16Gb) |
| 4621 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
| 4622 | if (phba->lmt & LMT_10Gb) |
| 4623 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
| 4624 | if (phba->lmt & LMT_8Gb) |
| 4625 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
| 4626 | if (phba->lmt & LMT_4Gb) |
| 4627 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 4628 | if (phba->lmt & LMT_2Gb) |
| 4629 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 4630 | if (phba->lmt & LMT_1Gb) |
| 4631 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 4632 | } |
| 4633 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4634 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4635 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4636 | * @shost: pointer to SCSI host data structure. |
| 4637 | * |
| 4638 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 4639 | * SCSI host can be either on top of a physical port or a virtual port. |
| 4640 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4641 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 4642 | { |
| 4643 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4644 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4645 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4646 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4647 | */ |
| 4648 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4649 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 4650 | 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] | 4651 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 4652 | |
| 4653 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4654 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4655 | fc_host_supported_fc4s(shost)[2] = 1; |
| 4656 | fc_host_supported_fc4s(shost)[7] = 1; |
| 4657 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4658 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 4659 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4660 | |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4661 | lpfc_host_supported_speeds_set(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4662 | |
| 4663 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4664 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 4665 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4666 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 4667 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 4668 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4669 | /* This value is also unchanging */ |
| 4670 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4671 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4672 | fc_host_active_fc4s(shost)[2] = 1; |
| 4673 | fc_host_active_fc4s(shost)[7] = 1; |
| 4674 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4675 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4676 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4677 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4678 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4679 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4680 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4681 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4682 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4683 | * @phba: pointer to lpfc hba data structure. |
| 4684 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4685 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 4686 | * from generating interrupts and stops the device driver's timers for the |
| 4687 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4688 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4689 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4690 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4691 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4692 | /* Clear all interrupt enable conditions */ |
| 4693 | writel(0, phba->HCregaddr); |
| 4694 | readl(phba->HCregaddr); /* flush */ |
| 4695 | /* Clear all pending interrupts */ |
| 4696 | writel(0xffffffff, phba->HAregaddr); |
| 4697 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4698 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4699 | /* Reset some HBA SLI setup states */ |
| 4700 | lpfc_stop_hba_timers(phba); |
| 4701 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4702 | } |
| 4703 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4704 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4705 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4706 | * @phba: pointer to lpfc hba data structure. |
| 4707 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4708 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 4709 | * from generating interrupts and stops the device driver's timers for the |
| 4710 | * device. |
| 4711 | **/ |
| 4712 | static void |
| 4713 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 4714 | { |
| 4715 | /* Reset some HBA SLI4 setup states */ |
| 4716 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4717 | if (phba->pport) |
| 4718 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4719 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | /** |
| 4723 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 4724 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4725 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4726 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 4727 | * the API jump table function pointer from the lpfc_hba struct. |
| 4728 | **/ |
| 4729 | void |
| 4730 | lpfc_stop_port(struct lpfc_hba *phba) |
| 4731 | { |
| 4732 | phba->lpfc_stop_port(phba); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 4733 | |
| 4734 | if (phba->wq) |
| 4735 | flush_workqueue(phba->wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4739 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 4740 | * @phba: Pointer to hba for which this call is being executed. |
| 4741 | * |
| 4742 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 4743 | **/ |
| 4744 | void |
| 4745 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 4746 | { |
| 4747 | unsigned long fcf_redisc_wait_tmo = |
| 4748 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 4749 | /* Start fcf rediscovery wait period timer */ |
| 4750 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 4751 | spin_lock_irq(&phba->hbalock); |
| 4752 | /* Allow action to new fcf asynchronous event */ |
| 4753 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 4754 | /* Mark the FCF rediscovery pending state */ |
| 4755 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 4756 | spin_unlock_irq(&phba->hbalock); |
| 4757 | } |
| 4758 | |
| 4759 | /** |
| 4760 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 4761 | * @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] | 4762 | * |
| 4763 | * This routine is invoked when waiting for FCF table rediscover has been |
| 4764 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 4765 | * wait period, a new FCF event shall be added to the FCOE async event |
| 4766 | * list, and then worker thread shall be waked up for processing from the |
| 4767 | * worker thread context. |
| 4768 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 4769 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4770 | lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4771 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4772 | struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4773 | |
| 4774 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 4775 | spin_lock_irq(&phba->hbalock); |
| 4776 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 4777 | spin_unlock_irq(&phba->hbalock); |
| 4778 | return; |
| 4779 | } |
| 4780 | /* Clear FCF rediscovery timer pending flag */ |
| 4781 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 4782 | /* FCF rediscovery event to worker thread */ |
| 4783 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 4784 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4785 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4786 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4787 | /* wake up worker thread */ |
| 4788 | lpfc_worker_wake_up(phba); |
| 4789 | } |
| 4790 | |
| 4791 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4792 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 4793 | * @phba: pointer to lpfc hba data structure. |
| 4794 | * @acqe_link: pointer to the async link completion queue entry. |
| 4795 | * |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4796 | * This routine is to parse the SLI4 link-attention link fault code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4797 | **/ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4798 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4799 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 4800 | struct lpfc_acqe_link *acqe_link) |
| 4801 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4802 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 4803 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 4804 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 4805 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4806 | case LPFC_ASYNC_LINK_FAULT_LR_LRR: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4807 | break; |
| 4808 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4809 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4810 | "0398 Unknown link fault code: x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4811 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4812 | break; |
| 4813 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | /** |
| 4817 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 4818 | * @phba: pointer to lpfc hba data structure. |
| 4819 | * @acqe_link: pointer to the async link completion queue entry. |
| 4820 | * |
| 4821 | * This routine is to parse the SLI4 link attention type and translate it |
| 4822 | * into the base driver's link attention type coding. |
| 4823 | * |
| 4824 | * Return: Link attention type in terms of base driver's coding. |
| 4825 | **/ |
| 4826 | static uint8_t |
| 4827 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 4828 | struct lpfc_acqe_link *acqe_link) |
| 4829 | { |
| 4830 | uint8_t att_type; |
| 4831 | |
| 4832 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 4833 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 4834 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4835 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4836 | break; |
| 4837 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 4838 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4839 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4840 | break; |
| 4841 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4842 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4843 | break; |
| 4844 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4845 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4846 | "0399 Invalid link attention type: x%x\n", |
| 4847 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4848 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4849 | break; |
| 4850 | } |
| 4851 | return att_type; |
| 4852 | } |
| 4853 | |
| 4854 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4855 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 4856 | * @phba: pointer to lpfc hba data structure. |
| 4857 | * |
| 4858 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 4859 | * |
| 4860 | * Return: link speed in terms of Mbps. |
| 4861 | **/ |
| 4862 | uint32_t |
| 4863 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 4864 | { |
| 4865 | uint32_t link_speed; |
| 4866 | |
| 4867 | if (!lpfc_is_link_up(phba)) |
| 4868 | return 0; |
| 4869 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4870 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 4871 | switch (phba->fc_linkspeed) { |
| 4872 | case LPFC_LINK_SPEED_1GHZ: |
| 4873 | link_speed = 1000; |
| 4874 | break; |
| 4875 | case LPFC_LINK_SPEED_2GHZ: |
| 4876 | link_speed = 2000; |
| 4877 | break; |
| 4878 | case LPFC_LINK_SPEED_4GHZ: |
| 4879 | link_speed = 4000; |
| 4880 | break; |
| 4881 | case LPFC_LINK_SPEED_8GHZ: |
| 4882 | link_speed = 8000; |
| 4883 | break; |
| 4884 | case LPFC_LINK_SPEED_10GHZ: |
| 4885 | link_speed = 10000; |
| 4886 | break; |
| 4887 | case LPFC_LINK_SPEED_16GHZ: |
| 4888 | link_speed = 16000; |
| 4889 | break; |
| 4890 | default: |
| 4891 | link_speed = 0; |
| 4892 | } |
| 4893 | } else { |
| 4894 | if (phba->sli4_hba.link_state.logical_speed) |
| 4895 | link_speed = |
| 4896 | phba->sli4_hba.link_state.logical_speed; |
| 4897 | else |
| 4898 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4899 | } |
| 4900 | return link_speed; |
| 4901 | } |
| 4902 | |
| 4903 | /** |
| 4904 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 4905 | * @phba: pointer to lpfc hba data structure. |
| 4906 | * @evt_code: asynchronous event code. |
| 4907 | * @speed_code: asynchronous event link speed code. |
| 4908 | * |
| 4909 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4910 | * value of Mbps for the link speed. |
| 4911 | * |
| 4912 | * Return: link speed in terms of Mbps. |
| 4913 | **/ |
| 4914 | static uint32_t |
| 4915 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 4916 | uint8_t speed_code) |
| 4917 | { |
| 4918 | uint32_t port_speed; |
| 4919 | |
| 4920 | switch (evt_code) { |
| 4921 | case LPFC_TRAILER_CODE_LINK: |
| 4922 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4923 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4924 | port_speed = 0; |
| 4925 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4926 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4927 | port_speed = 10; |
| 4928 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4929 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4930 | port_speed = 100; |
| 4931 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4932 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4933 | port_speed = 1000; |
| 4934 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4935 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4936 | port_speed = 10000; |
| 4937 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4938 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 4939 | port_speed = 20000; |
| 4940 | break; |
| 4941 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 4942 | port_speed = 25000; |
| 4943 | break; |
| 4944 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 4945 | port_speed = 40000; |
| 4946 | break; |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 4947 | case LPFC_ASYNC_LINK_SPEED_100GBPS: |
| 4948 | port_speed = 100000; |
| 4949 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4950 | default: |
| 4951 | port_speed = 0; |
| 4952 | } |
| 4953 | break; |
| 4954 | case LPFC_TRAILER_CODE_FC: |
| 4955 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4956 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4957 | port_speed = 0; |
| 4958 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4959 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4960 | port_speed = 1000; |
| 4961 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4962 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4963 | port_speed = 2000; |
| 4964 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4965 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4966 | port_speed = 4000; |
| 4967 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4968 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4969 | port_speed = 8000; |
| 4970 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4971 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4972 | port_speed = 10000; |
| 4973 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4974 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4975 | port_speed = 16000; |
| 4976 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4977 | case LPFC_FC_LA_SPEED_32G: |
| 4978 | port_speed = 32000; |
| 4979 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 4980 | case LPFC_FC_LA_SPEED_64G: |
| 4981 | port_speed = 64000; |
| 4982 | break; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4983 | case LPFC_FC_LA_SPEED_128G: |
| 4984 | port_speed = 128000; |
| 4985 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4986 | default: |
| 4987 | port_speed = 0; |
| 4988 | } |
| 4989 | break; |
| 4990 | default: |
| 4991 | port_speed = 0; |
| 4992 | } |
| 4993 | return port_speed; |
| 4994 | } |
| 4995 | |
| 4996 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4997 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4998 | * @phba: pointer to lpfc hba data structure. |
| 4999 | * @acqe_link: pointer to the async link completion queue entry. |
| 5000 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5001 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5002 | **/ |
| 5003 | static void |
| 5004 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 5005 | struct lpfc_acqe_link *acqe_link) |
| 5006 | { |
| 5007 | struct lpfc_dmabuf *mp; |
| 5008 | LPFC_MBOXQ_t *pmb; |
| 5009 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5010 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5011 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5012 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5013 | |
| 5014 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5015 | 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] | 5016 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 5017 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5018 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5019 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5020 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5021 | "0395 The mboxq allocation failed\n"); |
| 5022 | return; |
| 5023 | } |
| 5024 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5025 | if (!mp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5026 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5027 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 5028 | goto out_free_pmb; |
| 5029 | } |
| 5030 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 5031 | if (!mp->virt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5032 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5033 | "0397 The mbuf allocation failed\n"); |
| 5034 | goto out_free_dmabuf; |
| 5035 | } |
| 5036 | |
| 5037 | /* Cleanup any outstanding ELS commands */ |
| 5038 | lpfc_els_flush_all_cmd(phba); |
| 5039 | |
| 5040 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5041 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5042 | |
| 5043 | /* Update link event statistics */ |
| 5044 | phba->sli.slistat.link_event++; |
| 5045 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5046 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5047 | lpfc_read_topology(phba, pmb, mp); |
| 5048 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5049 | pmb->vport = phba->pport; |
| 5050 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5051 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5052 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5053 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 5054 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5055 | phba->sli4_hba.link_state.duplex = |
| 5056 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 5057 | phba->sli4_hba.link_state.status = |
| 5058 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5059 | phba->sli4_hba.link_state.type = |
| 5060 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 5061 | phba->sli4_hba.link_state.number = |
| 5062 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5063 | phba->sli4_hba.link_state.fault = |
| 5064 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 5065 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5066 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 5067 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5068 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 5069 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 5070 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 5071 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5072 | phba->sli4_hba.link_state.speed, |
| 5073 | phba->sli4_hba.link_state.topology, |
| 5074 | phba->sli4_hba.link_state.status, |
| 5075 | phba->sli4_hba.link_state.type, |
| 5076 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5077 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5078 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5079 | /* |
| 5080 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 5081 | * topology info. Note: Optional for non FC-AL ports. |
| 5082 | */ |
| 5083 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 5084 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5085 | if (rc == MBX_NOT_FINISHED) |
| 5086 | goto out_free_dmabuf; |
| 5087 | return; |
| 5088 | } |
| 5089 | /* |
| 5090 | * For FCoE Mode: fill in all the topology information we need and call |
| 5091 | * the READ_TOPOLOGY completion routine to continue without actually |
| 5092 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 5093 | */ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5094 | /* Initialize completion status */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5095 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5096 | mb->mbxStatus = MBX_SUCCESS; |
| 5097 | |
| 5098 | /* Parse port fault information field */ |
| 5099 | lpfc_sli4_parse_latt_fault(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5100 | |
| 5101 | /* Parse and translate link attention fields */ |
| 5102 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 5103 | la->eventTag = acqe_link->event_tag; |
| 5104 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 5105 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5106 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5107 | |
| 5108 | /* Fake the the following irrelvant fields */ |
| 5109 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 5110 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 5111 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 5112 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 5113 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 5114 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5115 | |
| 5116 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5117 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5118 | |
| 5119 | return; |
| 5120 | |
| 5121 | out_free_dmabuf: |
| 5122 | kfree(mp); |
| 5123 | out_free_pmb: |
| 5124 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5125 | } |
| 5126 | |
| 5127 | /** |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5128 | * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read |
| 5129 | * topology. |
| 5130 | * @phba: pointer to lpfc hba data structure. |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5131 | * @speed_code: asynchronous event link speed code. |
| 5132 | * |
| 5133 | * This routine is to parse the giving SLI4 async event link speed code into |
| 5134 | * value of Read topology link speed. |
| 5135 | * |
| 5136 | * Return: link speed in terms of Read topology. |
| 5137 | **/ |
| 5138 | static uint8_t |
| 5139 | lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code) |
| 5140 | { |
| 5141 | uint8_t port_speed; |
| 5142 | |
| 5143 | switch (speed_code) { |
| 5144 | case LPFC_FC_LA_SPEED_1G: |
| 5145 | port_speed = LPFC_LINK_SPEED_1GHZ; |
| 5146 | break; |
| 5147 | case LPFC_FC_LA_SPEED_2G: |
| 5148 | port_speed = LPFC_LINK_SPEED_2GHZ; |
| 5149 | break; |
| 5150 | case LPFC_FC_LA_SPEED_4G: |
| 5151 | port_speed = LPFC_LINK_SPEED_4GHZ; |
| 5152 | break; |
| 5153 | case LPFC_FC_LA_SPEED_8G: |
| 5154 | port_speed = LPFC_LINK_SPEED_8GHZ; |
| 5155 | break; |
| 5156 | case LPFC_FC_LA_SPEED_16G: |
| 5157 | port_speed = LPFC_LINK_SPEED_16GHZ; |
| 5158 | break; |
| 5159 | case LPFC_FC_LA_SPEED_32G: |
| 5160 | port_speed = LPFC_LINK_SPEED_32GHZ; |
| 5161 | break; |
| 5162 | case LPFC_FC_LA_SPEED_64G: |
| 5163 | port_speed = LPFC_LINK_SPEED_64GHZ; |
| 5164 | break; |
| 5165 | case LPFC_FC_LA_SPEED_128G: |
| 5166 | port_speed = LPFC_LINK_SPEED_128GHZ; |
| 5167 | break; |
| 5168 | case LPFC_FC_LA_SPEED_256G: |
| 5169 | port_speed = LPFC_LINK_SPEED_256GHZ; |
| 5170 | break; |
| 5171 | default: |
| 5172 | port_speed = 0; |
| 5173 | break; |
| 5174 | } |
| 5175 | |
| 5176 | return port_speed; |
| 5177 | } |
| 5178 | |
| 5179 | #define trunk_link_status(__idx)\ |
| 5180 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5181 | ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\ |
| 5182 | "Link up" : "Link down") : "NA" |
| 5183 | /* Did port __idx reported an error */ |
| 5184 | #define trunk_port_fault(__idx)\ |
| 5185 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5186 | (port_fault & (1 << __idx) ? "YES" : "NO") : "NA" |
| 5187 | |
| 5188 | static void |
| 5189 | lpfc_update_trunk_link_status(struct lpfc_hba *phba, |
| 5190 | struct lpfc_acqe_fc_la *acqe_fc) |
| 5191 | { |
| 5192 | uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc); |
| 5193 | uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc); |
| 5194 | |
| 5195 | phba->sli4_hba.link_state.speed = |
| 5196 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5197 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5198 | |
| 5199 | phba->sli4_hba.link_state.logical_speed = |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5200 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5201 | /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */ |
| 5202 | phba->fc_linkspeed = |
| 5203 | lpfc_async_link_speed_to_read_top( |
| 5204 | phba, |
| 5205 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5206 | |
| 5207 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) { |
| 5208 | phba->trunk_link.link0.state = |
| 5209 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc) |
| 5210 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5211 | phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5212 | } |
| 5213 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) { |
| 5214 | phba->trunk_link.link1.state = |
| 5215 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc) |
| 5216 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5217 | phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5218 | } |
| 5219 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) { |
| 5220 | phba->trunk_link.link2.state = |
| 5221 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc) |
| 5222 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5223 | phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5224 | } |
| 5225 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) { |
| 5226 | phba->trunk_link.link3.state = |
| 5227 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc) |
| 5228 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5229 | phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5230 | } |
| 5231 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5232 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5233 | "2910 Async FC Trunking Event - Speed:%d\n" |
| 5234 | "\tLogical speed:%d " |
| 5235 | "port0: %s port1: %s port2: %s port3: %s\n", |
| 5236 | phba->sli4_hba.link_state.speed, |
| 5237 | phba->sli4_hba.link_state.logical_speed, |
| 5238 | trunk_link_status(0), trunk_link_status(1), |
| 5239 | trunk_link_status(2), trunk_link_status(3)); |
| 5240 | |
| 5241 | if (port_fault) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5242 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5243 | "3202 trunk error:0x%x (%s) seen on port0:%s " |
| 5244 | /* |
| 5245 | * SLI-4: We have only 0xA error codes |
| 5246 | * defined as of now. print an appropriate |
| 5247 | * message in case driver needs to be updated. |
| 5248 | */ |
| 5249 | "port1:%s port2:%s port3:%s\n", err, err > 0xA ? |
| 5250 | "UNDEFINED. update driver." : trunk_errmsg[err], |
| 5251 | trunk_port_fault(0), trunk_port_fault(1), |
| 5252 | trunk_port_fault(2), trunk_port_fault(3)); |
| 5253 | } |
| 5254 | |
| 5255 | |
| 5256 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5257 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 5258 | * @phba: pointer to lpfc hba data structure. |
| 5259 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 5260 | * |
| 5261 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 5262 | * that the event was received and then issue a read_topology mailbox command so |
| 5263 | * that the rest of the driver will treat it the same as SLI3. |
| 5264 | **/ |
| 5265 | static void |
| 5266 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 5267 | { |
| 5268 | struct lpfc_dmabuf *mp; |
| 5269 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5270 | MAILBOX_t *mb; |
| 5271 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5272 | int rc; |
| 5273 | |
| 5274 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 5275 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5276 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5277 | "2895 Non FC link Event detected.(%d)\n", |
| 5278 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 5279 | return; |
| 5280 | } |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5281 | |
| 5282 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5283 | LPFC_FC_LA_TYPE_TRUNKING_EVENT) { |
| 5284 | lpfc_update_trunk_link_status(phba, acqe_fc); |
| 5285 | return; |
| 5286 | } |
| 5287 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5288 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5289 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5290 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5291 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5292 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 5293 | phba->sli4_hba.link_state.topology = |
| 5294 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 5295 | phba->sli4_hba.link_state.status = |
| 5296 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 5297 | phba->sli4_hba.link_state.type = |
| 5298 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 5299 | phba->sli4_hba.link_state.number = |
| 5300 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 5301 | phba->sli4_hba.link_state.fault = |
| 5302 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5303 | |
| 5304 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5305 | LPFC_FC_LA_TYPE_LINK_DOWN) |
| 5306 | phba->sli4_hba.link_state.logical_speed = 0; |
| 5307 | else if (!phba->sli4_hba.conf_trunk) |
| 5308 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5309 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5310 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5311 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5312 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 5313 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 5314 | "%dMbps Fault:%d\n", |
| 5315 | phba->sli4_hba.link_state.speed, |
| 5316 | phba->sli4_hba.link_state.topology, |
| 5317 | phba->sli4_hba.link_state.status, |
| 5318 | phba->sli4_hba.link_state.type, |
| 5319 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5320 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5321 | phba->sli4_hba.link_state.fault); |
| 5322 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5323 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5324 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5325 | "2897 The mboxq allocation failed\n"); |
| 5326 | return; |
| 5327 | } |
| 5328 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5329 | if (!mp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5330 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5331 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 5332 | goto out_free_pmb; |
| 5333 | } |
| 5334 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 5335 | if (!mp->virt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5336 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5337 | "2899 The mbuf allocation failed\n"); |
| 5338 | goto out_free_dmabuf; |
| 5339 | } |
| 5340 | |
| 5341 | /* Cleanup any outstanding ELS commands */ |
| 5342 | lpfc_els_flush_all_cmd(phba); |
| 5343 | |
| 5344 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5345 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5346 | |
| 5347 | /* Update link event statistics */ |
| 5348 | phba->sli.slistat.link_event++; |
| 5349 | |
| 5350 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5351 | lpfc_read_topology(phba, pmb, mp); |
| 5352 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 5353 | pmb->vport = phba->pport; |
| 5354 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5355 | 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] | 5356 | phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK); |
| 5357 | |
| 5358 | switch (phba->sli4_hba.link_state.status) { |
| 5359 | case LPFC_FC_LA_TYPE_MDS_LINK_DOWN: |
| 5360 | phba->link_flag |= LS_MDS_LINK_DOWN; |
| 5361 | break; |
| 5362 | case LPFC_FC_LA_TYPE_MDS_LOOPBACK: |
| 5363 | phba->link_flag |= LS_MDS_LOOPBACK; |
| 5364 | break; |
| 5365 | default: |
| 5366 | break; |
| 5367 | } |
| 5368 | |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5369 | /* Initialize completion status */ |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5370 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5371 | mb->mbxStatus = MBX_SUCCESS; |
| 5372 | |
| 5373 | /* Parse port fault information field */ |
| 5374 | lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5375 | |
| 5376 | /* Parse and translate link attention fields */ |
| 5377 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 5378 | la->eventTag = acqe_fc->event_tag; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5379 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 5380 | if (phba->sli4_hba.link_state.status == |
| 5381 | LPFC_FC_LA_TYPE_UNEXP_WWPN) { |
| 5382 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5383 | LPFC_FC_LA_TYPE_UNEXP_WWPN); |
| 5384 | } else { |
| 5385 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5386 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 5387 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5388 | /* Invoke the mailbox command callback function */ |
| 5389 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 5390 | |
| 5391 | return; |
| 5392 | } |
| 5393 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5394 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5395 | if (rc == MBX_NOT_FINISHED) |
| 5396 | goto out_free_dmabuf; |
| 5397 | return; |
| 5398 | |
| 5399 | out_free_dmabuf: |
| 5400 | kfree(mp); |
| 5401 | out_free_pmb: |
| 5402 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5403 | } |
| 5404 | |
| 5405 | /** |
| 5406 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 5407 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5408 | * @acqe_sli: pointer to the async SLI completion queue entry. |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5409 | * |
| 5410 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 5411 | **/ |
| 5412 | static void |
| 5413 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 5414 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5415 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 5416 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5417 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5418 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5419 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5420 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5421 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5422 | struct Scsi_Host *shost; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5423 | struct lpfc_vport **vports; |
| 5424 | int rc, i; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5425 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5426 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 5427 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5428 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5429 | "2901 Async SLI event - Type:%d, Event Data: x%08x " |
| 5430 | "x%08x x%08x x%08x\n", evt_type, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5431 | acqe_sli->event_data1, acqe_sli->event_data2, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5432 | acqe_sli->reserved, acqe_sli->trailer); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5433 | |
| 5434 | port_name = phba->Port[0]; |
| 5435 | if (port_name == 0x00) |
| 5436 | port_name = '?'; /* get port name is empty */ |
| 5437 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5438 | switch (evt_type) { |
| 5439 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 5440 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5441 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 5442 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5443 | |
| 5444 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5445 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 5446 | acqe_sli->event_data1, port_name); |
| 5447 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5448 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5449 | shost = lpfc_shost_from_vport(phba->pport); |
| 5450 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5451 | sizeof(temp_event_data), |
| 5452 | (char *)&temp_event_data, |
| 5453 | SCSI_NL_VID_TYPE_PCI |
| 5454 | | PCI_VENDOR_ID_EMULEX); |
| 5455 | break; |
| 5456 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 5457 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5458 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 5459 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5460 | |
| 5461 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5462 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 5463 | acqe_sli->event_data1, port_name); |
| 5464 | |
| 5465 | shost = lpfc_shost_from_vport(phba->pport); |
| 5466 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5467 | sizeof(temp_event_data), |
| 5468 | (char *)&temp_event_data, |
| 5469 | SCSI_NL_VID_TYPE_PCI |
| 5470 | | PCI_VENDOR_ID_EMULEX); |
| 5471 | break; |
| 5472 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 5473 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5474 | &acqe_sli->event_data1; |
| 5475 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5476 | /* fetch the status for this port */ |
| 5477 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5478 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5479 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 5480 | &misconfigured->theEvent); |
| 5481 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5482 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5483 | break; |
| 5484 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5485 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 5486 | &misconfigured->theEvent); |
| 5487 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5488 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5489 | break; |
| 5490 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5491 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 5492 | &misconfigured->theEvent); |
| 5493 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5494 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5495 | break; |
| 5496 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5497 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 5498 | &misconfigured->theEvent); |
| 5499 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5500 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5501 | break; |
| 5502 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5503 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5504 | "3296 " |
| 5505 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 5506 | "event: Invalid link %d", |
| 5507 | phba->sli4_hba.lnk_info.lnk_no); |
| 5508 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5509 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5510 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5511 | /* Skip if optic state unchanged */ |
| 5512 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 5513 | return; |
| 5514 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5515 | switch (status) { |
| 5516 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5517 | sprintf(message, "Physical Link is functional"); |
| 5518 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5519 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 5520 | sprintf(message, "Optics faulted/incorrectly " |
| 5521 | "installed/not installed - Reseat optics, " |
| 5522 | "if issue not resolved, replace."); |
| 5523 | break; |
| 5524 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 5525 | sprintf(message, |
| 5526 | "Optics of two types installed - Remove one " |
| 5527 | "optic or install matching pair of optics."); |
| 5528 | break; |
| 5529 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 5530 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 5531 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5532 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5533 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 5534 | sprintf(message, "Unqualified optics - Replace with " |
| 5535 | "Avago optics for Warranty and Technical " |
| 5536 | "Support - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5537 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5538 | break; |
| 5539 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 5540 | sprintf(message, "Uncertified optics - Replace with " |
| 5541 | "Avago-certified optics to enable link " |
| 5542 | "operation - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5543 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5544 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5545 | default: |
| 5546 | /* firmware is reporting a status we don't know about */ |
| 5547 | sprintf(message, "Unknown event status x%02x", status); |
| 5548 | break; |
| 5549 | } |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5550 | |
| 5551 | /* Issue READ_CONFIG mbox command to refresh supported speeds */ |
| 5552 | rc = lpfc_sli4_read_config(phba); |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5553 | if (rc) { |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5554 | phba->lmt = 0; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5555 | lpfc_printf_log(phba, KERN_ERR, |
| 5556 | LOG_TRACE_EVENT, |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5557 | "3194 Unable to retrieve supported " |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5558 | "speeds, rc = 0x%x\n", rc); |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5559 | } |
| 5560 | vports = lpfc_create_vport_work_array(phba); |
| 5561 | if (vports != NULL) { |
| 5562 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5563 | i++) { |
| 5564 | shost = lpfc_shost_from_vport(vports[i]); |
| 5565 | lpfc_host_supported_speeds_set(shost); |
| 5566 | } |
| 5567 | } |
| 5568 | lpfc_destroy_vport_work_array(phba, vports); |
| 5569 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5570 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5571 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5572 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5573 | break; |
| 5574 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 5575 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5576 | "3192 Remote DPort Test Initiated - " |
| 5577 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 5578 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5579 | break; |
James Smart | e7d8595 | 2019-10-18 14:18:29 -0700 | [diff] [blame] | 5580 | case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN: |
| 5581 | /* Misconfigured WWN. Reports that the SLI Port is configured |
| 5582 | * to use FA-WWN, but the attached device doesn’t support it. |
| 5583 | * No driver action is required. |
| 5584 | * Event Data1 - N.A, Event Data2 - N.A |
| 5585 | */ |
| 5586 | lpfc_log_msg(phba, KERN_WARNING, LOG_SLI, |
| 5587 | "2699 Misconfigured FA-WWN - Attached device does " |
| 5588 | "not support FA-WWN\n"); |
| 5589 | break; |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5590 | case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE: |
| 5591 | /* EEPROM failure. No driver action is required */ |
| 5592 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5593 | "2518 EEPROM failure - " |
| 5594 | "Event Data1: x%08x Event Data2: x%08x\n", |
| 5595 | acqe_sli->event_data1, acqe_sli->event_data2); |
| 5596 | break; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5597 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5598 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5599 | "3193 Unrecognized SLI event, type: 0x%x", |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5600 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5601 | break; |
| 5602 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5606 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 5607 | * @vport: pointer to vport data structure. |
| 5608 | * |
| 5609 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 5610 | * response to a CVL event. |
| 5611 | * |
| 5612 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 5613 | * return NULL. |
| 5614 | **/ |
| 5615 | static struct lpfc_nodelist * |
| 5616 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 5617 | { |
| 5618 | struct lpfc_nodelist *ndlp; |
| 5619 | struct Scsi_Host *shost; |
| 5620 | struct lpfc_hba *phba; |
| 5621 | |
| 5622 | if (!vport) |
| 5623 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5624 | phba = vport->phba; |
| 5625 | if (!phba) |
| 5626 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5627 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 5628 | if (!ndlp) { |
| 5629 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5630 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5631 | if (!ndlp) |
| 5632 | return 0; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5633 | /* Set the node type */ |
| 5634 | ndlp->nlp_type |= NLP_FABRIC; |
| 5635 | /* Put ndlp onto node list */ |
| 5636 | lpfc_enqueue_node(vport, ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5637 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5638 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 5639 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5640 | return NULL; |
| 5641 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5642 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 5643 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5644 | return NULL; |
| 5645 | shost = lpfc_shost_from_vport(vport); |
| 5646 | if (!shost) |
| 5647 | return NULL; |
| 5648 | lpfc_linkdown_port(vport); |
| 5649 | lpfc_cleanup_pending_mbox(vport); |
| 5650 | spin_lock_irq(shost->host_lock); |
| 5651 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 5652 | spin_unlock_irq(shost->host_lock); |
| 5653 | |
| 5654 | return ndlp; |
| 5655 | } |
| 5656 | |
| 5657 | /** |
| 5658 | * 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] | 5659 | * @phba: pointer to lpfc hba data structure. |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5660 | * |
| 5661 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 5662 | * response to a FCF dead event. |
| 5663 | **/ |
| 5664 | static void |
| 5665 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 5666 | { |
| 5667 | struct lpfc_vport **vports; |
| 5668 | int i; |
| 5669 | |
| 5670 | vports = lpfc_create_vport_work_array(phba); |
| 5671 | if (vports) |
| 5672 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 5673 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 5674 | lpfc_destroy_vport_work_array(phba, vports); |
| 5675 | } |
| 5676 | |
| 5677 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5678 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5679 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5680 | * @acqe_fip: pointer to the async fcoe completion queue entry. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5681 | * |
| 5682 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 5683 | **/ |
| 5684 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5685 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5686 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5687 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5688 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5689 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5690 | struct lpfc_vport *vport; |
| 5691 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5692 | int active_vlink_present; |
| 5693 | struct lpfc_vport **vports; |
| 5694 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5695 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5696 | phba->fc_eventTag = acqe_fip->event_tag; |
| 5697 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5698 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5699 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 5700 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 5701 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5702 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5703 | "2546 New FCF event, evt_tag:x%x, " |
| 5704 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5705 | acqe_fip->event_tag, |
| 5706 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5707 | else |
| 5708 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 5709 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5710 | "2788 FCF param modified event, " |
| 5711 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5712 | acqe_fip->event_tag, |
| 5713 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5714 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5715 | /* |
| 5716 | * During period of FCF discovery, read the FCF |
| 5717 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5718 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5719 | */ |
| 5720 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5721 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5722 | "2779 Read FCF (x%x) for updating " |
| 5723 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5724 | acqe_fip->index); |
| 5725 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5726 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5727 | |
| 5728 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5729 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5730 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5731 | spin_unlock_irq(&phba->hbalock); |
| 5732 | break; |
| 5733 | } |
| 5734 | /* If fast FCF failover rescan event is pending, do nothing */ |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 5735 | if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5736 | spin_unlock_irq(&phba->hbalock); |
| 5737 | break; |
| 5738 | } |
| 5739 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5740 | /* If the FCF has been in discovered state, do nothing. */ |
| 5741 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5742 | spin_unlock_irq(&phba->hbalock); |
| 5743 | break; |
| 5744 | } |
| 5745 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5746 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5747 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 5748 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5749 | "2770 Start FCF table scan per async FCF " |
| 5750 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5751 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5752 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 5753 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5754 | if (rc) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5755 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5756 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5757 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5758 | break; |
| 5759 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5760 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5761 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 5762 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
| 5763 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 5764 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5765 | break; |
| 5766 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5767 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5768 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5769 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 5770 | "2549 FCF (x%x) disconnected from network, " |
| 5771 | "tag:x%x\n", acqe_fip->index, |
| 5772 | acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5773 | /* |
| 5774 | * If we are in the middle of FCF failover process, clear |
| 5775 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5776 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5777 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame] | 5778 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 5779 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5780 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5781 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5782 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5783 | break; |
| 5784 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5785 | spin_unlock_irq(&phba->hbalock); |
| 5786 | |
| 5787 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5788 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5789 | break; |
| 5790 | |
| 5791 | /* |
| 5792 | * Otherwise, request the port to rediscover the entire FCF |
| 5793 | * table for a fast recovery from case that the current FCF |
| 5794 | * is no longer valid as we are not in the middle of FCF |
| 5795 | * failover process already. |
| 5796 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5797 | spin_lock_irq(&phba->hbalock); |
| 5798 | /* Mark the fast failover process in progress */ |
| 5799 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 5800 | spin_unlock_irq(&phba->hbalock); |
| 5801 | |
| 5802 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 5803 | "2771 Start FCF fast failover process due to " |
| 5804 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 5805 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 5806 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 5807 | if (rc) { |
| 5808 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5809 | LOG_TRACE_EVENT, |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5810 | "2772 Issue FCF rediscover mailbox " |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5811 | "command failed, fail through to FCF " |
| 5812 | "dead event\n"); |
| 5813 | spin_lock_irq(&phba->hbalock); |
| 5814 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 5815 | spin_unlock_irq(&phba->hbalock); |
| 5816 | /* |
| 5817 | * Last resort will fail over by treating this |
| 5818 | * as a link down to FCF registration. |
| 5819 | */ |
| 5820 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 5821 | } else { |
| 5822 | /* Reset FCF roundrobin bmask for new discovery */ |
| 5823 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 5824 | /* |
| 5825 | * Handling fast FCF failover to a DEAD FCF event is |
| 5826 | * considered equalivant to receiving CVL to all vports. |
| 5827 | */ |
| 5828 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 5829 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5830 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5831 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5832 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5833 | lpfc_printf_log(phba, KERN_ERR, |
| 5834 | LOG_TRACE_EVENT, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5835 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5836 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5837 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5838 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5839 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5840 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5841 | if (!ndlp) |
| 5842 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5843 | active_vlink_present = 0; |
| 5844 | |
| 5845 | vports = lpfc_create_vport_work_array(phba); |
| 5846 | if (vports) { |
| 5847 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5848 | i++) { |
| 5849 | if ((!(vports[i]->fc_flag & |
| 5850 | FC_VPORT_CVL_RCVD)) && |
| 5851 | (vports[i]->port_state > LPFC_FDISC)) { |
| 5852 | active_vlink_present = 1; |
| 5853 | break; |
| 5854 | } |
| 5855 | } |
| 5856 | lpfc_destroy_vport_work_array(phba, vports); |
| 5857 | } |
| 5858 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 5859 | /* |
| 5860 | * Don't re-instantiate if vport is marked for deletion. |
| 5861 | * If we are here first then vport_delete is going to wait |
| 5862 | * for discovery to complete. |
| 5863 | */ |
| 5864 | if (!(vport->load_flag & FC_UNLOADING) && |
| 5865 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5866 | /* |
| 5867 | * If there are other active VLinks present, |
| 5868 | * re-instantiate the Vlink using FDISC. |
| 5869 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 5870 | mod_timer(&ndlp->nlp_delayfunc, |
| 5871 | jiffies + msecs_to_jiffies(1000)); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5872 | spin_lock_irq(&ndlp->lock); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5873 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5874 | spin_unlock_irq(&ndlp->lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5875 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 5876 | vport->port_state = LPFC_FDISC; |
| 5877 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5878 | /* |
| 5879 | * Otherwise, we request port to rediscover |
| 5880 | * the entire FCF table for a fast recovery |
| 5881 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5882 | * is no longer valid if we are not already |
| 5883 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5884 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5885 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5886 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5887 | spin_unlock_irq(&phba->hbalock); |
| 5888 | break; |
| 5889 | } |
| 5890 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5891 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5892 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5893 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5894 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5895 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5896 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5897 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5898 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5899 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5900 | LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5901 | "2774 Issue FCF rediscover " |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5902 | "mailbox command failed, " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5903 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5904 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5905 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5906 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5907 | /* |
| 5908 | * Last resort will be re-try on the |
| 5909 | * the current registered FCF entry. |
| 5910 | */ |
| 5911 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5912 | } else |
| 5913 | /* |
| 5914 | * Reset FCF roundrobin bmask for new |
| 5915 | * discovery. |
| 5916 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 5917 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5918 | } |
| 5919 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5920 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5921 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 5922 | "0288 Unknown FCoE event type 0x%x event tag " |
| 5923 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5924 | break; |
| 5925 | } |
| 5926 | } |
| 5927 | |
| 5928 | /** |
| 5929 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 5930 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5931 | * @acqe_dcbx: pointer to the async dcbx completion queue entry. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5932 | * |
| 5933 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 5934 | **/ |
| 5935 | static void |
| 5936 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 5937 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 5938 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5939 | phba->fc_eventTag = acqe_dcbx->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5940 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5941 | "0290 The SLI4 DCBX asynchronous event is not " |
| 5942 | "handled yet\n"); |
| 5943 | } |
| 5944 | |
| 5945 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5946 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 5947 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5948 | * @acqe_grp5: pointer to the async grp5 completion queue entry. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5949 | * |
| 5950 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 5951 | * is an asynchronous notified of a logical link speed change. The Port |
| 5952 | * reports the logical link speed in units of 10Mbps. |
| 5953 | **/ |
| 5954 | static void |
| 5955 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 5956 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 5957 | { |
| 5958 | uint16_t prev_ll_spd; |
| 5959 | |
| 5960 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 5961 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 5962 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 5963 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5964 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5965 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5966 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5967 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 5968 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5972 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 5973 | * @phba: pointer to lpfc hba data structure. |
| 5974 | * |
| 5975 | * This routine is invoked by the worker thread to process all the pending |
| 5976 | * SLI4 asynchronous events. |
| 5977 | **/ |
| 5978 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 5979 | { |
| 5980 | struct lpfc_cq_event *cq_event; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5981 | unsigned long iflags; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5982 | |
| 5983 | /* First, declare the async event has been handled */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5984 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5985 | phba->hba_flag &= ~ASYNC_EVENT; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5986 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 5987 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5988 | /* Now, handle all the async events */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5989 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5990 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5991 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 5992 | cq_event, struct lpfc_cq_event, list); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5993 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, |
| 5994 | iflags); |
| 5995 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5996 | /* Process the asynchronous event */ |
| 5997 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 5998 | case LPFC_TRAILER_CODE_LINK: |
| 5999 | lpfc_sli4_async_link_evt(phba, |
| 6000 | &cq_event->cqe.acqe_link); |
| 6001 | break; |
| 6002 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6003 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6004 | break; |
| 6005 | case LPFC_TRAILER_CODE_DCBX: |
| 6006 | lpfc_sli4_async_dcbx_evt(phba, |
| 6007 | &cq_event->cqe.acqe_dcbx); |
| 6008 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 6009 | case LPFC_TRAILER_CODE_GRP5: |
| 6010 | lpfc_sli4_async_grp5_evt(phba, |
| 6011 | &cq_event->cqe.acqe_grp5); |
| 6012 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6013 | case LPFC_TRAILER_CODE_FC: |
| 6014 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 6015 | break; |
| 6016 | case LPFC_TRAILER_CODE_SLI: |
| 6017 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 6018 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6019 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6020 | lpfc_printf_log(phba, KERN_ERR, |
| 6021 | LOG_TRACE_EVENT, |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 6022 | "1804 Invalid asynchronous event code: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6023 | "x%x\n", bf_get(lpfc_trailer_code, |
| 6024 | &cq_event->cqe.mcqe_cmpl)); |
| 6025 | break; |
| 6026 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6027 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6028 | /* Free the completion event processed to the free pool */ |
| 6029 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6030 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6031 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6032 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6033 | } |
| 6034 | |
| 6035 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6036 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 6037 | * @phba: pointer to lpfc hba data structure. |
| 6038 | * |
| 6039 | * This routine is invoked by the worker thread to process FCF table |
| 6040 | * rediscovery pending completion event. |
| 6041 | **/ |
| 6042 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 6043 | { |
| 6044 | int rc; |
| 6045 | |
| 6046 | spin_lock_irq(&phba->hbalock); |
| 6047 | /* Clear FCF rediscovery timeout event */ |
| 6048 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 6049 | /* Clear driver fast failover FCF record flag */ |
| 6050 | phba->fcf.failover_rec.flag = 0; |
| 6051 | /* Set state for FCF fast failover */ |
| 6052 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 6053 | spin_unlock_irq(&phba->hbalock); |
| 6054 | |
| 6055 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6056 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6057 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6058 | 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] | 6059 | if (rc) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6060 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6061 | "2747 Issue FCF scan read FCF mailbox " |
| 6062 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6063 | } |
| 6064 | |
| 6065 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6066 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 6067 | * @phba: pointer to lpfc hba data structure. |
| 6068 | * @dev_grp: The HBA PCI-Device group number. |
| 6069 | * |
| 6070 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 6071 | * API jump table entries. |
| 6072 | * |
| 6073 | * Return: 0 if success, otherwise -ENODEV |
| 6074 | **/ |
| 6075 | int |
| 6076 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6077 | { |
| 6078 | int rc; |
| 6079 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6080 | /* Set up lpfc PCI-device group */ |
| 6081 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6082 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6083 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 6084 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 6085 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6086 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6087 | /* Set up device INIT API function jump table */ |
| 6088 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 6089 | if (rc) |
| 6090 | return -ENODEV; |
| 6091 | /* Set up SCSI API function jump table */ |
| 6092 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 6093 | if (rc) |
| 6094 | return -ENODEV; |
| 6095 | /* Set up SLI API function jump table */ |
| 6096 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 6097 | if (rc) |
| 6098 | return -ENODEV; |
| 6099 | /* Set up MBOX API function jump table */ |
| 6100 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 6101 | if (rc) |
| 6102 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6103 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6104 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6105 | } |
| 6106 | |
| 6107 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6108 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6109 | * @phba: pointer to lpfc hba data structure. |
| 6110 | * @intr_mode: active interrupt mode adopted. |
| 6111 | * |
| 6112 | * This routine it invoked to log the currently used active interrupt mode |
| 6113 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6114 | **/ |
| 6115 | 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] | 6116 | { |
| 6117 | switch (intr_mode) { |
| 6118 | case 0: |
| 6119 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6120 | "0470 Enable INTx interrupt mode.\n"); |
| 6121 | break; |
| 6122 | case 1: |
| 6123 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6124 | "0481 Enabled MSI interrupt mode.\n"); |
| 6125 | break; |
| 6126 | case 2: |
| 6127 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6128 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 6129 | break; |
| 6130 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6131 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6132 | "0482 Illegal interrupt mode.\n"); |
| 6133 | break; |
| 6134 | } |
| 6135 | return; |
| 6136 | } |
| 6137 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6138 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6139 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6140 | * @phba: pointer to lpfc hba data structure. |
| 6141 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6142 | * This routine is invoked to enable the PCI device that is common to all |
| 6143 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6144 | * |
| 6145 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6146 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6147 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6148 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6149 | static int |
| 6150 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6151 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6152 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6153 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6154 | /* Obtain PCI device reference */ |
| 6155 | if (!phba->pcidev) |
| 6156 | goto out_error; |
| 6157 | else |
| 6158 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6159 | /* Enable PCI device */ |
| 6160 | if (pci_enable_device_mem(pdev)) |
| 6161 | goto out_error; |
| 6162 | /* Request PCI resource for the device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6163 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6164 | goto out_disable_device; |
| 6165 | /* Set up device as PCI master and save state for EEH */ |
| 6166 | pci_set_master(pdev); |
| 6167 | pci_try_set_mwi(pdev); |
| 6168 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6169 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6170 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 6171 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6172 | pdev->needs_freset = 1; |
| 6173 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6174 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6175 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6176 | out_disable_device: |
| 6177 | pci_disable_device(pdev); |
| 6178 | out_error: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6179 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6180 | "1401 Failed to enable pci device\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6181 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6182 | } |
| 6183 | |
| 6184 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6185 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6186 | * @phba: pointer to lpfc hba data structure. |
| 6187 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6188 | * This routine is invoked to disable the PCI device that is common to all |
| 6189 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6190 | **/ |
| 6191 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6192 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6193 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6194 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6195 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6196 | /* Obtain PCI device reference */ |
| 6197 | if (!phba->pcidev) |
| 6198 | return; |
| 6199 | else |
| 6200 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6201 | /* Release PCI resource and disable PCI device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6202 | pci_release_mem_regions(pdev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6203 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6204 | |
| 6205 | return; |
| 6206 | } |
| 6207 | |
| 6208 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6209 | * lpfc_reset_hba - Reset a hba |
| 6210 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6211 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6212 | * This routine is invoked to reset a hba device. It brings the HBA |
| 6213 | * offline, performs a board restart, and then brings the board back |
| 6214 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 6215 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6216 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6217 | void |
| 6218 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6219 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6220 | /* If resets are disabled then set error state and return. */ |
| 6221 | if (!phba->cfg_enable_hba_reset) { |
| 6222 | phba->link_state = LPFC_HBA_ERROR; |
| 6223 | return; |
| 6224 | } |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 6225 | |
| 6226 | /* If not LPFC_SLI_ACTIVE, force all IO to be flushed */ |
| 6227 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6228 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 6229 | } else { |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6230 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 6231 | lpfc_sli_flush_io_rings(phba); |
| 6232 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6233 | lpfc_offline(phba); |
| 6234 | lpfc_sli_brdrestart(phba); |
| 6235 | lpfc_online(phba); |
| 6236 | lpfc_unblock_mgmt_io(phba); |
| 6237 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6238 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6239 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6240 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 6241 | * @phba: pointer to lpfc hba data structure. |
| 6242 | * |
| 6243 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6244 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6245 | * enable the number of virtual functions to the physical function. As |
| 6246 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6247 | * API call does not considered as an error condition for most of the device. |
| 6248 | **/ |
| 6249 | uint16_t |
| 6250 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 6251 | { |
| 6252 | struct pci_dev *pdev = phba->pcidev; |
| 6253 | uint16_t nr_virtfn; |
| 6254 | int pos; |
| 6255 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6256 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 6257 | if (pos == 0) |
| 6258 | return 0; |
| 6259 | |
| 6260 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 6261 | return nr_virtfn; |
| 6262 | } |
| 6263 | |
| 6264 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6265 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 6266 | * @phba: pointer to lpfc hba data structure. |
| 6267 | * @nr_vfn: number of virtual functions to be enabled. |
| 6268 | * |
| 6269 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6270 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6271 | * enable the number of virtual functions to the physical function. As |
| 6272 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6273 | * API call does not considered as an error condition for most of the device. |
| 6274 | **/ |
| 6275 | int |
| 6276 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 6277 | { |
| 6278 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6279 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6280 | int rc; |
| 6281 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6282 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 6283 | if (nr_vfn > max_nr_vfn) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6284 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6285 | "3057 Requested vfs (%d) greater than " |
| 6286 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 6287 | return -EINVAL; |
| 6288 | } |
| 6289 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6290 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 6291 | if (rc) { |
| 6292 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6293 | "2806 Failed to enable sriov on this device " |
| 6294 | "with vfn number nr_vf:%d, rc:%d\n", |
| 6295 | nr_vfn, rc); |
| 6296 | } else |
| 6297 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6298 | "2807 Successful enable sriov on this device " |
| 6299 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 6300 | return rc; |
| 6301 | } |
| 6302 | |
| 6303 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6304 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6305 | * @phba: pointer to lpfc hba data structure. |
| 6306 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6307 | * This routine is invoked to set up the driver internal resources before the |
| 6308 | * device specific resource setup to support the HBA device it attached to. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6309 | * |
| 6310 | * Return codes |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6311 | * 0 - successful |
| 6312 | * other values - error |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6313 | **/ |
| 6314 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6315 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6316 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6317 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6318 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6319 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6320 | * Driver resources common to all SLI revisions |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6321 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6322 | atomic_set(&phba->fast_event_count, 0); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6323 | atomic_set(&phba->dbg_log_idx, 0); |
| 6324 | atomic_set(&phba->dbg_log_cnt, 0); |
| 6325 | atomic_set(&phba->dbg_log_dmping, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6326 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6327 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6328 | /* Initialize port_list spinlock */ |
| 6329 | spin_lock_init(&phba->port_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6330 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6331 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6332 | INIT_LIST_HEAD(&phba->work_list); |
| 6333 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| 6334 | |
| 6335 | /* Initialize the wait queue head for the kernel thread */ |
| 6336 | init_waitqueue_head(&phba->work_waitq); |
| 6337 | |
| 6338 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6339 | "1403 Protocols supported %s %s %s\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6340 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
| 6341 | "SCSI" : " "), |
| 6342 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6343 | "NVME" : " "), |
| 6344 | (phba->nvmet_support ? "NVMET" : " ")); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6345 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6346 | /* Initialize the IO buffer list used by driver for SLI3 SCSI */ |
| 6347 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 6348 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 6349 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 6350 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6351 | |
| 6352 | /* Initialize the fabric iocb list */ |
| 6353 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 6354 | |
| 6355 | /* Initialize list to save ELS buffers */ |
| 6356 | INIT_LIST_HEAD(&phba->elsbuf); |
| 6357 | |
| 6358 | /* Initialize FCF connection rec list */ |
| 6359 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| 6360 | |
| 6361 | /* Initialize OAS configuration list */ |
| 6362 | spin_lock_init(&phba->devicelock); |
| 6363 | INIT_LIST_HEAD(&phba->luns); |
| 6364 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6365 | /* MBOX heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6366 | timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6367 | /* Fabric block timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6368 | timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6369 | /* EA polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6370 | timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6371 | /* Heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6372 | timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6373 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6374 | INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work); |
| 6375 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 6376 | INIT_DELAYED_WORK(&phba->idle_stat_delay_work, |
| 6377 | lpfc_idle_stat_delay_work); |
| 6378 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6379 | return 0; |
| 6380 | } |
| 6381 | |
| 6382 | /** |
| 6383 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev |
| 6384 | * @phba: pointer to lpfc hba data structure. |
| 6385 | * |
| 6386 | * This routine is invoked to set up the driver internal resources specific to |
| 6387 | * support the SLI-3 HBA device it attached to. |
| 6388 | * |
| 6389 | * Return codes |
| 6390 | * 0 - successful |
| 6391 | * other values - error |
| 6392 | **/ |
| 6393 | static int |
| 6394 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 6395 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6396 | int rc, entry_sz; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6397 | |
| 6398 | /* |
| 6399 | * Initialize timers used by driver |
| 6400 | */ |
| 6401 | |
| 6402 | /* FCP polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6403 | timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6404 | |
| 6405 | /* Host attention work mask setup */ |
| 6406 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 6407 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 6408 | |
| 6409 | /* Get all the module params for configuring this host */ |
| 6410 | lpfc_get_cfgparam(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6411 | /* Set up phase-1 common device driver resources */ |
| 6412 | |
| 6413 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6414 | if (rc) |
| 6415 | return -ENODEV; |
| 6416 | |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6417 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 6418 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 6419 | /* check for menlo minimum sg count */ |
| 6420 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 6421 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 6422 | } |
| 6423 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6424 | if (!phba->sli.sli3_ring) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6425 | phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING, |
| 6426 | sizeof(struct lpfc_sli_ring), |
| 6427 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6428 | if (!phba->sli.sli3_ring) |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6429 | return -ENOMEM; |
| 6430 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6431 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6432 | * 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] | 6433 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6434 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6435 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6436 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6437 | entry_sz = sizeof(struct sli4_sge); |
| 6438 | else |
| 6439 | entry_sz = sizeof(struct ulp_bde64); |
| 6440 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6441 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 6442 | if (phba->cfg_enable_bg) { |
| 6443 | /* |
| 6444 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 6445 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 6446 | * over how many protection data segments the SCSI Layer |
| 6447 | * will hand us (ie: there could be one for every block |
| 6448 | * in the IO), we just allocate enough BDEs to accomidate |
| 6449 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 6450 | * minimize the risk of running out. |
| 6451 | */ |
| 6452 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6453 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6454 | (LPFC_MAX_SG_SEG_CNT * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6455 | |
| 6456 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 6457 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 6458 | |
| 6459 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 6460 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 6461 | } else { |
| 6462 | /* |
| 6463 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 6464 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 6465 | * cfg_sg_seg_cnt data segments. |
| 6466 | */ |
| 6467 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6468 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6469 | ((phba->cfg_sg_seg_cnt + 2) * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6470 | |
| 6471 | /* Total BDEs in BPL for scsi_sg_list */ |
| 6472 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 6473 | } |
| 6474 | |
| 6475 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 6476 | "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6477 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 6478 | phba->cfg_total_seg_cnt); |
| 6479 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6480 | phba->max_vpi = LPFC_MAX_VPI; |
| 6481 | /* This will be set to correct value after config_port mbox */ |
| 6482 | phba->max_vports = 0; |
| 6483 | |
| 6484 | /* |
| 6485 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 6486 | */ |
| 6487 | lpfc_sli_setup(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6488 | lpfc_sli_queue_init(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6489 | |
| 6490 | /* Allocate device driver memory */ |
| 6491 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 6492 | return -ENOMEM; |
| 6493 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6494 | phba->lpfc_sg_dma_buf_pool = |
| 6495 | dma_pool_create("lpfc_sg_dma_buf_pool", |
| 6496 | &phba->pcidev->dev, phba->cfg_sg_dma_buf_size, |
| 6497 | BPL_ALIGN_SZ, 0); |
| 6498 | |
| 6499 | if (!phba->lpfc_sg_dma_buf_pool) |
| 6500 | goto fail_free_mem; |
| 6501 | |
| 6502 | phba->lpfc_cmd_rsp_buf_pool = |
| 6503 | dma_pool_create("lpfc_cmd_rsp_buf_pool", |
| 6504 | &phba->pcidev->dev, |
| 6505 | sizeof(struct fcp_cmnd) + |
| 6506 | sizeof(struct fcp_rsp), |
| 6507 | BPL_ALIGN_SZ, 0); |
| 6508 | |
| 6509 | if (!phba->lpfc_cmd_rsp_buf_pool) |
| 6510 | goto fail_free_dma_buf_pool; |
| 6511 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6512 | /* |
| 6513 | * Enable sr-iov virtual functions if supported and configured |
| 6514 | * through the module parameter. |
| 6515 | */ |
| 6516 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6517 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6518 | phba->cfg_sriov_nr_virtfn); |
| 6519 | if (rc) { |
| 6520 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6521 | "2808 Requested number of SR-IOV " |
| 6522 | "virtual functions (%d) is not " |
| 6523 | "supported\n", |
| 6524 | phba->cfg_sriov_nr_virtfn); |
| 6525 | phba->cfg_sriov_nr_virtfn = 0; |
| 6526 | } |
| 6527 | } |
| 6528 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6529 | return 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6530 | |
| 6531 | fail_free_dma_buf_pool: |
| 6532 | dma_pool_destroy(phba->lpfc_sg_dma_buf_pool); |
| 6533 | phba->lpfc_sg_dma_buf_pool = NULL; |
| 6534 | fail_free_mem: |
| 6535 | lpfc_mem_free(phba); |
| 6536 | return -ENOMEM; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6537 | } |
| 6538 | |
| 6539 | /** |
| 6540 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 6541 | * @phba: pointer to lpfc hba data structure. |
| 6542 | * |
| 6543 | * This routine is invoked to unset the driver internal resources set up |
| 6544 | * specific for supporting the SLI-3 HBA device it attached to. |
| 6545 | **/ |
| 6546 | static void |
| 6547 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 6548 | { |
| 6549 | /* Free device driver memory allocated */ |
| 6550 | lpfc_mem_free_all(phba); |
| 6551 | |
| 6552 | return; |
| 6553 | } |
| 6554 | |
| 6555 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6556 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 6557 | * @phba: pointer to lpfc hba data structure. |
| 6558 | * |
| 6559 | * This routine is invoked to set up the driver internal resources specific to |
| 6560 | * support the SLI-4 HBA device it attached to. |
| 6561 | * |
| 6562 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6563 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6564 | * other values - error |
| 6565 | **/ |
| 6566 | static int |
| 6567 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 6568 | { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6569 | LPFC_MBOXQ_t *mboxq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6570 | MAILBOX_t *mb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6571 | int rc, i, max_buf_size; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6572 | int longs; |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6573 | int extra; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6574 | uint64_t wwn; |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6575 | u32 if_type; |
| 6576 | u32 if_fam; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6577 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6578 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | eede497 | 2019-11-21 09:55:56 -0800 | [diff] [blame] | 6579 | phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6580 | phba->sli4_hba.curr_disp_cpu = 0; |
| 6581 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 6582 | /* Get all the module params for configuring this host */ |
| 6583 | lpfc_get_cfgparam(phba); |
| 6584 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6585 | /* Set up phase-1 common device driver resources */ |
| 6586 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6587 | if (rc) |
| 6588 | return -ENODEV; |
| 6589 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6590 | /* Before proceed, wait for POST done and device ready */ |
| 6591 | rc = lpfc_sli4_post_status_check(phba); |
| 6592 | if (rc) |
| 6593 | return -ENODEV; |
| 6594 | |
James Smart | 3cee98d | 2019-08-14 16:56:34 -0700 | [diff] [blame] | 6595 | /* Allocate all driver workqueues here */ |
| 6596 | |
| 6597 | /* The lpfc_wq workqueue for deferred irq use */ |
| 6598 | phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); |
| 6599 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6600 | /* |
| 6601 | * Initialize timers used by driver |
| 6602 | */ |
| 6603 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6604 | timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6605 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6606 | /* FCF rediscover timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6607 | 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] | 6608 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6609 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 6610 | * Control structure for handling external multi-buffer mailbox |
| 6611 | * command pass-through. |
| 6612 | */ |
| 6613 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 6614 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 6615 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 6616 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6617 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6618 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6619 | /* This will be set to correct value after the read_config mbox */ |
| 6620 | phba->max_vports = 0; |
| 6621 | |
| 6622 | /* Program the default value of vlan_id and fc_map */ |
| 6623 | phba->valid_vlan = 0; |
| 6624 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 6625 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 6626 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 6627 | |
| 6628 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6629 | * 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] | 6630 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
| 6631 | * The WQ create will allocate the ring. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6632 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6633 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6634 | /* Initialize buffer queue management fields */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6635 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6636 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 6637 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 6638 | |
| 6639 | /* |
| 6640 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 6641 | */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 6642 | /* Initialize the Abort buffer list used by driver */ |
| 6643 | spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock); |
| 6644 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6645 | |
| 6646 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6647 | /* Initialize the Abort nvme buffer list used by driver */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6648 | spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 6649 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6650 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list); |
James Smart | 79d8c4c | 2019-05-21 17:48:56 -0700 | [diff] [blame] | 6651 | spin_lock_init(&phba->sli4_hba.t_active_list_lock); |
| 6652 | INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6653 | } |
| 6654 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6655 | /* This abort list used by worker thread */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6656 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6657 | spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6658 | spin_lock_init(&phba->sli4_hba.asynce_list_lock); |
| 6659 | spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6660 | |
| 6661 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6662 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6663 | */ |
| 6664 | |
| 6665 | /* Driver internel slow-path CQ Event pool */ |
| 6666 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 6667 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6668 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6669 | /* Asynchronous event CQ Event work queue list */ |
| 6670 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6671 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 6672 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 6673 | /* Receive queue CQ Event work queue list */ |
| 6674 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 6675 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6676 | /* Initialize extent block lists. */ |
| 6677 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 6678 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 6679 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 6680 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 6681 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6682 | /* Initialize mboxq lists. If the early init routines fail |
| 6683 | * these lists need to be correctly initialized. |
| 6684 | */ |
| 6685 | INIT_LIST_HEAD(&phba->sli.mboxq); |
| 6686 | INIT_LIST_HEAD(&phba->sli.mboxq_cmpl); |
| 6687 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6688 | /* initialize optic_state to 0xFF */ |
| 6689 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 6690 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6691 | /* Allocate device driver memory */ |
| 6692 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 6693 | if (rc) |
| 6694 | return -ENOMEM; |
| 6695 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6696 | /* IF Type 2 ports get initialized now. */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 6697 | 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] | 6698 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 6699 | rc = lpfc_pci_function_reset(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6700 | if (unlikely(rc)) { |
| 6701 | rc = -ENODEV; |
| 6702 | goto out_free_mem; |
| 6703 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6704 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6705 | } |
| 6706 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6707 | /* Create the bootstrap mailbox command */ |
| 6708 | rc = lpfc_create_bootstrap_mbox(phba); |
| 6709 | if (unlikely(rc)) |
| 6710 | goto out_free_mem; |
| 6711 | |
| 6712 | /* Set up the host's endian order with the device. */ |
| 6713 | rc = lpfc_setup_endian_order(phba); |
| 6714 | if (unlikely(rc)) |
| 6715 | goto out_free_bsmbx; |
| 6716 | |
| 6717 | /* Set up the hba's configuration parameters. */ |
| 6718 | rc = lpfc_sli4_read_config(phba); |
| 6719 | if (unlikely(rc)) |
| 6720 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6721 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 6722 | if (unlikely(rc)) |
| 6723 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6724 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6725 | /* IF Type 0 ports get initialized now. */ |
| 6726 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6727 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6728 | rc = lpfc_pci_function_reset(phba); |
| 6729 | if (unlikely(rc)) |
| 6730 | goto out_free_bsmbx; |
| 6731 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6732 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6733 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6734 | GFP_KERNEL); |
| 6735 | if (!mboxq) { |
| 6736 | rc = -ENOMEM; |
| 6737 | goto out_free_bsmbx; |
| 6738 | } |
| 6739 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6740 | /* Check for NVMET being configured */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6741 | phba->nvmet_support = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6742 | if (lpfc_enable_nvmet_cnt) { |
| 6743 | |
| 6744 | /* First get WWN of HBA instance */ |
| 6745 | lpfc_read_nv(phba, mboxq); |
| 6746 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6747 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6748 | lpfc_printf_log(phba, KERN_ERR, |
| 6749 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6750 | "6016 Mailbox failed , mbxCmd x%x " |
| 6751 | "READ_NV, mbxStatus x%x\n", |
| 6752 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 6753 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6754 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6755 | rc = -EIO; |
| 6756 | goto out_free_bsmbx; |
| 6757 | } |
| 6758 | mb = &mboxq->u.mb; |
| 6759 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, |
| 6760 | sizeof(uint64_t)); |
| 6761 | wwn = cpu_to_be64(wwn); |
| 6762 | phba->sli4_hba.wwnn.u.name = wwn; |
| 6763 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, |
| 6764 | sizeof(uint64_t)); |
| 6765 | /* wwn is WWPN of HBA instance */ |
| 6766 | wwn = cpu_to_be64(wwn); |
| 6767 | phba->sli4_hba.wwpn.u.name = wwn; |
| 6768 | |
| 6769 | /* Check to see if it matches any module parameter */ |
| 6770 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { |
| 6771 | if (wwn == lpfc_enable_nvmet[i]) { |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6772 | #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6773 | if (lpfc_nvmet_mem_alloc(phba)) |
| 6774 | break; |
| 6775 | |
| 6776 | phba->nvmet_support = 1; /* a match */ |
| 6777 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6778 | lpfc_printf_log(phba, KERN_ERR, |
| 6779 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6780 | "6017 NVME Target %016llx\n", |
| 6781 | wwn); |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6782 | #else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6783 | lpfc_printf_log(phba, KERN_ERR, |
| 6784 | LOG_TRACE_EVENT, |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6785 | "6021 Can't enable NVME Target." |
| 6786 | " NVME_TARGET_FC infrastructure" |
| 6787 | " is not in kernel\n"); |
| 6788 | #endif |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 6789 | /* Not supported for NVMET */ |
| 6790 | phba->cfg_xri_rebalancing = 0; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 6791 | if (phba->irq_chann_mode == NHT_MODE) { |
| 6792 | phba->cfg_irq_chann = |
| 6793 | phba->sli4_hba.num_present_cpu; |
| 6794 | phba->cfg_hdw_queue = |
| 6795 | phba->sli4_hba.num_present_cpu; |
| 6796 | phba->irq_chann_mode = NORMAL_MODE; |
| 6797 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6798 | break; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6799 | } |
| 6800 | } |
| 6801 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6802 | |
| 6803 | lpfc_nvme_mod_param_dep(phba); |
| 6804 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6805 | /* |
| 6806 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6807 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 6808 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6809 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6810 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 6811 | if (rc) { |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6812 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6813 | &phba->sli4_hba.sli_intf); |
| 6814 | if_fam = bf_get(lpfc_sli_intf_sli_family, |
| 6815 | &phba->sli4_hba.sli_intf); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6816 | if (phba->sli4_hba.extents_in_use && |
| 6817 | phba->sli4_hba.rpi_hdrs_in_use) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6818 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6819 | "2999 Unsupported SLI4 Parameters " |
| 6820 | "Extents and RPI headers enabled.\n"); |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6821 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6822 | if_fam == LPFC_SLI_INTF_FAMILY_BE2) { |
| 6823 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6824 | rc = -EIO; |
| 6825 | goto out_free_bsmbx; |
| 6826 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6827 | } |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6828 | if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6829 | if_fam == LPFC_SLI_INTF_FAMILY_BE2)) { |
| 6830 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6831 | rc = -EIO; |
| 6832 | goto out_free_bsmbx; |
| 6833 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6834 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6835 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6836 | /* |
| 6837 | * 1 for cmd, 1 for rsp, NVME adds an extra one |
| 6838 | * for boundary conditions in its max_sgl_segment template. |
| 6839 | */ |
| 6840 | extra = 2; |
| 6841 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 6842 | extra++; |
| 6843 | |
| 6844 | /* |
| 6845 | * It doesn't matter what family our adapter is in, we are |
| 6846 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 6847 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 6848 | */ |
| 6849 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
| 6850 | |
| 6851 | /* |
| 6852 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
| 6853 | * used to create the sg_dma_buf_pool must be calculated. |
| 6854 | */ |
| 6855 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 6856 | /* Both cfg_enable_bg and cfg_external_dif code paths */ |
| 6857 | |
| 6858 | /* |
| 6859 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
| 6860 | * the FCP rsp, and a SGE. Sice we have no control |
| 6861 | * over how many protection segments the SCSI Layer |
| 6862 | * will hand us (ie: there could be one for every block |
| 6863 | * in the IO), just allocate enough SGEs to accomidate |
| 6864 | * our max amount and we need to limit lpfc_sg_seg_cnt |
| 6865 | * to minimize the risk of running out. |
| 6866 | */ |
| 6867 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6868 | sizeof(struct fcp_rsp) + max_buf_size; |
| 6869 | |
| 6870 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 6871 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 6872 | |
| 6873 | /* |
| 6874 | * If supporting DIF, reduce the seg count for scsi to |
| 6875 | * allow room for the DIF sges. |
| 6876 | */ |
| 6877 | if (phba->cfg_enable_bg && |
| 6878 | phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF) |
| 6879 | phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF; |
| 6880 | else |
| 6881 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6882 | |
| 6883 | } else { |
| 6884 | /* |
| 6885 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
| 6886 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 6887 | * cfg_sg_seg_cnt data segments. |
| 6888 | */ |
| 6889 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6890 | sizeof(struct fcp_rsp) + |
| 6891 | ((phba->cfg_sg_seg_cnt + extra) * |
| 6892 | sizeof(struct sli4_sge)); |
| 6893 | |
| 6894 | /* Total SGEs for scsi_sg_list */ |
| 6895 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra; |
| 6896 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6897 | |
| 6898 | /* |
| 6899 | * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only |
| 6900 | * need to post 1 page for the SGL. |
| 6901 | */ |
| 6902 | } |
| 6903 | |
| 6904 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 6905 | phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE; |
| 6906 | else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 6907 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 6908 | else |
| 6909 | phba->cfg_sg_dma_buf_size = |
| 6910 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 6911 | |
| 6912 | phba->border_sge_num = phba->cfg_sg_dma_buf_size / |
| 6913 | sizeof(struct sli4_sge); |
| 6914 | |
| 6915 | /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */ |
| 6916 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6917 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { |
| 6918 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, |
| 6919 | "6300 Reducing NVME sg segment " |
| 6920 | "cnt to %d\n", |
| 6921 | LPFC_MAX_NVME_SEG_CNT); |
| 6922 | phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
| 6923 | } else |
| 6924 | phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6925 | } |
| 6926 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6927 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 6928 | "9087 sg_seg_cnt:%d dmabuf_size:%d " |
| 6929 | "total:%d scsi:%d nvme:%d\n", |
| 6930 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 6931 | phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt, |
| 6932 | phba->cfg_nvme_seg_cnt); |
| 6933 | |
| 6934 | if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE) |
| 6935 | i = phba->cfg_sg_dma_buf_size; |
| 6936 | else |
| 6937 | i = SLI4_PAGE_SIZE; |
| 6938 | |
| 6939 | phba->lpfc_sg_dma_buf_pool = |
| 6940 | dma_pool_create("lpfc_sg_dma_buf_pool", |
| 6941 | &phba->pcidev->dev, |
| 6942 | phba->cfg_sg_dma_buf_size, |
| 6943 | i, 0); |
| 6944 | if (!phba->lpfc_sg_dma_buf_pool) |
| 6945 | goto out_free_bsmbx; |
| 6946 | |
| 6947 | phba->lpfc_cmd_rsp_buf_pool = |
| 6948 | dma_pool_create("lpfc_cmd_rsp_buf_pool", |
| 6949 | &phba->pcidev->dev, |
| 6950 | sizeof(struct fcp_cmnd) + |
| 6951 | sizeof(struct fcp_rsp), |
| 6952 | i, 0); |
| 6953 | if (!phba->lpfc_cmd_rsp_buf_pool) |
| 6954 | goto out_free_sg_dma_buf; |
| 6955 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6956 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6957 | |
| 6958 | /* Verify OAS is supported */ |
| 6959 | lpfc_sli4_oas_verify(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6960 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6961 | /* Verify RAS support on adapter */ |
| 6962 | lpfc_sli4_ras_init(phba); |
| 6963 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6964 | /* Verify all the SLI4 queues */ |
| 6965 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6966 | if (rc) |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6967 | goto out_free_cmd_rsp_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6968 | |
| 6969 | /* Create driver internal CQE event pool */ |
| 6970 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 6971 | if (rc) |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6972 | goto out_free_cmd_rsp_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6973 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6974 | /* Initialize sgl lists per host */ |
| 6975 | lpfc_init_sgl_list(phba); |
| 6976 | |
| 6977 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6978 | rc = lpfc_init_active_sgl_array(phba); |
| 6979 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6980 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6981 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6982 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6983 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6984 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 6985 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6986 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6987 | "1432 Failed to initialize rpi headers.\n"); |
| 6988 | goto out_free_active_sgl; |
| 6989 | } |
| 6990 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6991 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6992 | 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] | 6993 | phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6994 | GFP_KERNEL); |
| 6995 | if (!phba->fcf.fcf_rr_bmask) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6996 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6997 | "2759 Failed allocate memory for FCF round " |
| 6998 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6999 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7000 | goto out_remove_rpi_hdrs; |
| 7001 | } |
| 7002 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 7003 | phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 7004 | sizeof(struct lpfc_hba_eq_hdl), |
| 7005 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7006 | if (!phba->sli4_hba.hba_eq_hdl) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7007 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7008 | "2572 Failed allocate memory for " |
| 7009 | "fast-path per-EQ handle array\n"); |
| 7010 | rc = -ENOMEM; |
| 7011 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7012 | } |
| 7013 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 7014 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7015 | sizeof(struct lpfc_vector_map_info), |
| 7016 | GFP_KERNEL); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7017 | if (!phba->sli4_hba.cpu_map) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7018 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7019 | "3327 Failed allocate memory for msi-x " |
| 7020 | "interrupt vector mapping\n"); |
| 7021 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7022 | goto out_free_hba_eq_hdl; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7023 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 7024 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7025 | phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info); |
| 7026 | if (!phba->sli4_hba.eq_info) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7027 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7028 | "3321 Failed allocation for per_cpu stats\n"); |
| 7029 | rc = -ENOMEM; |
| 7030 | goto out_free_hba_cpu_map; |
| 7031 | } |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7032 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7033 | phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu, |
| 7034 | sizeof(*phba->sli4_hba.idle_stat), |
| 7035 | GFP_KERNEL); |
| 7036 | if (!phba->sli4_hba.idle_stat) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7037 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7038 | "3390 Failed allocation for idle_stat\n"); |
| 7039 | rc = -ENOMEM; |
| 7040 | goto out_free_hba_eq_info; |
| 7041 | } |
| 7042 | |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7043 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 7044 | phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat); |
| 7045 | if (!phba->sli4_hba.c_stat) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7046 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7047 | "3332 Failed allocating per cpu hdwq stats\n"); |
| 7048 | rc = -ENOMEM; |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7049 | goto out_free_hba_idle_stat; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7050 | } |
| 7051 | #endif |
| 7052 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7053 | /* |
| 7054 | * Enable sr-iov virtual functions if supported and configured |
| 7055 | * through the module parameter. |
| 7056 | */ |
| 7057 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 7058 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 7059 | phba->cfg_sriov_nr_virtfn); |
| 7060 | if (rc) { |
| 7061 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7062 | "3020 Requested number of SR-IOV " |
| 7063 | "virtual functions (%d) is not " |
| 7064 | "supported\n", |
| 7065 | phba->cfg_sriov_nr_virtfn); |
| 7066 | phba->cfg_sriov_nr_virtfn = 0; |
| 7067 | } |
| 7068 | } |
| 7069 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 7070 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7071 | |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7072 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7073 | out_free_hba_idle_stat: |
| 7074 | kfree(phba->sli4_hba.idle_stat); |
| 7075 | #endif |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7076 | out_free_hba_eq_info: |
| 7077 | free_percpu(phba->sli4_hba.eq_info); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7078 | out_free_hba_cpu_map: |
| 7079 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7080 | out_free_hba_eq_hdl: |
| 7081 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7082 | out_free_fcf_rr_bmask: |
| 7083 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7084 | out_remove_rpi_hdrs: |
| 7085 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 7086 | out_free_active_sgl: |
| 7087 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7088 | out_destroy_cq_event_pool: |
| 7089 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 7090 | out_free_cmd_rsp_buf: |
| 7091 | dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool); |
| 7092 | phba->lpfc_cmd_rsp_buf_pool = NULL; |
| 7093 | out_free_sg_dma_buf: |
| 7094 | dma_pool_destroy(phba->lpfc_sg_dma_buf_pool); |
| 7095 | phba->lpfc_sg_dma_buf_pool = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7096 | out_free_bsmbx: |
| 7097 | lpfc_destroy_bootstrap_mbox(phba); |
| 7098 | out_free_mem: |
| 7099 | lpfc_mem_free(phba); |
| 7100 | return rc; |
| 7101 | } |
| 7102 | |
| 7103 | /** |
| 7104 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 7105 | * @phba: pointer to lpfc hba data structure. |
| 7106 | * |
| 7107 | * This routine is invoked to unset the driver internal resources set up |
| 7108 | * specific for supporting the SLI-4 HBA device it attached to. |
| 7109 | **/ |
| 7110 | static void |
| 7111 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 7112 | { |
| 7113 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 7114 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7115 | free_percpu(phba->sli4_hba.eq_info); |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7116 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 7117 | free_percpu(phba->sli4_hba.c_stat); |
| 7118 | #endif |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7119 | kfree(phba->sli4_hba.idle_stat); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7120 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7121 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 7122 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 7123 | phba->sli4_hba.num_possible_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7124 | phba->sli4_hba.num_present_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 7125 | phba->sli4_hba.curr_disp_cpu = 0; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 7126 | cpumask_clear(&phba->sli4_hba.irq_aff_mask); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7127 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7128 | /* Free memory allocated for fast-path work queue handles */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7129 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7130 | |
| 7131 | /* Free the allocated rpi headers. */ |
| 7132 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 7133 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7134 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7135 | /* Free eligible FCF index bmask */ |
| 7136 | kfree(phba->fcf.fcf_rr_bmask); |
| 7137 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7138 | /* Free the ELS sgl list */ |
| 7139 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7140 | lpfc_free_els_sgl_list(phba); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7141 | lpfc_free_nvmet_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7142 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7143 | /* Free the completion queue EQ event pool */ |
| 7144 | lpfc_sli4_cq_event_release_all(phba); |
| 7145 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7146 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7147 | /* Release resource identifiers. */ |
| 7148 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 7149 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7150 | /* Free the bsmbx region. */ |
| 7151 | lpfc_destroy_bootstrap_mbox(phba); |
| 7152 | |
| 7153 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 7154 | lpfc_mem_free_all(phba); |
| 7155 | |
| 7156 | /* Free the current connect table */ |
| 7157 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7158 | &phba->fcf_conn_rec_list, list) { |
| 7159 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7160 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7161 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7162 | |
| 7163 | return; |
| 7164 | } |
| 7165 | |
| 7166 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7167 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7168 | * @phba: The hba struct for which this call is being executed. |
| 7169 | * @dev_grp: The HBA PCI-Device group number. |
| 7170 | * |
| 7171 | * This routine sets up the device INIT interface API function jump table |
| 7172 | * in @phba struct. |
| 7173 | * |
| 7174 | * Returns: 0 - success, -ENODEV - failure. |
| 7175 | **/ |
| 7176 | int |
| 7177 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7178 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 7179 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 7180 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 7181 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7182 | switch (dev_grp) { |
| 7183 | case LPFC_PCI_DEV_LP: |
| 7184 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 7185 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 7186 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 7187 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7188 | case LPFC_PCI_DEV_OC: |
| 7189 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 7190 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 7191 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 7192 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7193 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7194 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7195 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 7196 | dev_grp); |
| 7197 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7198 | } |
| 7199 | return 0; |
| 7200 | } |
| 7201 | |
| 7202 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7203 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 7204 | * @phba: pointer to lpfc hba data structure. |
| 7205 | * |
| 7206 | * This routine is invoked to set up the driver internal resources after the |
| 7207 | * device specific resource setup to support the HBA device it attached to. |
| 7208 | * |
| 7209 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7210 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7211 | * other values - error |
| 7212 | **/ |
| 7213 | static int |
| 7214 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 7215 | { |
| 7216 | int error; |
| 7217 | |
| 7218 | /* Startup the kernel thread for this host adapter. */ |
| 7219 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 7220 | "lpfc_worker_%d", phba->brd_no); |
| 7221 | if (IS_ERR(phba->worker_thread)) { |
| 7222 | error = PTR_ERR(phba->worker_thread); |
| 7223 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7224 | } |
| 7225 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7226 | return 0; |
| 7227 | } |
| 7228 | |
| 7229 | /** |
| 7230 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 7231 | * @phba: pointer to lpfc hba data structure. |
| 7232 | * |
| 7233 | * This routine is invoked to unset the driver internal resources set up after |
| 7234 | * the device specific resource setup for supporting the HBA device it |
| 7235 | * attached to. |
| 7236 | **/ |
| 7237 | static void |
| 7238 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 7239 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 7240 | if (phba->wq) { |
| 7241 | flush_workqueue(phba->wq); |
| 7242 | destroy_workqueue(phba->wq); |
| 7243 | phba->wq = NULL; |
| 7244 | } |
| 7245 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7246 | /* Stop kernel worker thread */ |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 7247 | if (phba->worker_thread) |
| 7248 | kthread_stop(phba->worker_thread); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7249 | } |
| 7250 | |
| 7251 | /** |
| 7252 | * lpfc_free_iocb_list - Free iocb list. |
| 7253 | * @phba: pointer to lpfc hba data structure. |
| 7254 | * |
| 7255 | * This routine is invoked to free the driver's IOCB list and memory. |
| 7256 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7257 | void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7258 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 7259 | { |
| 7260 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 7261 | |
| 7262 | spin_lock_irq(&phba->hbalock); |
| 7263 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 7264 | &phba->lpfc_iocb_list, list) { |
| 7265 | list_del(&iocbq_entry->list); |
| 7266 | kfree(iocbq_entry); |
| 7267 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7268 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7269 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7270 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7271 | return; |
| 7272 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7273 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7274 | /** |
| 7275 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 7276 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 7277 | * @iocb_count: number of requested iocbs |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7278 | * |
| 7279 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 7280 | * list and set up the IOCB tag array accordingly. |
| 7281 | * |
| 7282 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7283 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7284 | * other values - error |
| 7285 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7286 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7287 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 7288 | { |
| 7289 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 7290 | uint16_t iotag; |
| 7291 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7292 | |
| 7293 | /* Initialize and populate the iocb list per host. */ |
| 7294 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7295 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 7296 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7297 | if (iocbq_entry == NULL) { |
| 7298 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 7299 | "expected %d count. Unloading driver.\n", |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7300 | __func__, i, iocb_count); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7301 | goto out_free_iocbq; |
| 7302 | } |
| 7303 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7304 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 7305 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7306 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7307 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7308 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7309 | goto out_free_iocbq; |
| 7310 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7311 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7312 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7313 | |
| 7314 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7315 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 7316 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7317 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7318 | } |
| 7319 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7320 | return 0; |
| 7321 | |
| 7322 | out_free_iocbq: |
| 7323 | lpfc_free_iocb_list(phba); |
| 7324 | |
| 7325 | return -ENOMEM; |
| 7326 | } |
| 7327 | |
| 7328 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7329 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7330 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7331 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7332 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7333 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7334 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7335 | void |
| 7336 | 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] | 7337 | { |
| 7338 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7339 | |
| 7340 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 7341 | list_del(&sglq_entry->list); |
| 7342 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7343 | kfree(sglq_entry); |
| 7344 | } |
| 7345 | } |
| 7346 | |
| 7347 | /** |
| 7348 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 7349 | * @phba: pointer to lpfc hba data structure. |
| 7350 | * |
| 7351 | * This routine is invoked to free the driver's els sgl list and memory. |
| 7352 | **/ |
| 7353 | static void |
| 7354 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 7355 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7356 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7357 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7358 | /* Retrieve all els sgls from driver list */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 7359 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7360 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 7361 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7362 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7363 | /* Now free the sgl list */ |
| 7364 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7365 | } |
| 7366 | |
| 7367 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7368 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. |
| 7369 | * @phba: pointer to lpfc hba data structure. |
| 7370 | * |
| 7371 | * This routine is invoked to free the driver's nvmet sgl list and memory. |
| 7372 | **/ |
| 7373 | static void |
| 7374 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) |
| 7375 | { |
| 7376 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7377 | LIST_HEAD(sglq_list); |
| 7378 | |
| 7379 | /* Retrieve all nvmet sgls from driver list */ |
| 7380 | spin_lock_irq(&phba->hbalock); |
| 7381 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7382 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); |
| 7383 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 7384 | spin_unlock_irq(&phba->hbalock); |
| 7385 | |
| 7386 | /* Now free the sgl list */ |
| 7387 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { |
| 7388 | list_del(&sglq_entry->list); |
| 7389 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7390 | kfree(sglq_entry); |
| 7391 | } |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 7392 | |
| 7393 | /* Update the nvmet_xri_cnt to reflect no current sgls. |
| 7394 | * The next initialization cycle sets the count and allocates |
| 7395 | * the sgls over again. |
| 7396 | */ |
| 7397 | phba->sli4_hba.nvmet_xri_cnt = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7398 | } |
| 7399 | |
| 7400 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7401 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 7402 | * @phba: pointer to lpfc hba data structure. |
| 7403 | * |
| 7404 | * This routine is invoked to allocate the driver's active sgl memory. |
| 7405 | * This array will hold the sglq_entry's for active IOs. |
| 7406 | **/ |
| 7407 | static int |
| 7408 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 7409 | { |
| 7410 | int size; |
| 7411 | size = sizeof(struct lpfc_sglq *); |
| 7412 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 7413 | |
| 7414 | phba->sli4_hba.lpfc_sglq_active_list = |
| 7415 | kzalloc(size, GFP_KERNEL); |
| 7416 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 7417 | return -ENOMEM; |
| 7418 | return 0; |
| 7419 | } |
| 7420 | |
| 7421 | /** |
| 7422 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 7423 | * @phba: pointer to lpfc hba data structure. |
| 7424 | * |
| 7425 | * This routine is invoked to walk through the array of active sglq entries |
| 7426 | * and free all of the resources. |
| 7427 | * This is just a place holder for now. |
| 7428 | **/ |
| 7429 | static void |
| 7430 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 7431 | { |
| 7432 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 7433 | } |
| 7434 | |
| 7435 | /** |
| 7436 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 7437 | * @phba: pointer to lpfc hba data structure. |
| 7438 | * |
| 7439 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 7440 | * list and set up the sgl xritag tag array accordingly. |
| 7441 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7442 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7443 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7444 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 7445 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7446 | /* Initialize and populate the sglq list per host/VF. */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7447 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7448 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7449 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 7450 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7451 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7452 | /* els xri-sgl book keeping */ |
| 7453 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7454 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7455 | /* nvme xri-buffer book keeping */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7456 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7457 | } |
| 7458 | |
| 7459 | /** |
| 7460 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 7461 | * @phba: pointer to lpfc hba data structure. |
| 7462 | * |
| 7463 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7464 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7465 | * 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] | 7466 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 7467 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7468 | * |
| 7469 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7470 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7471 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7472 | **/ |
| 7473 | int |
| 7474 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 7475 | { |
| 7476 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7477 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7478 | |
| 7479 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7480 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7481 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7482 | if (phba->sli4_hba.extents_in_use) |
| 7483 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7484 | |
| 7485 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 7486 | if (!rpi_hdr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7487 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7488 | "0391 Error during rpi post operation\n"); |
| 7489 | lpfc_sli4_remove_rpis(phba); |
| 7490 | rc = -ENODEV; |
| 7491 | } |
| 7492 | |
| 7493 | return rc; |
| 7494 | } |
| 7495 | |
| 7496 | /** |
| 7497 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 7498 | * @phba: pointer to lpfc hba data structure. |
| 7499 | * |
| 7500 | * This routine is invoked to allocate a single 4KB memory region to |
| 7501 | * support rpis and stores them in the phba. This single region |
| 7502 | * provides support for up to 64 rpis. The region is used globally |
| 7503 | * by the device. |
| 7504 | * |
| 7505 | * Returns: |
| 7506 | * A valid rpi hdr on success. |
| 7507 | * A NULL pointer on any failure. |
| 7508 | **/ |
| 7509 | struct lpfc_rpi_hdr * |
| 7510 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 7511 | { |
| 7512 | uint16_t rpi_limit, curr_rpi_range; |
| 7513 | struct lpfc_dmabuf *dmabuf; |
| 7514 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7515 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7516 | /* |
| 7517 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 7518 | * required. Set the expected maximum count and let the actual value |
| 7519 | * get set when extents are fully allocated. |
| 7520 | */ |
| 7521 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7522 | return NULL; |
| 7523 | if (phba->sli4_hba.extents_in_use) |
| 7524 | return NULL; |
| 7525 | |
| 7526 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7527 | rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7528 | |
| 7529 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7530 | /* |
| 7531 | * Establish the starting RPI in this header block. The starting |
| 7532 | * rpi is normalized to a zero base because the physical rpi is |
| 7533 | * port based. |
| 7534 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7535 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7536 | spin_unlock_irq(&phba->hbalock); |
| 7537 | |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7538 | /* Reached full RPI range */ |
| 7539 | if (curr_rpi_range == rpi_limit) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7540 | return NULL; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7541 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7542 | /* |
| 7543 | * First allocate the protocol header region for the port. The |
| 7544 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 7545 | */ |
| 7546 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 7547 | if (!dmabuf) |
| 7548 | return NULL; |
| 7549 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7550 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 7551 | LPFC_HDR_TEMPLATE_SIZE, |
| 7552 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7553 | if (!dmabuf->virt) { |
| 7554 | rpi_hdr = NULL; |
| 7555 | goto err_free_dmabuf; |
| 7556 | } |
| 7557 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7558 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 7559 | rpi_hdr = NULL; |
| 7560 | goto err_free_coherent; |
| 7561 | } |
| 7562 | |
| 7563 | /* Save the rpi header data for cleanup later. */ |
| 7564 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 7565 | if (!rpi_hdr) |
| 7566 | goto err_free_coherent; |
| 7567 | |
| 7568 | rpi_hdr->dmabuf = dmabuf; |
| 7569 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 7570 | rpi_hdr->page_count = 1; |
| 7571 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7572 | |
| 7573 | /* The rpi_hdr stores the logical index only. */ |
| 7574 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7575 | 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] | 7576 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 7577 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7578 | spin_unlock_irq(&phba->hbalock); |
| 7579 | return rpi_hdr; |
| 7580 | |
| 7581 | err_free_coherent: |
| 7582 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 7583 | dmabuf->virt, dmabuf->phys); |
| 7584 | err_free_dmabuf: |
| 7585 | kfree(dmabuf); |
| 7586 | return NULL; |
| 7587 | } |
| 7588 | |
| 7589 | /** |
| 7590 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 7591 | * @phba: pointer to lpfc hba data structure. |
| 7592 | * |
| 7593 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7594 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 7595 | * presumes the caller has released all rpis consumed by fabric or port |
| 7596 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7597 | **/ |
| 7598 | void |
| 7599 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 7600 | { |
| 7601 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 7602 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7603 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7604 | goto exit; |
| 7605 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7606 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 7607 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 7608 | list_del(&rpi_hdr->list); |
| 7609 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 7610 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 7611 | kfree(rpi_hdr->dmabuf); |
| 7612 | kfree(rpi_hdr); |
| 7613 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7614 | exit: |
| 7615 | /* There are no rpis available to the port now. */ |
| 7616 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7617 | } |
| 7618 | |
| 7619 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7620 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 7621 | * @pdev: pointer to pci device data structure. |
| 7622 | * |
| 7623 | * This routine is invoked to allocate the driver hba data structure for an |
| 7624 | * HBA device. If the allocation is successful, the phba reference to the |
| 7625 | * PCI device data structure is set. |
| 7626 | * |
| 7627 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7628 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7629 | * NULL - error |
| 7630 | **/ |
| 7631 | static struct lpfc_hba * |
| 7632 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 7633 | { |
| 7634 | struct lpfc_hba *phba; |
| 7635 | |
| 7636 | /* Allocate memory for HBA structure */ |
| 7637 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 7638 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 7639 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7640 | return NULL; |
| 7641 | } |
| 7642 | |
| 7643 | /* Set reference to PCI device in HBA structure */ |
| 7644 | phba->pcidev = pdev; |
| 7645 | |
| 7646 | /* Assign an unused board number */ |
| 7647 | phba->brd_no = lpfc_get_instance(); |
| 7648 | if (phba->brd_no < 0) { |
| 7649 | kfree(phba); |
| 7650 | return NULL; |
| 7651 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7652 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7653 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 7654 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 7655 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 7656 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7657 | return phba; |
| 7658 | } |
| 7659 | |
| 7660 | /** |
| 7661 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 7662 | * @phba: pointer to lpfc hba data structure. |
| 7663 | * |
| 7664 | * This routine is invoked to free the driver hba data structure with an |
| 7665 | * HBA device. |
| 7666 | **/ |
| 7667 | static void |
| 7668 | lpfc_hba_free(struct lpfc_hba *phba) |
| 7669 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7670 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7671 | kfree(phba->sli4_hba.hdwq); |
| 7672 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7673 | /* Release the driver assigned board number */ |
| 7674 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 7675 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7676 | /* Free memory allocated with sli3 rings */ |
| 7677 | kfree(phba->sli.sli3_ring); |
| 7678 | phba->sli.sli3_ring = NULL; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7679 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7680 | kfree(phba); |
| 7681 | return; |
| 7682 | } |
| 7683 | |
| 7684 | /** |
| 7685 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 7686 | * @phba: pointer to lpfc hba data structure. |
| 7687 | * |
| 7688 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 7689 | * host with it. |
| 7690 | * |
| 7691 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7692 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7693 | * other values - error |
| 7694 | **/ |
| 7695 | static int |
| 7696 | lpfc_create_shost(struct lpfc_hba *phba) |
| 7697 | { |
| 7698 | struct lpfc_vport *vport; |
| 7699 | struct Scsi_Host *shost; |
| 7700 | |
| 7701 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7702 | phba->fc_edtov = FF_DEF_EDTOV; |
| 7703 | phba->fc_ratov = FF_DEF_RATOV; |
| 7704 | phba->fc_altov = FF_DEF_ALTOV; |
| 7705 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 7706 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7707 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 7708 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7709 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7710 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7711 | |
| 7712 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7713 | phba->pport = vport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7714 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7715 | if (phba->nvmet_support) { |
| 7716 | /* Only 1 vport (pport) will support NVME target */ |
James Smart | ea85a20 | 2019-10-18 14:18:25 -0700 | [diff] [blame] | 7717 | phba->targetport = NULL; |
| 7718 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; |
| 7719 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC, |
| 7720 | "6076 NVME Target Found\n"); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7721 | } |
| 7722 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7723 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7724 | /* Put reference to SCSI host to driver's device private data */ |
| 7725 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7726 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7727 | /* |
| 7728 | * At this point we are fully registered with PSA. In addition, |
| 7729 | * any initial discovery should be completed. |
| 7730 | */ |
| 7731 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7732 | if (phba->cfg_enable_SmartSAN || |
| 7733 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7734 | |
| 7735 | /* Setup appropriate attribute masks */ |
| 7736 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7737 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7738 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 7739 | else |
| 7740 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 7741 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7742 | return 0; |
| 7743 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7744 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7745 | /** |
| 7746 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 7747 | * @phba: pointer to lpfc hba data structure. |
| 7748 | * |
| 7749 | * This routine is invoked to destroy HBA physical port and the associated |
| 7750 | * SCSI host. |
| 7751 | **/ |
| 7752 | static void |
| 7753 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 7754 | { |
| 7755 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7756 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7757 | /* Destroy physical port that associated with the SCSI host */ |
| 7758 | destroy_port(vport); |
| 7759 | |
| 7760 | return; |
| 7761 | } |
| 7762 | |
| 7763 | /** |
| 7764 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 7765 | * @phba: pointer to lpfc hba data structure. |
| 7766 | * @shost: the shost to be used to detect Block guard settings. |
| 7767 | * |
| 7768 | * This routine sets up the local Block guard protocol settings for @shost. |
| 7769 | * This routine also allocates memory for debugging bg buffers. |
| 7770 | **/ |
| 7771 | static void |
| 7772 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 7773 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7774 | uint32_t old_mask; |
| 7775 | uint32_t old_guard; |
| 7776 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7777 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7778 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7779 | "1478 Registering BlockGuard with the " |
| 7780 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7781 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7782 | old_mask = phba->cfg_prot_mask; |
| 7783 | old_guard = phba->cfg_prot_guard; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7784 | |
| 7785 | /* Only allow supported values */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7786 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7787 | SHOST_DIX_TYPE0_PROTECTION | |
| 7788 | SHOST_DIX_TYPE1_PROTECTION); |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7789 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
| 7790 | SHOST_DIX_GUARD_CRC); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7791 | |
| 7792 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7793 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 7794 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7795 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7796 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
| 7797 | if ((old_mask != phba->cfg_prot_mask) || |
| 7798 | (old_guard != phba->cfg_prot_guard)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7799 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7800 | "1475 Registering BlockGuard with the " |
| 7801 | "SCSI layer: mask %d guard %d\n", |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7802 | phba->cfg_prot_mask, |
| 7803 | phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7804 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7805 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
| 7806 | scsi_host_set_guard(shost, phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7807 | } else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7808 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7809 | "1479 Not Registering BlockGuard with the SCSI " |
| 7810 | "layer, Bad protection parameters: %d %d\n", |
| 7811 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7812 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7813 | } |
| 7814 | |
| 7815 | /** |
| 7816 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 7817 | * @phba: pointer to lpfc hba data structure. |
| 7818 | * |
| 7819 | * This routine is invoked to perform all the necessary post initialization |
| 7820 | * setup for the device. |
| 7821 | **/ |
| 7822 | static void |
| 7823 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 7824 | { |
| 7825 | struct Scsi_Host *shost; |
| 7826 | struct lpfc_adapter_event_header adapter_event; |
| 7827 | |
| 7828 | /* Get the default values for Model Name and Description */ |
| 7829 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 7830 | |
| 7831 | /* |
| 7832 | * hba setup may have changed the hba_queue_depth so we need to |
| 7833 | * adjust the value of can_queue. |
| 7834 | */ |
| 7835 | shost = pci_get_drvdata(phba->pcidev); |
| 7836 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7837 | |
| 7838 | lpfc_host_attrib_init(shost); |
| 7839 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7840 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 7841 | spin_lock_irq(shost->host_lock); |
| 7842 | lpfc_poll_start_timer(phba); |
| 7843 | spin_unlock_irq(shost->host_lock); |
| 7844 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 7845 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7846 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7847 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7848 | /* Send board arrival event to upper layer */ |
| 7849 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 7850 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 7851 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7852 | sizeof(adapter_event), |
| 7853 | (char *) &adapter_event, |
| 7854 | LPFC_NL_VENDOR_ID); |
| 7855 | return; |
| 7856 | } |
| 7857 | |
| 7858 | /** |
| 7859 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 7860 | * @phba: pointer to lpfc hba data structure. |
| 7861 | * |
| 7862 | * This routine is invoked to set up the PCI device memory space for device |
| 7863 | * with SLI-3 interface spec. |
| 7864 | * |
| 7865 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7866 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7867 | * other values - error |
| 7868 | **/ |
| 7869 | static int |
| 7870 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 7871 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7872 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7873 | unsigned long bar0map_len, bar2map_len; |
| 7874 | int i, hbq_count; |
| 7875 | void *ptr; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7876 | int error; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7877 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7878 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7879 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7880 | |
| 7881 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7882 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 7883 | if (error) |
| 7884 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 7885 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7886 | return error; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7887 | error = -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7888 | |
| 7889 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 7890 | * required by each mapping. |
| 7891 | */ |
| 7892 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7893 | bar0map_len = pci_resource_len(pdev, 0); |
| 7894 | |
| 7895 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 7896 | bar2map_len = pci_resource_len(pdev, 2); |
| 7897 | |
| 7898 | /* Map HBA SLIM to a kernel virtual address. */ |
| 7899 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 7900 | if (!phba->slim_memmap_p) { |
| 7901 | dev_printk(KERN_ERR, &pdev->dev, |
| 7902 | "ioremap failed for SLIM memory.\n"); |
| 7903 | goto out; |
| 7904 | } |
| 7905 | |
| 7906 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 7907 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 7908 | if (!phba->ctrl_regs_memmap_p) { |
| 7909 | dev_printk(KERN_ERR, &pdev->dev, |
| 7910 | "ioremap failed for HBA control registers.\n"); |
| 7911 | goto out_iounmap_slim; |
| 7912 | } |
| 7913 | |
| 7914 | /* Allocate memory for SLI-2 structures */ |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7915 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7916 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7917 | if (!phba->slim2p.virt) |
| 7918 | goto out_iounmap; |
| 7919 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7920 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7921 | phba->mbox_ext = (phba->slim2p.virt + |
| 7922 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7923 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 7924 | phba->IOCBs = (phba->slim2p.virt + |
| 7925 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 7926 | |
| 7927 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 7928 | lpfc_sli_hbq_size(), |
| 7929 | &phba->hbqslimp.phys, |
| 7930 | GFP_KERNEL); |
| 7931 | if (!phba->hbqslimp.virt) |
| 7932 | goto out_free_slim; |
| 7933 | |
| 7934 | hbq_count = lpfc_sli_hbq_count(); |
| 7935 | ptr = phba->hbqslimp.virt; |
| 7936 | for (i = 0; i < hbq_count; ++i) { |
| 7937 | phba->hbqs[i].hbq_virt = ptr; |
| 7938 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 7939 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 7940 | sizeof(struct lpfc_hbq_entry)); |
| 7941 | } |
| 7942 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 7943 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 7944 | |
| 7945 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 7946 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7947 | phba->MBslimaddr = phba->slim_memmap_p; |
| 7948 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 7949 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 7950 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 7951 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7952 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7953 | return 0; |
| 7954 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7955 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7956 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7957 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7958 | out_iounmap: |
| 7959 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7960 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7961 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7962 | out: |
| 7963 | return error; |
| 7964 | } |
| 7965 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7966 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7967 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 7968 | * @phba: pointer to lpfc hba data structure. |
| 7969 | * |
| 7970 | * This routine is invoked to unset the PCI device memory space for device |
| 7971 | * with SLI-3 interface spec. |
| 7972 | **/ |
| 7973 | static void |
| 7974 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 7975 | { |
| 7976 | struct pci_dev *pdev; |
| 7977 | |
| 7978 | /* Obtain PCI device reference */ |
| 7979 | if (!phba->pcidev) |
| 7980 | return; |
| 7981 | else |
| 7982 | pdev = phba->pcidev; |
| 7983 | |
| 7984 | /* Free coherent DMA memory allocated */ |
| 7985 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 7986 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 7987 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7988 | phba->slim2p.virt, phba->slim2p.phys); |
| 7989 | |
| 7990 | /* I/O memory unmap */ |
| 7991 | iounmap(phba->ctrl_regs_memmap_p); |
| 7992 | iounmap(phba->slim_memmap_p); |
| 7993 | |
| 7994 | return; |
| 7995 | } |
| 7996 | |
| 7997 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7998 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 7999 | * @phba: pointer to lpfc hba data structure. |
| 8000 | * |
| 8001 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 8002 | * done and check status. |
| 8003 | * |
| 8004 | * Return 0 if successful, otherwise -ENODEV. |
| 8005 | **/ |
| 8006 | int |
| 8007 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 8008 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8009 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 8010 | struct lpfc_register reg_data; |
| 8011 | int i, port_error = 0; |
| 8012 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8013 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8014 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 8015 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8016 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8017 | return -ENODEV; |
| 8018 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8019 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 8020 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8021 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 8022 | &portsmphr_reg.word0) || |
| 8023 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8024 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8025 | port_error = -ENODEV; |
| 8026 | break; |
| 8027 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8028 | if (LPFC_POST_STAGE_PORT_READY == |
| 8029 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8030 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8031 | msleep(10); |
| 8032 | } |
| 8033 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8034 | /* |
| 8035 | * If there was a port error during POST, then don't proceed with |
| 8036 | * other register reads as the data may not be valid. Just exit. |
| 8037 | */ |
| 8038 | if (port_error) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8039 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8040 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 8041 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 8042 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 8043 | portsmphr_reg.word0, |
| 8044 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 8045 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 8046 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 8047 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 8048 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 8049 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 8050 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 8051 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 8052 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8053 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8054 | "2534 Device Info: SLIFamily=0x%x, " |
| 8055 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 8056 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8057 | bf_get(lpfc_sli_intf_sli_family, |
| 8058 | &phba->sli4_hba.sli_intf), |
| 8059 | bf_get(lpfc_sli_intf_slirev, |
| 8060 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 8061 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8062 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 8063 | bf_get(lpfc_sli_intf_sli_hint1, |
| 8064 | &phba->sli4_hba.sli_intf), |
| 8065 | bf_get(lpfc_sli_intf_sli_hint2, |
| 8066 | &phba->sli4_hba.sli_intf), |
| 8067 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8068 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8069 | /* |
| 8070 | * Check for other Port errors during the initialization |
| 8071 | * process. Fail the load if the port did not come up |
| 8072 | * correctly. |
| 8073 | */ |
| 8074 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8075 | &phba->sli4_hba.sli_intf); |
| 8076 | switch (if_type) { |
| 8077 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8078 | phba->sli4_hba.ue_mask_lo = |
| 8079 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 8080 | phba->sli4_hba.ue_mask_hi = |
| 8081 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 8082 | uerrlo_reg.word0 = |
| 8083 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 8084 | uerrhi_reg.word0 = |
| 8085 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 8086 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 8087 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8088 | lpfc_printf_log(phba, KERN_ERR, |
| 8089 | LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8090 | "1422 Unrecoverable Error " |
| 8091 | "Detected during POST " |
| 8092 | "uerr_lo_reg=0x%x, " |
| 8093 | "uerr_hi_reg=0x%x, " |
| 8094 | "ue_mask_lo_reg=0x%x, " |
| 8095 | "ue_mask_hi_reg=0x%x\n", |
| 8096 | uerrlo_reg.word0, |
| 8097 | uerrhi_reg.word0, |
| 8098 | phba->sli4_hba.ue_mask_lo, |
| 8099 | phba->sli4_hba.ue_mask_hi); |
| 8100 | port_error = -ENODEV; |
| 8101 | } |
| 8102 | break; |
| 8103 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8104 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8105 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8106 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 8107 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8108 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 8109 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8110 | phba->work_status[0] = |
| 8111 | readl(phba->sli4_hba.u.if_type2. |
| 8112 | ERR1regaddr); |
| 8113 | phba->work_status[1] = |
| 8114 | readl(phba->sli4_hba.u.if_type2. |
| 8115 | ERR2regaddr); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8116 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 8117 | "2888 Unrecoverable port error " |
| 8118 | "following POST: port status reg " |
| 8119 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8120 | "error 1=0x%x, error 2=0x%x\n", |
| 8121 | reg_data.word0, |
| 8122 | portsmphr_reg.word0, |
| 8123 | phba->work_status[0], |
| 8124 | phba->work_status[1]); |
| 8125 | port_error = -ENODEV; |
| 8126 | } |
| 8127 | break; |
| 8128 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8129 | default: |
| 8130 | break; |
| 8131 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8132 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8133 | return port_error; |
| 8134 | } |
| 8135 | |
| 8136 | /** |
| 8137 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 8138 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8139 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8140 | * |
| 8141 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 8142 | * memory map. |
| 8143 | **/ |
| 8144 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8145 | 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] | 8146 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8147 | switch (if_type) { |
| 8148 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8149 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 8150 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 8151 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 8152 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 8153 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 8154 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 8155 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 8156 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 8157 | phba->sli4_hba.SLIINTFregaddr = |
| 8158 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8159 | break; |
| 8160 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 8161 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8162 | phba->sli4_hba.conf_regs_memmap_p + |
| 8163 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8164 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8165 | phba->sli4_hba.conf_regs_memmap_p + |
| 8166 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8167 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8168 | phba->sli4_hba.conf_regs_memmap_p + |
| 8169 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8170 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8171 | phba->sli4_hba.conf_regs_memmap_p + |
| 8172 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8173 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8174 | phba->sli4_hba.conf_regs_memmap_p + |
| 8175 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8176 | phba->sli4_hba.SLIINTFregaddr = |
| 8177 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8178 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8179 | phba->sli4_hba.conf_regs_memmap_p + |
| 8180 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8181 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8182 | phba->sli4_hba.conf_regs_memmap_p + |
| 8183 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8184 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8185 | phba->sli4_hba.conf_regs_memmap_p + |
| 8186 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8187 | phba->sli4_hba.CQDBregaddr = |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8188 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8189 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8190 | phba->sli4_hba.MQDBregaddr = |
| 8191 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 8192 | phba->sli4_hba.BMBXregaddr = |
| 8193 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8194 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8195 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8196 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8197 | phba->sli4_hba.conf_regs_memmap_p + |
| 8198 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
| 8199 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
| 8200 | phba->sli4_hba.conf_regs_memmap_p + |
| 8201 | LPFC_CTL_PORT_ER1_OFFSET; |
| 8202 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
| 8203 | phba->sli4_hba.conf_regs_memmap_p + |
| 8204 | LPFC_CTL_PORT_ER2_OFFSET; |
| 8205 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
| 8206 | phba->sli4_hba.conf_regs_memmap_p + |
| 8207 | LPFC_CTL_PORT_CTL_OFFSET; |
| 8208 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
| 8209 | phba->sli4_hba.conf_regs_memmap_p + |
| 8210 | LPFC_CTL_PORT_STA_OFFSET; |
| 8211 | phba->sli4_hba.PSMPHRregaddr = |
| 8212 | phba->sli4_hba.conf_regs_memmap_p + |
| 8213 | LPFC_CTL_PORT_SEM_OFFSET; |
| 8214 | phba->sli4_hba.BMBXregaddr = |
| 8215 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8216 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8217 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8218 | default: |
| 8219 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8220 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8221 | if_type); |
| 8222 | break; |
| 8223 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8224 | } |
| 8225 | |
| 8226 | /** |
| 8227 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 8228 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 8229 | * @if_type: sli if type to operate on. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8230 | * |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8231 | * This routine is invoked to set up SLI4 BAR1 register memory map. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8232 | **/ |
| 8233 | static void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8234 | 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] | 8235 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8236 | switch (if_type) { |
| 8237 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8238 | phba->sli4_hba.PSMPHRregaddr = |
| 8239 | phba->sli4_hba.ctrl_regs_memmap_p + |
| 8240 | LPFC_SLIPORT_IF0_SMPHR; |
| 8241 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8242 | LPFC_HST_ISR0; |
| 8243 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8244 | LPFC_HST_IMR0; |
| 8245 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8246 | LPFC_HST_ISCR0; |
| 8247 | break; |
| 8248 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8249 | phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8250 | LPFC_IF6_RQ_DOORBELL; |
| 8251 | phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8252 | LPFC_IF6_WQ_DOORBELL; |
| 8253 | phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8254 | LPFC_IF6_CQ_DOORBELL; |
| 8255 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8256 | LPFC_IF6_EQ_DOORBELL; |
| 8257 | phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8258 | LPFC_IF6_MQ_DOORBELL; |
| 8259 | break; |
| 8260 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8261 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8262 | default: |
| 8263 | dev_err(&phba->pcidev->dev, |
| 8264 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8265 | if_type); |
| 8266 | break; |
| 8267 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8268 | } |
| 8269 | |
| 8270 | /** |
| 8271 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 8272 | * @phba: pointer to lpfc hba data structure. |
| 8273 | * @vf: virtual function number |
| 8274 | * |
| 8275 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 8276 | * based on the given viftual function number, @vf. |
| 8277 | * |
| 8278 | * Return 0 if successful, otherwise -ENODEV. |
| 8279 | **/ |
| 8280 | static int |
| 8281 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 8282 | { |
| 8283 | if (vf > LPFC_VIR_FUNC_MAX) |
| 8284 | return -ENODEV; |
| 8285 | |
| 8286 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8287 | vf * LPFC_VFR_PAGE_SIZE + |
| 8288 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8289 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8290 | vf * LPFC_VFR_PAGE_SIZE + |
| 8291 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8292 | phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8293 | vf * LPFC_VFR_PAGE_SIZE + |
| 8294 | LPFC_EQCQ_DOORBELL); |
| 8295 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8296 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8297 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 8298 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8299 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 8300 | return 0; |
| 8301 | } |
| 8302 | |
| 8303 | /** |
| 8304 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 8305 | * @phba: pointer to lpfc hba data structure. |
| 8306 | * |
| 8307 | * This routine is invoked to create the bootstrap mailbox |
| 8308 | * region consistent with the SLI-4 interface spec. This |
| 8309 | * routine allocates all memory necessary to communicate |
| 8310 | * mailbox commands to the port and sets up all alignment |
| 8311 | * needs. No locks are expected to be held when calling |
| 8312 | * this routine. |
| 8313 | * |
| 8314 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8315 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8316 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8317 | **/ |
| 8318 | static int |
| 8319 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 8320 | { |
| 8321 | uint32_t bmbx_size; |
| 8322 | struct lpfc_dmabuf *dmabuf; |
| 8323 | struct dma_address *dma_address; |
| 8324 | uint32_t pa_addr; |
| 8325 | uint64_t phys_addr; |
| 8326 | |
| 8327 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 8328 | if (!dmabuf) |
| 8329 | return -ENOMEM; |
| 8330 | |
| 8331 | /* |
| 8332 | * The bootstrap mailbox region is comprised of 2 parts |
| 8333 | * plus an alignment restriction of 16 bytes. |
| 8334 | */ |
| 8335 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 8336 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 8337 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8338 | if (!dmabuf->virt) { |
| 8339 | kfree(dmabuf); |
| 8340 | return -ENOMEM; |
| 8341 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8342 | |
| 8343 | /* |
| 8344 | * Initialize the bootstrap mailbox pointers now so that the register |
| 8345 | * operations are simple later. The mailbox dma address is required |
| 8346 | * to be 16-byte aligned. Also align the virtual memory as each |
| 8347 | * maibox is copied into the bmbx mailbox region before issuing the |
| 8348 | * command to the port. |
| 8349 | */ |
| 8350 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 8351 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 8352 | |
| 8353 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 8354 | LPFC_ALIGN_16_BYTE); |
| 8355 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 8356 | LPFC_ALIGN_16_BYTE); |
| 8357 | |
| 8358 | /* |
| 8359 | * Set the high and low physical addresses now. The SLI4 alignment |
| 8360 | * requirement is 16 bytes and the mailbox is posted to the port |
| 8361 | * as two 30-bit addresses. The other data is a bit marking whether |
| 8362 | * the 30-bit address is the high or low address. |
| 8363 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 8364 | * clean on 32 bit machines. |
| 8365 | */ |
| 8366 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8367 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 8368 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 8369 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 8370 | LPFC_BMBX_BIT1_ADDR_HI); |
| 8371 | |
| 8372 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 8373 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 8374 | LPFC_BMBX_BIT1_ADDR_LO); |
| 8375 | return 0; |
| 8376 | } |
| 8377 | |
| 8378 | /** |
| 8379 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 8380 | * @phba: pointer to lpfc hba data structure. |
| 8381 | * |
| 8382 | * This routine is invoked to teardown the bootstrap mailbox |
| 8383 | * region and release all host resources. This routine requires |
| 8384 | * the caller to ensure all mailbox commands recovered, no |
| 8385 | * additional mailbox comands are sent, and interrupts are disabled |
| 8386 | * before calling this routine. |
| 8387 | * |
| 8388 | **/ |
| 8389 | static void |
| 8390 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 8391 | { |
| 8392 | dma_free_coherent(&phba->pcidev->dev, |
| 8393 | phba->sli4_hba.bmbx.bmbx_size, |
| 8394 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 8395 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 8396 | |
| 8397 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 8398 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 8399 | } |
| 8400 | |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8401 | static const char * const lpfc_topo_to_str[] = { |
| 8402 | "Loop then P2P", |
| 8403 | "Loopback", |
| 8404 | "P2P Only", |
| 8405 | "Unsupported", |
| 8406 | "Loop Only", |
| 8407 | "Unsupported", |
| 8408 | "P2P then Loop", |
| 8409 | }; |
| 8410 | |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 8411 | #define LINK_FLAGS_DEF 0x0 |
| 8412 | #define LINK_FLAGS_P2P 0x1 |
| 8413 | #define LINK_FLAGS_LOOP 0x2 |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8414 | /** |
| 8415 | * lpfc_map_topology - Map the topology read from READ_CONFIG |
| 8416 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 8417 | * @rd_config: pointer to read config data |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8418 | * |
| 8419 | * This routine is invoked to map the topology values as read |
| 8420 | * from the read config mailbox command. If the persistent |
| 8421 | * topology feature is supported, the firmware will provide the |
| 8422 | * saved topology information to be used in INIT_LINK |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8423 | **/ |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8424 | static void |
| 8425 | lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config) |
| 8426 | { |
| 8427 | u8 ptv, tf, pt; |
| 8428 | |
| 8429 | ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config); |
| 8430 | tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config); |
| 8431 | pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config); |
| 8432 | |
| 8433 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8434 | "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x", |
| 8435 | ptv, tf, pt); |
| 8436 | if (!ptv) { |
| 8437 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8438 | "2019 FW does not support persistent topology " |
| 8439 | "Using driver parameter defined value [%s]", |
| 8440 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8441 | return; |
| 8442 | } |
| 8443 | /* FW supports persistent topology - override module parameter value */ |
| 8444 | phba->hba_flag |= HBA_PERSISTENT_TOPO; |
| 8445 | switch (phba->pcidev->device) { |
| 8446 | case PCI_DEVICE_ID_LANCER_G7_FC: |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8447 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 8448 | if (!tf) { |
| 8449 | phba->cfg_topology = ((pt == LINK_FLAGS_LOOP) |
| 8450 | ? FLAGS_TOPOLOGY_MODE_LOOP |
| 8451 | : FLAGS_TOPOLOGY_MODE_PT_PT); |
| 8452 | } else { |
| 8453 | phba->hba_flag &= ~HBA_PERSISTENT_TOPO; |
| 8454 | } |
| 8455 | break; |
| 8456 | default: /* G5 */ |
| 8457 | if (tf) { |
| 8458 | /* If topology failover set - pt is '0' or '1' */ |
| 8459 | phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP : |
| 8460 | FLAGS_TOPOLOGY_MODE_LOOP_PT); |
| 8461 | } else { |
| 8462 | phba->cfg_topology = ((pt == LINK_FLAGS_P2P) |
| 8463 | ? FLAGS_TOPOLOGY_MODE_PT_PT |
| 8464 | : FLAGS_TOPOLOGY_MODE_LOOP); |
| 8465 | } |
| 8466 | break; |
| 8467 | } |
| 8468 | if (phba->hba_flag & HBA_PERSISTENT_TOPO) { |
| 8469 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8470 | "2020 Using persistent topology value [%s]", |
| 8471 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8472 | } else { |
| 8473 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8474 | "2021 Invalid topology values from FW " |
| 8475 | "Using driver parameter defined value [%s]", |
| 8476 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8477 | } |
| 8478 | } |
| 8479 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8480 | /** |
| 8481 | * lpfc_sli4_read_config - Get the config parameters. |
| 8482 | * @phba: pointer to lpfc hba data structure. |
| 8483 | * |
| 8484 | * This routine is invoked to read the configuration parameters from the HBA. |
| 8485 | * The configuration parameters are used to set the base and maximum values |
| 8486 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 8487 | * allocation for the port. |
| 8488 | * |
| 8489 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8490 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8491 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8492 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8493 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8494 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8495 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 8496 | { |
| 8497 | LPFC_MBOXQ_t *pmb; |
| 8498 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8499 | union lpfc_sli4_cfg_shdr *shdr; |
| 8500 | uint32_t shdr_status, shdr_add_status; |
| 8501 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 8502 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8503 | char *pdesc_0; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8504 | uint16_t forced_link_speed; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8505 | uint32_t if_type, qmin; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8506 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8507 | |
| 8508 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8509 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8510 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8511 | "2011 Unable to allocate memory for issuing " |
| 8512 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 8513 | return -ENOMEM; |
| 8514 | } |
| 8515 | |
| 8516 | lpfc_read_config(phba, pmb); |
| 8517 | |
| 8518 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8519 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8520 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 8521 | "2012 Mailbox failed , mbxCmd x%x " |
| 8522 | "READ_CONFIG, mbxStatus x%x\n", |
| 8523 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8524 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8525 | rc = -EIO; |
| 8526 | } else { |
| 8527 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8528 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 8529 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 8530 | phba->sli4_hba.lnk_info.lnk_tp = |
| 8531 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 8532 | phba->sli4_hba.lnk_info.lnk_no = |
| 8533 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 8534 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8535 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 8536 | phba->sli4_hba.lnk_info.lnk_tp, |
| 8537 | phba->sli4_hba.lnk_info.lnk_no); |
| 8538 | } else |
| 8539 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8540 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 8541 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 8542 | if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) { |
| 8543 | phba->bbcredit_support = 1; |
| 8544 | phba->sli4_hba.bbscn_params.word0 = rd_config->word8; |
| 8545 | } |
| 8546 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8547 | phba->sli4_hba.conf_trunk = |
| 8548 | bf_get(lpfc_mbx_rd_conf_trunk, rd_config); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8549 | phba->sli4_hba.extents_in_use = |
| 8550 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8551 | phba->sli4_hba.max_cfg_param.max_xri = |
| 8552 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
James Smart | 31f06d2 | 2019-08-14 16:56:31 -0700 | [diff] [blame] | 8553 | /* Reduce resource usage in kdump environment */ |
| 8554 | if (is_kdump_kernel() && |
| 8555 | phba->sli4_hba.max_cfg_param.max_xri > 512) |
| 8556 | phba->sli4_hba.max_cfg_param.max_xri = 512; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8557 | phba->sli4_hba.max_cfg_param.xri_base = |
| 8558 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 8559 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 8560 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
James Smart | 8b47ae6 | 2018-11-29 16:09:33 -0800 | [diff] [blame] | 8561 | /* Limit the max we support */ |
| 8562 | if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS) |
| 8563 | phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8564 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 8565 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 8566 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 8567 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 8568 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 8569 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 8570 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 8571 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 8572 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 8573 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 8574 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 8575 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8576 | phba->sli4_hba.max_cfg_param.max_eq = |
| 8577 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 8578 | phba->sli4_hba.max_cfg_param.max_rq = |
| 8579 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 8580 | phba->sli4_hba.max_cfg_param.max_wq = |
| 8581 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 8582 | phba->sli4_hba.max_cfg_param.max_cq = |
| 8583 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 8584 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 8585 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 8586 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 8587 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8588 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 8589 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8590 | phba->max_vports = phba->max_vpi; |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8591 | lpfc_map_topology(phba, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8592 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8593 | "2003 cfg params Extents? %d " |
| 8594 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8595 | "VPI(B:%d M:%d) " |
| 8596 | "VFI(B:%d M:%d) " |
| 8597 | "RPI(B:%d M:%d) " |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 8598 | "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] | 8599 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8600 | phba->sli4_hba.max_cfg_param.xri_base, |
| 8601 | phba->sli4_hba.max_cfg_param.max_xri, |
| 8602 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 8603 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 8604 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 8605 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 8606 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 8607 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8608 | phba->sli4_hba.max_cfg_param.max_fcfi, |
| 8609 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8610 | phba->sli4_hba.max_cfg_param.max_cq, |
| 8611 | phba->sli4_hba.max_cfg_param.max_wq, |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 8612 | phba->sli4_hba.max_cfg_param.max_rq, |
| 8613 | phba->lmt); |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8614 | |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8615 | /* |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8616 | * Calculate queue resources based on how |
| 8617 | * many WQ/CQ/EQs are available. |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8618 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8619 | qmin = phba->sli4_hba.max_cfg_param.max_wq; |
| 8620 | if (phba->sli4_hba.max_cfg_param.max_cq < qmin) |
| 8621 | qmin = phba->sli4_hba.max_cfg_param.max_cq; |
| 8622 | if (phba->sli4_hba.max_cfg_param.max_eq < qmin) |
| 8623 | qmin = phba->sli4_hba.max_cfg_param.max_eq; |
| 8624 | /* |
| 8625 | * Whats left after this can go toward NVME / FCP. |
| 8626 | * The minus 4 accounts for ELS, NVME LS, MBOX |
| 8627 | * plus one extra. When configured for |
| 8628 | * NVMET, FCP io channel WQs are not created. |
| 8629 | */ |
| 8630 | qmin -= 4; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8631 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8632 | /* Check to see if there is enough for NVME */ |
| 8633 | if ((phba->cfg_irq_chann > qmin) || |
| 8634 | (phba->cfg_hdw_queue > qmin)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8635 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 9e3e365 | 2020-08-03 14:02:23 -0700 | [diff] [blame] | 8636 | "2005 Reducing Queues - " |
| 8637 | "FW resource limitation: " |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8638 | "WQ %d CQ %d EQ %d: min %d: " |
| 8639 | "IRQ %d HDWQ %d\n", |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8640 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8641 | phba->sli4_hba.max_cfg_param.max_cq, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8642 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8643 | qmin, phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8644 | phba->cfg_hdw_queue); |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8645 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8646 | if (phba->cfg_irq_chann > qmin) |
| 8647 | phba->cfg_irq_chann = qmin; |
| 8648 | if (phba->cfg_hdw_queue > qmin) |
| 8649 | phba->cfg_hdw_queue = qmin; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8650 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8651 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8652 | |
| 8653 | if (rc) |
| 8654 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8655 | |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8656 | /* Update link speed if forced link speed is supported */ |
| 8657 | 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] | 8658 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8659 | forced_link_speed = |
| 8660 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); |
| 8661 | if (forced_link_speed) { |
| 8662 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; |
| 8663 | |
| 8664 | switch (forced_link_speed) { |
| 8665 | case LINK_SPEED_1G: |
| 8666 | phba->cfg_link_speed = |
| 8667 | LPFC_USER_LINK_SPEED_1G; |
| 8668 | break; |
| 8669 | case LINK_SPEED_2G: |
| 8670 | phba->cfg_link_speed = |
| 8671 | LPFC_USER_LINK_SPEED_2G; |
| 8672 | break; |
| 8673 | case LINK_SPEED_4G: |
| 8674 | phba->cfg_link_speed = |
| 8675 | LPFC_USER_LINK_SPEED_4G; |
| 8676 | break; |
| 8677 | case LINK_SPEED_8G: |
| 8678 | phba->cfg_link_speed = |
| 8679 | LPFC_USER_LINK_SPEED_8G; |
| 8680 | break; |
| 8681 | case LINK_SPEED_10G: |
| 8682 | phba->cfg_link_speed = |
| 8683 | LPFC_USER_LINK_SPEED_10G; |
| 8684 | break; |
| 8685 | case LINK_SPEED_16G: |
| 8686 | phba->cfg_link_speed = |
| 8687 | LPFC_USER_LINK_SPEED_16G; |
| 8688 | break; |
| 8689 | case LINK_SPEED_32G: |
| 8690 | phba->cfg_link_speed = |
| 8691 | LPFC_USER_LINK_SPEED_32G; |
| 8692 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 8693 | case LINK_SPEED_64G: |
| 8694 | phba->cfg_link_speed = |
| 8695 | LPFC_USER_LINK_SPEED_64G; |
| 8696 | break; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8697 | case 0xffff: |
| 8698 | phba->cfg_link_speed = |
| 8699 | LPFC_USER_LINK_SPEED_AUTO; |
| 8700 | break; |
| 8701 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8702 | lpfc_printf_log(phba, KERN_ERR, |
| 8703 | LOG_TRACE_EVENT, |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8704 | "0047 Unrecognized link " |
| 8705 | "speed : %d\n", |
| 8706 | forced_link_speed); |
| 8707 | phba->cfg_link_speed = |
| 8708 | LPFC_USER_LINK_SPEED_AUTO; |
| 8709 | } |
| 8710 | } |
| 8711 | } |
| 8712 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8713 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 8714 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 8715 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 8716 | if (phba->cfg_hba_queue_depth > length) { |
| 8717 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8718 | "3361 HBA queue depth changed from %d to %d\n", |
| 8719 | phba->cfg_hba_queue_depth, length); |
| 8720 | phba->cfg_hba_queue_depth = length; |
| 8721 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8722 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8723 | 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] | 8724 | LPFC_SLI_INTF_IF_TYPE_2) |
| 8725 | goto read_cfg_out; |
| 8726 | |
| 8727 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 8728 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 8729 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8730 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8731 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 8732 | length, LPFC_SLI4_MBX_EMBED); |
| 8733 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8734 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8735 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8736 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8737 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8738 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8739 | if (rc2 || shdr_status || shdr_add_status) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8740 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8741 | "3026 Mailbox failed , mbxCmd x%x " |
| 8742 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 8743 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8744 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8745 | goto read_cfg_out; |
| 8746 | } |
| 8747 | |
| 8748 | /* search for fc_fcoe resrouce descriptor */ |
| 8749 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8750 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8751 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 8752 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 8753 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 8754 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 8755 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 8756 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 8757 | goto read_cfg_out; |
| 8758 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8759 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8760 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8761 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8762 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8763 | phba->sli4_hba.iov.pf_number = |
| 8764 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 8765 | phba->sli4_hba.iov.vf_number = |
| 8766 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 8767 | break; |
| 8768 | } |
| 8769 | } |
| 8770 | |
| 8771 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 8772 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8773 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 8774 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 8775 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8776 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8777 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8778 | "3028 GET_FUNCTION_CONFIG: failed to find " |
Colin Ian King | c4dba18 | 2018-10-16 18:28:53 +0100 | [diff] [blame] | 8779 | "Resource Descriptor:x%x\n", |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8780 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8781 | |
| 8782 | read_cfg_out: |
| 8783 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8784 | return rc; |
| 8785 | } |
| 8786 | |
| 8787 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8788 | * 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] | 8789 | * @phba: pointer to lpfc hba data structure. |
| 8790 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8791 | * This routine is invoked to setup the port-side endian order when |
| 8792 | * the port if_type is 0. This routine has no function for other |
| 8793 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8794 | * |
| 8795 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8796 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8797 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8798 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8799 | **/ |
| 8800 | static int |
| 8801 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 8802 | { |
| 8803 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8804 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8805 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 8806 | HOST_ENDIAN_HIGH_WORD1}; |
| 8807 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8808 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8809 | switch (if_type) { |
| 8810 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8811 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 8812 | GFP_KERNEL); |
| 8813 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8814 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8815 | "0492 Unable to allocate memory for " |
| 8816 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 8817 | "command\n"); |
| 8818 | return -ENOMEM; |
| 8819 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8820 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8821 | /* |
| 8822 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 8823 | * two words to contain special data values and no other data. |
| 8824 | */ |
| 8825 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 8826 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 8827 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8828 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8829 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8830 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 8831 | "failed with status x%x\n", |
| 8832 | rc); |
| 8833 | rc = -EIO; |
| 8834 | } |
| 8835 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8836 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8837 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8838 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8839 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8840 | default: |
| 8841 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8842 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8843 | return rc; |
| 8844 | } |
| 8845 | |
| 8846 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8847 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8848 | * @phba: pointer to lpfc hba data structure. |
| 8849 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8850 | * This routine is invoked to check the user settable queue counts for EQs. |
| 8851 | * 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] | 8852 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 8853 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8854 | * |
| 8855 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8856 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8857 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8858 | **/ |
| 8859 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8860 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8861 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8862 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8863 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8864 | * device parameters |
| 8865 | */ |
| 8866 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8867 | if (phba->nvmet_support) { |
James Smart | 97a9ed3 | 2019-10-18 14:18:17 -0700 | [diff] [blame] | 8868 | if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq) |
| 8869 | phba->cfg_nvmet_mrq = phba->cfg_hdw_queue; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 8870 | if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) |
| 8871 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8872 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8873 | |
| 8874 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8875 | "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n", |
| 8876 | phba->cfg_hdw_queue, phba->cfg_irq_chann, |
| 8877 | phba->cfg_nvmet_mrq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8878 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8879 | /* Get EQ depth from module parameter, fake the default for now */ |
| 8880 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8881 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8882 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8883 | /* Get CQ depth from module parameter, fake the default for now */ |
| 8884 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8885 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8886 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8887 | } |
| 8888 | |
| 8889 | static int |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8890 | lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8891 | { |
| 8892 | struct lpfc_queue *qdesc; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8893 | u32 wqesize; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8894 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8895 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8896 | cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ); |
| 8897 | /* Create Fast Path IO CQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8898 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8899 | /* Increase the CQ size when WQEs contain an embedded cdb */ |
| 8900 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8901 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8902 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8903 | |
| 8904 | else |
| 8905 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8906 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8907 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8908 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8909 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 8910 | "0499 Failed allocate fast-path IO CQ (%d)\n", |
| 8911 | idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8912 | return 1; |
| 8913 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8914 | qdesc->qe_valid = 1; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8915 | qdesc->hdwq = idx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8916 | qdesc->chann = cpu; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8917 | phba->sli4_hba.hdwq[idx].io_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8918 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8919 | /* Create Fast Path IO WQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8920 | if (phba->enab_exp_wqcq_pages) { |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8921 | /* Increase the WQ size when WQEs contain an embedded cdb */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8922 | wqesize = (phba->fcp_embed_io) ? |
| 8923 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8924 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8925 | wqesize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8926 | LPFC_WQE_EXP_COUNT, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8927 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8928 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8929 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8930 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8931 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8932 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8933 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8934 | "0503 Failed allocate fast-path IO WQ (%d)\n", |
| 8935 | idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8936 | return 1; |
| 8937 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8938 | qdesc->hdwq = idx; |
| 8939 | qdesc->chann = cpu; |
| 8940 | phba->sli4_hba.hdwq[idx].io_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8941 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8942 | return 0; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8943 | } |
| 8944 | |
| 8945 | /** |
| 8946 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 8947 | * @phba: pointer to lpfc hba data structure. |
| 8948 | * |
| 8949 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 8950 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 8951 | * count (queue depth) shall be taken from the module parameter. For now, |
| 8952 | * we just use some constant number as place holder. |
| 8953 | * |
| 8954 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 8955 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8956 | * -ENOMEM - No availble memory |
| 8957 | * -EIO - The mailbox failed to complete successfully. |
| 8958 | **/ |
| 8959 | int |
| 8960 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 8961 | { |
| 8962 | struct lpfc_queue *qdesc; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8963 | int idx, cpu, eqcpu; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8964 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8965 | struct lpfc_vector_map_info *cpup; |
| 8966 | struct lpfc_vector_map_info *eqcpup; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8967 | struct lpfc_eq_intr_info *eqi; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8968 | |
| 8969 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8970 | * Create HBA Record arrays. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8971 | * Both NVME and FCP will share that same vectors / EQs |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8972 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8973 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 8974 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 8975 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 8976 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 8977 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 8978 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8979 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8980 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8981 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8982 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8983 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8984 | if (!phba->sli4_hba.hdwq) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8985 | phba->sli4_hba.hdwq = kcalloc( |
| 8986 | phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue), |
| 8987 | GFP_KERNEL); |
| 8988 | if (!phba->sli4_hba.hdwq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8989 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8990 | "6427 Failed allocate memory for " |
| 8991 | "fast-path Hardware Queue array\n"); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8992 | goto out_error; |
| 8993 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8994 | /* Prepare hardware queues to take IO buffers */ |
| 8995 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 8996 | qp = &phba->sli4_hba.hdwq[idx]; |
| 8997 | spin_lock_init(&qp->io_buf_list_get_lock); |
| 8998 | spin_lock_init(&qp->io_buf_list_put_lock); |
| 8999 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 9000 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 9001 | qp->get_io_bufs = 0; |
| 9002 | qp->put_io_bufs = 0; |
| 9003 | qp->total_io_bufs = 0; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9004 | spin_lock_init(&qp->abts_io_buf_list_lock); |
| 9005 | INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9006 | qp->abts_scsi_io_bufs = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9007 | qp->abts_nvme_io_bufs = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 9008 | INIT_LIST_HEAD(&qp->sgl_list); |
| 9009 | INIT_LIST_HEAD(&qp->cmd_rsp_buf_list); |
| 9010 | spin_lock_init(&qp->hdwq_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9011 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9012 | } |
| 9013 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9014 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9015 | if (phba->nvmet_support) { |
| 9016 | phba->sli4_hba.nvmet_cqset = kcalloc( |
| 9017 | phba->cfg_nvmet_mrq, |
| 9018 | sizeof(struct lpfc_queue *), |
| 9019 | GFP_KERNEL); |
| 9020 | if (!phba->sli4_hba.nvmet_cqset) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9021 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9022 | "3121 Fail allocate memory for " |
| 9023 | "fast-path CQ set array\n"); |
| 9024 | goto out_error; |
| 9025 | } |
| 9026 | phba->sli4_hba.nvmet_mrq_hdr = kcalloc( |
| 9027 | phba->cfg_nvmet_mrq, |
| 9028 | sizeof(struct lpfc_queue *), |
| 9029 | GFP_KERNEL); |
| 9030 | if (!phba->sli4_hba.nvmet_mrq_hdr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9031 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9032 | "3122 Fail allocate memory for " |
| 9033 | "fast-path RQ set hdr array\n"); |
| 9034 | goto out_error; |
| 9035 | } |
| 9036 | phba->sli4_hba.nvmet_mrq_data = kcalloc( |
| 9037 | phba->cfg_nvmet_mrq, |
| 9038 | sizeof(struct lpfc_queue *), |
| 9039 | GFP_KERNEL); |
| 9040 | if (!phba->sli4_hba.nvmet_mrq_data) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9041 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9042 | "3124 Fail allocate memory for " |
| 9043 | "fast-path RQ set data array\n"); |
| 9044 | goto out_error; |
| 9045 | } |
| 9046 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9047 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9048 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9049 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9050 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9051 | /* Create HBA Event Queues (EQs) */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9052 | for_each_present_cpu(cpu) { |
| 9053 | /* We only want to create 1 EQ per vector, even though |
| 9054 | * multiple CPUs might be using that vector. so only |
| 9055 | * selects the CPUs that are LPFC_CPU_FIRST_IRQ. |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9056 | */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9057 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9058 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9059 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9060 | |
| 9061 | /* Get a ptr to the Hardware Queue associated with this CPU */ |
| 9062 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 9063 | |
| 9064 | /* Allocate an EQ */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9065 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9066 | phba->sli4_hba.eq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9067 | phba->sli4_hba.eq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9068 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9069 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9070 | "0497 Failed allocate EQ (%d)\n", |
| 9071 | cpup->hdwq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9072 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9073 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9074 | qdesc->qe_valid = 1; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9075 | qdesc->hdwq = cpup->hdwq; |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 9076 | qdesc->chann = cpu; /* First CPU this EQ is affinitized to */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 9077 | qdesc->last_cpu = qdesc->chann; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9078 | |
| 9079 | /* Save the allocated EQ in the Hardware Queue */ |
| 9080 | qp->hba_eq = qdesc; |
| 9081 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 9082 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu); |
| 9083 | list_add(&qdesc->cpu_list, &eqi->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9084 | } |
| 9085 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9086 | /* Now we need to populate the other Hardware Queues, that share |
| 9087 | * an IRQ vector, with the associated EQ ptr. |
| 9088 | */ |
| 9089 | for_each_present_cpu(cpu) { |
| 9090 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9091 | |
| 9092 | /* Check for EQ already allocated in previous loop */ |
| 9093 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 9094 | continue; |
| 9095 | |
| 9096 | /* Check for multiple CPUs per hdwq */ |
| 9097 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 9098 | if (qp->hba_eq) |
| 9099 | continue; |
| 9100 | |
| 9101 | /* We need to share an EQ for this hdwq */ |
| 9102 | eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ); |
| 9103 | eqcpup = &phba->sli4_hba.cpu_map[eqcpu]; |
| 9104 | qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq; |
| 9105 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9106 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9107 | /* Allocate IO Path SLI4 CQ/WQs */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9108 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9109 | if (lpfc_alloc_io_wq_cq(phba, idx)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9110 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9111 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9112 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9113 | if (phba->nvmet_support) { |
| 9114 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
| 9115 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 9116 | LPFC_FIND_BY_HDWQ); |
| 9117 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9118 | LPFC_DEFAULT_PAGE_SIZE, |
| 9119 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9120 | phba->sli4_hba.cq_ecount, |
| 9121 | cpu); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9122 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9123 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9124 | "3142 Failed allocate NVME " |
| 9125 | "CQ Set (%d)\n", idx); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9126 | goto out_error; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9127 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9128 | qdesc->qe_valid = 1; |
| 9129 | qdesc->hdwq = idx; |
| 9130 | qdesc->chann = cpu; |
| 9131 | phba->sli4_hba.nvmet_cqset[idx] = qdesc; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9132 | } |
| 9133 | } |
| 9134 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9135 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9136 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9137 | */ |
| 9138 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9139 | cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9140 | /* Create slow-path Mailbox Command Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9141 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9142 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9143 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9144 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9145 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9146 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9147 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9148 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9149 | qdesc->qe_valid = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9150 | phba->sli4_hba.mbx_cq = qdesc; |
| 9151 | |
| 9152 | /* Create slow-path ELS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9153 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9154 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9155 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9156 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9157 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9158 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9159 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9160 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9161 | qdesc->qe_valid = 1; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9162 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9163 | phba->sli4_hba.els_cq = qdesc; |
| 9164 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9165 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9166 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9167 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9168 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9169 | |
| 9170 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9171 | |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9172 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9173 | phba->sli4_hba.mq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9174 | phba->sli4_hba.mq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9175 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9176 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9177 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9178 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9179 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9180 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9181 | phba->sli4_hba.mbx_wq = qdesc; |
| 9182 | |
| 9183 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9184 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9185 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9186 | |
| 9187 | /* Create slow-path ELS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9188 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9189 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9190 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9191 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9192 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9193 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9194 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9195 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9196 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9197 | phba->sli4_hba.els_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9198 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9199 | |
| 9200 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9201 | /* Create NVME LS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9202 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9203 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9204 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9205 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9206 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9207 | "6079 Failed allocate NVME LS CQ\n"); |
| 9208 | goto out_error; |
| 9209 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9210 | qdesc->chann = cpu; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9211 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9212 | phba->sli4_hba.nvmels_cq = qdesc; |
| 9213 | |
| 9214 | /* Create NVME LS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9215 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9216 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9217 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [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 | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9220 | "6080 Failed allocate NVME LS WQ\n"); |
| 9221 | goto out_error; |
| 9222 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9223 | qdesc->chann = cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9224 | phba->sli4_hba.nvmels_wq = qdesc; |
| 9225 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9226 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9227 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9228 | /* |
| 9229 | * Create Receive Queue (RQ) |
| 9230 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9231 | |
| 9232 | /* Create Receive Queue for header */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9233 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9234 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9235 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9236 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9237 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9238 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9239 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9240 | } |
| 9241 | phba->sli4_hba.hdr_rq = qdesc; |
| 9242 | |
| 9243 | /* Create Receive Queue for data */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9244 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9245 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9246 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9247 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9248 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9249 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9250 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9251 | } |
| 9252 | phba->sli4_hba.dat_rq = qdesc; |
| 9253 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9254 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 9255 | phba->nvmet_support) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9256 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9257 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 9258 | LPFC_FIND_BY_HDWQ); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9259 | /* Create NVMET Receive Queue for header */ |
| 9260 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9261 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9262 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9263 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9264 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9265 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9266 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9267 | "3146 Failed allocate " |
| 9268 | "receive HRQ\n"); |
| 9269 | goto out_error; |
| 9270 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9271 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9272 | phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc; |
| 9273 | |
| 9274 | /* Only needed for header of RQ pair */ |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9275 | qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp), |
| 9276 | GFP_KERNEL, |
| 9277 | cpu_to_node(cpu)); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9278 | if (qdesc->rqbp == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9279 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9280 | "6131 Failed allocate " |
| 9281 | "Header RQBP\n"); |
| 9282 | goto out_error; |
| 9283 | } |
| 9284 | |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 9285 | /* Put list in known state in case driver load fails. */ |
| 9286 | INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list); |
| 9287 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9288 | /* Create NVMET Receive Queue for data */ |
| 9289 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9290 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9291 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9292 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9293 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9294 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9295 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9296 | "3156 Failed allocate " |
| 9297 | "receive DRQ\n"); |
| 9298 | goto out_error; |
| 9299 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9300 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9301 | phba->sli4_hba.nvmet_mrq_data[idx] = qdesc; |
| 9302 | } |
| 9303 | } |
| 9304 | |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9305 | /* Clear NVME stats */ |
| 9306 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9307 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9308 | memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0, |
| 9309 | sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat)); |
| 9310 | } |
| 9311 | } |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9312 | |
| 9313 | /* Clear SCSI stats */ |
| 9314 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 9315 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9316 | memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0, |
| 9317 | sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat)); |
| 9318 | } |
| 9319 | } |
| 9320 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9321 | return 0; |
| 9322 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9323 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9324 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9325 | return -ENOMEM; |
| 9326 | } |
| 9327 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9328 | static inline void |
| 9329 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) |
| 9330 | { |
| 9331 | if (*qp != NULL) { |
| 9332 | lpfc_sli4_queue_free(*qp); |
| 9333 | *qp = NULL; |
| 9334 | } |
| 9335 | } |
| 9336 | |
| 9337 | static inline void |
| 9338 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) |
| 9339 | { |
| 9340 | int idx; |
| 9341 | |
| 9342 | if (*qs == NULL) |
| 9343 | return; |
| 9344 | |
| 9345 | for (idx = 0; idx < max; idx++) |
| 9346 | __lpfc_sli4_release_queue(&(*qs)[idx]); |
| 9347 | |
| 9348 | kfree(*qs); |
| 9349 | *qs = NULL; |
| 9350 | } |
| 9351 | |
| 9352 | static inline void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9353 | lpfc_sli4_release_hdwq(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9354 | { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9355 | struct lpfc_sli4_hdw_queue *hdwq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9356 | struct lpfc_queue *eq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9357 | uint32_t idx; |
| 9358 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9359 | hdwq = phba->sli4_hba.hdwq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9360 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9361 | /* Loop thru all Hardware Queues */ |
| 9362 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9363 | /* Free the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9364 | lpfc_sli4_queue_free(hdwq[idx].io_cq); |
| 9365 | lpfc_sli4_queue_free(hdwq[idx].io_wq); |
James Smart | 821bc88 | 2020-01-27 16:23:05 -0800 | [diff] [blame] | 9366 | hdwq[idx].hba_eq = NULL; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9367 | hdwq[idx].io_cq = NULL; |
| 9368 | hdwq[idx].io_wq = NULL; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 9369 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 9370 | lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]); |
| 9371 | lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9372 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9373 | /* Loop thru all IRQ vectors */ |
| 9374 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 9375 | /* Free the EQ corresponding to the IRQ vector */ |
| 9376 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 9377 | lpfc_sli4_queue_free(eq); |
| 9378 | phba->sli4_hba.hba_eq_hdl[idx].eq = NULL; |
| 9379 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9380 | } |
| 9381 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9382 | /** |
| 9383 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 9384 | * @phba: pointer to lpfc hba data structure. |
| 9385 | * |
| 9386 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 9387 | * operation. |
| 9388 | * |
| 9389 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9390 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9391 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9392 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9393 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9394 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9395 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 9396 | { |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9397 | /* |
| 9398 | * Set FREE_INIT before beginning to free the queues. |
| 9399 | * Wait until the users of queues to acknowledge to |
| 9400 | * release queues by clearing FREE_WAIT. |
| 9401 | */ |
| 9402 | spin_lock_irq(&phba->hbalock); |
| 9403 | phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT; |
| 9404 | while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) { |
| 9405 | spin_unlock_irq(&phba->hbalock); |
| 9406 | msleep(20); |
| 9407 | spin_lock_irq(&phba->hbalock); |
| 9408 | } |
| 9409 | spin_unlock_irq(&phba->hbalock); |
| 9410 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 9411 | lpfc_sli4_cleanup_poll_list(phba); |
| 9412 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9413 | /* Release HBA eqs */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9414 | if (phba->sli4_hba.hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9415 | lpfc_sli4_release_hdwq(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9416 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9417 | if (phba->nvmet_support) { |
| 9418 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset, |
| 9419 | phba->cfg_nvmet_mrq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9420 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9421 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr, |
| 9422 | phba->cfg_nvmet_mrq); |
| 9423 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data, |
| 9424 | phba->cfg_nvmet_mrq); |
| 9425 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9426 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9427 | /* Release mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9428 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9429 | |
| 9430 | /* Release ELS work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9431 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); |
| 9432 | |
| 9433 | /* Release ELS work queue */ |
| 9434 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9435 | |
| 9436 | /* Release unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9437 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); |
| 9438 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9439 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9440 | /* Release ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9441 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); |
| 9442 | |
| 9443 | /* Release NVME LS complete queue */ |
| 9444 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9445 | |
| 9446 | /* Release mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9447 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); |
| 9448 | |
| 9449 | /* Everything on this list has been freed */ |
| 9450 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9451 | |
| 9452 | /* Done with freeing the queues */ |
| 9453 | spin_lock_irq(&phba->hbalock); |
| 9454 | phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT; |
| 9455 | spin_unlock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9456 | } |
| 9457 | |
| 9458 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9459 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) |
| 9460 | { |
| 9461 | struct lpfc_rqb *rqbp; |
| 9462 | struct lpfc_dmabuf *h_buf; |
| 9463 | struct rqb_dmabuf *rqb_buffer; |
| 9464 | |
| 9465 | rqbp = rq->rqbp; |
| 9466 | while (!list_empty(&rqbp->rqb_buffer_list)) { |
| 9467 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 9468 | struct lpfc_dmabuf, list); |
| 9469 | |
| 9470 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 9471 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); |
| 9472 | rqbp->buffer_count--; |
| 9473 | } |
| 9474 | return 1; |
| 9475 | } |
| 9476 | |
| 9477 | static int |
| 9478 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 9479 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, |
| 9480 | int qidx, uint32_t qtype) |
| 9481 | { |
| 9482 | struct lpfc_sli_ring *pring; |
| 9483 | int rc; |
| 9484 | |
| 9485 | if (!eq || !cq || !wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9486 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9487 | "6085 Fast-path %s (%d) not allocated\n", |
| 9488 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); |
| 9489 | return -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9490 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9491 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9492 | /* create the Cq first */ |
| 9493 | rc = lpfc_cq_create(phba, cq, eq, |
| 9494 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); |
| 9495 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9496 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 9497 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", |
| 9498 | qidx, (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9499 | return rc; |
| 9500 | } |
| 9501 | |
| 9502 | if (qtype != LPFC_MBOX) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9503 | /* Setup cq_map for fast lookup */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9504 | if (cq_map) |
| 9505 | *cq_map = cq->queue_id; |
| 9506 | |
| 9507 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9508 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", |
| 9509 | qidx, cq->queue_id, qidx, eq->queue_id); |
| 9510 | |
| 9511 | /* create the wq */ |
| 9512 | rc = lpfc_wq_create(phba, wq, cq, qtype); |
| 9513 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9514 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c835c08 | 2019-03-12 16:30:30 -0700 | [diff] [blame] | 9515 | "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9516 | qidx, (uint32_t)rc); |
| 9517 | /* no need to tear down cq - caller will do so */ |
| 9518 | return rc; |
| 9519 | } |
| 9520 | |
| 9521 | /* Bind this CQ/WQ to the NVME ring */ |
| 9522 | pring = wq->pring; |
| 9523 | pring->sli.sli4.wqp = (void *)wq; |
| 9524 | cq->pring = pring; |
| 9525 | |
| 9526 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9527 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", |
| 9528 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); |
| 9529 | } else { |
| 9530 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); |
| 9531 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9532 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 9533 | "0539 Failed setup of slow-path MQ: " |
| 9534 | "rc = 0x%x\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9535 | /* no need to tear down cq - caller will do so */ |
| 9536 | return rc; |
| 9537 | } |
| 9538 | |
| 9539 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9540 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9541 | phba->sli4_hba.mbx_wq->queue_id, |
| 9542 | phba->sli4_hba.mbx_cq->queue_id); |
| 9543 | } |
| 9544 | |
| 9545 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9546 | } |
| 9547 | |
| 9548 | /** |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9549 | * lpfc_setup_cq_lookup - Setup the CQ lookup table |
| 9550 | * @phba: pointer to lpfc hba data structure. |
| 9551 | * |
| 9552 | * This routine will populate the cq_lookup table by all |
| 9553 | * available CQ queue_id's. |
| 9554 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 9555 | static void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9556 | lpfc_setup_cq_lookup(struct lpfc_hba *phba) |
| 9557 | { |
| 9558 | struct lpfc_queue *eq, *childq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9559 | int qidx; |
| 9560 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9561 | memset(phba->sli4_hba.cq_lookup, 0, |
| 9562 | (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1))); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9563 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9564 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9565 | /* Get the EQ corresponding to the IRQ vector */ |
| 9566 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9567 | if (!eq) |
| 9568 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9569 | /* Loop through all CQs associated with that EQ */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9570 | list_for_each_entry(childq, &eq->child_list, list) { |
| 9571 | if (childq->queue_id > phba->sli4_hba.cq_max) |
| 9572 | continue; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9573 | if (childq->subtype == LPFC_IO) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9574 | phba->sli4_hba.cq_lookup[childq->queue_id] = |
| 9575 | childq; |
| 9576 | } |
| 9577 | } |
| 9578 | } |
| 9579 | |
| 9580 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9581 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 9582 | * @phba: pointer to lpfc hba data structure. |
| 9583 | * |
| 9584 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 9585 | * operation. |
| 9586 | * |
| 9587 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9588 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9589 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9590 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9591 | **/ |
| 9592 | int |
| 9593 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 9594 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9595 | uint32_t shdr_status, shdr_add_status; |
| 9596 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9597 | struct lpfc_vector_map_info *cpup; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9598 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9599 | LPFC_MBOXQ_t *mboxq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9600 | int qidx, cpu; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9601 | uint32_t length, usdelay; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9602 | int rc = -ENOMEM; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9603 | |
| 9604 | /* Check for dual-ULP support */ |
| 9605 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9606 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9607 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9608 | "3249 Unable to allocate memory for " |
| 9609 | "QUERY_FW_CFG mailbox command\n"); |
| 9610 | return -ENOMEM; |
| 9611 | } |
| 9612 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 9613 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9614 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9615 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 9616 | length, LPFC_SLI4_MBX_EMBED); |
| 9617 | |
| 9618 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9619 | |
| 9620 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 9621 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 9622 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 9623 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 9624 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9625 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9626 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 9627 | "x%x add_status x%x, mbx status x%x\n", |
| 9628 | shdr_status, shdr_add_status, rc); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 9629 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9630 | rc = -ENXIO; |
| 9631 | goto out_error; |
| 9632 | } |
| 9633 | |
| 9634 | phba->sli4_hba.fw_func_mode = |
| 9635 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 9636 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 9637 | 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] | 9638 | phba->sli4_hba.physical_port = |
| 9639 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9640 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9641 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 9642 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 9643 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 9644 | |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 9645 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9646 | |
| 9647 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9648 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9649 | */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9650 | qp = phba->sli4_hba.hdwq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9651 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9652 | /* Set up HBA event queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9653 | if (!qp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9654 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9655 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9656 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9657 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9658 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9659 | |
| 9660 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9661 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9662 | /* Create HBA Event Queues (EQs) in order */ |
| 9663 | for_each_present_cpu(cpu) { |
| 9664 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9665 | |
| 9666 | /* Look for the CPU thats using that vector with |
| 9667 | * LPFC_CPU_FIRST_IRQ set. |
| 9668 | */ |
| 9669 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 9670 | continue; |
| 9671 | if (qidx != cpup->eq) |
| 9672 | continue; |
| 9673 | |
| 9674 | /* Create an EQ for that vector */ |
| 9675 | rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq, |
| 9676 | phba->cfg_fcp_imax); |
| 9677 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9678 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9679 | "0523 Failed setup of fast-path" |
| 9680 | " EQ (%d), rc = 0x%x\n", |
| 9681 | cpup->eq, (uint32_t)rc); |
| 9682 | goto out_destroy; |
| 9683 | } |
| 9684 | |
| 9685 | /* Save the EQ for that vector in the hba_eq_hdl */ |
| 9686 | phba->sli4_hba.hba_eq_hdl[cpup->eq].eq = |
| 9687 | qp[cpup->hdwq].hba_eq; |
| 9688 | |
| 9689 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9690 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
| 9691 | cpup->eq, |
| 9692 | qp[cpup->hdwq].hba_eq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9693 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9694 | } |
| 9695 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9696 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9697 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9698 | cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ); |
| 9699 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9700 | |
| 9701 | /* Create the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9702 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9703 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9704 | qp[qidx].io_cq, |
| 9705 | qp[qidx].io_wq, |
| 9706 | &phba->sli4_hba.hdwq[qidx].io_cq_map, |
| 9707 | qidx, |
| 9708 | LPFC_IO); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9709 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9710 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9711 | "0535 Failed to setup fastpath " |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9712 | "IO WQ/CQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9713 | qidx, (uint32_t)rc); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9714 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9715 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9716 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9717 | |
| 9718 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9719 | * Set up Slow Path Complete Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9720 | */ |
| 9721 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9722 | /* Set up slow-path MBOX CQ/MQ */ |
| 9723 | |
| 9724 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9725 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9726 | "0528 %s not allocated\n", |
| 9727 | phba->sli4_hba.mbx_cq ? |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9728 | "Mailbox WQ" : "Mailbox CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9729 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9730 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9731 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9732 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9733 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9734 | phba->sli4_hba.mbx_cq, |
| 9735 | phba->sli4_hba.mbx_wq, |
| 9736 | NULL, 0, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9737 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9738 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9739 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
| 9740 | (uint32_t)rc); |
| 9741 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9742 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9743 | if (phba->nvmet_support) { |
| 9744 | if (!phba->sli4_hba.nvmet_cqset) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9745 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9746 | "3165 Fast-path NVME CQ Set " |
| 9747 | "array not allocated\n"); |
| 9748 | rc = -ENOMEM; |
| 9749 | goto out_destroy; |
| 9750 | } |
| 9751 | if (phba->cfg_nvmet_mrq > 1) { |
| 9752 | rc = lpfc_cq_create_set(phba, |
| 9753 | phba->sli4_hba.nvmet_cqset, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9754 | qp, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9755 | LPFC_WCQ, LPFC_NVMET); |
| 9756 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9757 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9758 | "3164 Failed setup of NVME CQ " |
| 9759 | "Set, rc = 0x%x\n", |
| 9760 | (uint32_t)rc); |
| 9761 | goto out_destroy; |
| 9762 | } |
| 9763 | } else { |
| 9764 | /* Set up NVMET Receive Complete Queue */ |
| 9765 | rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0], |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9766 | qp[0].hba_eq, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9767 | LPFC_WCQ, LPFC_NVMET); |
| 9768 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9769 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9770 | "6089 Failed setup NVMET CQ: " |
| 9771 | "rc = 0x%x\n", (uint32_t)rc); |
| 9772 | goto out_destroy; |
| 9773 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9774 | phba->sli4_hba.nvmet_cqset[0]->chann = 0; |
| 9775 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9776 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9777 | "6090 NVMET CQ setup: cq-id=%d, " |
| 9778 | "parent eq-id=%d\n", |
| 9779 | phba->sli4_hba.nvmet_cqset[0]->queue_id, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9780 | qp[0].hba_eq->queue_id); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9781 | } |
| 9782 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9783 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9784 | /* Set up slow-path ELS WQ/CQ */ |
| 9785 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9786 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9787 | "0530 ELS %s not allocated\n", |
| 9788 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9789 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9790 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9791 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9792 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9793 | phba->sli4_hba.els_cq, |
| 9794 | phba->sli4_hba.els_wq, |
| 9795 | NULL, 0, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9796 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9797 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9798 | "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
| 9799 | (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9800 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9801 | } |
| 9802 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9803 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9804 | phba->sli4_hba.els_wq->queue_id, |
| 9805 | phba->sli4_hba.els_cq->queue_id); |
| 9806 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9807 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9808 | /* Set up NVME LS Complete Queue */ |
| 9809 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9810 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9811 | "6091 LS %s not allocated\n", |
| 9812 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); |
| 9813 | rc = -ENOMEM; |
| 9814 | goto out_destroy; |
| 9815 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9816 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9817 | phba->sli4_hba.nvmels_cq, |
| 9818 | phba->sli4_hba.nvmels_wq, |
| 9819 | NULL, 0, LPFC_NVME_LS); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9820 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9821 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9822 | "0526 Failed setup of NVVME LS WQ/CQ: " |
| 9823 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9824 | goto out_destroy; |
| 9825 | } |
| 9826 | |
| 9827 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9828 | "6096 ELS WQ setup: wq-id=%d, " |
| 9829 | "parent cq-id=%d\n", |
| 9830 | phba->sli4_hba.nvmels_wq->queue_id, |
| 9831 | phba->sli4_hba.nvmels_cq->queue_id); |
| 9832 | } |
| 9833 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9834 | /* |
| 9835 | * Create NVMET Receive Queue (RQ) |
| 9836 | */ |
| 9837 | if (phba->nvmet_support) { |
| 9838 | if ((!phba->sli4_hba.nvmet_cqset) || |
| 9839 | (!phba->sli4_hba.nvmet_mrq_hdr) || |
| 9840 | (!phba->sli4_hba.nvmet_mrq_data)) { |
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 | "6130 MRQ CQ Queues not " |
| 9843 | "allocated\n"); |
| 9844 | rc = -ENOMEM; |
| 9845 | goto out_destroy; |
| 9846 | } |
| 9847 | if (phba->cfg_nvmet_mrq > 1) { |
| 9848 | rc = lpfc_mrq_create(phba, |
| 9849 | phba->sli4_hba.nvmet_mrq_hdr, |
| 9850 | phba->sli4_hba.nvmet_mrq_data, |
| 9851 | phba->sli4_hba.nvmet_cqset, |
| 9852 | LPFC_NVMET); |
| 9853 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9854 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9855 | "6098 Failed setup of NVMET " |
| 9856 | "MRQ: rc = 0x%x\n", |
| 9857 | (uint32_t)rc); |
| 9858 | goto out_destroy; |
| 9859 | } |
| 9860 | |
| 9861 | } else { |
| 9862 | rc = lpfc_rq_create(phba, |
| 9863 | phba->sli4_hba.nvmet_mrq_hdr[0], |
| 9864 | phba->sli4_hba.nvmet_mrq_data[0], |
| 9865 | phba->sli4_hba.nvmet_cqset[0], |
| 9866 | LPFC_NVMET); |
| 9867 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9868 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9869 | "6057 Failed setup of NVMET " |
| 9870 | "Receive Queue: rc = 0x%x\n", |
| 9871 | (uint32_t)rc); |
| 9872 | goto out_destroy; |
| 9873 | } |
| 9874 | |
| 9875 | lpfc_printf_log( |
| 9876 | phba, KERN_INFO, LOG_INIT, |
| 9877 | "6099 NVMET RQ setup: hdr-rq-id=%d, " |
| 9878 | "dat-rq-id=%d parent cq-id=%d\n", |
| 9879 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id, |
| 9880 | phba->sli4_hba.nvmet_mrq_data[0]->queue_id, |
| 9881 | phba->sli4_hba.nvmet_cqset[0]->queue_id); |
| 9882 | |
| 9883 | } |
| 9884 | } |
| 9885 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9886 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9887 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9888 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9889 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9890 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9891 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9892 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9893 | 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] | 9894 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9895 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9896 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9897 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9898 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9899 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9900 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9901 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9902 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9903 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 9904 | "parent cq-id=%d\n", |
| 9905 | phba->sli4_hba.hdr_rq->queue_id, |
| 9906 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 9907 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9908 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9909 | if (phba->cfg_fcp_imax) |
| 9910 | usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax; |
| 9911 | else |
| 9912 | usdelay = 0; |
| 9913 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9914 | for (qidx = 0; qidx < phba->cfg_irq_chann; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9915 | qidx += LPFC_MAX_EQ_DELAY_EQID_CNT) |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 9916 | 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] | 9917 | usdelay); |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 9918 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9919 | if (phba->sli4_hba.cq_max) { |
| 9920 | kfree(phba->sli4_hba.cq_lookup); |
| 9921 | phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1), |
| 9922 | sizeof(struct lpfc_queue *), GFP_KERNEL); |
| 9923 | if (!phba->sli4_hba.cq_lookup) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9924 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9925 | "0549 Failed setup of CQ Lookup table: " |
| 9926 | "size 0x%x\n", phba->sli4_hba.cq_max); |
Dan Carpenter | fad28e3 | 2019-02-11 21:43:00 +0300 | [diff] [blame] | 9927 | rc = -ENOMEM; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9928 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9929 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9930 | lpfc_setup_cq_lookup(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9931 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9932 | return 0; |
| 9933 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9934 | out_destroy: |
| 9935 | lpfc_sli4_queue_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9936 | out_error: |
| 9937 | return rc; |
| 9938 | } |
| 9939 | |
| 9940 | /** |
| 9941 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 9942 | * @phba: pointer to lpfc hba data structure. |
| 9943 | * |
| 9944 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 9945 | * operation. |
| 9946 | * |
| 9947 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9948 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9949 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9950 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9951 | **/ |
| 9952 | void |
| 9953 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 9954 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9955 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9956 | struct lpfc_queue *eq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9957 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9958 | |
| 9959 | /* Unset mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9960 | if (phba->sli4_hba.mbx_wq) |
| 9961 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 9962 | |
| 9963 | /* Unset NVME LS work queue */ |
| 9964 | if (phba->sli4_hba.nvmels_wq) |
| 9965 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); |
| 9966 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9967 | /* Unset ELS work queue */ |
Colin Ian King | 019c0d6 | 2017-05-06 23:13:55 +0100 | [diff] [blame] | 9968 | if (phba->sli4_hba.els_wq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9969 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 9970 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9971 | /* Unset unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9972 | if (phba->sli4_hba.hdr_rq) |
| 9973 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, |
| 9974 | phba->sli4_hba.dat_rq); |
| 9975 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9976 | /* Unset mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9977 | if (phba->sli4_hba.mbx_cq) |
| 9978 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 9979 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9980 | /* Unset ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9981 | if (phba->sli4_hba.els_cq) |
| 9982 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 9983 | |
| 9984 | /* Unset NVME LS complete queue */ |
| 9985 | if (phba->sli4_hba.nvmels_cq) |
| 9986 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); |
| 9987 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9988 | if (phba->nvmet_support) { |
| 9989 | /* Unset NVMET MRQ queue */ |
| 9990 | if (phba->sli4_hba.nvmet_mrq_hdr) { |
| 9991 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9992 | lpfc_rq_destroy( |
| 9993 | phba, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9994 | phba->sli4_hba.nvmet_mrq_hdr[qidx], |
| 9995 | phba->sli4_hba.nvmet_mrq_data[qidx]); |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9996 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9997 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9998 | /* Unset NVMET CQ Set complete queue */ |
| 9999 | if (phba->sli4_hba.nvmet_cqset) { |
| 10000 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 10001 | lpfc_cq_destroy( |
| 10002 | phba, phba->sli4_hba.nvmet_cqset[qidx]); |
| 10003 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10004 | } |
| 10005 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10006 | /* Unset fast-path SLI4 queues */ |
| 10007 | if (phba->sli4_hba.hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10008 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10009 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10010 | /* Destroy the CQ/WQ corresponding to Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10011 | qp = &phba->sli4_hba.hdwq[qidx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10012 | lpfc_wq_destroy(phba, qp->io_wq); |
| 10013 | lpfc_cq_destroy(phba, qp->io_cq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10014 | } |
| 10015 | /* Loop thru all IRQ vectors */ |
| 10016 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 10017 | /* Destroy the EQ corresponding to the IRQ vector */ |
| 10018 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
| 10019 | lpfc_eq_destroy(phba, eq); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10020 | } |
| 10021 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10022 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10023 | kfree(phba->sli4_hba.cq_lookup); |
| 10024 | phba->sli4_hba.cq_lookup = NULL; |
| 10025 | phba->sli4_hba.cq_max = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10026 | } |
| 10027 | |
| 10028 | /** |
| 10029 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 10030 | * @phba: pointer to lpfc hba data structure. |
| 10031 | * |
| 10032 | * This routine is invoked to allocate and set up a pool of completion queue |
| 10033 | * events. The body of the completion queue event is a completion queue entry |
| 10034 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 10035 | * the following HBA completion queue events for the worker thread to process: |
| 10036 | * - Mailbox asynchronous events |
| 10037 | * - Receive queue completion unsolicited events |
| 10038 | * Later, this can be used for all the slow-path events. |
| 10039 | * |
| 10040 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10041 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10042 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10043 | **/ |
| 10044 | static int |
| 10045 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 10046 | { |
| 10047 | struct lpfc_cq_event *cq_event; |
| 10048 | int i; |
| 10049 | |
| 10050 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 10051 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 10052 | if (!cq_event) |
| 10053 | goto out_pool_create_fail; |
| 10054 | list_add_tail(&cq_event->list, |
| 10055 | &phba->sli4_hba.sp_cqe_event_pool); |
| 10056 | } |
| 10057 | return 0; |
| 10058 | |
| 10059 | out_pool_create_fail: |
| 10060 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 10061 | return -ENOMEM; |
| 10062 | } |
| 10063 | |
| 10064 | /** |
| 10065 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 10066 | * @phba: pointer to lpfc hba data structure. |
| 10067 | * |
| 10068 | * This routine is invoked to free the pool of completion queue events at |
| 10069 | * driver unload time. Note that, it is the responsibility of the driver |
| 10070 | * cleanup routine to free all the outstanding completion-queue events |
| 10071 | * allocated from this pool back into the pool before invoking this routine |
| 10072 | * to destroy the pool. |
| 10073 | **/ |
| 10074 | static void |
| 10075 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 10076 | { |
| 10077 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 10078 | |
| 10079 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 10080 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 10081 | list_del(&cq_event->list); |
| 10082 | kfree(cq_event); |
| 10083 | } |
| 10084 | } |
| 10085 | |
| 10086 | /** |
| 10087 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 10088 | * @phba: pointer to lpfc hba data structure. |
| 10089 | * |
| 10090 | * This routine is the lock free version of the API invoked to allocate a |
| 10091 | * completion-queue event from the free pool. |
| 10092 | * |
| 10093 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 10094 | * NULL otherwise. |
| 10095 | **/ |
| 10096 | struct lpfc_cq_event * |
| 10097 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 10098 | { |
| 10099 | struct lpfc_cq_event *cq_event = NULL; |
| 10100 | |
| 10101 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 10102 | struct lpfc_cq_event, list); |
| 10103 | return cq_event; |
| 10104 | } |
| 10105 | |
| 10106 | /** |
| 10107 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 10108 | * @phba: pointer to lpfc hba data structure. |
| 10109 | * |
| 10110 | * This routine is the lock version of the API invoked to allocate a |
| 10111 | * completion-queue event from the free pool. |
| 10112 | * |
| 10113 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 10114 | * NULL otherwise. |
| 10115 | **/ |
| 10116 | struct lpfc_cq_event * |
| 10117 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 10118 | { |
| 10119 | struct lpfc_cq_event *cq_event; |
| 10120 | unsigned long iflags; |
| 10121 | |
| 10122 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10123 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 10124 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10125 | return cq_event; |
| 10126 | } |
| 10127 | |
| 10128 | /** |
| 10129 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 10130 | * @phba: pointer to lpfc hba data structure. |
| 10131 | * @cq_event: pointer to the completion queue event to be freed. |
| 10132 | * |
| 10133 | * This routine is the lock free version of the API invoked to release a |
| 10134 | * completion-queue event back into the free pool. |
| 10135 | **/ |
| 10136 | void |
| 10137 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 10138 | struct lpfc_cq_event *cq_event) |
| 10139 | { |
| 10140 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 10141 | } |
| 10142 | |
| 10143 | /** |
| 10144 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 10145 | * @phba: pointer to lpfc hba data structure. |
| 10146 | * @cq_event: pointer to the completion queue event to be freed. |
| 10147 | * |
| 10148 | * This routine is the lock version of the API invoked to release a |
| 10149 | * completion-queue event back into the free pool. |
| 10150 | **/ |
| 10151 | void |
| 10152 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 10153 | struct lpfc_cq_event *cq_event) |
| 10154 | { |
| 10155 | unsigned long iflags; |
| 10156 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10157 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 10158 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10159 | } |
| 10160 | |
| 10161 | /** |
| 10162 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 10163 | * @phba: pointer to lpfc hba data structure. |
| 10164 | * |
| 10165 | * This routine is to free all the pending completion-queue events to the |
| 10166 | * back into the free pool for device reset. |
| 10167 | **/ |
| 10168 | static void |
| 10169 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 10170 | { |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 10171 | LIST_HEAD(cq_event_list); |
| 10172 | struct lpfc_cq_event *cq_event; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10173 | unsigned long iflags; |
| 10174 | |
| 10175 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10176 | |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 10177 | /* Pending ELS XRI abort events */ |
| 10178 | spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
| 10179 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10180 | &cq_event_list); |
| 10181 | spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
| 10182 | |
| 10183 | /* Pending asynnc events */ |
| 10184 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
| 10185 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 10186 | &cq_event_list); |
| 10187 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags); |
| 10188 | |
| 10189 | while (!list_empty(&cq_event_list)) { |
| 10190 | list_remove_head(&cq_event_list, cq_event, |
| 10191 | struct lpfc_cq_event, list); |
| 10192 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10193 | } |
| 10194 | } |
| 10195 | |
| 10196 | /** |
| 10197 | * lpfc_pci_function_reset - Reset pci function. |
| 10198 | * @phba: pointer to lpfc hba data structure. |
| 10199 | * |
| 10200 | * This routine is invoked to request a PCI function reset. It will destroys |
| 10201 | * all resources assigned to the PCI function which originates this request. |
| 10202 | * |
| 10203 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10204 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10205 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10206 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10207 | **/ |
| 10208 | int |
| 10209 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 10210 | { |
| 10211 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10212 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10213 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10214 | uint32_t rdy_chk; |
| 10215 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10216 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10217 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10218 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10219 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10220 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10221 | switch (if_type) { |
| 10222 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10223 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 10224 | GFP_KERNEL); |
| 10225 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10226 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10227 | "0494 Unable to allocate memory for " |
| 10228 | "issuing SLI_FUNCTION_RESET mailbox " |
| 10229 | "command\n"); |
| 10230 | return -ENOMEM; |
| 10231 | } |
| 10232 | |
| 10233 | /* Setup PCI function reset mailbox-ioctl command */ |
| 10234 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10235 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 10236 | LPFC_SLI4_MBX_EMBED); |
| 10237 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10238 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 10239 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 10240 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 10241 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 10242 | &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 10243 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10244 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10245 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10246 | "0495 SLI_FUNCTION_RESET mailbox " |
| 10247 | "failed with status x%x add_status x%x," |
| 10248 | " mbx status x%x\n", |
| 10249 | shdr_status, shdr_add_status, rc); |
| 10250 | rc = -ENXIO; |
| 10251 | } |
| 10252 | break; |
| 10253 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10254 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10255 | wait: |
| 10256 | /* |
| 10257 | * Poll the Port Status Register and wait for RDY for |
| 10258 | * up to 30 seconds. If the port doesn't respond, treat |
| 10259 | * it as an error. |
| 10260 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 10261 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10262 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 10263 | STATUSregaddr, ®_data.word0)) { |
| 10264 | rc = -ENODEV; |
| 10265 | goto out; |
| 10266 | } |
| 10267 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 10268 | break; |
| 10269 | msleep(20); |
| 10270 | } |
| 10271 | |
| 10272 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 10273 | phba->work_status[0] = readl( |
| 10274 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10275 | phba->work_status[1] = readl( |
| 10276 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10277 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10278 | "2890 Port not ready, port status reg " |
| 10279 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 10280 | reg_data.word0, |
| 10281 | phba->work_status[0], |
| 10282 | phba->work_status[1]); |
| 10283 | rc = -ENODEV; |
| 10284 | goto out; |
| 10285 | } |
| 10286 | |
| 10287 | if (!port_reset) { |
| 10288 | /* |
| 10289 | * Reset the port now |
| 10290 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10291 | reg_data.word0 = 0; |
| 10292 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 10293 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 10294 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 10295 | LPFC_SLIPORT_INIT_PORT); |
| 10296 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 10297 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 10298 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10299 | pci_read_config_word(phba->pcidev, |
| 10300 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10301 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10302 | port_reset = 1; |
| 10303 | msleep(20); |
| 10304 | goto wait; |
| 10305 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 10306 | rc = -ENODEV; |
| 10307 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10308 | } |
| 10309 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10310 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10311 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10312 | default: |
| 10313 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10314 | } |
| 10315 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 10316 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10317 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10318 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10319 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10320 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10321 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10322 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10323 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10324 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10325 | return rc; |
| 10326 | } |
| 10327 | |
| 10328 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10329 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 10330 | * @phba: pointer to lpfc hba data structure. |
| 10331 | * |
| 10332 | * This routine is invoked to set up the PCI device memory space for device |
| 10333 | * with SLI-4 interface spec. |
| 10334 | * |
| 10335 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10336 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10337 | * other values - error |
| 10338 | **/ |
| 10339 | static int |
| 10340 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 10341 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10342 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10343 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10344 | int error; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10345 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10346 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10347 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10348 | return -ENODEV; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10349 | |
| 10350 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10351 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 10352 | if (error) |
| 10353 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10354 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10355 | return error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10356 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10357 | /* |
| 10358 | * The BARs and register set definitions and offset locations are |
| 10359 | * dependent on the if_type. |
| 10360 | */ |
| 10361 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 10362 | &phba->sli4_hba.sli_intf.word0)) { |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10363 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10364 | } |
| 10365 | |
| 10366 | /* There is no SLI3 failback for SLI4 devices. */ |
| 10367 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 10368 | LPFC_SLI_INTF_VALID) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10369 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10370 | "2894 SLI_INTF reg contents invalid " |
| 10371 | "sli_intf reg 0x%x\n", |
| 10372 | phba->sli4_hba.sli_intf.word0); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10373 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10374 | } |
| 10375 | |
| 10376 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10377 | /* |
| 10378 | * Get the bus address of SLI4 device Bar regions and the |
| 10379 | * number of bytes required by each mapping. The mapping of the |
| 10380 | * particular PCI BARs regions is dependent on the type of |
| 10381 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10382 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10383 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 10384 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 10385 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10386 | |
| 10387 | /* |
| 10388 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 10389 | * addr |
| 10390 | */ |
| 10391 | phba->sli4_hba.conf_regs_memmap_p = |
| 10392 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 10393 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10394 | dev_printk(KERN_ERR, &pdev->dev, |
| 10395 | "ioremap failed for SLI4 PCI config " |
| 10396 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10397 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10398 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10399 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10400 | /* Set up BAR0 PCI config space register memory map */ |
| 10401 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10402 | } else { |
| 10403 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 10404 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10405 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10406 | dev_printk(KERN_ERR, &pdev->dev, |
| 10407 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10408 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10409 | } |
| 10410 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10411 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10412 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10413 | dev_printk(KERN_ERR, &pdev->dev, |
| 10414 | "ioremap failed for SLI4 PCI config " |
| 10415 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10416 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10417 | } |
| 10418 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10419 | } |
| 10420 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10421 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10422 | if (pci_resource_start(pdev, PCI_64BIT_BAR2)) { |
| 10423 | /* |
| 10424 | * Map SLI4 if type 0 HBA Control Register base to a |
| 10425 | * kernel virtual address and setup the registers. |
| 10426 | */ |
| 10427 | phba->pci_bar1_map = pci_resource_start(pdev, |
| 10428 | PCI_64BIT_BAR2); |
| 10429 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10430 | phba->sli4_hba.ctrl_regs_memmap_p = |
| 10431 | ioremap(phba->pci_bar1_map, |
| 10432 | bar1map_len); |
| 10433 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 10434 | dev_err(&pdev->dev, |
| 10435 | "ioremap failed for SLI4 HBA " |
| 10436 | "control registers.\n"); |
| 10437 | error = -ENOMEM; |
| 10438 | goto out_iounmap_conf; |
| 10439 | } |
| 10440 | phba->pci_bar2_memmap_p = |
| 10441 | phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10442 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10443 | } else { |
| 10444 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10445 | goto out_iounmap_conf; |
| 10446 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10447 | } |
| 10448 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10449 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) && |
| 10450 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
| 10451 | /* |
| 10452 | * Map SLI4 if type 6 HBA Doorbell Register base to a kernel |
| 10453 | * virtual address and setup the registers. |
| 10454 | */ |
| 10455 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 10456 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10457 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10458 | ioremap(phba->pci_bar1_map, bar1map_len); |
| 10459 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10460 | dev_err(&pdev->dev, |
| 10461 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10462 | error = -ENOMEM; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10463 | goto out_iounmap_conf; |
| 10464 | } |
| 10465 | phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
| 10466 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
| 10467 | } |
| 10468 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10469 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10470 | if (pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10471 | /* |
| 10472 | * Map SLI4 if type 0 HBA Doorbell Register base to |
| 10473 | * a kernel virtual address and setup the registers. |
| 10474 | */ |
| 10475 | phba->pci_bar2_map = pci_resource_start(pdev, |
| 10476 | PCI_64BIT_BAR4); |
| 10477 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10478 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10479 | ioremap(phba->pci_bar2_map, |
| 10480 | bar2map_len); |
| 10481 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10482 | dev_err(&pdev->dev, |
| 10483 | "ioremap failed for SLI4 HBA" |
| 10484 | " doorbell registers.\n"); |
| 10485 | error = -ENOMEM; |
| 10486 | goto out_iounmap_ctrl; |
| 10487 | } |
| 10488 | phba->pci_bar4_memmap_p = |
| 10489 | phba->sli4_hba.drbl_regs_memmap_p; |
| 10490 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 10491 | if (error) |
| 10492 | goto out_iounmap_all; |
| 10493 | } else { |
| 10494 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10495 | goto out_iounmap_all; |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10496 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10497 | } |
| 10498 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10499 | if (if_type == LPFC_SLI_INTF_IF_TYPE_6 && |
| 10500 | pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10501 | /* |
| 10502 | * Map SLI4 if type 6 HBA DPP Register base to a kernel |
| 10503 | * virtual address and setup the registers. |
| 10504 | */ |
| 10505 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 10506 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10507 | phba->sli4_hba.dpp_regs_memmap_p = |
| 10508 | ioremap(phba->pci_bar2_map, bar2map_len); |
| 10509 | if (!phba->sli4_hba.dpp_regs_memmap_p) { |
| 10510 | dev_err(&pdev->dev, |
| 10511 | "ioremap failed for SLI4 HBA dpp registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10512 | error = -ENOMEM; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10513 | goto out_iounmap_ctrl; |
| 10514 | } |
| 10515 | phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; |
| 10516 | } |
| 10517 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10518 | /* Set up the EQ/CQ register handeling functions now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10519 | switch (if_type) { |
| 10520 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10521 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10522 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10523 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db; |
| 10524 | phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10525 | break; |
| 10526 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10527 | 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] | 10528 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db; |
| 10529 | 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] | 10530 | break; |
| 10531 | default: |
| 10532 | break; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10533 | } |
| 10534 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10535 | return 0; |
| 10536 | |
| 10537 | out_iounmap_all: |
| 10538 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10539 | out_iounmap_ctrl: |
| 10540 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10541 | out_iounmap_conf: |
| 10542 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10543 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10544 | return error; |
| 10545 | } |
| 10546 | |
| 10547 | /** |
| 10548 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 10549 | * @phba: pointer to lpfc hba data structure. |
| 10550 | * |
| 10551 | * This routine is invoked to unset the PCI device memory space for device |
| 10552 | * with SLI-4 interface spec. |
| 10553 | **/ |
| 10554 | static void |
| 10555 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 10556 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10557 | uint32_t if_type; |
| 10558 | 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] | 10559 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10560 | switch (if_type) { |
| 10561 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10562 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10563 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10564 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10565 | break; |
| 10566 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 10567 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10568 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10569 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10570 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10571 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
James Smart | 0b43919 | 2019-12-18 15:58:05 -0800 | [diff] [blame] | 10572 | if (phba->sli4_hba.dpp_regs_memmap_p) |
| 10573 | iounmap(phba->sli4_hba.dpp_regs_memmap_p); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10574 | break; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10575 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10576 | default: |
| 10577 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 10578 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 10579 | if_type); |
| 10580 | break; |
| 10581 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10582 | } |
| 10583 | |
| 10584 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10585 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 10586 | * @phba: pointer to lpfc hba data structure. |
| 10587 | * |
| 10588 | * 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] | 10589 | * with SLI-3 interface specs. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10590 | * |
| 10591 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10592 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10593 | * other values - error |
| 10594 | **/ |
| 10595 | static int |
| 10596 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 10597 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10598 | int rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10599 | LPFC_MBOXQ_t *pmb; |
| 10600 | |
| 10601 | /* Set up MSI-X multi-message vectors */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10602 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 10603 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); |
| 10604 | if (rc < 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10605 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10606 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10607 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10608 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10609 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10610 | /* |
| 10611 | * Assign MSI-X vectors to interrupt handlers |
| 10612 | */ |
| 10613 | |
| 10614 | /* vector-0 is associated to slow-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10615 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10616 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10617 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 10618 | if (rc) { |
| 10619 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10620 | "0421 MSI-X slow-path request_irq failed " |
| 10621 | "(%d)\n", rc); |
| 10622 | goto msi_fail_out; |
| 10623 | } |
| 10624 | |
| 10625 | /* vector-1 is associated to fast-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10626 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10627 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10628 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 10629 | |
| 10630 | if (rc) { |
| 10631 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10632 | "0429 MSI-X fast-path request_irq failed " |
| 10633 | "(%d)\n", rc); |
| 10634 | goto irq_fail_out; |
| 10635 | } |
| 10636 | |
| 10637 | /* |
| 10638 | * Configure HBA MSI-X attention conditions to messages |
| 10639 | */ |
| 10640 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 10641 | |
| 10642 | if (!pmb) { |
| 10643 | rc = -ENOMEM; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10644 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10645 | "0474 Unable to allocate memory for issuing " |
| 10646 | "MBOX_CONFIG_MSI command\n"); |
| 10647 | goto mem_fail_out; |
| 10648 | } |
| 10649 | rc = lpfc_config_msi(phba, pmb); |
| 10650 | if (rc) |
| 10651 | goto mbx_fail_out; |
| 10652 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 10653 | if (rc != MBX_SUCCESS) { |
| 10654 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 10655 | "0351 Config MSI mailbox command failed, " |
| 10656 | "mbxCmd x%x, mbxStatus x%x\n", |
| 10657 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 10658 | goto mbx_fail_out; |
| 10659 | } |
| 10660 | |
| 10661 | /* Free memory allocated for mailbox command */ |
| 10662 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10663 | return rc; |
| 10664 | |
| 10665 | mbx_fail_out: |
| 10666 | /* Free memory allocated for mailbox command */ |
| 10667 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10668 | |
| 10669 | mem_fail_out: |
| 10670 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10671 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10672 | |
| 10673 | irq_fail_out: |
| 10674 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10675 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10676 | |
| 10677 | msi_fail_out: |
| 10678 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10679 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10680 | |
| 10681 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10682 | return rc; |
| 10683 | } |
| 10684 | |
| 10685 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10686 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 10687 | * @phba: pointer to lpfc hba data structure. |
| 10688 | * |
| 10689 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 10690 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 10691 | * enable the MSI vector. The device driver is responsible for calling the |
| 10692 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 10693 | * is done in this function. |
| 10694 | * |
| 10695 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10696 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10697 | * other values - error |
| 10698 | */ |
| 10699 | static int |
| 10700 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 10701 | { |
| 10702 | int rc; |
| 10703 | |
| 10704 | rc = pci_enable_msi(phba->pcidev); |
| 10705 | if (!rc) |
| 10706 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10707 | "0462 PCI enable MSI mode success.\n"); |
| 10708 | else { |
| 10709 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10710 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 10711 | return rc; |
| 10712 | } |
| 10713 | |
| 10714 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10715 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10716 | if (rc) { |
| 10717 | pci_disable_msi(phba->pcidev); |
| 10718 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10719 | "0478 MSI request_irq failed (%d)\n", rc); |
| 10720 | } |
| 10721 | return rc; |
| 10722 | } |
| 10723 | |
| 10724 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10725 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 10726 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 10727 | * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X). |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10728 | * |
| 10729 | * This routine is invoked to enable device interrupt and associate driver's |
| 10730 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 10731 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 10732 | * will try to fallback from the configured interrupt mode to an interrupt |
| 10733 | * mode which is supported by the platform, kernel, and device in the order |
| 10734 | * of: |
| 10735 | * MSI-X -> MSI -> IRQ. |
| 10736 | * |
| 10737 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10738 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10739 | * other values - error |
| 10740 | **/ |
| 10741 | static uint32_t |
| 10742 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 10743 | { |
| 10744 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 10745 | int retval; |
| 10746 | |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 10747 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 10748 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 10749 | if (retval) |
| 10750 | return intr_mode; |
| 10751 | phba->hba_flag &= ~HBA_NEEDS_CFG_PORT; |
| 10752 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10753 | if (cfg_mode == 2) { |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 10754 | /* Now, try to enable MSI-X interrupt mode */ |
| 10755 | retval = lpfc_sli_enable_msix(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10756 | if (!retval) { |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 10757 | /* Indicate initialization to MSI-X mode */ |
| 10758 | phba->intr_type = MSIX; |
| 10759 | intr_mode = 2; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10760 | } |
| 10761 | } |
| 10762 | |
| 10763 | /* Fallback to MSI if MSI-X initialization failed */ |
| 10764 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 10765 | retval = lpfc_sli_enable_msi(phba); |
| 10766 | if (!retval) { |
| 10767 | /* Indicate initialization to MSI mode */ |
| 10768 | phba->intr_type = MSI; |
| 10769 | intr_mode = 1; |
| 10770 | } |
| 10771 | } |
| 10772 | |
| 10773 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 10774 | if (phba->intr_type == NONE) { |
| 10775 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 10776 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 10777 | if (!retval) { |
| 10778 | /* Indicate initialization to INTx mode */ |
| 10779 | phba->intr_type = INTx; |
| 10780 | intr_mode = 0; |
| 10781 | } |
| 10782 | } |
| 10783 | return intr_mode; |
| 10784 | } |
| 10785 | |
| 10786 | /** |
| 10787 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 10788 | * @phba: pointer to lpfc hba data structure. |
| 10789 | * |
| 10790 | * This routine is invoked to disable device interrupt and disassociate the |
| 10791 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 10792 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 10793 | * release the interrupt vector(s) for the message signaled interrupt. |
| 10794 | **/ |
| 10795 | static void |
| 10796 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 10797 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10798 | int nr_irqs, i; |
| 10799 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10800 | if (phba->intr_type == MSIX) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10801 | nr_irqs = LPFC_MSIX_VECTORS; |
| 10802 | else |
| 10803 | nr_irqs = 1; |
| 10804 | |
| 10805 | for (i = 0; i < nr_irqs; i++) |
| 10806 | free_irq(pci_irq_vector(phba->pcidev, i), phba); |
| 10807 | pci_free_irq_vectors(phba->pcidev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10808 | |
| 10809 | /* Reset interrupt management states */ |
| 10810 | phba->intr_type = NONE; |
| 10811 | phba->sli.slistat.sli_intr = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10812 | } |
| 10813 | |
| 10814 | /** |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10815 | * 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] | 10816 | * @phba: pointer to lpfc hba data structure. |
| 10817 | * @id: EQ vector index or Hardware Queue index |
| 10818 | * @match: LPFC_FIND_BY_EQ = match by EQ |
| 10819 | * LPFC_FIND_BY_HDWQ = match by Hardware Queue |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10820 | * Return the CPU that matches the selection criteria |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10821 | */ |
| 10822 | static uint16_t |
| 10823 | lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match) |
| 10824 | { |
| 10825 | struct lpfc_vector_map_info *cpup; |
| 10826 | int cpu; |
| 10827 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10828 | /* Loop through all CPUs */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10829 | for_each_present_cpu(cpu) { |
| 10830 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10831 | |
| 10832 | /* If we are matching by EQ, there may be multiple CPUs using |
| 10833 | * using the same vector, so select the one with |
| 10834 | * LPFC_CPU_FIRST_IRQ set. |
| 10835 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10836 | if ((match == LPFC_FIND_BY_EQ) && |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10837 | (cpup->flag & LPFC_CPU_FIRST_IRQ) && |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10838 | (cpup->eq == id)) |
| 10839 | return cpu; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10840 | |
| 10841 | /* If matching by HDWQ, select the first CPU that matches */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10842 | if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id)) |
| 10843 | return cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10844 | } |
| 10845 | return 0; |
| 10846 | } |
| 10847 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10848 | #ifdef CONFIG_X86 |
| 10849 | /** |
| 10850 | * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded |
| 10851 | * @phba: pointer to lpfc hba data structure. |
| 10852 | * @cpu: CPU map index |
| 10853 | * @phys_id: CPU package physical id |
| 10854 | * @core_id: CPU core id |
| 10855 | */ |
| 10856 | static int |
| 10857 | lpfc_find_hyper(struct lpfc_hba *phba, int cpu, |
| 10858 | uint16_t phys_id, uint16_t core_id) |
| 10859 | { |
| 10860 | struct lpfc_vector_map_info *cpup; |
| 10861 | int idx; |
| 10862 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10863 | for_each_present_cpu(idx) { |
| 10864 | cpup = &phba->sli4_hba.cpu_map[idx]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10865 | /* Does the cpup match the one we are looking for */ |
| 10866 | if ((cpup->phys_id == phys_id) && |
| 10867 | (cpup->core_id == core_id) && |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10868 | (cpu != idx)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10869 | return 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10870 | } |
| 10871 | return 0; |
| 10872 | } |
| 10873 | #endif |
| 10874 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10875 | /* |
| 10876 | * lpfc_assign_eq_map_info - Assigns eq for vector_map structure |
| 10877 | * @phba: pointer to lpfc hba data structure. |
| 10878 | * @eqidx: index for eq and irq vector |
| 10879 | * @flag: flags to set for vector_map structure |
| 10880 | * @cpu: cpu used to index vector_map structure |
| 10881 | * |
| 10882 | * The routine assigns eq info into vector_map structure |
| 10883 | */ |
| 10884 | static inline void |
| 10885 | lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag, |
| 10886 | unsigned int cpu) |
| 10887 | { |
| 10888 | struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10889 | struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx); |
| 10890 | |
| 10891 | cpup->eq = eqidx; |
| 10892 | cpup->flag |= flag; |
| 10893 | |
| 10894 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10895 | "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n", |
| 10896 | cpu, eqhdl->irq, cpup->eq, cpup->flag); |
| 10897 | } |
| 10898 | |
| 10899 | /** |
| 10900 | * lpfc_cpu_map_array_init - Initialize cpu_map structure |
| 10901 | * @phba: pointer to lpfc hba data structure. |
| 10902 | * |
| 10903 | * The routine initializes the cpu_map array structure |
| 10904 | */ |
| 10905 | static void |
| 10906 | lpfc_cpu_map_array_init(struct lpfc_hba *phba) |
| 10907 | { |
| 10908 | struct lpfc_vector_map_info *cpup; |
| 10909 | struct lpfc_eq_intr_info *eqi; |
| 10910 | int cpu; |
| 10911 | |
| 10912 | for_each_possible_cpu(cpu) { |
| 10913 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10914 | cpup->phys_id = LPFC_VECTOR_MAP_EMPTY; |
| 10915 | cpup->core_id = LPFC_VECTOR_MAP_EMPTY; |
| 10916 | cpup->hdwq = LPFC_VECTOR_MAP_EMPTY; |
| 10917 | cpup->eq = LPFC_VECTOR_MAP_EMPTY; |
| 10918 | cpup->flag = 0; |
| 10919 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu); |
| 10920 | INIT_LIST_HEAD(&eqi->list); |
| 10921 | eqi->icnt = 0; |
| 10922 | } |
| 10923 | } |
| 10924 | |
| 10925 | /** |
| 10926 | * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure |
| 10927 | * @phba: pointer to lpfc hba data structure. |
| 10928 | * |
| 10929 | * The routine initializes the hba_eq_hdl array structure |
| 10930 | */ |
| 10931 | static void |
| 10932 | lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba) |
| 10933 | { |
| 10934 | struct lpfc_hba_eq_hdl *eqhdl; |
| 10935 | int i; |
| 10936 | |
| 10937 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 10938 | eqhdl = lpfc_get_eq_hdl(i); |
| 10939 | eqhdl->irq = LPFC_VECTOR_MAP_EMPTY; |
| 10940 | eqhdl->phba = phba; |
| 10941 | } |
| 10942 | } |
| 10943 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10944 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10945 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10946 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10947 | * @vectors: number of msix vectors allocated. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10948 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10949 | * The routine will figure out the CPU affinity assignment for every |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10950 | * MSI-X vector allocated for the HBA. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10951 | * In addition, the CPU to IO channel mapping will be calculated |
| 10952 | * and the phba->sli4_hba.cpu_map array will reflect this. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10953 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10954 | static void |
| 10955 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10956 | { |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 10957 | int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10958 | int max_phys_id, min_phys_id; |
| 10959 | int max_core_id, min_core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10960 | struct lpfc_vector_map_info *cpup; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10961 | struct lpfc_vector_map_info *new_cpup; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10962 | #ifdef CONFIG_X86 |
| 10963 | struct cpuinfo_x86 *cpuinfo; |
| 10964 | #endif |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 10965 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 10966 | struct lpfc_hdwq_stat *c_stat; |
| 10967 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10968 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10969 | max_phys_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10970 | min_phys_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10971 | max_core_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10972 | min_core_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10973 | |
| 10974 | /* Update CPU map with physical id and core id of each CPU */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10975 | for_each_present_cpu(cpu) { |
| 10976 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10977 | #ifdef CONFIG_X86 |
| 10978 | cpuinfo = &cpu_data(cpu); |
| 10979 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 10980 | cpup->core_id = cpuinfo->cpu_core_id; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10981 | if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) |
| 10982 | cpup->flag |= LPFC_CPU_MAP_HYPER; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10983 | #else |
| 10984 | /* No distinction between CPUs for other platforms */ |
| 10985 | cpup->phys_id = 0; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10986 | cpup->core_id = cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10987 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10988 | |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10989 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 10990 | "3328 CPU %d physid %d coreid %d flag x%x\n", |
| 10991 | cpu, cpup->phys_id, cpup->core_id, cpup->flag); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10992 | |
| 10993 | if (cpup->phys_id > max_phys_id) |
| 10994 | max_phys_id = cpup->phys_id; |
| 10995 | if (cpup->phys_id < min_phys_id) |
| 10996 | min_phys_id = cpup->phys_id; |
| 10997 | |
| 10998 | if (cpup->core_id > max_core_id) |
| 10999 | max_core_id = cpup->core_id; |
| 11000 | if (cpup->core_id < min_core_id) |
| 11001 | min_core_id = cpup->core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11002 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11003 | |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11004 | /* After looking at each irq vector assigned to this pcidev, its |
| 11005 | * possible to see that not ALL CPUs have been accounted for. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11006 | * Next we will set any unassigned (unaffinitized) cpu map |
| 11007 | * entries to a IRQ on the same phys_id. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11008 | */ |
| 11009 | first_cpu = cpumask_first(cpu_present_mask); |
| 11010 | start_cpu = first_cpu; |
| 11011 | |
| 11012 | for_each_present_cpu(cpu) { |
| 11013 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11014 | |
| 11015 | /* Is this CPU entry unassigned */ |
| 11016 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 11017 | /* Mark CPU as IRQ not assigned by the kernel */ |
| 11018 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 11019 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11020 | /* If so, find a new_cpup thats on the the SAME |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11021 | * phys_id as cpup. start_cpu will start where we |
| 11022 | * left off so all unassigned entries don't get assgined |
| 11023 | * the IRQ of the first entry. |
| 11024 | */ |
| 11025 | new_cpu = start_cpu; |
| 11026 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11027 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11028 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11029 | (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) && |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11030 | (new_cpup->phys_id == cpup->phys_id)) |
| 11031 | goto found_same; |
| 11032 | new_cpu = cpumask_next( |
| 11033 | new_cpu, cpu_present_mask); |
| 11034 | if (new_cpu == nr_cpumask_bits) |
| 11035 | new_cpu = first_cpu; |
| 11036 | } |
| 11037 | /* At this point, we leave the CPU as unassigned */ |
| 11038 | continue; |
| 11039 | found_same: |
| 11040 | /* We found a matching phys_id, so copy the IRQ info */ |
| 11041 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11042 | |
| 11043 | /* Bump start_cpu to the next slot to minmize the |
| 11044 | * chance of having multiple unassigned CPU entries |
| 11045 | * selecting the same IRQ. |
| 11046 | */ |
| 11047 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11048 | if (start_cpu == nr_cpumask_bits) |
| 11049 | start_cpu = first_cpu; |
| 11050 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11051 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11052 | "3337 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11053 | "eq %d from peer cpu %d same " |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11054 | "phys_id (%d)\n", |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11055 | cpu, cpup->eq, new_cpu, |
| 11056 | cpup->phys_id); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11057 | } |
| 11058 | } |
| 11059 | |
| 11060 | /* Set any unassigned cpu map entries to a IRQ on any phys_id */ |
| 11061 | start_cpu = first_cpu; |
| 11062 | |
| 11063 | for_each_present_cpu(cpu) { |
| 11064 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11065 | |
| 11066 | /* Is this entry unassigned */ |
| 11067 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 11068 | /* Mark it as IRQ not assigned by the kernel */ |
| 11069 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 11070 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11071 | /* If so, find a new_cpup thats on ANY phys_id |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11072 | * as the cpup. start_cpu will start where we |
| 11073 | * left off so all unassigned entries don't get |
| 11074 | * assigned the IRQ of the first entry. |
| 11075 | */ |
| 11076 | new_cpu = start_cpu; |
| 11077 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11078 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11079 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11080 | (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY)) |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11081 | goto found_any; |
| 11082 | new_cpu = cpumask_next( |
| 11083 | new_cpu, cpu_present_mask); |
| 11084 | if (new_cpu == nr_cpumask_bits) |
| 11085 | new_cpu = first_cpu; |
| 11086 | } |
| 11087 | /* We should never leave an entry unassigned */ |
| 11088 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11089 | "3339 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11090 | "eq %d UNASSIGNED\n", |
| 11091 | cpup->hdwq, cpup->eq); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11092 | continue; |
| 11093 | found_any: |
| 11094 | /* We found an available entry, copy the IRQ info */ |
| 11095 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11096 | |
| 11097 | /* Bump start_cpu to the next slot to minmize the |
| 11098 | * chance of having multiple unassigned CPU entries |
| 11099 | * selecting the same IRQ. |
| 11100 | */ |
| 11101 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11102 | if (start_cpu == nr_cpumask_bits) |
| 11103 | start_cpu = first_cpu; |
| 11104 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11105 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11106 | "3338 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11107 | "eq %d from peer cpu %d (%d/%d)\n", |
| 11108 | cpu, cpup->eq, new_cpu, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11109 | new_cpup->phys_id, new_cpup->core_id); |
| 11110 | } |
| 11111 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11112 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11113 | /* Assign hdwq indices that are unique across all cpus in the map |
| 11114 | * that are also FIRST_CPUs. |
| 11115 | */ |
| 11116 | idx = 0; |
| 11117 | for_each_present_cpu(cpu) { |
| 11118 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11119 | |
| 11120 | /* Only FIRST IRQs get a hdwq index assignment. */ |
| 11121 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 11122 | continue; |
| 11123 | |
| 11124 | /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */ |
| 11125 | cpup->hdwq = idx; |
| 11126 | idx++; |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 11127 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11128 | "3333 Set Affinity: CPU %d (phys %d core %d): " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11129 | "hdwq %d eq %d flg x%x\n", |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11130 | cpu, cpup->phys_id, cpup->core_id, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11131 | cpup->hdwq, cpup->eq, cpup->flag); |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11132 | } |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11133 | /* Associate a hdwq with each cpu_map entry |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11134 | * This will be 1 to 1 - hdwq to cpu, unless there are less |
| 11135 | * hardware queues then CPUs. For that case we will just round-robin |
| 11136 | * the available hardware queues as they get assigned to CPUs. |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11137 | * The next_idx is the idx from the FIRST_CPU loop above to account |
| 11138 | * for irq_chann < hdwq. The idx is used for round-robin assignments |
| 11139 | * and needs to start at 0. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11140 | */ |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11141 | next_idx = idx; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11142 | start_cpu = 0; |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11143 | idx = 0; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11144 | for_each_present_cpu(cpu) { |
| 11145 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11146 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11147 | /* FIRST cpus are already mapped. */ |
| 11148 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 11149 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11150 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11151 | /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq |
| 11152 | * of the unassigned cpus to the next idx so that all |
| 11153 | * hdw queues are fully utilized. |
| 11154 | */ |
| 11155 | if (next_idx < phba->cfg_hdw_queue) { |
| 11156 | cpup->hdwq = next_idx; |
| 11157 | next_idx++; |
| 11158 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11159 | } |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11160 | |
| 11161 | /* Not a First CPU and all hdw_queues are used. Reuse a |
| 11162 | * Hardware Queue for another CPU, so be smart about it |
| 11163 | * and pick one that has its IRQ/EQ mapped to the same phys_id |
| 11164 | * (CPU package) and core_id. |
| 11165 | */ |
| 11166 | new_cpu = start_cpu; |
| 11167 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11168 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11169 | if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && |
| 11170 | new_cpup->phys_id == cpup->phys_id && |
| 11171 | new_cpup->core_id == cpup->core_id) { |
| 11172 | goto found_hdwq; |
| 11173 | } |
| 11174 | new_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11175 | if (new_cpu == nr_cpumask_bits) |
| 11176 | new_cpu = first_cpu; |
| 11177 | } |
| 11178 | |
| 11179 | /* If we can't match both phys_id and core_id, |
| 11180 | * settle for just a phys_id match. |
| 11181 | */ |
| 11182 | new_cpu = start_cpu; |
| 11183 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11184 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11185 | if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && |
| 11186 | new_cpup->phys_id == cpup->phys_id) |
| 11187 | goto found_hdwq; |
| 11188 | |
| 11189 | new_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11190 | if (new_cpu == nr_cpumask_bits) |
| 11191 | new_cpu = first_cpu; |
| 11192 | } |
| 11193 | |
| 11194 | /* Otherwise just round robin on cfg_hdw_queue */ |
| 11195 | cpup->hdwq = idx % phba->cfg_hdw_queue; |
| 11196 | idx++; |
| 11197 | goto logit; |
| 11198 | found_hdwq: |
| 11199 | /* We found an available entry, copy the IRQ info */ |
| 11200 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11201 | if (start_cpu == nr_cpumask_bits) |
| 11202 | start_cpu = first_cpu; |
| 11203 | cpup->hdwq = new_cpup->hdwq; |
| 11204 | logit: |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 11205 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11206 | "3335 Set Affinity: CPU %d (phys %d core %d): " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11207 | "hdwq %d eq %d flg x%x\n", |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11208 | cpu, cpup->phys_id, cpup->core_id, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11209 | cpup->hdwq, cpup->eq, cpup->flag); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11210 | } |
| 11211 | |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11212 | /* |
| 11213 | * Initialize the cpu_map slots for not-present cpus in case |
| 11214 | * a cpu is hot-added. Perform a simple hdwq round robin assignment. |
| 11215 | */ |
| 11216 | idx = 0; |
| 11217 | for_each_possible_cpu(cpu) { |
| 11218 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 11219 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 11220 | c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu); |
| 11221 | c_stat->hdwq_no = cpup->hdwq; |
| 11222 | #endif |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11223 | if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) |
| 11224 | continue; |
| 11225 | |
| 11226 | cpup->hdwq = idx++ % phba->cfg_hdw_queue; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 11227 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 11228 | c_stat->hdwq_no = cpup->hdwq; |
| 11229 | #endif |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11230 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11231 | "3340 Set Affinity: not present " |
| 11232 | "CPU %d hdwq %d\n", |
| 11233 | cpu, cpup->hdwq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11234 | } |
| 11235 | |
| 11236 | /* The cpu_map array will be used later during initialization |
| 11237 | * when EQ / CQ / WQs are allocated and configured. |
| 11238 | */ |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11239 | return; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11240 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11241 | |
| 11242 | /** |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11243 | * lpfc_cpuhp_get_eq |
| 11244 | * |
| 11245 | * @phba: pointer to lpfc hba data structure. |
| 11246 | * @cpu: cpu going offline |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 11247 | * @eqlist: eq list to append to |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11248 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11249 | static int |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11250 | lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu, |
| 11251 | struct list_head *eqlist) |
| 11252 | { |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11253 | const struct cpumask *maskp; |
| 11254 | struct lpfc_queue *eq; |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11255 | struct cpumask *tmp; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11256 | u16 idx; |
| 11257 | |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11258 | tmp = kzalloc(cpumask_size(), GFP_KERNEL); |
| 11259 | if (!tmp) |
| 11260 | return -ENOMEM; |
| 11261 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11262 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 11263 | maskp = pci_irq_get_affinity(phba->pcidev, idx); |
| 11264 | if (!maskp) |
| 11265 | continue; |
| 11266 | /* |
| 11267 | * if irq is not affinitized to the cpu going |
| 11268 | * then we don't need to poll the eq attached |
| 11269 | * to it. |
| 11270 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11271 | if (!cpumask_and(tmp, maskp, cpumask_of(cpu))) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11272 | continue; |
| 11273 | /* get the cpus that are online and are affini- |
| 11274 | * tized to this irq vector. If the count is |
| 11275 | * more than 1 then cpuhp is not going to shut- |
| 11276 | * down this vector. Since this cpu has not |
| 11277 | * gone offline yet, we need >1. |
| 11278 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11279 | cpumask_and(tmp, maskp, cpu_online_mask); |
| 11280 | if (cpumask_weight(tmp) > 1) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11281 | continue; |
| 11282 | |
| 11283 | /* Now that we have an irq to shutdown, get the eq |
| 11284 | * mapped to this irq. Note: multiple hdwq's in |
| 11285 | * the software can share an eq, but eventually |
| 11286 | * only eq will be mapped to this vector |
| 11287 | */ |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11288 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 11289 | list_add(&eq->_poll_list, eqlist); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11290 | } |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11291 | kfree(tmp); |
| 11292 | return 0; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11293 | } |
| 11294 | |
| 11295 | static void __lpfc_cpuhp_remove(struct lpfc_hba *phba) |
| 11296 | { |
| 11297 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 11298 | return; |
| 11299 | |
| 11300 | cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state, |
| 11301 | &phba->cpuhp); |
| 11302 | /* |
| 11303 | * unregistering the instance doesn't stop the polling |
| 11304 | * timer. Wait for the poll timer to retire. |
| 11305 | */ |
| 11306 | synchronize_rcu(); |
| 11307 | del_timer_sync(&phba->cpuhp_poll_timer); |
| 11308 | } |
| 11309 | |
| 11310 | static void lpfc_cpuhp_remove(struct lpfc_hba *phba) |
| 11311 | { |
| 11312 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 11313 | return; |
| 11314 | |
| 11315 | __lpfc_cpuhp_remove(phba); |
| 11316 | } |
| 11317 | |
| 11318 | static void lpfc_cpuhp_add(struct lpfc_hba *phba) |
| 11319 | { |
| 11320 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 11321 | return; |
| 11322 | |
| 11323 | rcu_read_lock(); |
| 11324 | |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 11325 | if (!list_empty(&phba->poll_list)) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11326 | mod_timer(&phba->cpuhp_poll_timer, |
| 11327 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11328 | |
| 11329 | rcu_read_unlock(); |
| 11330 | |
| 11331 | cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, |
| 11332 | &phba->cpuhp); |
| 11333 | } |
| 11334 | |
| 11335 | static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval) |
| 11336 | { |
| 11337 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 11338 | *retval = -EAGAIN; |
| 11339 | return true; |
| 11340 | } |
| 11341 | |
| 11342 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11343 | *retval = 0; |
| 11344 | return true; |
| 11345 | } |
| 11346 | |
| 11347 | /* proceed with the hotplug */ |
| 11348 | return false; |
| 11349 | } |
| 11350 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11351 | /** |
| 11352 | * lpfc_irq_set_aff - set IRQ affinity |
| 11353 | * @eqhdl: EQ handle |
| 11354 | * @cpu: cpu to set affinity |
| 11355 | * |
| 11356 | **/ |
| 11357 | static inline void |
| 11358 | lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu) |
| 11359 | { |
| 11360 | cpumask_clear(&eqhdl->aff_mask); |
| 11361 | cpumask_set_cpu(cpu, &eqhdl->aff_mask); |
| 11362 | irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING); |
| 11363 | irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask); |
| 11364 | } |
| 11365 | |
| 11366 | /** |
| 11367 | * lpfc_irq_clear_aff - clear IRQ affinity |
| 11368 | * @eqhdl: EQ handle |
| 11369 | * |
| 11370 | **/ |
| 11371 | static inline void |
| 11372 | lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl) |
| 11373 | { |
| 11374 | cpumask_clear(&eqhdl->aff_mask); |
| 11375 | irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11376 | } |
| 11377 | |
| 11378 | /** |
| 11379 | * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event |
| 11380 | * @phba: pointer to HBA context object. |
| 11381 | * @cpu: cpu going offline/online |
| 11382 | * @offline: true, cpu is going offline. false, cpu is coming online. |
| 11383 | * |
| 11384 | * 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] | 11385 | * online cpu on the phba's original_mask and migrate all offlining IRQ |
| 11386 | * affinities. |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11387 | * |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11388 | * 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] | 11389 | * |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11390 | * 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] | 11391 | * PCI_IRQ_AFFINITY to auto-manage IRQ affinity. |
| 11392 | * |
| 11393 | **/ |
| 11394 | static void |
| 11395 | lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline) |
| 11396 | { |
| 11397 | struct lpfc_vector_map_info *cpup; |
| 11398 | struct cpumask *aff_mask; |
| 11399 | unsigned int cpu_select, cpu_next, idx; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11400 | const struct cpumask *orig_mask; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11401 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11402 | if (phba->irq_chann_mode == NORMAL_MODE) |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11403 | return; |
| 11404 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11405 | orig_mask = &phba->sli4_hba.irq_aff_mask; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11406 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11407 | if (!cpumask_test_cpu(cpu, orig_mask)) |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11408 | return; |
| 11409 | |
| 11410 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11411 | |
| 11412 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 11413 | return; |
| 11414 | |
| 11415 | if (offline) { |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11416 | /* Find next online CPU on original mask */ |
| 11417 | cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true); |
| 11418 | cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11419 | |
| 11420 | /* Found a valid CPU */ |
| 11421 | if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) { |
| 11422 | /* Go through each eqhdl and ensure offlining |
| 11423 | * cpu aff_mask is migrated |
| 11424 | */ |
| 11425 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 11426 | aff_mask = lpfc_get_aff_mask(idx); |
| 11427 | |
| 11428 | /* Migrate affinity */ |
| 11429 | if (cpumask_test_cpu(cpu, aff_mask)) |
| 11430 | lpfc_irq_set_aff(lpfc_get_eq_hdl(idx), |
| 11431 | cpu_select); |
| 11432 | } |
| 11433 | } else { |
| 11434 | /* Rely on irqbalance if no online CPUs left on NUMA */ |
| 11435 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) |
| 11436 | lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx)); |
| 11437 | } |
| 11438 | } else { |
| 11439 | /* Migrate affinity back to this CPU */ |
| 11440 | lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu); |
| 11441 | } |
| 11442 | } |
| 11443 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11444 | static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node) |
| 11445 | { |
| 11446 | struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp); |
| 11447 | struct lpfc_queue *eq, *next; |
| 11448 | LIST_HEAD(eqlist); |
| 11449 | int retval; |
| 11450 | |
| 11451 | if (!phba) { |
| 11452 | WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id()); |
| 11453 | return 0; |
| 11454 | } |
| 11455 | |
| 11456 | if (__lpfc_cpuhp_checks(phba, &retval)) |
| 11457 | return retval; |
| 11458 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11459 | lpfc_irq_rebalance(phba, cpu, true); |
| 11460 | |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11461 | retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist); |
| 11462 | if (retval) |
| 11463 | return retval; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11464 | |
| 11465 | /* start polling on these eq's */ |
| 11466 | list_for_each_entry_safe(eq, next, &eqlist, _poll_list) { |
| 11467 | list_del_init(&eq->_poll_list); |
| 11468 | lpfc_sli4_start_polling(eq); |
| 11469 | } |
| 11470 | |
| 11471 | return 0; |
| 11472 | } |
| 11473 | |
| 11474 | static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node) |
| 11475 | { |
| 11476 | struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp); |
| 11477 | struct lpfc_queue *eq, *next; |
| 11478 | unsigned int n; |
| 11479 | int retval; |
| 11480 | |
| 11481 | if (!phba) { |
| 11482 | WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id()); |
| 11483 | return 0; |
| 11484 | } |
| 11485 | |
| 11486 | if (__lpfc_cpuhp_checks(phba, &retval)) |
| 11487 | return retval; |
| 11488 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11489 | lpfc_irq_rebalance(phba, cpu, false); |
| 11490 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11491 | list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) { |
| 11492 | n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ); |
| 11493 | if (n == cpu) |
| 11494 | lpfc_sli4_stop_polling(eq); |
| 11495 | } |
| 11496 | |
| 11497 | return 0; |
| 11498 | } |
| 11499 | |
| 11500 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11501 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 11502 | * @phba: pointer to lpfc hba data structure. |
| 11503 | * |
| 11504 | * 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] | 11505 | * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them |
| 11506 | * to cpus on the system. |
| 11507 | * |
| 11508 | * When cfg_irq_numa is enabled, the adapter will only allocate vectors for |
| 11509 | * the number of cpus on the same numa node as this adapter. The vectors are |
| 11510 | * allocated without requesting OS affinity mapping. A vector will be |
| 11511 | * allocated and assigned to each online and offline cpu. If the cpu is |
| 11512 | * online, then affinity will be set to that cpu. If the cpu is offline, then |
| 11513 | * affinity will be set to the nearest peer cpu within the numa node that is |
| 11514 | * online. If there are no online cpus within the numa node, affinity is not |
| 11515 | * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping |
| 11516 | * is consistent with the way cpu online/offline is handled when cfg_irq_numa is |
| 11517 | * configured. |
| 11518 | * |
| 11519 | * If numa mode is not enabled and there is more than 1 vector allocated, then |
| 11520 | * the driver relies on the managed irq interface where the OS assigns vector to |
| 11521 | * cpu affinity. The driver will then use that affinity mapping to setup its |
| 11522 | * cpu mapping table. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11523 | * |
| 11524 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11525 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11526 | * other values - error |
| 11527 | **/ |
| 11528 | static int |
| 11529 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 11530 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11531 | int vectors, rc, index; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11532 | char *name; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11533 | const struct cpumask *aff_mask = NULL; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11534 | unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids; |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11535 | struct lpfc_vector_map_info *cpup; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11536 | struct lpfc_hba_eq_hdl *eqhdl; |
| 11537 | const struct cpumask *maskp; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11538 | unsigned int flags = PCI_IRQ_MSIX; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11539 | |
| 11540 | /* Set up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11541 | vectors = phba->cfg_irq_chann; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11542 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11543 | if (phba->irq_chann_mode != NORMAL_MODE) |
| 11544 | aff_mask = &phba->sli4_hba.irq_aff_mask; |
| 11545 | |
| 11546 | if (aff_mask) { |
| 11547 | cpu_cnt = cpumask_weight(aff_mask); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11548 | vectors = min(phba->cfg_irq_chann, cpu_cnt); |
| 11549 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11550 | /* cpu: iterates over aff_mask including offline or online |
| 11551 | * cpu_select: iterates over online aff_mask to set affinity |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11552 | */ |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11553 | cpu = cpumask_first(aff_mask); |
| 11554 | cpu_select = lpfc_next_online_cpu(aff_mask, cpu); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11555 | } else { |
| 11556 | flags |= PCI_IRQ_AFFINITY; |
| 11557 | } |
| 11558 | |
| 11559 | rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags); |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11560 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11561 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11562 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11563 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11564 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11565 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11566 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11567 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11568 | for (index = 0; index < vectors; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11569 | eqhdl = lpfc_get_eq_hdl(index); |
| 11570 | name = eqhdl->handler_name; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11571 | memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ); |
| 11572 | snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 11573 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11574 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11575 | eqhdl->idx = index; |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 11576 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
| 11577 | &lpfc_sli4_hba_intr_handler, 0, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11578 | name, eqhdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11579 | if (rc) { |
| 11580 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11581 | "0486 MSI-X fast-path (%d) " |
| 11582 | "request_irq failed (%d)\n", index, rc); |
| 11583 | goto cfg_fail_out; |
| 11584 | } |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11585 | |
| 11586 | eqhdl->irq = pci_irq_vector(phba->pcidev, index); |
| 11587 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11588 | if (aff_mask) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11589 | /* If found a neighboring online cpu, set affinity */ |
| 11590 | if (cpu_select < nr_cpu_ids) |
| 11591 | lpfc_irq_set_aff(eqhdl, cpu_select); |
| 11592 | |
| 11593 | /* Assign EQ to cpu_map */ |
| 11594 | lpfc_assign_eq_map_info(phba, index, |
| 11595 | LPFC_CPU_FIRST_IRQ, |
| 11596 | cpu); |
| 11597 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11598 | /* Iterate to next offline or online cpu in aff_mask */ |
| 11599 | cpu = cpumask_next(cpu, aff_mask); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11600 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11601 | /* Find next online cpu in aff_mask to set affinity */ |
| 11602 | cpu_select = lpfc_next_online_cpu(aff_mask, cpu); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11603 | } else if (vectors == 1) { |
| 11604 | cpu = cpumask_first(cpu_present_mask); |
| 11605 | lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ, |
| 11606 | cpu); |
| 11607 | } else { |
| 11608 | maskp = pci_irq_get_affinity(phba->pcidev, index); |
| 11609 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11610 | /* Loop through all CPUs associated with vector index */ |
| 11611 | for_each_cpu_and(cpu, maskp, cpu_present_mask) { |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11612 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11613 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11614 | /* If this is the first CPU thats assigned to |
| 11615 | * this vector, set LPFC_CPU_FIRST_IRQ. |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11616 | * |
| 11617 | * With certain platforms its possible that irq |
| 11618 | * vectors are affinitized to all the cpu's. |
| 11619 | * This can result in each cpu_map.eq to be set |
| 11620 | * to the last vector, resulting in overwrite |
| 11621 | * of all the previous cpu_map.eq. Ensure that |
| 11622 | * each vector receives a place in cpu_map. |
| 11623 | * Later call to lpfc_cpu_affinity_check will |
| 11624 | * ensure we are nicely balanced out. |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11625 | */ |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11626 | if (cpup->eq != LPFC_VECTOR_MAP_EMPTY) |
| 11627 | continue; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11628 | lpfc_assign_eq_map_info(phba, index, |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11629 | LPFC_CPU_FIRST_IRQ, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11630 | cpu); |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11631 | break; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11632 | } |
| 11633 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11634 | } |
| 11635 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11636 | if (vectors != phba->cfg_irq_chann) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11637 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11638 | "3238 Reducing IO channels to match number of " |
| 11639 | "MSI-X vectors, requested %d got %d\n", |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11640 | phba->cfg_irq_chann, vectors); |
| 11641 | if (phba->cfg_irq_chann > vectors) |
| 11642 | phba->cfg_irq_chann = vectors; |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11643 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11644 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11645 | return rc; |
| 11646 | |
| 11647 | cfg_fail_out: |
| 11648 | /* free the irq already requested */ |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11649 | for (--index; index >= 0; index--) { |
| 11650 | eqhdl = lpfc_get_eq_hdl(index); |
| 11651 | lpfc_irq_clear_aff(eqhdl); |
| 11652 | irq_set_affinity_hint(eqhdl->irq, NULL); |
| 11653 | free_irq(eqhdl->irq, eqhdl); |
| 11654 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11655 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11656 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11657 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11658 | |
| 11659 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11660 | return rc; |
| 11661 | } |
| 11662 | |
| 11663 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11664 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 11665 | * @phba: pointer to lpfc hba data structure. |
| 11666 | * |
| 11667 | * 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] | 11668 | * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is |
| 11669 | * called to enable the MSI vector. The device driver is responsible for |
| 11670 | * calling the request_irq() to register MSI vector with a interrupt the |
| 11671 | * handler, which is done in this function. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11672 | * |
| 11673 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11674 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11675 | * other values - error |
| 11676 | **/ |
| 11677 | static int |
| 11678 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 11679 | { |
| 11680 | int rc, index; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11681 | unsigned int cpu; |
| 11682 | struct lpfc_hba_eq_hdl *eqhdl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11683 | |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11684 | rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1, |
| 11685 | PCI_IRQ_MSI | PCI_IRQ_AFFINITY); |
| 11686 | if (rc > 0) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11687 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11688 | "0487 PCI enable MSI mode success.\n"); |
| 11689 | else { |
| 11690 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11691 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11692 | return rc ? rc : -1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11693 | } |
| 11694 | |
| 11695 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 11696 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11697 | if (rc) { |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11698 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11699 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11700 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11701 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11702 | } |
| 11703 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11704 | eqhdl = lpfc_get_eq_hdl(0); |
| 11705 | eqhdl->irq = pci_irq_vector(phba->pcidev, 0); |
| 11706 | |
| 11707 | cpu = cpumask_first(cpu_present_mask); |
| 11708 | lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu); |
| 11709 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11710 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11711 | eqhdl = lpfc_get_eq_hdl(index); |
| 11712 | eqhdl->idx = index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11713 | } |
| 11714 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11715 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11716 | } |
| 11717 | |
| 11718 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11719 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 11720 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 11721 | * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X). |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11722 | * |
| 11723 | * This routine is invoked to enable device interrupt and associate driver's |
| 11724 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 11725 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 11726 | * the driver will try to fallback from the configured interrupt mode to an |
| 11727 | * interrupt mode which is supported by the platform, kernel, and device in |
| 11728 | * the order of: |
| 11729 | * MSI-X -> MSI -> IRQ. |
| 11730 | * |
| 11731 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11732 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11733 | * other values - error |
| 11734 | **/ |
| 11735 | static uint32_t |
| 11736 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 11737 | { |
| 11738 | uint32_t intr_mode = LPFC_INTR_ERROR; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11739 | int retval, idx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11740 | |
| 11741 | if (cfg_mode == 2) { |
| 11742 | /* Preparation before conf_msi mbox cmd */ |
| 11743 | retval = 0; |
| 11744 | if (!retval) { |
| 11745 | /* Now, try to enable MSI-X interrupt mode */ |
| 11746 | retval = lpfc_sli4_enable_msix(phba); |
| 11747 | if (!retval) { |
| 11748 | /* Indicate initialization to MSI-X mode */ |
| 11749 | phba->intr_type = MSIX; |
| 11750 | intr_mode = 2; |
| 11751 | } |
| 11752 | } |
| 11753 | } |
| 11754 | |
| 11755 | /* Fallback to MSI if MSI-X initialization failed */ |
| 11756 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 11757 | retval = lpfc_sli4_enable_msi(phba); |
| 11758 | if (!retval) { |
| 11759 | /* Indicate initialization to MSI mode */ |
| 11760 | phba->intr_type = MSI; |
| 11761 | intr_mode = 1; |
| 11762 | } |
| 11763 | } |
| 11764 | |
| 11765 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 11766 | if (phba->intr_type == NONE) { |
| 11767 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 11768 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 11769 | if (!retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11770 | struct lpfc_hba_eq_hdl *eqhdl; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11771 | unsigned int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11772 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11773 | /* Indicate initialization to INTx mode */ |
| 11774 | phba->intr_type = INTx; |
| 11775 | intr_mode = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11776 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11777 | eqhdl = lpfc_get_eq_hdl(0); |
| 11778 | eqhdl->irq = pci_irq_vector(phba->pcidev, 0); |
| 11779 | |
| 11780 | cpu = cpumask_first(cpu_present_mask); |
| 11781 | lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, |
| 11782 | cpu); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11783 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11784 | eqhdl = lpfc_get_eq_hdl(idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11785 | eqhdl->idx = idx; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11786 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11787 | } |
| 11788 | } |
| 11789 | return intr_mode; |
| 11790 | } |
| 11791 | |
| 11792 | /** |
| 11793 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 11794 | * @phba: pointer to lpfc hba data structure. |
| 11795 | * |
| 11796 | * This routine is invoked to disable device interrupt and disassociate |
| 11797 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 11798 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 11799 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 11800 | **/ |
| 11801 | static void |
| 11802 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 11803 | { |
| 11804 | /* Disable the currently initialized interrupt mode */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11805 | if (phba->intr_type == MSIX) { |
| 11806 | int index; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11807 | struct lpfc_hba_eq_hdl *eqhdl; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11808 | |
| 11809 | /* Free up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11810 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11811 | eqhdl = lpfc_get_eq_hdl(index); |
| 11812 | lpfc_irq_clear_aff(eqhdl); |
| 11813 | irq_set_affinity_hint(eqhdl->irq, NULL); |
| 11814 | free_irq(eqhdl->irq, eqhdl); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11815 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11816 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11817 | free_irq(phba->pcidev->irq, phba); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11818 | } |
| 11819 | |
| 11820 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11821 | |
| 11822 | /* Reset interrupt management states */ |
| 11823 | phba->intr_type = NONE; |
| 11824 | phba->sli.slistat.sli_intr = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11825 | } |
| 11826 | |
| 11827 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11828 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 11829 | * @phba: pointer to lpfc hba data structure. |
| 11830 | * |
| 11831 | * This routine is invoked to unset the HBA device initialization steps to |
| 11832 | * a device with SLI-3 interface spec. |
| 11833 | **/ |
| 11834 | static void |
| 11835 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 11836 | { |
| 11837 | struct lpfc_vport *vport = phba->pport; |
| 11838 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 11839 | |
| 11840 | spin_lock_irq(shost->host_lock); |
| 11841 | vport->load_flag |= FC_UNLOADING; |
| 11842 | spin_unlock_irq(shost->host_lock); |
| 11843 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 11844 | kfree(phba->vpi_bmask); |
| 11845 | kfree(phba->vpi_ids); |
| 11846 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11847 | lpfc_stop_hba_timers(phba); |
| 11848 | |
| 11849 | phba->pport->work_port_events = 0; |
| 11850 | |
| 11851 | lpfc_sli_hba_down(phba); |
| 11852 | |
| 11853 | lpfc_sli_brdrestart(phba); |
| 11854 | |
| 11855 | lpfc_sli_disable_intr(phba); |
| 11856 | |
| 11857 | return; |
| 11858 | } |
| 11859 | |
| 11860 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11861 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 11862 | * @phba: Pointer to HBA context object. |
| 11863 | * |
| 11864 | * This function is called in the SLI4 code path to wait for completion |
| 11865 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 11866 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 11867 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 11868 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 11869 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 11870 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 11871 | * the rest of the driver unload resource release. |
| 11872 | **/ |
| 11873 | static void |
| 11874 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 11875 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11876 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11877 | int idx, ccnt; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11878 | int wait_time = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11879 | int io_xri_cmpl = 1; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11880 | int nvmet_xri_cmpl = 1; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11881 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 11882 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11883 | /* Driver just aborted IOs during the hba_unset process. Pause |
| 11884 | * here to give the HBA time to complete the IO and get entries |
| 11885 | * into the abts lists. |
| 11886 | */ |
| 11887 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5); |
| 11888 | |
| 11889 | /* Wait for NVME pending IO to flush back to transport. */ |
| 11890 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11891 | lpfc_nvme_wait_for_io_drain(phba); |
| 11892 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11893 | ccnt = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11894 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11895 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11896 | io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list); |
| 11897 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11898 | ccnt++; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11899 | } |
| 11900 | if (ccnt) |
| 11901 | io_xri_cmpl = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11902 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11903 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11904 | nvmet_xri_cmpl = |
| 11905 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11906 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11907 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11908 | while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11909 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 11910 | if (!nvmet_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11911 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 11912 | "6424 NVMET XRI exchange busy " |
| 11913 | "wait time: %d seconds.\n", |
| 11914 | wait_time/1000); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11915 | if (!io_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11916 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11917 | "6100 IO XRI exchange busy " |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11918 | "wait time: %d seconds.\n", |
| 11919 | wait_time/1000); |
| 11920 | if (!els_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11921 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11922 | "2878 ELS XRI exchange busy " |
| 11923 | "wait time: %d seconds.\n", |
| 11924 | wait_time/1000); |
| 11925 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 11926 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 11927 | } else { |
| 11928 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 11929 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 11930 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11931 | |
| 11932 | ccnt = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11933 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11934 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11935 | io_xri_cmpl = list_empty( |
| 11936 | &qp->lpfc_abts_io_buf_list); |
| 11937 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11938 | ccnt++; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11939 | } |
| 11940 | if (ccnt) |
| 11941 | io_xri_cmpl = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11942 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11943 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11944 | nvmet_xri_cmpl = list_empty( |
| 11945 | &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11946 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11947 | els_xri_cmpl = |
| 11948 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11949 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11950 | } |
| 11951 | } |
| 11952 | |
| 11953 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11954 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 11955 | * @phba: Pointer to HBA context object. |
| 11956 | * |
| 11957 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 11958 | * function. The caller is not required to hold any lock. This routine |
| 11959 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 11960 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 11961 | * free any pending commands. |
| 11962 | **/ |
| 11963 | static void |
| 11964 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 11965 | { |
| 11966 | int wait_cnt = 0; |
| 11967 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11968 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11969 | |
| 11970 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11971 | if (phba->pport) |
| 11972 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11973 | |
| 11974 | /* |
| 11975 | * Gracefully wait out the potential current outstanding asynchronous |
| 11976 | * mailbox command. |
| 11977 | */ |
| 11978 | |
| 11979 | /* First, block any pending async mailbox command from posted */ |
| 11980 | spin_lock_irq(&phba->hbalock); |
| 11981 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 11982 | spin_unlock_irq(&phba->hbalock); |
| 11983 | /* Now, trying to wait it out if we can */ |
| 11984 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11985 | msleep(10); |
| 11986 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 11987 | break; |
| 11988 | } |
| 11989 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 11990 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11991 | spin_lock_irq(&phba->hbalock); |
| 11992 | mboxq = phba->sli.mbox_active; |
| 11993 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 11994 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 11995 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11996 | phba->sli.mbox_active = NULL; |
| 11997 | spin_unlock_irq(&phba->hbalock); |
| 11998 | } |
| 11999 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 12000 | /* Abort all iocbs associated with the hba */ |
| 12001 | lpfc_sli_hba_iocb_abort(phba); |
| 12002 | |
| 12003 | /* Wait for completion of device XRI exchange busy */ |
| 12004 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 12005 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12006 | /* per-phba callback de-registration for hotplug event */ |
SeongJae Park | 46da547 | 2020-06-23 10:41:22 +0200 | [diff] [blame] | 12007 | if (phba->pport) |
| 12008 | lpfc_cpuhp_remove(phba); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12009 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12010 | /* Disable PCI subsystem interrupt */ |
| 12011 | lpfc_sli4_disable_intr(phba); |
| 12012 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 12013 | /* Disable SR-IOV if enabled */ |
| 12014 | if (phba->cfg_sriov_nr_virtfn) |
| 12015 | pci_disable_sriov(pdev); |
| 12016 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12017 | /* Stop kthread signal shall trigger work_done one more time */ |
| 12018 | kthread_stop(phba->worker_thread); |
| 12019 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12020 | /* Disable FW logging to host memory */ |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 12021 | lpfc_ras_stop_fwlog(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12022 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 12023 | /* Unset the queues shared with the hardware then release all |
| 12024 | * allocated resources. |
| 12025 | */ |
| 12026 | lpfc_sli4_queue_unset(phba); |
| 12027 | lpfc_sli4_queue_destroy(phba); |
| 12028 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 12029 | /* Reset SLI4 HBA FCoE function */ |
| 12030 | lpfc_pci_function_reset(phba); |
| 12031 | |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 12032 | /* Free RAS DMA memory */ |
| 12033 | if (phba->ras_fwlog.ras_enabled) |
| 12034 | lpfc_sli4_ras_dma_free(phba); |
| 12035 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12036 | /* Stop the SLI4 device port */ |
James Smart | 1ffdd2c | 2019-03-04 15:27:51 -0800 | [diff] [blame] | 12037 | if (phba->pport) |
| 12038 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12039 | } |
| 12040 | |
| 12041 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12042 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 12043 | * @phba: Pointer to HBA context object. |
| 12044 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 12045 | * |
| 12046 | * This function is called in the SLI4 code path to read the port's |
| 12047 | * sli4 capabilities. |
| 12048 | * |
| 12049 | * This function may be be called from any context that can block-wait |
| 12050 | * for the completion. The expectation is that this routine is called |
| 12051 | * typically from probe_one or from the online routine. |
| 12052 | **/ |
| 12053 | int |
| 12054 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 12055 | { |
| 12056 | int rc; |
| 12057 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 12058 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12059 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12060 | int length; |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12061 | bool exp_wqcq_pages = true; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12062 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 12063 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 12064 | /* |
| 12065 | * By default, the driver assumes the SLI4 port requires RPI |
| 12066 | * header postings. The SLI4_PARAM response will correct this |
| 12067 | * assumption. |
| 12068 | */ |
| 12069 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 12070 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12071 | /* Read the port's SLI4 Config Parameters */ |
| 12072 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 12073 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12074 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12075 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 12076 | length, LPFC_SLI4_MBX_EMBED); |
| 12077 | if (!phba->sli4_hba.intr_enable) |
| 12078 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12079 | else { |
| 12080 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 12081 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 12082 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12083 | if (unlikely(rc)) |
| 12084 | return rc; |
| 12085 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 12086 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 12087 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 12088 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 12089 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 12090 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 12091 | mbx_sli4_parameters); |
| 12092 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 12093 | mbx_sli4_parameters); |
| 12094 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 12095 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 12096 | else |
| 12097 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 12098 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
James Smart | b62232b | 2021-04-11 18:31:22 -0700 | [diff] [blame] | 12099 | sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope, |
| 12100 | mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12101 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12102 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 12103 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 12104 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 12105 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 12106 | sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters); |
| 12107 | sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 12108 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 12109 | sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters); |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 12110 | sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12111 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 12112 | mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12113 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12114 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 12115 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 12116 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 12117 | 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] | 12118 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 12119 | /* Check for Extended Pre-Registered SGL support */ |
| 12120 | phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters); |
| 12121 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12122 | /* Check for firmware nvme support */ |
| 12123 | rc = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
| 12124 | bf_get(cfg_xib, mbx_sli4_parameters)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12125 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12126 | if (rc) { |
| 12127 | /* Save this to indicate the Firmware supports NVME */ |
| 12128 | sli4_params->nvme = 1; |
| 12129 | |
| 12130 | /* Firmware NVME support, check driver FC4 NVME support */ |
| 12131 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) { |
| 12132 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
| 12133 | "6133 Disabling NVME support: " |
| 12134 | "FC4 type not supported: x%x\n", |
| 12135 | phba->cfg_enable_fc4_type); |
| 12136 | goto fcponly; |
| 12137 | } |
| 12138 | } else { |
| 12139 | /* No firmware NVME support, check driver FC4 NVME support */ |
| 12140 | sli4_params->nvme = 0; |
| 12141 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 12142 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, |
| 12143 | "6101 Disabling NVME support: Not " |
| 12144 | "supported by firmware (%d %d) x%x\n", |
| 12145 | bf_get(cfg_nvme, mbx_sli4_parameters), |
| 12146 | bf_get(cfg_xib, mbx_sli4_parameters), |
| 12147 | phba->cfg_enable_fc4_type); |
| 12148 | fcponly: |
| 12149 | phba->nvme_support = 0; |
| 12150 | phba->nvmet_support = 0; |
| 12151 | phba->cfg_nvmet_mrq = 0; |
James Smart | 6a224b4 | 2019-08-14 16:56:57 -0700 | [diff] [blame] | 12152 | phba->cfg_nvme_seg_cnt = 0; |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12153 | |
| 12154 | /* If no FC4 type support, move to just SCSI support */ |
| 12155 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 12156 | return -ENODEV; |
| 12157 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; |
| 12158 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12159 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12160 | |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12161 | /* 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] | 12162 | * accommodate 512K and 1M IOs in a single nvme buf. |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12163 | */ |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 12164 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12165 | phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12166 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12167 | /* Only embed PBDE for if_type 6, PBDE support requires xib be set */ |
| 12168 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 12169 | LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters))) |
| 12170 | phba->cfg_enable_pbde = 0; |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12171 | |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 12172 | /* |
| 12173 | * To support Suppress Response feature we must satisfy 3 conditions. |
| 12174 | * lpfc_suppress_rsp module parameter must be set (default). |
| 12175 | * In SLI4-Parameters Descriptor: |
| 12176 | * Extended Inline Buffers (XIB) must be supported. |
| 12177 | * Suppress Response IU Not Supported (SRIUNS) must NOT be supported |
| 12178 | * (double negative). |
| 12179 | */ |
| 12180 | if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) && |
| 12181 | !(bf_get(cfg_nosr, mbx_sli4_parameters))) |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12182 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 12183 | else |
| 12184 | phba->cfg_suppress_rsp = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12185 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 12186 | if (bf_get(cfg_eqdr, mbx_sli4_parameters)) |
| 12187 | phba->sli.sli_flag |= LPFC_SLI_USE_EQDR; |
| 12188 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12189 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 12190 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 12191 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 12192 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 12193 | /* |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12194 | * Check whether the adapter supports an embedded copy of the |
| 12195 | * FCP CMD IU within the WQE for FCP_Ixxx commands. In order |
| 12196 | * to use this option, 128-byte WQEs must be used. |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 12197 | */ |
| 12198 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 12199 | phba->fcp_embed_io = 1; |
| 12200 | else |
| 12201 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 12202 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12203 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12204 | "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n", |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12205 | bf_get(cfg_xib, mbx_sli4_parameters), |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12206 | phba->cfg_enable_pbde, |
| 12207 | phba->fcp_embed_io, phba->nvme_support, |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 12208 | phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp); |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12209 | |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12210 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 12211 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 12212 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
James Smart | c221768 | 2018-05-24 21:09:00 -0700 | [diff] [blame] | 12213 | LPFC_SLI_INTF_FAMILY_LNCR_A0)) |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12214 | exp_wqcq_pages = false; |
| 12215 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12216 | if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) && |
| 12217 | (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) && |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12218 | exp_wqcq_pages && |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12219 | (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT)) |
| 12220 | phba->enab_exp_wqcq_pages = 1; |
| 12221 | else |
| 12222 | phba->enab_exp_wqcq_pages = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 12223 | /* |
| 12224 | * Check if the SLI port supports MDS Diagnostics |
| 12225 | */ |
| 12226 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 12227 | phba->mds_diags_support = 1; |
| 12228 | else |
| 12229 | phba->mds_diags_support = 0; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12230 | |
James Smart | 0d8af09 | 2019-08-14 16:57:10 -0700 | [diff] [blame] | 12231 | /* |
| 12232 | * Check if the SLI port supports NSLER |
| 12233 | */ |
| 12234 | if (bf_get(cfg_nsler, mbx_sli4_parameters)) |
| 12235 | phba->nsler = 1; |
| 12236 | else |
| 12237 | phba->nsler = 0; |
| 12238 | |
James Smart | 8aaa7bc | 2020-10-20 13:27:17 -0700 | [diff] [blame] | 12239 | /* Save PB info for use during HBA setup */ |
| 12240 | sli4_params->mi_ver = bf_get(cfg_mi_ver, mbx_sli4_parameters); |
| 12241 | sli4_params->mib_bde_cnt = bf_get(cfg_mib_bde_cnt, mbx_sli4_parameters); |
| 12242 | sli4_params->mib_size = mbx_sli4_parameters->mib_size; |
| 12243 | sli4_params->mi_value = LPFC_DFLT_MIB_VAL; |
| 12244 | |
| 12245 | /* Next we check for Vendor MIB support */ |
| 12246 | if (sli4_params->mi_ver && phba->cfg_enable_mi) |
| 12247 | phba->cfg_fdmi_on = LPFC_FDMI_SUPPORT; |
| 12248 | |
| 12249 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12250 | "6461 MIB attr %d enable %d FDMI %d buf %d:%d\n", |
| 12251 | sli4_params->mi_ver, phba->cfg_enable_mi, |
| 12252 | sli4_params->mi_value, sli4_params->mib_bde_cnt, |
| 12253 | sli4_params->mib_size); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12254 | return 0; |
| 12255 | } |
| 12256 | |
| 12257 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12258 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 12259 | * @pdev: pointer to PCI device |
| 12260 | * @pid: pointer to PCI device identifier |
| 12261 | * |
| 12262 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 12263 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 12264 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 12265 | * information of the device and driver to see if the driver state that it can |
| 12266 | * support this kind of device. If the match is successful, the driver core |
| 12267 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 12268 | * does all the initialization that it needs to do to handle the HBA properly. |
| 12269 | * |
| 12270 | * Return code |
| 12271 | * 0 - driver can claim the device |
| 12272 | * negative value - driver can not claim the device |
| 12273 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12274 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12275 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 12276 | { |
| 12277 | struct lpfc_hba *phba; |
| 12278 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12279 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12280 | int error; |
| 12281 | uint32_t cfg_mode, intr_mode; |
| 12282 | |
| 12283 | /* Allocate memory for HBA structure */ |
| 12284 | phba = lpfc_hba_alloc(pdev); |
| 12285 | if (!phba) |
| 12286 | return -ENOMEM; |
| 12287 | |
| 12288 | /* Perform generic PCI device enabling operation */ |
| 12289 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12290 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12291 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12292 | |
| 12293 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 12294 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 12295 | if (error) |
| 12296 | goto out_disable_pci_dev; |
| 12297 | |
| 12298 | /* Set up SLI-3 specific device PCI memory space */ |
| 12299 | error = lpfc_sli_pci_mem_setup(phba); |
| 12300 | if (error) { |
| 12301 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12302 | "1402 Failed to set up pci memory space.\n"); |
| 12303 | goto out_disable_pci_dev; |
| 12304 | } |
| 12305 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12306 | /* Set up SLI-3 specific device driver resources */ |
| 12307 | error = lpfc_sli_driver_resource_setup(phba); |
| 12308 | if (error) { |
| 12309 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12310 | "1404 Failed to set up driver resource.\n"); |
| 12311 | goto out_unset_pci_mem_s3; |
| 12312 | } |
| 12313 | |
| 12314 | /* Initialize and populate the iocb list per host */ |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 12315 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12316 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 12317 | if (error) { |
| 12318 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12319 | "1405 Failed to initialize iocb list.\n"); |
| 12320 | goto out_unset_driver_resource_s3; |
| 12321 | } |
| 12322 | |
| 12323 | /* Set up common device driver resources */ |
| 12324 | error = lpfc_setup_driver_resource_phase2(phba); |
| 12325 | if (error) { |
| 12326 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12327 | "1406 Failed to set up driver resource.\n"); |
| 12328 | goto out_free_iocb_list; |
| 12329 | } |
| 12330 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12331 | /* Get the default values for Model Name and Description */ |
| 12332 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 12333 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12334 | /* Create SCSI host to the physical port */ |
| 12335 | error = lpfc_create_shost(phba); |
| 12336 | if (error) { |
| 12337 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12338 | "1407 Failed to create scsi host.\n"); |
| 12339 | goto out_unset_driver_resource; |
| 12340 | } |
| 12341 | |
| 12342 | /* Configure sysfs attributes */ |
| 12343 | vport = phba->pport; |
| 12344 | error = lpfc_alloc_sysfs_attr(vport); |
| 12345 | if (error) { |
| 12346 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12347 | "1476 Failed to allocate sysfs attr\n"); |
| 12348 | goto out_destroy_shost; |
| 12349 | } |
| 12350 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12351 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12352 | /* Now, trying to enable interrupt and bring up the device */ |
| 12353 | cfg_mode = phba->cfg_use_msi; |
| 12354 | while (true) { |
| 12355 | /* Put device to a known state before enabling interrupt */ |
| 12356 | lpfc_stop_port(phba); |
| 12357 | /* Configure and enable interrupt */ |
| 12358 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 12359 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12360 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12361 | "0431 Failed to enable interrupt.\n"); |
| 12362 | error = -ENODEV; |
| 12363 | goto out_free_sysfs_attr; |
| 12364 | } |
| 12365 | /* SLI-3 HBA setup */ |
| 12366 | if (lpfc_sli_hba_setup(phba)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12367 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12368 | "1477 Failed to set up hba\n"); |
| 12369 | error = -ENODEV; |
| 12370 | goto out_remove_device; |
| 12371 | } |
| 12372 | |
| 12373 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 12374 | msleep(50); |
| 12375 | /* Check active interrupts on message signaled interrupts */ |
| 12376 | if (intr_mode == 0 || |
| 12377 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 12378 | /* Log the current active interrupt mode */ |
| 12379 | phba->intr_mode = intr_mode; |
| 12380 | lpfc_log_intr_mode(phba, intr_mode); |
| 12381 | break; |
| 12382 | } else { |
| 12383 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12384 | "0447 Configure interrupt mode (%d) " |
| 12385 | "failed active interrupt test.\n", |
| 12386 | intr_mode); |
| 12387 | /* Disable the current interrupt mode */ |
| 12388 | lpfc_sli_disable_intr(phba); |
| 12389 | /* Try next level of interrupt mode */ |
| 12390 | cfg_mode = --intr_mode; |
| 12391 | } |
| 12392 | } |
| 12393 | |
| 12394 | /* Perform post initialization setup */ |
| 12395 | lpfc_post_init_setup(phba); |
| 12396 | |
| 12397 | /* Check if there are static vports to be created. */ |
| 12398 | lpfc_create_static_vport(phba); |
| 12399 | |
| 12400 | return 0; |
| 12401 | |
| 12402 | out_remove_device: |
| 12403 | lpfc_unset_hba(phba); |
| 12404 | out_free_sysfs_attr: |
| 12405 | lpfc_free_sysfs_attr(vport); |
| 12406 | out_destroy_shost: |
| 12407 | lpfc_destroy_shost(phba); |
| 12408 | out_unset_driver_resource: |
| 12409 | lpfc_unset_driver_resource_phase2(phba); |
| 12410 | out_free_iocb_list: |
| 12411 | lpfc_free_iocb_list(phba); |
| 12412 | out_unset_driver_resource_s3: |
| 12413 | lpfc_sli_driver_resource_unset(phba); |
| 12414 | out_unset_pci_mem_s3: |
| 12415 | lpfc_sli_pci_mem_unset(phba); |
| 12416 | out_disable_pci_dev: |
| 12417 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12418 | if (shost) |
| 12419 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12420 | out_free_phba: |
| 12421 | lpfc_hba_free(phba); |
| 12422 | return error; |
| 12423 | } |
| 12424 | |
| 12425 | /** |
| 12426 | * 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] | 12427 | * @pdev: pointer to PCI device |
| 12428 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12429 | * This routine is to be called to disattach a device with SLI-3 interface |
| 12430 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 12431 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 12432 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12433 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12434 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12435 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12436 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12437 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12438 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12439 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12440 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12441 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 12442 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 12443 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12444 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 12445 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12446 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12447 | lpfc_free_sysfs_attr(vport); |
| 12448 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12449 | /* Release all the vports against this physical port */ |
| 12450 | vports = lpfc_create_vport_work_array(phba); |
| 12451 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12452 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 12453 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 12454 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12455 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12456 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12457 | lpfc_destroy_vport_work_array(phba, vports); |
| 12458 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 12459 | /* Remove FC host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12460 | fc_remove_host(shost); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 12461 | scsi_remove_host(shost); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 12462 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 12463 | /* Clean up all nodes, mailboxes and IOs. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 12464 | lpfc_cleanup(vport); |
| 12465 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12466 | /* |
| 12467 | * Bring down the SLI Layer. This step disable all interrupts, |
| 12468 | * clears the rings, discards all mailbox commands, and resets |
| 12469 | * the HBA. |
| 12470 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12471 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 12472 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12473 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12474 | /* Stop kthread signal shall trigger work_done one more time */ |
| 12475 | kthread_stop(phba->worker_thread); |
| 12476 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12477 | lpfc_sli_brdrestart(phba); |
| 12478 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 12479 | kfree(phba->vpi_bmask); |
| 12480 | kfree(phba->vpi_ids); |
| 12481 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12482 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12483 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12484 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12485 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12486 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12487 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12488 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 12489 | /* Disable SR-IOV if enabled */ |
| 12490 | if (phba->cfg_sriov_nr_virtfn) |
| 12491 | pci_disable_sriov(pdev); |
| 12492 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12493 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12494 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12495 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12496 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12497 | |
| 12498 | /* |
| 12499 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 12500 | * corresponding pools here. |
| 12501 | */ |
| 12502 | lpfc_scsi_free(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 12503 | lpfc_free_iocb_list(phba); |
| 12504 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12505 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12506 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12507 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 12508 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12509 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12510 | /* Free resources associated with SLI2 interface */ |
| 12511 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12512 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12513 | |
| 12514 | /* unmap adapter SLIM and Control Registers */ |
| 12515 | iounmap(phba->ctrl_regs_memmap_p); |
| 12516 | iounmap(phba->slim_memmap_p); |
| 12517 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12518 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12519 | |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 12520 | pci_release_mem_regions(pdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12521 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12522 | } |
| 12523 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12524 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12525 | * 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] | 12526 | * @dev_d: pointer to device |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12527 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12528 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12529 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 12530 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 12531 | * worker thread for the device, turning off device's interrupt and DMA, |
| 12532 | * and bring the device offline. Note that as the driver implements the |
| 12533 | * minimum PM requirements to a power-aware driver's PM support for the |
| 12534 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 12535 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 12536 | * fully reinitialize its device during resume() method call, the driver will |
| 12537 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 12538 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12539 | * |
| 12540 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12541 | * 0 - driver suspended the device |
| 12542 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12543 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12544 | static int __maybe_unused |
| 12545 | lpfc_pci_suspend_one_s3(struct device *dev_d) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12546 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12547 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12548 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12549 | |
| 12550 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12551 | "0473 PCI device Power Management suspend.\n"); |
| 12552 | |
| 12553 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12554 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12555 | lpfc_offline(phba); |
| 12556 | kthread_stop(phba->worker_thread); |
| 12557 | |
| 12558 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12559 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12560 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12561 | return 0; |
| 12562 | } |
| 12563 | |
| 12564 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12565 | * 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] | 12566 | * @dev_d: pointer to device |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12567 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12568 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12569 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 12570 | * invokes this method, it restores the device's PCI config space state and |
| 12571 | * fully reinitializes the device and brings it online. Note that as the |
| 12572 | * driver implements the minimum PM requirements to a power-aware driver's |
| 12573 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 12574 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 12575 | * driver will fully reinitialize its device during resume() method call, |
| 12576 | * the device will be set to PCI_D0 directly in PCI config space before |
| 12577 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12578 | * |
| 12579 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12580 | * 0 - driver suspended the device |
| 12581 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12582 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12583 | static int __maybe_unused |
| 12584 | lpfc_pci_resume_one_s3(struct device *dev_d) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12585 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12586 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12587 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12588 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12589 | int error; |
| 12590 | |
| 12591 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12592 | "0452 PCI device Power Management resume.\n"); |
| 12593 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12594 | /* Startup the kernel thread for this host adapter. */ |
| 12595 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 12596 | "lpfc_worker_%d", phba->brd_no); |
| 12597 | if (IS_ERR(phba->worker_thread)) { |
| 12598 | error = PTR_ERR(phba->worker_thread); |
| 12599 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12600 | "0434 PM resume failed to start worker " |
| 12601 | "thread: error=x%x.\n", error); |
| 12602 | return error; |
| 12603 | } |
| 12604 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12605 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12606 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12607 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12608 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12609 | "0430 PM resume Failed to enable interrupt\n"); |
| 12610 | return -EIO; |
| 12611 | } else |
| 12612 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12613 | |
| 12614 | /* Restart HBA and bring it online */ |
| 12615 | lpfc_sli_brdrestart(phba); |
| 12616 | lpfc_online(phba); |
| 12617 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12618 | /* Log the current active interrupt mode */ |
| 12619 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12620 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12621 | return 0; |
| 12622 | } |
| 12623 | |
| 12624 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12625 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 12626 | * @phba: pointer to lpfc hba data structure. |
| 12627 | * |
| 12628 | * 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] | 12629 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12630 | **/ |
| 12631 | static void |
| 12632 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 12633 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12634 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12635 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12636 | |
| 12637 | /* |
| 12638 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 12639 | * and let the SCSI mid-layer to retry them to recover. |
| 12640 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12641 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12642 | } |
| 12643 | |
| 12644 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12645 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 12646 | * @phba: pointer to lpfc hba data structure. |
| 12647 | * |
| 12648 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 12649 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 12650 | * pending I/Os. |
| 12651 | **/ |
| 12652 | static void |
| 12653 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 12654 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12655 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12656 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12657 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12658 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12659 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12660 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12661 | /* Block all SCSI devices' I/Os on the host */ |
| 12662 | lpfc_scsi_dev_block(phba); |
| 12663 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12664 | /* 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] | 12665 | lpfc_sli_flush_io_rings(phba); |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12666 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12667 | /* stop all timers */ |
| 12668 | lpfc_stop_hba_timers(phba); |
| 12669 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12670 | /* Disable interrupt and pci device */ |
| 12671 | lpfc_sli_disable_intr(phba); |
| 12672 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12673 | } |
| 12674 | |
| 12675 | /** |
| 12676 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 12677 | * @phba: pointer to lpfc hba data structure. |
| 12678 | * |
| 12679 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 12680 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 12681 | * pending I/Os. |
| 12682 | **/ |
| 12683 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12684 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12685 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12686 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12687 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12688 | /* Block all SCSI devices' I/Os on the host */ |
| 12689 | lpfc_scsi_dev_block(phba); |
| 12690 | |
| 12691 | /* stop all timers */ |
| 12692 | lpfc_stop_hba_timers(phba); |
| 12693 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12694 | /* Clean up all driver's outstanding SCSI I/Os */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12695 | lpfc_sli_flush_io_rings(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12696 | } |
| 12697 | |
| 12698 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12699 | * 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] | 12700 | * @pdev: pointer to PCI device. |
| 12701 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12702 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12703 | * This routine is called from the PCI subsystem for I/O error handling to |
| 12704 | * device with SLI-3 interface spec. This function is called by the PCI |
| 12705 | * subsystem after a PCI bus error affecting this device has been detected. |
| 12706 | * When this function is invoked, it will need to stop all the I/Os and |
| 12707 | * interrupt(s) to the device. Once that is done, it will return |
| 12708 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 12709 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12710 | * |
| 12711 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12712 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12713 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12714 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12715 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12716 | static pci_ers_result_t |
| 12717 | 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] | 12718 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12719 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12720 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12721 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12722 | switch (state) { |
| 12723 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12724 | /* Non-fatal error, prepare for recovery */ |
| 12725 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12726 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 12727 | case pci_channel_io_frozen: |
| 12728 | /* Fatal error, prepare for slot reset */ |
| 12729 | lpfc_sli_prep_dev_for_reset(phba); |
| 12730 | return PCI_ERS_RESULT_NEED_RESET; |
| 12731 | case pci_channel_io_perm_failure: |
| 12732 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12733 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12734 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12735 | default: |
| 12736 | /* Unknown state, prepare and request slot reset */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12737 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12738 | "0472 Unknown PCI error state: x%x\n", state); |
| 12739 | lpfc_sli_prep_dev_for_reset(phba); |
| 12740 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 12741 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12742 | } |
| 12743 | |
| 12744 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12745 | * 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] | 12746 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12747 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12748 | * This routine is called from the PCI subsystem for error handling to |
| 12749 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 12750 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 12751 | * During the PCI subsystem error recovery, after driver returns |
| 12752 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 12753 | * recovery and then call this routine before calling the .resume method |
| 12754 | * to recover the device. This function will initialize the HBA device, |
| 12755 | * enable the interrupt, but it will just put the HBA to offline state |
| 12756 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12757 | * |
| 12758 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12759 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 12760 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12761 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12762 | static pci_ers_result_t |
| 12763 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12764 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12765 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12766 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12767 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12768 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12769 | |
| 12770 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 12771 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12772 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 12773 | "PCI device after reset.\n"); |
| 12774 | return PCI_ERS_RESULT_DISCONNECT; |
| 12775 | } |
| 12776 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12777 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12778 | |
| 12779 | /* |
| 12780 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12781 | * device saved_state flag, need to save the restored state again. |
| 12782 | */ |
| 12783 | pci_save_state(pdev); |
| 12784 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12785 | if (pdev->is_busmaster) |
| 12786 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12787 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12788 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12789 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12790 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12791 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12792 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12793 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12794 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12795 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12796 | "0427 Cannot re-enable interrupt after " |
| 12797 | "slot reset.\n"); |
| 12798 | return PCI_ERS_RESULT_DISCONNECT; |
| 12799 | } else |
| 12800 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12801 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12802 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12803 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12804 | lpfc_offline(phba); |
| 12805 | lpfc_sli_brdrestart(phba); |
| 12806 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12807 | /* Log the current active interrupt mode */ |
| 12808 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12809 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12810 | return PCI_ERS_RESULT_RECOVERED; |
| 12811 | } |
| 12812 | |
| 12813 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12814 | * 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] | 12815 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12816 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12817 | * This routine is called from the PCI subsystem for error handling to device |
| 12818 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 12819 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 12820 | * error recovery. After this call, traffic can start to flow from this device |
| 12821 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12822 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12823 | static void |
| 12824 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12825 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12826 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12827 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12828 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12829 | /* 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] | 12830 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12831 | } |
| 12832 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12833 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12834 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 12835 | * @phba: pointer to lpfc hba data structure. |
| 12836 | * |
| 12837 | * returns the number of ELS/CT IOCBs to reserve |
| 12838 | **/ |
| 12839 | int |
| 12840 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 12841 | { |
| 12842 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 12843 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12844 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 12845 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12846 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12847 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12848 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12849 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12850 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12851 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12852 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12853 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12854 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12855 | else if (max_xri <= 2048) |
| 12856 | return 200; |
| 12857 | else |
| 12858 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12859 | } else |
| 12860 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12861 | } |
| 12862 | |
| 12863 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12864 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve |
| 12865 | * @phba: pointer to lpfc hba data structure. |
| 12866 | * |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12867 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12868 | **/ |
| 12869 | int |
| 12870 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) |
| 12871 | { |
| 12872 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); |
| 12873 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12874 | if (phba->nvmet_support) |
| 12875 | max_xri += LPFC_NVMET_BUF_POST; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12876 | return max_xri; |
| 12877 | } |
| 12878 | |
| 12879 | |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12880 | static int |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12881 | lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset, |
| 12882 | uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize, |
| 12883 | const struct firmware *fw) |
| 12884 | { |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12885 | int rc; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12886 | |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12887 | /* Three cases: (1) FW was not supported on the detected adapter. |
| 12888 | * (2) FW update has been locked out administratively. |
| 12889 | * (3) Some other error during FW update. |
| 12890 | * In each case, an unmaskable message is written to the console |
| 12891 | * for admin diagnosis. |
| 12892 | */ |
| 12893 | if (offset == ADD_STATUS_FW_NOT_SUPPORTED || |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12894 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
James Smart | 5792a0e | 2019-10-25 11:43:42 -0700 | [diff] [blame] | 12895 | magic_number != MAGIC_NUMBER_G6) || |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12896 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC && |
James Smart | 5792a0e | 2019-10-25 11:43:42 -0700 | [diff] [blame] | 12897 | magic_number != MAGIC_NUMBER_G7)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12898 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12899 | "3030 This firmware version is not supported on" |
| 12900 | " this HBA model. Device:%x Magic:%x Type:%x " |
| 12901 | "ID:%x Size %d %zd\n", |
| 12902 | phba->pcidev->device, magic_number, ftype, fid, |
| 12903 | fsize, fw->size); |
| 12904 | rc = -EINVAL; |
| 12905 | } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12906 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12907 | "3021 Firmware downloads have been prohibited " |
| 12908 | "by a system configuration setting on " |
| 12909 | "Device:%x Magic:%x Type:%x ID:%x Size %d " |
| 12910 | "%zd\n", |
| 12911 | phba->pcidev->device, magic_number, ftype, fid, |
| 12912 | fsize, fw->size); |
| 12913 | rc = -EACCES; |
| 12914 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12915 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12916 | "3022 FW Download failed. Add Status x%x " |
| 12917 | "Device:%x Magic:%x Type:%x ID:%x Size %d " |
| 12918 | "%zd\n", |
| 12919 | offset, phba->pcidev->device, magic_number, |
| 12920 | ftype, fid, fsize, fw->size); |
| 12921 | rc = -EIO; |
| 12922 | } |
| 12923 | return rc; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12924 | } |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12925 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12926 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12927 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12928 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12929 | * @context: pointer to firmware image returned from request_firmware. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12930 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12931 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12932 | static void |
| 12933 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12934 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12935 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 12936 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12937 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12938 | struct list_head dma_buffer_list; |
| 12939 | int i, rc = 0; |
| 12940 | struct lpfc_dmabuf *dmabuf, *next; |
| 12941 | uint32_t offset = 0, temp_offset = 0; |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12942 | uint32_t magic_number, ftype, fid, fsize; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12943 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12944 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12945 | if (!fw) { |
| 12946 | rc = -ENXIO; |
| 12947 | goto out; |
| 12948 | } |
| 12949 | image = (struct lpfc_grp_hdr *)fw->data; |
| 12950 | |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12951 | magic_number = be32_to_cpu(image->magic_number); |
| 12952 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12953 | fid = bf_get_be32(lpfc_grp_hdr_id, image); |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12954 | fsize = be32_to_cpu(image->size); |
| 12955 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12956 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12957 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12958 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12959 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12960 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12961 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12962 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12963 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 12964 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 12965 | GFP_KERNEL); |
| 12966 | if (!dmabuf) { |
| 12967 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12968 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12969 | } |
| 12970 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 12971 | SLI4_PAGE_SIZE, |
| 12972 | &dmabuf->phys, |
| 12973 | GFP_KERNEL); |
| 12974 | if (!dmabuf->virt) { |
| 12975 | kfree(dmabuf); |
| 12976 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12977 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12978 | } |
| 12979 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 12980 | } |
| 12981 | while (offset < fw->size) { |
| 12982 | temp_offset = offset; |
| 12983 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12984 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12985 | memcpy(dmabuf->virt, |
| 12986 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12987 | fw->size - temp_offset); |
| 12988 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12989 | break; |
| 12990 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12991 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 12992 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 12993 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12994 | } |
| 12995 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 12996 | (fw->size - offset), &offset); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12997 | if (rc) { |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12998 | rc = lpfc_log_write_firmware_error(phba, offset, |
| 12999 | magic_number, |
| 13000 | ftype, |
| 13001 | fid, |
| 13002 | fsize, |
| 13003 | fw); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13004 | goto release_out; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13005 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13006 | } |
| 13007 | rc = offset; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13008 | } else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13009 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13010 | "3029 Skipped Firmware update, Current " |
| 13011 | "Version:%s New Version:%s\n", |
| 13012 | fwrev, image->revision); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13013 | |
| 13014 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13015 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 13016 | list_del(&dmabuf->list); |
| 13017 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 13018 | dmabuf->virt, dmabuf->phys); |
| 13019 | kfree(dmabuf); |
| 13020 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13021 | release_firmware(fw); |
| 13022 | out: |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13023 | if (rc < 0) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13024 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13025 | "3062 Firmware update error, status %d.\n", rc); |
| 13026 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13027 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13028 | "3024 Firmware update success: size %d.\n", rc); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13029 | } |
| 13030 | |
| 13031 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13032 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 13033 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 13034 | * @fw_upgrade: which firmware to update. |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13035 | * |
| 13036 | * This routine is called to perform Linux generic firmware upgrade on device |
| 13037 | * that supports such feature. |
| 13038 | **/ |
| 13039 | int |
| 13040 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 13041 | { |
| 13042 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 13043 | int ret; |
| 13044 | const struct firmware *fw; |
| 13045 | |
| 13046 | /* Only supported on SLI4 interface type 2 for now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 13047 | 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] | 13048 | LPFC_SLI_INTF_IF_TYPE_2) |
| 13049 | return -EPERM; |
| 13050 | |
| 13051 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 13052 | |
| 13053 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 13054 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 13055 | file_name, &phba->pcidev->dev, |
| 13056 | GFP_KERNEL, (void *)phba, |
| 13057 | lpfc_write_firmware); |
| 13058 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 13059 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 13060 | if (!ret) |
| 13061 | lpfc_write_firmware(fw, (void *)phba); |
| 13062 | } else { |
| 13063 | ret = -EINVAL; |
| 13064 | } |
| 13065 | |
| 13066 | return ret; |
| 13067 | } |
| 13068 | |
| 13069 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13070 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 13071 | * @pdev: pointer to PCI device |
| 13072 | * @pid: pointer to PCI device identifier |
| 13073 | * |
| 13074 | * This routine is called from the kernel's PCI subsystem to device with |
| 13075 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 13076 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 13077 | * information of the device and driver to see if the driver state that it |
| 13078 | * can support this kind of device. If the match is successful, the driver |
| 13079 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 13080 | * it does all the initialization that it needs to do to handle the HBA |
| 13081 | * properly. |
| 13082 | * |
| 13083 | * Return code |
| 13084 | * 0 - driver can claim the device |
| 13085 | * negative value - driver can not claim the device |
| 13086 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13087 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13088 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13089 | { |
| 13090 | struct lpfc_hba *phba; |
| 13091 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13092 | struct Scsi_Host *shost = NULL; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 13093 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13094 | uint32_t cfg_mode, intr_mode; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13095 | |
| 13096 | /* Allocate memory for HBA structure */ |
| 13097 | phba = lpfc_hba_alloc(pdev); |
| 13098 | if (!phba) |
| 13099 | return -ENOMEM; |
| 13100 | |
| 13101 | /* Perform generic PCI device enabling operation */ |
| 13102 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13103 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13104 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13105 | |
| 13106 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 13107 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 13108 | if (error) |
| 13109 | goto out_disable_pci_dev; |
| 13110 | |
| 13111 | /* Set up SLI-4 specific device PCI memory space */ |
| 13112 | error = lpfc_sli4_pci_mem_setup(phba); |
| 13113 | if (error) { |
| 13114 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13115 | "1410 Failed to set up pci memory space.\n"); |
| 13116 | goto out_disable_pci_dev; |
| 13117 | } |
| 13118 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13119 | /* Set up SLI-4 Specific device driver resources */ |
| 13120 | error = lpfc_sli4_driver_resource_setup(phba); |
| 13121 | if (error) { |
| 13122 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13123 | "1412 Failed to set up driver resource.\n"); |
| 13124 | goto out_unset_pci_mem_s4; |
| 13125 | } |
| 13126 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 13127 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 13128 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 13129 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13130 | /* Set up common device driver resources */ |
| 13131 | error = lpfc_setup_driver_resource_phase2(phba); |
| 13132 | if (error) { |
| 13133 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13134 | "1414 Failed to set up driver resource.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 13135 | goto out_unset_driver_resource_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13136 | } |
| 13137 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13138 | /* Get the default values for Model Name and Description */ |
| 13139 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 13140 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13141 | /* Now, trying to enable interrupt and bring up the device */ |
| 13142 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13143 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13144 | /* Put device to a known state before enabling interrupt */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13145 | phba->pport = NULL; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13146 | lpfc_stop_port(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13147 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 13148 | /* Init cpu_map array */ |
| 13149 | lpfc_cpu_map_array_init(phba); |
| 13150 | |
| 13151 | /* Init hba_eq_hdl array */ |
| 13152 | lpfc_hba_eq_hdl_array_init(phba); |
| 13153 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13154 | /* Configure and enable interrupt */ |
| 13155 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 13156 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13157 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13158 | "0426 Failed to enable interrupt.\n"); |
| 13159 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13160 | goto out_unset_driver_resource; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13161 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13162 | /* Default to single EQ for non-MSI-X */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13163 | if (phba->intr_type != MSIX) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13164 | phba->cfg_irq_chann = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13165 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13166 | if (phba->nvmet_support) |
| 13167 | phba->cfg_nvmet_mrq = 1; |
| 13168 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13169 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13170 | lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13171 | |
| 13172 | /* Create SCSI host to the physical port */ |
| 13173 | error = lpfc_create_shost(phba); |
| 13174 | if (error) { |
| 13175 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13176 | "1415 Failed to create scsi host.\n"); |
| 13177 | goto out_disable_intr; |
| 13178 | } |
| 13179 | vport = phba->pport; |
| 13180 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
| 13181 | |
| 13182 | /* Configure sysfs attributes */ |
| 13183 | error = lpfc_alloc_sysfs_attr(vport); |
| 13184 | if (error) { |
| 13185 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13186 | "1416 Failed to allocate sysfs attr\n"); |
| 13187 | goto out_destroy_shost; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13188 | } |
| 13189 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13190 | /* Set up SLI-4 HBA */ |
| 13191 | if (lpfc_sli4_hba_setup(phba)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13192 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13193 | "1421 Failed to set up hba\n"); |
| 13194 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13195 | goto out_free_sysfs_attr; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13196 | } |
| 13197 | |
| 13198 | /* Log the current active interrupt mode */ |
| 13199 | phba->intr_mode = intr_mode; |
| 13200 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13201 | |
| 13202 | /* Perform post initialization setup */ |
| 13203 | lpfc_post_init_setup(phba); |
| 13204 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13205 | /* NVME support in FW earlier in the driver load corrects the |
| 13206 | * FC4 type making a check for nvme_support unnecessary. |
| 13207 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 13208 | if (phba->nvmet_support == 0) { |
| 13209 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13210 | /* Create NVME binding with nvme_fc_transport. This |
| 13211 | * ensures the vport is initialized. If the localport |
| 13212 | * create fails, it should not unload the driver to |
| 13213 | * support field issues. |
| 13214 | */ |
| 13215 | error = lpfc_nvme_create_localport(vport); |
| 13216 | if (error) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13217 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 13218 | "6004 NVME registration " |
| 13219 | "failed, error x%x\n", |
| 13220 | error); |
| 13221 | } |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13222 | } |
| 13223 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13224 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13225 | /* check for firmware upgrade or downgrade */ |
| 13226 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 13227 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13228 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 13229 | /* Check if there are static vports to be created. */ |
| 13230 | lpfc_create_static_vport(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13231 | |
| 13232 | /* Enable RAS FW log support */ |
| 13233 | lpfc_sli4_ras_setup(phba); |
| 13234 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13235 | INIT_LIST_HEAD(&phba->poll_list); |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 13236 | timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13237 | cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp); |
| 13238 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13239 | return 0; |
| 13240 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13241 | out_free_sysfs_attr: |
| 13242 | lpfc_free_sysfs_attr(vport); |
| 13243 | out_destroy_shost: |
| 13244 | lpfc_destroy_shost(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13245 | out_disable_intr: |
| 13246 | lpfc_sli4_disable_intr(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13247 | out_unset_driver_resource: |
| 13248 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13249 | out_unset_driver_resource_s4: |
| 13250 | lpfc_sli4_driver_resource_unset(phba); |
| 13251 | out_unset_pci_mem_s4: |
| 13252 | lpfc_sli4_pci_mem_unset(phba); |
| 13253 | out_disable_pci_dev: |
| 13254 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13255 | if (shost) |
| 13256 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13257 | out_free_phba: |
| 13258 | lpfc_hba_free(phba); |
| 13259 | return error; |
| 13260 | } |
| 13261 | |
| 13262 | /** |
| 13263 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 13264 | * @pdev: pointer to PCI device |
| 13265 | * |
| 13266 | * This routine is called from the kernel's PCI subsystem to device with |
| 13267 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 13268 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 13269 | * device to be removed from the PCI subsystem properly. |
| 13270 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13271 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13272 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 13273 | { |
| 13274 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13275 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 13276 | struct lpfc_vport **vports; |
| 13277 | struct lpfc_hba *phba = vport->phba; |
| 13278 | int i; |
| 13279 | |
| 13280 | /* Mark the device unloading flag */ |
| 13281 | spin_lock_irq(&phba->hbalock); |
| 13282 | vport->load_flag |= FC_UNLOADING; |
| 13283 | spin_unlock_irq(&phba->hbalock); |
| 13284 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13285 | lpfc_free_sysfs_attr(vport); |
| 13286 | |
| 13287 | /* Release all the vports against this physical port */ |
| 13288 | vports = lpfc_create_vport_work_array(phba); |
| 13289 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 13290 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 13291 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 13292 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13293 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 13294 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13295 | lpfc_destroy_vport_work_array(phba, vports); |
| 13296 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 13297 | /* Remove FC host with the physical port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13298 | fc_remove_host(shost); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 13299 | scsi_remove_host(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13300 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13301 | /* Perform ndlp cleanup on the physical port. The nvme and nvmet |
| 13302 | * localports are destroyed after to cleanup all transport memory. |
| 13303 | */ |
| 13304 | lpfc_cleanup(vport); |
| 13305 | lpfc_nvmet_destroy_targetport(phba); |
| 13306 | lpfc_nvme_destroy_localport(vport); |
| 13307 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 13308 | /* De-allocate multi-XRI pools */ |
| 13309 | if (phba->cfg_xri_rebalancing) |
| 13310 | lpfc_destroy_multixri_pools(phba); |
| 13311 | |
James Smart | 281d619 | 2018-01-30 15:58:47 -0800 | [diff] [blame] | 13312 | /* |
| 13313 | * Bring down the SLI Layer. This step disables all interrupts, |
| 13314 | * clears the rings, discards all mailbox commands, and resets |
| 13315 | * the HBA FCoE function. |
| 13316 | */ |
| 13317 | lpfc_debugfs_terminate(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13318 | |
Dick Kennedy | 1901762 | 2017-09-29 17:34:27 -0700 | [diff] [blame] | 13319 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13320 | spin_lock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13321 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13322 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13323 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 13324 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13325 | * buffers are released to their corresponding pools here. |
| 13326 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13327 | lpfc_io_free(phba); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13328 | lpfc_free_iocb_list(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13329 | lpfc_sli4_hba_unset(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13330 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 13331 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13332 | lpfc_sli4_driver_resource_unset(phba); |
| 13333 | |
| 13334 | /* Unmap adapter Control and Doorbell registers */ |
| 13335 | lpfc_sli4_pci_mem_unset(phba); |
| 13336 | |
| 13337 | /* Release PCI resources and disable device's PCI function */ |
| 13338 | scsi_host_put(shost); |
| 13339 | lpfc_disable_pci_dev(phba); |
| 13340 | |
| 13341 | /* Finally, free the driver's device data structure */ |
| 13342 | lpfc_hba_free(phba); |
| 13343 | |
| 13344 | return; |
| 13345 | } |
| 13346 | |
| 13347 | /** |
| 13348 | * 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] | 13349 | * @dev_d: pointer to device |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13350 | * |
| 13351 | * This routine is called from the kernel's PCI subsystem to support system |
| 13352 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 13353 | * this method, it quiesces the device by stopping the driver's worker |
| 13354 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 13355 | * the device offline. Note that as the driver implements the minimum PM |
| 13356 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 13357 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 13358 | * method call will be treated as SUSPEND and the driver will fully |
| 13359 | * reinitialize its device during resume() method call, the driver will set |
| 13360 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 13361 | * according to the @msg provided by the PM. |
| 13362 | * |
| 13363 | * Return code |
| 13364 | * 0 - driver suspended the device |
| 13365 | * Error otherwise |
| 13366 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13367 | static int __maybe_unused |
| 13368 | lpfc_pci_suspend_one_s4(struct device *dev_d) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13369 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13370 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13371 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13372 | |
| 13373 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13374 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13375 | |
| 13376 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13377 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13378 | lpfc_offline(phba); |
| 13379 | kthread_stop(phba->worker_thread); |
| 13380 | |
| 13381 | /* Disable interrupt from device */ |
| 13382 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13383 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13384 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13385 | return 0; |
| 13386 | } |
| 13387 | |
| 13388 | /** |
| 13389 | * 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] | 13390 | * @dev_d: pointer to device |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13391 | * |
| 13392 | * This routine is called from the kernel's PCI subsystem to support system |
| 13393 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 13394 | * this method, it restores the device's PCI config space state and fully |
| 13395 | * reinitializes the device and brings it online. Note that as the driver |
| 13396 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 13397 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 13398 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 13399 | * will fully reinitialize its device during resume() method call, the device |
| 13400 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 13401 | * state. |
| 13402 | * |
| 13403 | * Return code |
| 13404 | * 0 - driver suspended the device |
| 13405 | * Error otherwise |
| 13406 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13407 | static int __maybe_unused |
| 13408 | lpfc_pci_resume_one_s4(struct device *dev_d) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13409 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13410 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13411 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13412 | uint32_t intr_mode; |
| 13413 | int error; |
| 13414 | |
| 13415 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13416 | "0292 PCI device Power Management resume.\n"); |
| 13417 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13418 | /* Startup the kernel thread for this host adapter. */ |
| 13419 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 13420 | "lpfc_worker_%d", phba->brd_no); |
| 13421 | if (IS_ERR(phba->worker_thread)) { |
| 13422 | error = PTR_ERR(phba->worker_thread); |
| 13423 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13424 | "0293 PM resume failed to start worker " |
| 13425 | "thread: error=x%x.\n", error); |
| 13426 | return error; |
| 13427 | } |
| 13428 | |
| 13429 | /* Configure and enable interrupt */ |
| 13430 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13431 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13432 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13433 | "0294 PM resume Failed to enable interrupt\n"); |
| 13434 | return -EIO; |
| 13435 | } else |
| 13436 | phba->intr_mode = intr_mode; |
| 13437 | |
| 13438 | /* Restart HBA and bring it online */ |
| 13439 | lpfc_sli_brdrestart(phba); |
| 13440 | lpfc_online(phba); |
| 13441 | |
| 13442 | /* Log the current active interrupt mode */ |
| 13443 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13444 | |
| 13445 | return 0; |
| 13446 | } |
| 13447 | |
| 13448 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13449 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 13450 | * @phba: pointer to lpfc hba data structure. |
| 13451 | * |
| 13452 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 13453 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 13454 | **/ |
| 13455 | static void |
| 13456 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 13457 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13458 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13459 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 13460 | /* |
| 13461 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 13462 | * and let the SCSI mid-layer to retry them to recover. |
| 13463 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 13464 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13465 | } |
| 13466 | |
| 13467 | /** |
| 13468 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 13469 | * @phba: pointer to lpfc hba data structure. |
| 13470 | * |
| 13471 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 13472 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 13473 | * pending I/Os. |
| 13474 | **/ |
| 13475 | static void |
| 13476 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 13477 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13478 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13479 | "2826 PCI channel disable preparing for reset\n"); |
| 13480 | |
| 13481 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13482 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13483 | |
| 13484 | /* Block all SCSI devices' I/Os on the host */ |
| 13485 | lpfc_scsi_dev_block(phba); |
| 13486 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13487 | /* Flush all driver's outstanding I/Os as we are to reset */ |
| 13488 | lpfc_sli_flush_io_rings(phba); |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 13489 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13490 | /* stop all timers */ |
| 13491 | lpfc_stop_hba_timers(phba); |
| 13492 | |
| 13493 | /* Disable interrupt and pci device */ |
| 13494 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13495 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13496 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13497 | } |
| 13498 | |
| 13499 | /** |
| 13500 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 13501 | * @phba: pointer to lpfc hba data structure. |
| 13502 | * |
| 13503 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 13504 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 13505 | * pending I/Os. |
| 13506 | **/ |
| 13507 | static void |
| 13508 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 13509 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13510 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13511 | "2827 PCI channel permanent disable for failure\n"); |
| 13512 | |
| 13513 | /* Block all SCSI devices' I/Os on the host */ |
| 13514 | lpfc_scsi_dev_block(phba); |
| 13515 | |
| 13516 | /* stop all timers */ |
| 13517 | lpfc_stop_hba_timers(phba); |
| 13518 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13519 | /* Clean up all driver's outstanding I/Os */ |
| 13520 | lpfc_sli_flush_io_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13521 | } |
| 13522 | |
| 13523 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13524 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 13525 | * @pdev: pointer to PCI device. |
| 13526 | * @state: the current PCI connection state. |
| 13527 | * |
| 13528 | * This routine is called from the PCI subsystem for error handling to device |
| 13529 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 13530 | * after a PCI bus error affecting this device has been detected. When this |
| 13531 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 13532 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 13533 | * for the PCI subsystem to perform proper recovery as desired. |
| 13534 | * |
| 13535 | * Return codes |
| 13536 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13537 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13538 | **/ |
| 13539 | static pci_ers_result_t |
| 13540 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 13541 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13542 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13543 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13544 | |
| 13545 | switch (state) { |
| 13546 | case pci_channel_io_normal: |
| 13547 | /* Non-fatal error, prepare for recovery */ |
| 13548 | lpfc_sli4_prep_dev_for_recover(phba); |
| 13549 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 13550 | case pci_channel_io_frozen: |
| 13551 | /* Fatal error, prepare for slot reset */ |
| 13552 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13553 | return PCI_ERS_RESULT_NEED_RESET; |
| 13554 | case pci_channel_io_perm_failure: |
| 13555 | /* Permanent failure, prepare for device down */ |
| 13556 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 13557 | return PCI_ERS_RESULT_DISCONNECT; |
| 13558 | default: |
| 13559 | /* Unknown state, prepare and request slot reset */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13560 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13561 | "2825 Unknown PCI error state: x%x\n", state); |
| 13562 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13563 | return PCI_ERS_RESULT_NEED_RESET; |
| 13564 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13565 | } |
| 13566 | |
| 13567 | /** |
| 13568 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 13569 | * @pdev: pointer to PCI device. |
| 13570 | * |
| 13571 | * This routine is called from the PCI subsystem for error handling to device |
| 13572 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 13573 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 13574 | * PCI subsystem error recovery, after the driver returns |
| 13575 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 13576 | * recovery and then call this routine before calling the .resume method to |
| 13577 | * recover the device. This function will initialize the HBA device, enable |
| 13578 | * the interrupt, but it will just put the HBA to offline state without |
| 13579 | * passing any I/O traffic. |
| 13580 | * |
| 13581 | * Return codes |
| 13582 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13583 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13584 | */ |
| 13585 | static pci_ers_result_t |
| 13586 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 13587 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13588 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13589 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13590 | struct lpfc_sli *psli = &phba->sli; |
| 13591 | uint32_t intr_mode; |
| 13592 | |
| 13593 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 13594 | if (pci_enable_device_mem(pdev)) { |
| 13595 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 13596 | "PCI device after reset.\n"); |
| 13597 | return PCI_ERS_RESULT_DISCONNECT; |
| 13598 | } |
| 13599 | |
| 13600 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 13601 | |
| 13602 | /* |
| 13603 | * As the new kernel behavior of pci_restore_state() API call clears |
| 13604 | * device saved_state flag, need to save the restored state again. |
| 13605 | */ |
| 13606 | pci_save_state(pdev); |
| 13607 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13608 | if (pdev->is_busmaster) |
| 13609 | pci_set_master(pdev); |
| 13610 | |
| 13611 | spin_lock_irq(&phba->hbalock); |
| 13612 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 13613 | spin_unlock_irq(&phba->hbalock); |
| 13614 | |
| 13615 | /* Configure and enable interrupt */ |
| 13616 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13617 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13618 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13619 | "2824 Cannot re-enable interrupt after " |
| 13620 | "slot reset.\n"); |
| 13621 | return PCI_ERS_RESULT_DISCONNECT; |
| 13622 | } else |
| 13623 | phba->intr_mode = intr_mode; |
| 13624 | |
| 13625 | /* Log the current active interrupt mode */ |
| 13626 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13627 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13628 | return PCI_ERS_RESULT_RECOVERED; |
| 13629 | } |
| 13630 | |
| 13631 | /** |
| 13632 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 13633 | * @pdev: pointer to PCI device |
| 13634 | * |
| 13635 | * This routine is called from the PCI subsystem for error handling to device |
| 13636 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 13637 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 13638 | * error recovery. After this call, traffic can start to flow from this device |
| 13639 | * again. |
| 13640 | **/ |
| 13641 | static void |
| 13642 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 13643 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13644 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13645 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13646 | |
| 13647 | /* |
| 13648 | * In case of slot reset, as function reset is performed through |
| 13649 | * mailbox command which needs DMA to be enabled, this operation |
| 13650 | * has to be moved to the io resume phase. Taking device offline |
| 13651 | * will perform the necessary cleanup. |
| 13652 | */ |
| 13653 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 13654 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13655 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13656 | lpfc_offline(phba); |
| 13657 | lpfc_sli_brdrestart(phba); |
| 13658 | /* Bring the device back online */ |
| 13659 | lpfc_online(phba); |
| 13660 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13661 | } |
| 13662 | |
| 13663 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13664 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 13665 | * @pdev: pointer to PCI device |
| 13666 | * @pid: pointer to PCI device identifier |
| 13667 | * |
| 13668 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13669 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 13670 | * at PCI device-specific information of the device and driver to see if the |
| 13671 | * driver state that it can support this kind of device. If the match is |
| 13672 | * successful, the driver core invokes this routine. This routine dispatches |
| 13673 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 13674 | * do all the initialization that it needs to do to handle the HBA device |
| 13675 | * properly. |
| 13676 | * |
| 13677 | * Return code |
| 13678 | * 0 - driver can claim the device |
| 13679 | * negative value - driver can not claim the device |
| 13680 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13681 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13682 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13683 | { |
| 13684 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13685 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13686 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13687 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13688 | return -ENODEV; |
| 13689 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13690 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13691 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13692 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13693 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13694 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13695 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13696 | return rc; |
| 13697 | } |
| 13698 | |
| 13699 | /** |
| 13700 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 13701 | * @pdev: pointer to PCI device |
| 13702 | * |
| 13703 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13704 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 13705 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 13706 | * remove routine, which will perform all the necessary cleanup for the |
| 13707 | * device to be removed from the PCI subsystem properly. |
| 13708 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13709 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13710 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 13711 | { |
| 13712 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13713 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13714 | |
| 13715 | switch (phba->pci_dev_grp) { |
| 13716 | case LPFC_PCI_DEV_LP: |
| 13717 | lpfc_pci_remove_one_s3(pdev); |
| 13718 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13719 | case LPFC_PCI_DEV_OC: |
| 13720 | lpfc_pci_remove_one_s4(pdev); |
| 13721 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13722 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13723 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13724 | "1424 Invalid PCI device group: 0x%x\n", |
| 13725 | phba->pci_dev_grp); |
| 13726 | break; |
| 13727 | } |
| 13728 | return; |
| 13729 | } |
| 13730 | |
| 13731 | /** |
| 13732 | * 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] | 13733 | * @dev: pointer to device |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13734 | * |
| 13735 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13736 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13737 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 13738 | * suspend the device. |
| 13739 | * |
| 13740 | * Return code |
| 13741 | * 0 - driver suspended the device |
| 13742 | * Error otherwise |
| 13743 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13744 | static int __maybe_unused |
| 13745 | lpfc_pci_suspend_one(struct device *dev) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13746 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13747 | struct Scsi_Host *shost = dev_get_drvdata(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13748 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13749 | int rc = -ENODEV; |
| 13750 | |
| 13751 | switch (phba->pci_dev_grp) { |
| 13752 | case LPFC_PCI_DEV_LP: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13753 | rc = lpfc_pci_suspend_one_s3(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13754 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13755 | case LPFC_PCI_DEV_OC: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13756 | rc = lpfc_pci_suspend_one_s4(dev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13757 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13758 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13759 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13760 | "1425 Invalid PCI device group: 0x%x\n", |
| 13761 | phba->pci_dev_grp); |
| 13762 | break; |
| 13763 | } |
| 13764 | return rc; |
| 13765 | } |
| 13766 | |
| 13767 | /** |
| 13768 | * 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] | 13769 | * @dev: pointer to device |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13770 | * |
| 13771 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13772 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13773 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 13774 | * resume the device. |
| 13775 | * |
| 13776 | * Return code |
| 13777 | * 0 - driver suspended the device |
| 13778 | * Error otherwise |
| 13779 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13780 | static int __maybe_unused |
| 13781 | lpfc_pci_resume_one(struct device *dev) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13782 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13783 | struct Scsi_Host *shost = dev_get_drvdata(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13784 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13785 | int rc = -ENODEV; |
| 13786 | |
| 13787 | switch (phba->pci_dev_grp) { |
| 13788 | case LPFC_PCI_DEV_LP: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13789 | rc = lpfc_pci_resume_one_s3(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13790 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13791 | case LPFC_PCI_DEV_OC: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13792 | rc = lpfc_pci_resume_one_s4(dev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13793 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13794 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13795 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13796 | "1426 Invalid PCI device group: 0x%x\n", |
| 13797 | phba->pci_dev_grp); |
| 13798 | break; |
| 13799 | } |
| 13800 | return rc; |
| 13801 | } |
| 13802 | |
| 13803 | /** |
| 13804 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 13805 | * @pdev: pointer to PCI device. |
| 13806 | * @state: the current PCI connection state. |
| 13807 | * |
| 13808 | * This routine is registered to the PCI subsystem for error handling. This |
| 13809 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 13810 | * this device has been detected. When this routine is invoked, it dispatches |
| 13811 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 13812 | * routine, which will perform the proper error detected operation. |
| 13813 | * |
| 13814 | * Return codes |
| 13815 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13816 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13817 | **/ |
| 13818 | static pci_ers_result_t |
| 13819 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 13820 | { |
| 13821 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13822 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13823 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13824 | |
| 13825 | switch (phba->pci_dev_grp) { |
| 13826 | case LPFC_PCI_DEV_LP: |
| 13827 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 13828 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13829 | case LPFC_PCI_DEV_OC: |
| 13830 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 13831 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13832 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13833 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13834 | "1427 Invalid PCI device group: 0x%x\n", |
| 13835 | phba->pci_dev_grp); |
| 13836 | break; |
| 13837 | } |
| 13838 | return rc; |
| 13839 | } |
| 13840 | |
| 13841 | /** |
| 13842 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 13843 | * @pdev: pointer to PCI device. |
| 13844 | * |
| 13845 | * This routine is registered to the PCI subsystem for error handling. This |
| 13846 | * function is called after PCI bus has been reset to restart the PCI card |
| 13847 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 13848 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 13849 | * routine, which will perform the proper device reset. |
| 13850 | * |
| 13851 | * Return codes |
| 13852 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13853 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13854 | **/ |
| 13855 | static pci_ers_result_t |
| 13856 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 13857 | { |
| 13858 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13859 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13860 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13861 | |
| 13862 | switch (phba->pci_dev_grp) { |
| 13863 | case LPFC_PCI_DEV_LP: |
| 13864 | rc = lpfc_io_slot_reset_s3(pdev); |
| 13865 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13866 | case LPFC_PCI_DEV_OC: |
| 13867 | rc = lpfc_io_slot_reset_s4(pdev); |
| 13868 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13869 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13870 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13871 | "1428 Invalid PCI device group: 0x%x\n", |
| 13872 | phba->pci_dev_grp); |
| 13873 | break; |
| 13874 | } |
| 13875 | return rc; |
| 13876 | } |
| 13877 | |
| 13878 | /** |
| 13879 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 13880 | * @pdev: pointer to PCI device |
| 13881 | * |
| 13882 | * This routine is registered to the PCI subsystem for error handling. It |
| 13883 | * is called when kernel error recovery tells the lpfc driver that it is |
| 13884 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 13885 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 13886 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 13887 | **/ |
| 13888 | static void |
| 13889 | lpfc_io_resume(struct pci_dev *pdev) |
| 13890 | { |
| 13891 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13892 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13893 | |
| 13894 | switch (phba->pci_dev_grp) { |
| 13895 | case LPFC_PCI_DEV_LP: |
| 13896 | lpfc_io_resume_s3(pdev); |
| 13897 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13898 | case LPFC_PCI_DEV_OC: |
| 13899 | lpfc_io_resume_s4(pdev); |
| 13900 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13901 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13902 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13903 | "1429 Invalid PCI device group: 0x%x\n", |
| 13904 | phba->pci_dev_grp); |
| 13905 | break; |
| 13906 | } |
| 13907 | return; |
| 13908 | } |
| 13909 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13910 | /** |
| 13911 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 13912 | * @phba: pointer to lpfc hba data structure. |
| 13913 | * |
| 13914 | * This routine checks to see if OAS is supported for this adapter. If |
| 13915 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 13916 | * the enable oas flag is cleared and the pool created for OAS device data |
| 13917 | * is destroyed. |
| 13918 | * |
| 13919 | **/ |
YueHaibing | c709297 | 2019-04-17 23:05:54 +0800 | [diff] [blame] | 13920 | static void |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13921 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 13922 | { |
| 13923 | |
| 13924 | if (!phba->cfg_EnableXLane) |
| 13925 | return; |
| 13926 | |
| 13927 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 13928 | phba->cfg_fof = 1; |
| 13929 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 13930 | phba->cfg_fof = 0; |
Saurav Girepunje | c3e5aac | 2019-10-27 01:17:17 +0530 | [diff] [blame] | 13931 | mempool_destroy(phba->device_data_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13932 | phba->device_data_mem_pool = NULL; |
| 13933 | } |
| 13934 | |
| 13935 | return; |
| 13936 | } |
| 13937 | |
| 13938 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13939 | * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter |
| 13940 | * @phba: pointer to lpfc hba data structure. |
| 13941 | * |
| 13942 | * This routine checks to see if RAS is supported by the adapter. Check the |
| 13943 | * function through which RAS support enablement is to be done. |
| 13944 | **/ |
| 13945 | void |
| 13946 | lpfc_sli4_ras_init(struct lpfc_hba *phba) |
| 13947 | { |
| 13948 | switch (phba->pcidev->device) { |
| 13949 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 13950 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 13951 | phba->ras_fwlog.ras_hwsupport = true; |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 13952 | if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) && |
| 13953 | phba->cfg_ras_fwlog_buffsize) |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13954 | phba->ras_fwlog.ras_enabled = true; |
| 13955 | else |
| 13956 | phba->ras_fwlog.ras_enabled = false; |
| 13957 | break; |
| 13958 | default: |
| 13959 | phba->ras_fwlog.ras_hwsupport = false; |
| 13960 | } |
| 13961 | } |
| 13962 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13963 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13964 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 13965 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 13966 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 13967 | .error_detected = lpfc_io_error_detected, |
| 13968 | .slot_reset = lpfc_io_slot_reset, |
| 13969 | .resume = lpfc_io_resume, |
| 13970 | }; |
| 13971 | |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13972 | static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one, |
| 13973 | lpfc_pci_suspend_one, |
| 13974 | lpfc_pci_resume_one); |
| 13975 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13976 | static struct pci_driver lpfc_driver = { |
| 13977 | .name = LPFC_DRIVER_NAME, |
| 13978 | .id_table = lpfc_id_table, |
| 13979 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13980 | .remove = lpfc_pci_remove_one, |
Anton Blanchard | 85e8a23 | 2017-02-13 08:49:20 +1100 | [diff] [blame] | 13981 | .shutdown = lpfc_pci_remove_one, |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13982 | .driver.pm = &lpfc_pci_pm_ops_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13983 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13984 | }; |
| 13985 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13986 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 13987 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 13988 | }; |
| 13989 | |
| 13990 | static struct miscdevice lpfc_mgmt_dev = { |
| 13991 | .minor = MISC_DYNAMIC_MINOR, |
| 13992 | .name = "lpfcmgmt", |
| 13993 | .fops = &lpfc_mgmt_fop, |
| 13994 | }; |
| 13995 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13996 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 13997 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13998 | * |
| 13999 | * This routine is to be invoked when the lpfc module is loaded into the |
| 14000 | * kernel. The special kernel macro module_init() is used to indicate the |
| 14001 | * role of this routine to the kernel as lpfc module entry point. |
| 14002 | * |
| 14003 | * Return codes |
| 14004 | * 0 - successful |
| 14005 | * -ENOMEM - FC attach transport failed |
| 14006 | * all others - failed |
| 14007 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14008 | static int __init |
| 14009 | lpfc_init(void) |
| 14010 | { |
| 14011 | int error = 0; |
| 14012 | |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 14013 | pr_info(LPFC_MODULE_DESC "\n"); |
| 14014 | pr_info(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14015 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14016 | error = misc_register(&lpfc_mgmt_dev); |
| 14017 | if (error) |
| 14018 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 14019 | "misc_register returned with status %d", error); |
| 14020 | |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14021 | error = -ENOMEM; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 14022 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 14023 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14024 | lpfc_transport_template = |
| 14025 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 14026 | if (lpfc_transport_template == NULL) |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14027 | goto unregister; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 14028 | lpfc_vport_transport_template = |
| 14029 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 14030 | if (lpfc_vport_transport_template == NULL) { |
| 14031 | fc_release_transport(lpfc_transport_template); |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14032 | goto unregister; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 14033 | } |
James Smart | 840a470 | 2020-11-15 11:26:40 -0800 | [diff] [blame] | 14034 | lpfc_wqe_cmd_template(); |
James Smart | bd3061b | 2018-03-05 12:04:05 -0800 | [diff] [blame] | 14035 | lpfc_nvmet_cmd_template(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 14036 | |
| 14037 | /* Initialize in case vector mapping is needed */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14038 | lpfc_present_cpu = num_present_cpus(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 14039 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14040 | error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, |
| 14041 | "lpfc/sli4:online", |
| 14042 | lpfc_cpu_online, lpfc_cpu_offline); |
| 14043 | if (error < 0) |
| 14044 | goto cpuhp_failure; |
| 14045 | lpfc_cpuhp_state = error; |
| 14046 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14047 | error = pci_register_driver(&lpfc_driver); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14048 | if (error) |
| 14049 | goto unwind; |
| 14050 | |
| 14051 | return error; |
| 14052 | |
| 14053 | unwind: |
| 14054 | cpuhp_remove_multi_state(lpfc_cpuhp_state); |
| 14055 | cpuhp_failure: |
| 14056 | fc_release_transport(lpfc_transport_template); |
| 14057 | fc_release_transport(lpfc_vport_transport_template); |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14058 | unregister: |
| 14059 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14060 | |
| 14061 | return error; |
| 14062 | } |
| 14063 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14064 | void lpfc_dmp_dbg(struct lpfc_hba *phba) |
| 14065 | { |
| 14066 | unsigned int start_idx; |
| 14067 | unsigned int dbg_cnt; |
| 14068 | unsigned int temp_idx; |
| 14069 | int i; |
| 14070 | int j = 0; |
| 14071 | unsigned long rem_nsec; |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 14072 | struct lpfc_vport **vports; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14073 | |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 14074 | /* Don't dump messages if we explicitly set log_verbose for the |
| 14075 | * physical port or any vport. |
| 14076 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14077 | if (phba->cfg_log_verbose) |
| 14078 | return; |
| 14079 | |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 14080 | vports = lpfc_create_vport_work_array(phba); |
| 14081 | if (vports != NULL) { |
| 14082 | for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
| 14083 | if (vports[i]->cfg_log_verbose) { |
| 14084 | lpfc_destroy_vport_work_array(phba, vports); |
| 14085 | return; |
| 14086 | } |
| 14087 | } |
| 14088 | } |
| 14089 | lpfc_destroy_vport_work_array(phba, vports); |
| 14090 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14091 | if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0) |
| 14092 | return; |
| 14093 | |
| 14094 | start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ; |
| 14095 | dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt); |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 14096 | if (!dbg_cnt) |
| 14097 | goto out; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14098 | temp_idx = start_idx; |
| 14099 | if (dbg_cnt >= DBG_LOG_SZ) { |
| 14100 | dbg_cnt = DBG_LOG_SZ; |
| 14101 | temp_idx -= 1; |
| 14102 | } else { |
| 14103 | if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) { |
| 14104 | temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ; |
| 14105 | } else { |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 14106 | if (start_idx < dbg_cnt) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14107 | start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx); |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 14108 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14109 | start_idx -= dbg_cnt; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14110 | } |
| 14111 | } |
| 14112 | dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n", |
| 14113 | start_idx, temp_idx, dbg_cnt); |
| 14114 | |
| 14115 | for (i = 0; i < dbg_cnt; i++) { |
| 14116 | if ((start_idx + i) < DBG_LOG_SZ) |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 14117 | temp_idx = (start_idx + i) % DBG_LOG_SZ; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14118 | else |
| 14119 | temp_idx = j++; |
| 14120 | rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC); |
| 14121 | dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s", |
| 14122 | temp_idx, |
| 14123 | (unsigned long)phba->dbg_log[temp_idx].t_ns, |
| 14124 | rem_nsec / 1000, |
| 14125 | phba->dbg_log[temp_idx].log); |
| 14126 | } |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 14127 | out: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14128 | atomic_set(&phba->dbg_log_cnt, 0); |
| 14129 | atomic_set(&phba->dbg_log_dmping, 0); |
| 14130 | } |
| 14131 | |
Lee Jones | 7fa03c7 | 2020-07-23 13:24:21 +0100 | [diff] [blame] | 14132 | __printf(2, 3) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14133 | void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...) |
| 14134 | { |
| 14135 | unsigned int idx; |
| 14136 | va_list args; |
| 14137 | int dbg_dmping = atomic_read(&phba->dbg_log_dmping); |
| 14138 | struct va_format vaf; |
| 14139 | |
| 14140 | |
| 14141 | va_start(args, fmt); |
| 14142 | if (unlikely(dbg_dmping)) { |
| 14143 | vaf.fmt = fmt; |
| 14144 | vaf.va = &args; |
| 14145 | dev_info(&phba->pcidev->dev, "%pV", &vaf); |
| 14146 | va_end(args); |
| 14147 | return; |
| 14148 | } |
| 14149 | idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) % |
| 14150 | DBG_LOG_SZ; |
| 14151 | |
| 14152 | atomic_inc(&phba->dbg_log_cnt); |
| 14153 | |
| 14154 | vscnprintf(phba->dbg_log[idx].log, |
| 14155 | sizeof(phba->dbg_log[idx].log), fmt, args); |
| 14156 | va_end(args); |
| 14157 | |
| 14158 | phba->dbg_log[idx].t_ns = local_clock(); |
| 14159 | } |
| 14160 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14161 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 14162 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14163 | * |
| 14164 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 14165 | * The special kernel macro module_exit() is used to indicate the role of |
| 14166 | * this routine to the kernel as lpfc module exit point. |
| 14167 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14168 | static void __exit |
| 14169 | lpfc_exit(void) |
| 14170 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14171 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14172 | pci_unregister_driver(&lpfc_driver); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14173 | cpuhp_remove_multi_state(lpfc_cpuhp_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14174 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 14175 | fc_release_transport(lpfc_vport_transport_template); |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 14176 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14177 | } |
| 14178 | |
| 14179 | module_init(lpfc_init); |
| 14180 | module_exit(lpfc_exit); |
| 14181 | MODULE_LICENSE("GPL"); |
| 14182 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 14183 | MODULE_AUTHOR("Broadcom"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14184 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |