| 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 *); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 96 | static int lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 97 | |
| 98 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 99 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 100 | static DEFINE_IDR(lpfc_hba_index); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 101 | #define LPFC_NVMET_BUF_POST 254 |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 102 | static int lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 105 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 106 | * @phba: pointer to lpfc hba data structure. |
| 107 | * |
| 108 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 109 | * mailbox command. It retrieves the revision information from the HBA and |
| 110 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 111 | * configuration of the HBA. |
| 112 | * |
| 113 | * Return codes: |
| 114 | * 0 - success. |
| 115 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 116 | * Any other value - indicates an error. |
| 117 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 119 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 120 | { |
| 121 | lpfc_vpd_t *vp = &phba->vpd; |
| 122 | int i = 0, rc; |
| 123 | LPFC_MBOXQ_t *pmb; |
| 124 | MAILBOX_t *mb; |
| 125 | char *lpfc_vpd_data = NULL; |
| 126 | uint16_t offset = 0; |
| 127 | static char licensed[56] = |
| 128 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 129 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 130 | |
| 131 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 132 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 133 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 134 | return -ENOMEM; |
| 135 | } |
| 136 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 137 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 138 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 139 | |
| 140 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 141 | if (init_key) { |
| 142 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 143 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 144 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 145 | *ptext = cpu_to_be32(*ptext); |
| 146 | init_key = 0; |
| 147 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 148 | |
| 149 | lpfc_read_nv(phba, pmb); |
| 150 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 151 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 152 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 153 | sizeof (licensed)); |
| 154 | |
| 155 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 156 | |
| 157 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 158 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 159 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | "error, mbxCmd x%x READ_NVPARM, " |
| 161 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 162 | mb->mbxCommand, mb->mbxStatus); |
| 163 | mempool_free(pmb, phba->mbox_mem_pool); |
| 164 | return -ERESTART; |
| 165 | } |
| 166 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 167 | sizeof(phba->wwnn)); |
| 168 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 169 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 170 | } |
| 171 | |
Martin Wilck | dfb7513 | 2018-11-12 09:58:37 +0100 | [diff] [blame] | 172 | /* |
| 173 | * Clear all option bits except LPFC_SLI3_BG_ENABLED, |
| 174 | * which was already set in lpfc_get_cfgparam() |
| 175 | */ |
| 176 | phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 177 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 178 | /* Setup and issue mailbox READ REV command */ |
| 179 | lpfc_read_rev(phba, pmb); |
| 180 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 181 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 182 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 183 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 184 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 185 | mb->mbxCommand, mb->mbxStatus); |
| 186 | mempool_free( pmb, phba->mbox_mem_pool); |
| 187 | return -ERESTART; |
| 188 | } |
| 189 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 190 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 191 | /* |
| 192 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 193 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 194 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 195 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 196 | vp->rev.rBit = 0; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 197 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 198 | "0440 Adapter failed to init, READ_REV has " |
| 199 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 200 | mempool_free(pmb, phba->mbox_mem_pool); |
| 201 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 202 | } |
| 203 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 204 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 205 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 206 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 207 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 208 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 209 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 210 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 211 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 212 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 213 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 214 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 215 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 216 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 217 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 218 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 219 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 220 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 221 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 222 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 223 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 224 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 225 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 226 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 227 | /* If the sli feature level is less then 9, we must |
| 228 | * tear down all RPIs and VPIs on link down if NPIV |
| 229 | * is enabled. |
| 230 | */ |
| 231 | if (vp->rev.feaLevelHigh < 9) |
| 232 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 233 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 234 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 235 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 236 | sizeof (phba->RandomData)); |
| 237 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 238 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 239 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 240 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 241 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 242 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 243 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 244 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 245 | |
| 246 | if (rc != MBX_SUCCESS) { |
| 247 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 248 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 249 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 250 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 251 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 252 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 253 | /* dump mem may return a zero when finished or we got a |
| 254 | * mailbox error, either way we are done. |
| 255 | */ |
| 256 | if (mb->un.varDmp.word_cnt == 0) |
| 257 | break; |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 258 | |
James Smart | e4ec102 | 2021-04-21 16:45:11 -0700 | [diff] [blame] | 259 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 260 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 261 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
James Smart | e4ec102 | 2021-04-21 16:45:11 -0700 | [diff] [blame] | 262 | lpfc_vpd_data + offset, |
| 263 | mb->un.varDmp.word_cnt); |
| 264 | offset += mb->un.varDmp.word_cnt; |
| 265 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 266 | |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 267 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 268 | |
| 269 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 270 | out_free_mbox: |
| 271 | mempool_free(pmb, phba->mbox_mem_pool); |
| 272 | return 0; |
| 273 | } |
| 274 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 275 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 276 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 277 | * @phba: pointer to lpfc hba data structure. |
| 278 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 279 | * |
| 280 | * This is the completion handler for driver's configuring asynchronous event |
| 281 | * mailbox command to the device. If the mailbox command returns successfully, |
| 282 | * it will set internal async event support flag to 1; otherwise, it will |
| 283 | * set internal async event support flag to 0. |
| 284 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 285 | static void |
| 286 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 287 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 288 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 289 | phba->temp_sensor_support = 1; |
| 290 | else |
| 291 | phba->temp_sensor_support = 0; |
| 292 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 293 | return; |
| 294 | } |
| 295 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 296 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 297 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 298 | * @phba: pointer to lpfc hba data structure. |
| 299 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 300 | * |
| 301 | * This is the completion handler for dump mailbox command for getting |
| 302 | * wake up parameters. When this command complete, the response contain |
| 303 | * Option rom version of the HBA. This function translate the version number |
| 304 | * into a human readable string and store it in OptionROMVersion. |
| 305 | **/ |
| 306 | static void |
| 307 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 308 | { |
| 309 | struct prog_id *prg; |
| 310 | uint32_t prog_id_word; |
| 311 | char dist = ' '; |
| 312 | /* character array used for decoding dist type. */ |
| 313 | char dist_char[] = "nabx"; |
| 314 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 315 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 316 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 317 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 318 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 319 | |
| 320 | prg = (struct prog_id *) &prog_id_word; |
| 321 | |
| 322 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 323 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 324 | |
| 325 | /* Decode the Option rom version word to a readable string */ |
| 326 | if (prg->dist < 4) |
| 327 | dist = dist_char[prg->dist]; |
| 328 | |
| 329 | if ((prg->dist == 3) && (prg->num == 0)) |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 330 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 331 | prg->ver, prg->rev, prg->lev); |
| 332 | else |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 333 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 334 | prg->ver, prg->rev, prg->lev, |
| 335 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 336 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 337 | return; |
| 338 | } |
| 339 | |
| 340 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 341 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 342 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 343 | * @vport: pointer to lpfc vport data structure. |
| 344 | * |
| 345 | * |
| 346 | * Return codes |
| 347 | * None. |
| 348 | **/ |
| 349 | void |
| 350 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 351 | { |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 352 | uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level; |
| 353 | u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0]; |
| 354 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 355 | /* If the soft name exists then update it using the service params */ |
| 356 | if (vport->phba->cfg_soft_wwnn) |
| 357 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 358 | vport->fc_sparam.nodeName.u.wwn); |
| 359 | if (vport->phba->cfg_soft_wwpn) |
| 360 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 361 | vport->fc_sparam.portName.u.wwn); |
| 362 | |
| 363 | /* |
| 364 | * If the name is empty or there exists a soft name |
| 365 | * then copy the service params name, otherwise use the fc name |
| 366 | */ |
| 367 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 368 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 369 | sizeof(struct lpfc_name)); |
| 370 | else |
| 371 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 372 | sizeof(struct lpfc_name)); |
| 373 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 374 | /* |
| 375 | * If the port name has changed, then set the Param changes flag |
| 376 | * to unreg the login |
| 377 | */ |
| 378 | if (vport->fc_portname.u.wwn[0] != 0 && |
| 379 | memcmp(&vport->fc_portname, &vport->fc_sparam.portName, |
| 380 | sizeof(struct lpfc_name))) |
| 381 | vport->vport_flag |= FAWWPN_PARAM_CHG; |
| 382 | |
| 383 | if (vport->fc_portname.u.wwn[0] == 0 || |
| 384 | vport->phba->cfg_soft_wwpn || |
| 385 | (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) || |
| 386 | vport->vport_flag & FAWWPN_SET) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 387 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 388 | sizeof(struct lpfc_name)); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 389 | vport->vport_flag &= ~FAWWPN_SET; |
| 390 | if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) |
| 391 | vport->vport_flag |= FAWWPN_SET; |
| 392 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 393 | else |
| 394 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 395 | sizeof(struct lpfc_name)); |
| 396 | } |
| 397 | |
| 398 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 399 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 400 | * @phba: pointer to lpfc hba data structure. |
| 401 | * |
| 402 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 403 | * command call. It performs all internal resource and state setups on the |
| 404 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 405 | * ELS ring timers, etc. |
| 406 | * |
| 407 | * Return codes |
| 408 | * 0 - success. |
| 409 | * Any other value - error. |
| 410 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 412 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 413 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 414 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 415 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 | LPFC_MBOXQ_t *pmb; |
| 417 | MAILBOX_t *mb; |
| 418 | struct lpfc_dmabuf *mp; |
| 419 | struct lpfc_sli *psli = &phba->sli; |
| 420 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 421 | int i, j; |
| 422 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 423 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 424 | spin_lock_irq(&phba->hbalock); |
| 425 | /* |
| 426 | * If the Config port completed correctly the HBA is not |
| 427 | * over heated any more. |
| 428 | */ |
| 429 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 430 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 431 | spin_unlock_irq(&phba->hbalock); |
| 432 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 433 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 434 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 435 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 436 | return -ENOMEM; |
| 437 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 438 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 439 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 440 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 441 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 442 | if (rc) { |
| 443 | mempool_free(pmb, phba->mbox_mem_pool); |
| 444 | return -ENOMEM; |
| 445 | } |
| 446 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 447 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 448 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 449 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 450 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 451 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 452 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 453 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 454 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 455 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 456 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 457 | kfree(mp); |
| 458 | return -EIO; |
| 459 | } |
| 460 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 461 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 462 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 463 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 464 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 465 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 466 | pmb->ctx_buf = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 467 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 468 | |
| 469 | /* Update the fc_host data structures with new wwn. */ |
| 470 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 471 | 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] | 472 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 473 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 474 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 475 | /* This should be consolidated into parse_vpd ? - mr */ |
| 476 | if (phba->SerialNumber[0] == 0) { |
| 477 | uint8_t *outptr; |
| 478 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 479 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 480 | for (i = 0; i < 12; i++) { |
| 481 | status = *outptr++; |
| 482 | j = ((status & 0xf0) >> 4); |
| 483 | if (j <= 9) |
| 484 | phba->SerialNumber[i] = |
| 485 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 486 | else |
| 487 | phba->SerialNumber[i] = |
| 488 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 489 | i++; |
| 490 | j = (status & 0xf); |
| 491 | if (j <= 9) |
| 492 | phba->SerialNumber[i] = |
| 493 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 494 | else |
| 495 | phba->SerialNumber[i] = |
| 496 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 497 | } |
| 498 | } |
| 499 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 500 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 501 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 502 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 503 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 504 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 505 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 507 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 508 | mempool_free( pmb, phba->mbox_mem_pool); |
| 509 | return -EIO; |
| 510 | } |
| 511 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 512 | /* Check if the port is disabled */ |
| 513 | lpfc_sli_read_link_ste(phba); |
| 514 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 515 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | f6770e7 | 2020-01-27 16:23:09 -0800 | [diff] [blame] | 516 | if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) { |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 517 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 518 | "3359 HBA queue depth changed from %d to %d\n", |
James Smart | f6770e7 | 2020-01-27 16:23:09 -0800 | [diff] [blame] | 519 | phba->cfg_hba_queue_depth, |
| 520 | mb->un.varRdConfig.max_xri); |
| 521 | phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri; |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 522 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 523 | |
| 524 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 525 | |
| 526 | /* Get the default values for Model Name and Description */ |
| 527 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 528 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 529 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 530 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 531 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 532 | if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr) |
| 533 | psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 534 | if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr) |
| 535 | psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 536 | |
| 537 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 538 | if (phba->sli_rev != 3) |
| 539 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 540 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 541 | /* |
| 542 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 543 | */ |
| 544 | if (phba->intr_type == MSIX) { |
| 545 | rc = lpfc_config_msi(phba, pmb); |
| 546 | if (rc) { |
| 547 | mempool_free(pmb, phba->mbox_mem_pool); |
| 548 | return -EIO; |
| 549 | } |
| 550 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 551 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 552 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 553 | "0352 Config MSI mailbox command " |
| 554 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 555 | pmb->u.mb.mbxCommand, |
| 556 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 557 | mempool_free(pmb, phba->mbox_mem_pool); |
| 558 | return -EIO; |
| 559 | } |
| 560 | } |
| 561 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 562 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 563 | /* Initialize ERATT handling flag */ |
| 564 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 565 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 566 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 567 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 568 | spin_unlock_irq(&phba->hbalock); |
| 569 | return -EIO; |
| 570 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 571 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 572 | if (psli->num_rings > 0) |
| 573 | status |= HC_R0INT_ENA; |
| 574 | if (psli->num_rings > 1) |
| 575 | status |= HC_R1INT_ENA; |
| 576 | if (psli->num_rings > 2) |
| 577 | status |= HC_R2INT_ENA; |
| 578 | if (psli->num_rings > 3) |
| 579 | status |= HC_R3INT_ENA; |
| 580 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 581 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 582 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 583 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 584 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 585 | writel(status, phba->HCregaddr); |
| 586 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 587 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 588 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 589 | /* Set up ring-0 (ELS) timer */ |
| 590 | timeout = phba->fc_ratov * 2; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 591 | mod_timer(&vport->els_tmofunc, |
| 592 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 593 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 594 | mod_timer(&phba->hb_tmofunc, |
| 595 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 596 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 597 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 598 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 599 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 600 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 601 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 602 | if (phba->hba_flag & LINK_DISABLED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 603 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 604 | "2598 Adapter Link is disabled.\n"); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 605 | lpfc_down_link(phba, pmb); |
| 606 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 607 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 608 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 609 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 610 | "2599 Adapter failed to issue DOWN_LINK" |
| 611 | " mbox command rc 0x%x\n", rc); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 612 | |
| 613 | mempool_free(pmb, phba->mbox_mem_pool); |
| 614 | return -EIO; |
| 615 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 616 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 617 | mempool_free(pmb, phba->mbox_mem_pool); |
| 618 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 619 | if (rc) |
| 620 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 621 | } |
| 622 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 623 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 624 | if (!pmb) { |
| 625 | phba->link_state = LPFC_HBA_ERROR; |
| 626 | return -ENOMEM; |
| 627 | } |
| 628 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 629 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 630 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 631 | pmb->vport = phba->pport; |
| 632 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 633 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 634 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 635 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 636 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 637 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 638 | rc); |
| 639 | mempool_free(pmb, phba->mbox_mem_pool); |
| 640 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 641 | |
| 642 | /* Get Option rom version */ |
| 643 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 644 | if (!pmb) { |
| 645 | phba->link_state = LPFC_HBA_ERROR; |
| 646 | return -ENOMEM; |
| 647 | } |
| 648 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 649 | lpfc_dump_wakeup_param(phba, pmb); |
| 650 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 651 | pmb->vport = phba->pport; |
| 652 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 653 | |
| 654 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 655 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 656 | "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 657 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 658 | mempool_free(pmb, phba->mbox_mem_pool); |
| 659 | } |
| 660 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 661 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 662 | } |
| 663 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 664 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 665 | * lpfc_hba_init_link - Initialize the FC link |
| 666 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 667 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 668 | * |
| 669 | * This routine will issue the INIT_LINK mailbox command call. |
| 670 | * It is available to other drivers through the lpfc_hba data |
| 671 | * structure for use as a delayed link up mechanism with the |
| 672 | * module parameter lpfc_suppress_link_up. |
| 673 | * |
| 674 | * Return code |
| 675 | * 0 - success |
| 676 | * Any other value - error |
| 677 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 678 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 679 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 680 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 681 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 686 | * @phba: pointer to lpfc hba data structure. |
| 687 | * @fc_topology: desired fc topology. |
| 688 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 689 | * |
| 690 | * This routine will issue the INIT_LINK mailbox command call. |
| 691 | * It is available to other drivers through the lpfc_hba data |
| 692 | * structure for use as a delayed link up mechanism with the |
| 693 | * module parameter lpfc_suppress_link_up. |
| 694 | * |
| 695 | * Return code |
| 696 | * 0 - success |
| 697 | * Any other value - error |
| 698 | **/ |
| 699 | int |
| 700 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 701 | uint32_t flag) |
| 702 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 703 | struct lpfc_vport *vport = phba->pport; |
| 704 | LPFC_MBOXQ_t *pmb; |
| 705 | MAILBOX_t *mb; |
| 706 | int rc; |
| 707 | |
| 708 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 709 | if (!pmb) { |
| 710 | phba->link_state = LPFC_HBA_ERROR; |
| 711 | return -ENOMEM; |
| 712 | } |
| 713 | mb = &pmb->u.mb; |
| 714 | pmb->vport = vport; |
| 715 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 716 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 717 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 718 | !(phba->lmt & LMT_1Gb)) || |
| 719 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 720 | !(phba->lmt & LMT_2Gb)) || |
| 721 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 722 | !(phba->lmt & LMT_4Gb)) || |
| 723 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 724 | !(phba->lmt & LMT_8Gb)) || |
| 725 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 726 | !(phba->lmt & LMT_10Gb)) || |
| 727 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 728 | !(phba->lmt & LMT_16Gb)) || |
| 729 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) && |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 730 | !(phba->lmt & LMT_32Gb)) || |
| 731 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) && |
| 732 | !(phba->lmt & LMT_64Gb))) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 733 | /* Reset link speed to auto */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 734 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 735 | "1302 Invalid speed for this board:%d " |
| 736 | "Reset link speed to auto.\n", |
| 737 | phba->cfg_link_speed); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 738 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 739 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 740 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 741 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 742 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 743 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 744 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 745 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 746 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 747 | "0498 Adapter failed to init, mbxCmd x%x " |
| 748 | "INIT_LINK, mbxStatus x%x\n", |
| 749 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 750 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 751 | /* Clear all interrupt enable conditions */ |
| 752 | writel(0, phba->HCregaddr); |
| 753 | readl(phba->HCregaddr); /* flush */ |
| 754 | /* Clear all pending interrupts */ |
| 755 | writel(0xffffffff, phba->HAregaddr); |
| 756 | readl(phba->HAregaddr); /* flush */ |
| 757 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 758 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 759 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 760 | mempool_free(pmb, phba->mbox_mem_pool); |
| 761 | return -EIO; |
| 762 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 763 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 764 | if (flag == MBX_POLL) |
| 765 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | /** |
| 771 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 772 | * @phba: pointer to lpfc hba data structure. |
| 773 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 774 | * |
| 775 | * This routine will issue the DOWN_LINK mailbox command call. |
| 776 | * It is available to other drivers through the lpfc_hba data |
| 777 | * structure for use to stop the link. |
| 778 | * |
| 779 | * Return code |
| 780 | * 0 - success |
| 781 | * Any other value - error |
| 782 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 783 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 784 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 785 | { |
| 786 | LPFC_MBOXQ_t *pmb; |
| 787 | int rc; |
| 788 | |
| 789 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 790 | if (!pmb) { |
| 791 | phba->link_state = LPFC_HBA_ERROR; |
| 792 | return -ENOMEM; |
| 793 | } |
| 794 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 795 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 796 | "0491 Adapter Link is disabled.\n"); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 797 | lpfc_down_link(phba, pmb); |
| 798 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 799 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 800 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 801 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 802 | "2522 Adapter failed to issue DOWN_LINK" |
| 803 | " mbox command rc 0x%x\n", rc); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 804 | |
| 805 | mempool_free(pmb, phba->mbox_mem_pool); |
| 806 | return -EIO; |
| 807 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 808 | if (flag == MBX_POLL) |
| 809 | mempool_free(pmb, phba->mbox_mem_pool); |
| 810 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 815 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 816 | * @phba: pointer to lpfc HBA data structure. |
| 817 | * |
| 818 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 819 | * bringing down the SLI Layer. |
| 820 | * |
| 821 | * Return codes |
| 822 | * 0 - success. |
| 823 | * Any other value - error. |
| 824 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 825 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 826 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 827 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 828 | struct lpfc_vport **vports; |
| 829 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 830 | |
| 831 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 832 | /* Disable interrupts */ |
| 833 | writel(0, phba->HCregaddr); |
| 834 | readl(phba->HCregaddr); /* flush */ |
| 835 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 836 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 837 | if (phba->pport->load_flag & FC_UNLOADING) |
| 838 | lpfc_cleanup_discovery_resources(phba->pport); |
| 839 | else { |
| 840 | vports = lpfc_create_vport_work_array(phba); |
| 841 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 842 | for (i = 0; i <= phba->max_vports && |
| 843 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 844 | lpfc_cleanup_discovery_resources(vports[i]); |
| 845 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 846 | } |
| 847 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 848 | } |
| 849 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 850 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 851 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 852 | * rspiocb which got deferred |
| 853 | * |
| 854 | * @phba: pointer to lpfc HBA data structure. |
| 855 | * |
| 856 | * This routine will cleanup completed slow path events after HBA is reset |
| 857 | * when bringing down the SLI Layer. |
| 858 | * |
| 859 | * |
| 860 | * Return codes |
| 861 | * void. |
| 862 | **/ |
| 863 | static void |
| 864 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 865 | { |
| 866 | struct lpfc_iocbq *rspiocbq; |
| 867 | struct hbq_dmabuf *dmabuf; |
| 868 | struct lpfc_cq_event *cq_event; |
| 869 | |
| 870 | spin_lock_irq(&phba->hbalock); |
| 871 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 872 | spin_unlock_irq(&phba->hbalock); |
| 873 | |
| 874 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 875 | /* Get the response iocb from the head of work queue */ |
| 876 | spin_lock_irq(&phba->hbalock); |
| 877 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 878 | cq_event, struct lpfc_cq_event, list); |
| 879 | spin_unlock_irq(&phba->hbalock); |
| 880 | |
| 881 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 882 | case CQE_CODE_COMPL_WQE: |
| 883 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 884 | cq_event); |
| 885 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 886 | break; |
| 887 | case CQE_CODE_RECEIVE: |
| 888 | case CQE_CODE_RECEIVE_V1: |
| 889 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 890 | cq_event); |
| 891 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 892 | } |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 897 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 898 | * @phba: pointer to lpfc HBA data structure. |
| 899 | * |
| 900 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 901 | * when bringing down the SLI Layer. |
| 902 | * |
| 903 | * |
| 904 | * Return codes |
| 905 | * void. |
| 906 | **/ |
| 907 | static void |
| 908 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 909 | { |
| 910 | struct lpfc_sli *psli = &phba->sli; |
| 911 | struct lpfc_sli_ring *pring; |
| 912 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 913 | LIST_HEAD(buflist); |
| 914 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 915 | |
| 916 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 917 | lpfc_sli_hbqbuf_free_all(phba); |
| 918 | else { |
| 919 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 920 | pring = &psli->sli3_ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 921 | spin_lock_irq(&phba->hbalock); |
| 922 | list_splice_init(&pring->postbufq, &buflist); |
| 923 | spin_unlock_irq(&phba->hbalock); |
| 924 | |
| 925 | count = 0; |
| 926 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 927 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 928 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 929 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 930 | kfree(mp); |
| 931 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 932 | |
| 933 | spin_lock_irq(&phba->hbalock); |
| 934 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 935 | spin_unlock_irq(&phba->hbalock); |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | /** |
| 940 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 941 | * @phba: pointer to lpfc HBA data structure. |
| 942 | * |
| 943 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 944 | * down the SLI Layer. |
| 945 | * |
| 946 | * Return codes |
| 947 | * void |
| 948 | **/ |
| 949 | static void |
| 950 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 951 | { |
| 952 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 953 | struct lpfc_queue *qp = NULL; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 954 | struct lpfc_sli_ring *pring; |
| 955 | LIST_HEAD(completions); |
| 956 | int i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 957 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 958 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 959 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 960 | for (i = 0; i < psli->num_rings; i++) { |
| 961 | pring = &psli->sli3_ring[i]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 962 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 963 | /* At this point in time the HBA is either reset or DOA |
| 964 | * Nothing should be on txcmplq as it will |
| 965 | * NEVER complete. |
| 966 | */ |
| 967 | list_splice_init(&pring->txcmplq, &completions); |
| 968 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 969 | spin_unlock_irq(&phba->hbalock); |
| 970 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 971 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 972 | } |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 973 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 974 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 975 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
| 976 | return; |
| 977 | } |
| 978 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 979 | pring = qp->pring; |
| 980 | if (!pring) |
| 981 | continue; |
| 982 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 983 | list_for_each_entry_safe(piocb, next_iocb, |
| 984 | &pring->txcmplq, list) |
| 985 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 986 | list_splice_init(&pring->txcmplq, &completions); |
| 987 | pring->txcmplq_cnt = 0; |
| 988 | spin_unlock_irq(&pring->ring_lock); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 989 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 990 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 991 | /* Cancel all the IOCBs from the completions list */ |
| 992 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 993 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 997 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 998 | * @phba: pointer to lpfc HBA data structure. |
| 999 | * |
| 1000 | * This routine will do uninitialization after the HBA is reset when bring |
| 1001 | * down the SLI Layer. |
| 1002 | * |
| 1003 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1004 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1005 | * Any other value - error. |
| 1006 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1007 | static int |
| 1008 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1009 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1010 | lpfc_hba_free_post_buf(phba); |
| 1011 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1012 | return 0; |
| 1013 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 1014 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1015 | /** |
| 1016 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 1017 | * @phba: pointer to lpfc HBA data structure. |
| 1018 | * |
| 1019 | * This routine will do uninitialization after the HBA is reset when bring |
| 1020 | * down the SLI Layer. |
| 1021 | * |
| 1022 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1023 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1024 | * Any other value - error. |
| 1025 | **/ |
| 1026 | static int |
| 1027 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 1028 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1029 | struct lpfc_io_buf *psb, *psb_next; |
James Smart | 7cacae2 | 2020-03-31 09:50:03 -0700 | [diff] [blame] | 1030 | struct lpfc_async_xchg_ctx *ctxp, *ctxp_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1031 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1032 | LIST_HEAD(aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1033 | LIST_HEAD(nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1034 | LIST_HEAD(nvmet_aborts); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1035 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1036 | int cnt, idx; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1037 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1038 | |
| 1039 | lpfc_sli_hbqbuf_free_all(phba); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1040 | lpfc_hba_clean_txcmplq(phba); |
| 1041 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1042 | /* At this point in time the HBA is either reset or DOA. Either |
| 1043 | * 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] | 1044 | * 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] | 1045 | * driver is unloading or reposted if the driver is restarting |
| 1046 | * the port. |
| 1047 | */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1048 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1049 | /* sgl_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1050 | * list. |
| 1051 | */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1052 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1053 | list_for_each_entry(sglq_entry, |
| 1054 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1055 | sglq_entry->state = SGL_FREED; |
| 1056 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1057 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1058 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1059 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1060 | |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1061 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1062 | |
| 1063 | /* abts_xxxx_buf_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1064 | * list. |
| 1065 | */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 1066 | spin_lock_irq(&phba->hbalock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1067 | cnt = 0; |
| 1068 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 1069 | qp = &phba->sli4_hba.hdwq[idx]; |
| 1070 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1071 | spin_lock(&qp->abts_io_buf_list_lock); |
| 1072 | list_splice_init(&qp->lpfc_abts_io_buf_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1073 | &aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1074 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 1075 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1076 | psb->pCmd = NULL; |
| 1077 | psb->status = IOSTAT_SUCCESS; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1078 | cnt++; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1079 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1080 | spin_lock(&qp->io_buf_list_put_lock); |
| 1081 | list_splice_init(&aborts, &qp->lpfc_io_buf_list_put); |
| 1082 | qp->put_io_bufs += qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1083 | qp->put_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1084 | qp->abts_scsi_io_bufs = 0; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1085 | qp->abts_nvme_io_bufs = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1086 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1087 | spin_unlock(&qp->abts_io_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1088 | } |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1089 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1090 | |
| 1091 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1092 | spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1093 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list, |
| 1094 | &nvmet_aborts); |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1095 | spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1096 | list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) { |
James Smart | 7b7f551 | 2020-03-31 09:50:04 -0700 | [diff] [blame] | 1097 | ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 1098 | lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1099 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1100 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1101 | |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1102 | lpfc_sli4_free_sp_events(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1103 | return cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | /** |
| 1107 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1108 | * @phba: pointer to lpfc HBA data structure. |
| 1109 | * |
| 1110 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1111 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1112 | * |
| 1113 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1114 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1115 | * Any other value - error. |
| 1116 | **/ |
| 1117 | int |
| 1118 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1119 | { |
| 1120 | return (*phba->lpfc_hba_down_post)(phba); |
| 1121 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1122 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1123 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1124 | * lpfc_hb_timeout - The HBA-timer timeout handler |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1125 | * @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] | 1126 | * |
| 1127 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1128 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1129 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1130 | * event will be used by the worker thread to invoke the actual timeout |
| 1131 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1132 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1133 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1134 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1135 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1136 | lpfc_hb_timeout(struct timer_list *t) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1137 | { |
| 1138 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1139 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1140 | unsigned long iflag; |
| 1141 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1142 | phba = from_timer(phba, t, hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1143 | |
| 1144 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1145 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1146 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1147 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1148 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1149 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1150 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1151 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1152 | if (!tmo_posted) |
| 1153 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1154 | return; |
| 1155 | } |
| 1156 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1157 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1158 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1159 | * @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] | 1160 | * |
| 1161 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1162 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1163 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1164 | * event will be used by the worker thread to invoke the actual timeout |
| 1165 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1166 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1167 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1168 | **/ |
| 1169 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1170 | lpfc_rrq_timeout(struct timer_list *t) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1171 | { |
| 1172 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1173 | unsigned long iflag; |
| 1174 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1175 | phba = from_timer(phba, t, rrq_tmr); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1176 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1177 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1178 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1179 | else |
| 1180 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1181 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1182 | |
| 1183 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1184 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1188 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1189 | * @phba: pointer to lpfc hba data structure. |
| 1190 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1191 | * |
| 1192 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1193 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1194 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1195 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1196 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1197 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1198 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1199 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1200 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1201 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1202 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1203 | static void |
| 1204 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1205 | { |
| 1206 | unsigned long drvr_flag; |
| 1207 | |
| 1208 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1209 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1210 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1211 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1212 | /* Check and reset heart-beat timer if necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1213 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1214 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1215 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1216 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1217 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1218 | jiffies + |
| 1219 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1220 | return; |
| 1221 | } |
| 1222 | |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1223 | /* |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 1224 | * lpfc_idle_stat_delay_work - idle_stat tracking |
| 1225 | * |
| 1226 | * This routine tracks per-cq idle_stat and determines polling decisions. |
| 1227 | * |
| 1228 | * Return codes: |
| 1229 | * None |
| 1230 | **/ |
| 1231 | static void |
| 1232 | lpfc_idle_stat_delay_work(struct work_struct *work) |
| 1233 | { |
| 1234 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1235 | struct lpfc_hba, |
| 1236 | idle_stat_delay_work); |
| 1237 | struct lpfc_queue *cq; |
| 1238 | struct lpfc_sli4_hdw_queue *hdwq; |
| 1239 | struct lpfc_idle_stat *idle_stat; |
| 1240 | u32 i, idle_percent; |
| 1241 | u64 wall, wall_idle, diff_wall, diff_idle, busy_time; |
| 1242 | |
| 1243 | if (phba->pport->load_flag & FC_UNLOADING) |
| 1244 | return; |
| 1245 | |
| 1246 | if (phba->link_state == LPFC_HBA_ERROR || |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 1247 | phba->pport->fc_flag & FC_OFFLINE_MODE || |
| 1248 | phba->cmf_active_mode != LPFC_CFG_OFF) |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 1249 | goto requeue; |
| 1250 | |
| 1251 | for_each_present_cpu(i) { |
| 1252 | hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq]; |
| 1253 | cq = hdwq->io_cq; |
| 1254 | |
| 1255 | /* Skip if we've already handled this cq's primary CPU */ |
| 1256 | if (cq->chann != i) |
| 1257 | continue; |
| 1258 | |
| 1259 | idle_stat = &phba->sli4_hba.idle_stat[i]; |
| 1260 | |
| 1261 | /* get_cpu_idle_time returns values as running counters. Thus, |
| 1262 | * to know the amount for this period, the prior counter values |
| 1263 | * need to be subtracted from the current counter values. |
| 1264 | * From there, the idle time stat can be calculated as a |
| 1265 | * percentage of 100 - the sum of the other consumption times. |
| 1266 | */ |
| 1267 | wall_idle = get_cpu_idle_time(i, &wall, 1); |
| 1268 | diff_idle = wall_idle - idle_stat->prev_idle; |
| 1269 | diff_wall = wall - idle_stat->prev_wall; |
| 1270 | |
| 1271 | if (diff_wall <= diff_idle) |
| 1272 | busy_time = 0; |
| 1273 | else |
| 1274 | busy_time = diff_wall - diff_idle; |
| 1275 | |
| 1276 | idle_percent = div64_u64(100 * busy_time, diff_wall); |
| 1277 | idle_percent = 100 - idle_percent; |
| 1278 | |
| 1279 | if (idle_percent < 15) |
| 1280 | cq->poll_mode = LPFC_QUEUE_WORK; |
| 1281 | else |
| 1282 | cq->poll_mode = LPFC_IRQ_POLL; |
| 1283 | |
| 1284 | idle_stat->prev_idle = wall_idle; |
| 1285 | idle_stat->prev_wall = wall; |
| 1286 | } |
| 1287 | |
| 1288 | requeue: |
| 1289 | schedule_delayed_work(&phba->idle_stat_delay_work, |
| 1290 | msecs_to_jiffies(LPFC_IDLE_STAT_DELAY)); |
| 1291 | } |
| 1292 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1293 | static void |
| 1294 | lpfc_hb_eq_delay_work(struct work_struct *work) |
| 1295 | { |
| 1296 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1297 | struct lpfc_hba, eq_delay_work); |
| 1298 | struct lpfc_eq_intr_info *eqi, *eqi_new; |
| 1299 | struct lpfc_queue *eq, *eq_next; |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1300 | unsigned char *ena_delay = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1301 | uint32_t usdelay; |
| 1302 | int i; |
| 1303 | |
| 1304 | if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING) |
| 1305 | return; |
| 1306 | |
| 1307 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1308 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1309 | goto requeue; |
| 1310 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1311 | ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay), |
| 1312 | GFP_KERNEL); |
| 1313 | if (!ena_delay) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1314 | goto requeue; |
| 1315 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1316 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 1317 | /* Get the EQ corresponding to the IRQ vector */ |
| 1318 | eq = phba->sli4_hba.hba_eq_hdl[i].eq; |
| 1319 | if (!eq) |
| 1320 | continue; |
| 1321 | if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) { |
| 1322 | eq->q_flag &= ~HBA_EQ_DELAY_CHK; |
| 1323 | ena_delay[eq->last_cpu] = 1; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame] | 1324 | } |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1325 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1326 | |
| 1327 | for_each_present_cpu(i) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1328 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i); |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1329 | if (ena_delay[i]) { |
| 1330 | usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP; |
| 1331 | if (usdelay > LPFC_MAX_AUTO_EQ_DELAY) |
| 1332 | usdelay = LPFC_MAX_AUTO_EQ_DELAY; |
| 1333 | } else { |
| 1334 | usdelay = 0; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame] | 1335 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1336 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1337 | eqi->icnt = 0; |
| 1338 | |
| 1339 | list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) { |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1340 | if (unlikely(eq->last_cpu != i)) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1341 | eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info, |
| 1342 | eq->last_cpu); |
| 1343 | list_move_tail(&eq->cpu_list, &eqi_new->list); |
| 1344 | continue; |
| 1345 | } |
| 1346 | if (usdelay != eq->q_mode) |
| 1347 | lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1, |
| 1348 | usdelay); |
| 1349 | } |
| 1350 | } |
| 1351 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1352 | kfree(ena_delay); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1353 | |
| 1354 | requeue: |
| 1355 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 1356 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 1357 | } |
| 1358 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1359 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1360 | * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution |
| 1361 | * @phba: pointer to lpfc hba data structure. |
| 1362 | * |
| 1363 | * For each heartbeat, this routine does some heuristic methods to adjust |
| 1364 | * XRI distribution. The goal is to fully utilize free XRIs. |
| 1365 | **/ |
| 1366 | static void lpfc_hb_mxp_handler(struct lpfc_hba *phba) |
| 1367 | { |
| 1368 | u32 i; |
| 1369 | u32 hwq_count; |
| 1370 | |
| 1371 | hwq_count = phba->cfg_hdw_queue; |
| 1372 | for (i = 0; i < hwq_count; i++) { |
| 1373 | /* Adjust XRIs in private pool */ |
| 1374 | lpfc_adjust_pvt_pool_count(phba, i); |
| 1375 | |
| 1376 | /* Adjust high watermark */ |
| 1377 | lpfc_adjust_high_watermark(phba, i); |
| 1378 | |
| 1379 | #ifdef LPFC_MXP_STAT |
| 1380 | /* Snapshot pbl, pvt and busy count */ |
| 1381 | lpfc_snapshot_mxp(phba, i); |
| 1382 | #endif |
| 1383 | } |
| 1384 | } |
| 1385 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1386 | /** |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1387 | * lpfc_issue_hb_mbox - Issues heart-beat mailbox command |
| 1388 | * @phba: pointer to lpfc hba data structure. |
| 1389 | * |
| 1390 | * If a HB mbox is not already in progrees, this routine will allocate |
| 1391 | * a LPFC_MBOXQ_t, populate it with a MBX_HEARTBEAT (0x31) command, |
| 1392 | * and issue it. The HBA_HBEAT_INP flag means the command is in progress. |
| 1393 | **/ |
| 1394 | int |
| 1395 | lpfc_issue_hb_mbox(struct lpfc_hba *phba) |
| 1396 | { |
| 1397 | LPFC_MBOXQ_t *pmboxq; |
| 1398 | int retval; |
| 1399 | |
| 1400 | /* Is a Heartbeat mbox already in progress */ |
| 1401 | if (phba->hba_flag & HBA_HBEAT_INP) |
| 1402 | return 0; |
| 1403 | |
| 1404 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 1405 | if (!pmboxq) |
| 1406 | return -ENOMEM; |
| 1407 | |
| 1408 | lpfc_heart_beat(phba, pmboxq); |
| 1409 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1410 | pmboxq->vport = phba->pport; |
| 1411 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 1412 | |
| 1413 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { |
| 1414 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1415 | return -ENXIO; |
| 1416 | } |
| 1417 | phba->hba_flag |= HBA_HBEAT_INP; |
| 1418 | |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
| 1422 | /** |
| 1423 | * lpfc_issue_hb_tmo - Signals heartbeat timer to issue mbox command |
| 1424 | * @phba: pointer to lpfc hba data structure. |
| 1425 | * |
| 1426 | * The heartbeat timer (every 5 sec) will fire. If the HBA_HBEAT_TMO |
| 1427 | * flag is set, it will force a MBX_HEARTBEAT mbox command, regardless |
| 1428 | * of the value of lpfc_enable_hba_heartbeat. |
| 1429 | * If lpfc_enable_hba_heartbeat is set, the timeout routine will always |
| 1430 | * try to issue a MBX_HEARTBEAT mbox command. |
| 1431 | **/ |
| 1432 | void |
| 1433 | lpfc_issue_hb_tmo(struct lpfc_hba *phba) |
| 1434 | { |
| 1435 | if (phba->cfg_enable_hba_heartbeat) |
| 1436 | return; |
| 1437 | phba->hba_flag |= HBA_HBEAT_TMO; |
| 1438 | } |
| 1439 | |
| 1440 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1441 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1442 | * @phba: pointer to lpfc hba data structure. |
| 1443 | * |
| 1444 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1445 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1446 | * handler performs any periodic operations needed for the device. If such |
| 1447 | * periodic event has already been attended to either in the interrupt handler |
| 1448 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1449 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1450 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1451 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1452 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1453 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1454 | * to offline. |
| 1455 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1456 | void |
| 1457 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1458 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1459 | struct lpfc_vport **vports; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1460 | struct lpfc_dmabuf *buf_ptr; |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1461 | int retval = 0; |
| 1462 | int i, tmo; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1463 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1464 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1465 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1466 | if (phba->cfg_xri_rebalancing) { |
| 1467 | /* Multi-XRI pools handler */ |
| 1468 | lpfc_hb_mxp_handler(phba); |
| 1469 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1470 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1471 | vports = lpfc_create_vport_work_array(phba); |
| 1472 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1473 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1474 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | e3ba04c | 2019-12-18 15:58:02 -0800 | [diff] [blame] | 1475 | lpfc_fdmi_change_check(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1476 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1477 | lpfc_destroy_vport_work_array(phba, vports); |
| 1478 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1479 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1480 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1481 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1482 | return; |
| 1483 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1484 | if (phba->elsbuf_cnt && |
| 1485 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1486 | spin_lock_irq(&phba->hbalock); |
| 1487 | list_splice_init(&phba->elsbuf, &completions); |
| 1488 | phba->elsbuf_cnt = 0; |
| 1489 | phba->elsbuf_prev_cnt = 0; |
| 1490 | spin_unlock_irq(&phba->hbalock); |
| 1491 | |
| 1492 | while (!list_empty(&completions)) { |
| 1493 | list_remove_head(&completions, buf_ptr, |
| 1494 | struct lpfc_dmabuf, list); |
| 1495 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1496 | kfree(buf_ptr); |
| 1497 | } |
| 1498 | } |
| 1499 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1500 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1501 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1502 | if (phba->cfg_enable_hba_heartbeat) { |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1503 | /* If IOs are completing, no need to issue a MBX_HEARTBEAT */ |
| 1504 | spin_lock_irq(&phba->pport->work_port_lock); |
| 1505 | if (time_after(phba->last_completion_time + |
| 1506 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1507 | jiffies)) { |
| 1508 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1509 | if (phba->hba_flag & HBA_HBEAT_INP) |
| 1510 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1511 | else |
| 1512 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
| 1513 | goto out; |
| 1514 | } |
| 1515 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1516 | |
| 1517 | /* Check if a MBX_HEARTBEAT is already in progress */ |
| 1518 | if (phba->hba_flag & HBA_HBEAT_INP) { |
| 1519 | /* |
| 1520 | * If heart beat timeout called with HBA_HBEAT_INP set |
| 1521 | * we need to give the hb mailbox cmd a chance to |
| 1522 | * complete or TMO. |
| 1523 | */ |
| 1524 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1525 | "0459 Adapter heartbeat still outstanding: " |
| 1526 | "last compl time was %d ms.\n", |
| 1527 | jiffies_to_msecs(jiffies |
| 1528 | - phba->last_completion_time)); |
| 1529 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1530 | } else { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1531 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1532 | (list_empty(&psli->mboxq))) { |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1533 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1534 | retval = lpfc_issue_hb_mbox(phba); |
| 1535 | if (retval) { |
| 1536 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
| 1537 | goto out; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1538 | } |
| 1539 | phba->skipped_hb = 0; |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1540 | } else if (time_before_eq(phba->last_completion_time, |
| 1541 | phba->skipped_hb)) { |
| 1542 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1543 | "2857 Last completion time not " |
| 1544 | " updated in %d ms\n", |
| 1545 | jiffies_to_msecs(jiffies |
| 1546 | - phba->last_completion_time)); |
| 1547 | } else |
| 1548 | phba->skipped_hb = jiffies; |
| 1549 | |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1550 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1551 | goto out; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1552 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1553 | } else { |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1554 | /* Check to see if we want to force a MBX_HEARTBEAT */ |
| 1555 | if (phba->hba_flag & HBA_HBEAT_TMO) { |
| 1556 | retval = lpfc_issue_hb_mbox(phba); |
| 1557 | if (retval) |
| 1558 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
| 1559 | else |
| 1560 | tmo = (1000 * LPFC_HB_MBOX_TIMEOUT); |
| 1561 | goto out; |
| 1562 | } |
| 1563 | tmo = (1000 * LPFC_HB_MBOX_INTERVAL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1564 | } |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 1565 | out: |
| 1566 | mod_timer(&phba->hb_tmofunc, jiffies + msecs_to_jiffies(tmo)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1567 | } |
| 1568 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1569 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1570 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1571 | * @phba: pointer to lpfc hba data structure. |
| 1572 | * |
| 1573 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1574 | * other than Port Error 6 has been detected. |
| 1575 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1576 | static void |
| 1577 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1578 | { |
| 1579 | struct lpfc_sli *psli = &phba->sli; |
| 1580 | |
| 1581 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1582 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1583 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1584 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1585 | |
| 1586 | lpfc_offline(phba); |
| 1587 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1588 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1589 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1590 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1591 | lpfc_hba_down_post(phba); |
| 1592 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1593 | lpfc_unblock_mgmt_io(phba); |
| 1594 | phba->link_state = LPFC_HBA_ERROR; |
| 1595 | return; |
| 1596 | } |
| 1597 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1598 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1599 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1600 | * @phba: pointer to lpfc hba data structure. |
| 1601 | * |
| 1602 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1603 | * other than Port Error 6 has been detected. |
| 1604 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1605 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1606 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1607 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1608 | spin_lock_irq(&phba->hbalock); |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 1609 | if (phba->link_state == LPFC_HBA_ERROR && |
| 1610 | phba->hba_flag & HBA_PCI_ERR) { |
| 1611 | spin_unlock_irq(&phba->hbalock); |
| 1612 | return; |
| 1613 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1614 | phba->link_state = LPFC_HBA_ERROR; |
| 1615 | spin_unlock_irq(&phba->hbalock); |
| 1616 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1617 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1618 | lpfc_sli_flush_io_rings(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1619 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1620 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1621 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1625 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1626 | * @phba: pointer to lpfc hba data structure. |
| 1627 | * |
| 1628 | * This routine is invoked to handle the deferred HBA hardware error |
| 1629 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1630 | * and another ER bit in the host status register. The driver will |
| 1631 | * wait until the ER1 bit clears before handling the error condition. |
| 1632 | **/ |
| 1633 | static void |
| 1634 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1635 | { |
| 1636 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1637 | struct lpfc_sli *psli = &phba->sli; |
| 1638 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1639 | /* If the pci channel is offline, ignore possible errors, |
| 1640 | * since we cannot communicate with the pci card anyway. |
| 1641 | */ |
| 1642 | if (pci_channel_offline(phba->pcidev)) { |
| 1643 | spin_lock_irq(&phba->hbalock); |
| 1644 | phba->hba_flag &= ~DEFER_ERATT; |
| 1645 | spin_unlock_irq(&phba->hbalock); |
| 1646 | return; |
| 1647 | } |
| 1648 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1649 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 1650 | "0479 Deferred Adapter Hardware Error " |
| 1651 | "Data: x%x x%x x%x\n", |
| 1652 | phba->work_hs, phba->work_status[0], |
| 1653 | phba->work_status[1]); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1654 | |
| 1655 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1656 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1657 | spin_unlock_irq(&phba->hbalock); |
| 1658 | |
| 1659 | |
| 1660 | /* |
| 1661 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1662 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1663 | * SCSI layer retry it after re-establishing link. |
| 1664 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1665 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1666 | |
| 1667 | /* |
| 1668 | * There was a firmware error. Take the hba offline and then |
| 1669 | * attempt to restart it. |
| 1670 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1671 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1672 | lpfc_offline(phba); |
| 1673 | |
| 1674 | /* Wait for the ER1 bit to clear.*/ |
| 1675 | while (phba->work_hs & HS_FFER1) { |
| 1676 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1677 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1678 | phba->work_hs = UNPLUG_ERR ; |
| 1679 | break; |
| 1680 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1681 | /* If driver is unloading let the worker thread continue */ |
| 1682 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1683 | phba->work_hs = 0; |
| 1684 | break; |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | /* |
| 1689 | * This is to ptrotect against a race condition in which |
| 1690 | * first write to the host attention register clear the |
| 1691 | * host status register. |
| 1692 | */ |
| 1693 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1694 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1695 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1696 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1697 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1698 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1699 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1700 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1701 | } |
| 1702 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1703 | static void |
| 1704 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1705 | { |
| 1706 | struct lpfc_board_event_header board_event; |
| 1707 | struct Scsi_Host *shost; |
| 1708 | |
| 1709 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1710 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1711 | shost = lpfc_shost_from_vport(phba->pport); |
| 1712 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1713 | sizeof(board_event), |
| 1714 | (char *) &board_event, |
| 1715 | LPFC_NL_VENDOR_ID); |
| 1716 | } |
| 1717 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1718 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1719 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1720 | * @phba: pointer to lpfc hba data structure. |
| 1721 | * |
| 1722 | * This routine is invoked to handle the following HBA hardware error |
| 1723 | * conditions: |
| 1724 | * 1 - HBA error attention interrupt |
| 1725 | * 2 - DMA ring index out of range |
| 1726 | * 3 - Mailbox command came back as unknown |
| 1727 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1728 | static void |
| 1729 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1730 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1731 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1732 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1733 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1734 | unsigned long temperature; |
| 1735 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1736 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1737 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1738 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1739 | * since we cannot communicate with the pci card anyway. |
| 1740 | */ |
| 1741 | if (pci_channel_offline(phba->pcidev)) { |
| 1742 | spin_lock_irq(&phba->hbalock); |
| 1743 | phba->hba_flag &= ~DEFER_ERATT; |
| 1744 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1745 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1746 | } |
| 1747 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1748 | /* If resets are disabled then leave the HBA alone and return */ |
| 1749 | if (!phba->cfg_enable_hba_reset) |
| 1750 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1751 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1752 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1753 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1754 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1755 | if (phba->hba_flag & DEFER_ERATT) |
| 1756 | lpfc_handle_deferred_eratt(phba); |
| 1757 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1758 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1759 | if (phba->work_hs & HS_FFER6) |
| 1760 | /* Re-establishing Link */ |
| 1761 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1762 | "1301 Re-establishing Link " |
| 1763 | "Data: x%x x%x x%x\n", |
| 1764 | phba->work_hs, phba->work_status[0], |
| 1765 | phba->work_status[1]); |
| 1766 | if (phba->work_hs & HS_FFER8) |
| 1767 | /* Device Zeroization */ |
| 1768 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1769 | "2861 Host Authentication device " |
| 1770 | "zeroization Data:x%x x%x x%x\n", |
| 1771 | phba->work_hs, phba->work_status[0], |
| 1772 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1773 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1774 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1775 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1776 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1777 | |
| 1778 | /* |
| 1779 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1780 | * That could cause the I/Os dropped by the firmware. |
| 1781 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1782 | * retry it after re-establishing link. |
| 1783 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1784 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1785 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1786 | /* |
| 1787 | * There was a firmware error. Take the hba offline and then |
| 1788 | * attempt to restart it. |
| 1789 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1790 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1791 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1792 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1793 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1794 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1795 | return; |
| 1796 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1797 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1798 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1799 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1800 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1801 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1802 | temp_event_data.data = (uint32_t)temperature; |
| 1803 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1804 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1805 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1806 | "(%ld), taking this port offline " |
| 1807 | "Data: x%x x%x x%x\n", |
| 1808 | temperature, phba->work_hs, |
| 1809 | phba->work_status[0], phba->work_status[1]); |
| 1810 | |
| 1811 | shost = lpfc_shost_from_vport(phba->pport); |
| 1812 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1813 | sizeof(temp_event_data), |
| 1814 | (char *) &temp_event_data, |
| 1815 | SCSI_NL_VID_TYPE_PCI |
| 1816 | | PCI_VENDOR_ID_EMULEX); |
| 1817 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1818 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1819 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1820 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1821 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1822 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1823 | } else { |
| 1824 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1825 | * failure is a value other than FFER6. Do not call the offline |
| 1826 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1827 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1828 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1829 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1830 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1831 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1832 | phba->work_status[0], phba->work_status[1]); |
| 1833 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1834 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1835 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1836 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1837 | sizeof(event_data), (char *) &event_data, |
| 1838 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1839 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1840 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1841 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1842 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1843 | } |
| 1844 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1845 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1846 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1847 | * @phba: pointer to lpfc hba data structure. |
| 1848 | * @mbx_action: flag for mailbox shutdown action. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1849 | * @en_rn_msg: send reset/port recovery message. |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1850 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1851 | * response to port status register polling attention. It waits for port |
| 1852 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1853 | * During this process, interrupt vectors are freed and later requested |
| 1854 | * for handling possible port resource change. |
| 1855 | **/ |
| 1856 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1857 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1858 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1859 | { |
| 1860 | int rc; |
| 1861 | uint32_t intr_mode; |
James Smart | a9978e3 | 2021-07-07 11:43:43 -0700 | [diff] [blame] | 1862 | LPFC_MBOXQ_t *mboxq; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1863 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1864 | 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] | 1865 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1866 | /* |
| 1867 | * On error status condition, driver need to wait for port |
| 1868 | * ready before performing reset. |
| 1869 | */ |
| 1870 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1871 | if (rc) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1872 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1873 | } |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1874 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1875 | /* need reset: attempt for port recovery */ |
| 1876 | if (en_rn_msg) |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 1877 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1878 | "2887 Reset Needed: Attempting Port " |
| 1879 | "Recovery...\n"); |
James Smart | 3ba6216 | 2021-01-04 10:02:31 -0800 | [diff] [blame] | 1880 | |
| 1881 | /* If we are no wait, the HBA has been reset and is not |
James Smart | a9978e3 | 2021-07-07 11:43:43 -0700 | [diff] [blame] | 1882 | * functional, thus we should clear |
| 1883 | * (LPFC_SLI_ACTIVE | LPFC_SLI_MBOX_ACTIVE) flags. |
James Smart | 3ba6216 | 2021-01-04 10:02:31 -0800 | [diff] [blame] | 1884 | */ |
| 1885 | if (mbx_action == LPFC_MBX_NO_WAIT) { |
| 1886 | spin_lock_irq(&phba->hbalock); |
| 1887 | phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a9978e3 | 2021-07-07 11:43:43 -0700 | [diff] [blame] | 1888 | if (phba->sli.mbox_active) { |
| 1889 | mboxq = phba->sli.mbox_active; |
| 1890 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 1891 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 1892 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 1893 | phba->sli.mbox_active = NULL; |
| 1894 | } |
James Smart | 3ba6216 | 2021-01-04 10:02:31 -0800 | [diff] [blame] | 1895 | spin_unlock_irq(&phba->hbalock); |
| 1896 | } |
| 1897 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1898 | lpfc_offline_prep(phba, mbx_action); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1899 | lpfc_sli_flush_io_rings(phba); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1900 | lpfc_offline(phba); |
| 1901 | /* release interrupt for possible resource change */ |
| 1902 | lpfc_sli4_disable_intr(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1903 | rc = lpfc_sli_brdrestart(phba); |
| 1904 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1905 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1906 | "6309 Failed to restart board\n"); |
| 1907 | return rc; |
| 1908 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1909 | /* request and enable interrupt */ |
| 1910 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1911 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1912 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1913 | "3175 Failed to enable interrupt\n"); |
| 1914 | return -EIO; |
| 1915 | } |
| 1916 | phba->intr_mode = intr_mode; |
| 1917 | rc = lpfc_online(phba); |
| 1918 | if (rc == 0) |
| 1919 | lpfc_unblock_mgmt_io(phba); |
| 1920 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1921 | return rc; |
| 1922 | } |
| 1923 | |
| 1924 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1925 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1926 | * @phba: pointer to lpfc hba data structure. |
| 1927 | * |
| 1928 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1929 | * conditions. |
| 1930 | **/ |
| 1931 | static void |
| 1932 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1933 | { |
| 1934 | struct lpfc_vport *vport = phba->pport; |
| 1935 | uint32_t event_data; |
| 1936 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1937 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1938 | struct lpfc_register portstat_reg = {0}; |
| 1939 | uint32_t reg_err1, reg_err2; |
| 1940 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1941 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1942 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1943 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1944 | struct lpfc_register portsmphr_reg; |
| 1945 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1946 | |
| 1947 | /* If the pci channel is offline, ignore possible errors, since |
| 1948 | * we cannot communicate with the pci card anyway. |
| 1949 | */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1950 | if (pci_channel_offline(phba->pcidev)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1951 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1952 | "3166 pci channel is offline\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1953 | return; |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1954 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1955 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1956 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1957 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1958 | switch (if_type) { |
| 1959 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1960 | pci_rd_rc1 = lpfc_readl( |
| 1961 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1962 | &uerrlo_reg); |
| 1963 | pci_rd_rc2 = lpfc_readl( |
| 1964 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1965 | &uemasklo_reg); |
| 1966 | /* consider PCI bus read error as pci_channel_offline */ |
| 1967 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1968 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1969 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1970 | lpfc_sli4_offline_eratt(phba); |
| 1971 | return; |
| 1972 | } |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1973 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1974 | "7623 Checking UE recoverable"); |
| 1975 | |
| 1976 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1977 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1978 | &portsmphr_reg.word0)) |
| 1979 | continue; |
| 1980 | |
| 1981 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1982 | &portsmphr_reg); |
| 1983 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1984 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1985 | break; |
| 1986 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1987 | msleep(1000); |
| 1988 | } |
| 1989 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1990 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1991 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1992 | smphr_port_status, i); |
| 1993 | |
| 1994 | /* Recoverable UE, reset the HBA device */ |
| 1995 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1996 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1997 | for (i = 0; i < 20; i++) { |
| 1998 | msleep(1000); |
| 1999 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 2000 | &portsmphr_reg.word0) && |
| 2001 | (LPFC_POST_STAGE_PORT_READY == |
| 2002 | bf_get(lpfc_port_smphr_port_status, |
| 2003 | &portsmphr_reg))) { |
| 2004 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 2005 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 2006 | if (rc == 0) |
| 2007 | return; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2008 | lpfc_printf_log(phba, KERN_ERR, |
| 2009 | LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 2010 | "4215 Failed to recover UE"); |
| 2011 | break; |
| 2012 | } |
| 2013 | } |
| 2014 | } |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2015 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 2016 | "7624 Firmware not ready: Failing UE recovery," |
| 2017 | " waited %dSec", i); |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 2018 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2019 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2020 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2021 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 2022 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2023 | pci_rd_rc1 = lpfc_readl( |
| 2024 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 2025 | &portstat_reg.word0); |
| 2026 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2027 | if (pci_rd_rc1 == -EIO) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2028 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2029 | "3151 PCI bus read access failure: x%x\n", |
| 2030 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 2031 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2032 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 2033 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2034 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 2035 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2036 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2037 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 2038 | "2889 Port Overtemperature event, " |
| 2039 | "taking port offline Data: x%x x%x\n", |
| 2040 | reg_err1, reg_err2); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2041 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 2042 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2043 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 2044 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 2045 | temp_event_data.data = 0xFFFFFFFF; |
| 2046 | |
| 2047 | shost = lpfc_shost_from_vport(phba->pport); |
| 2048 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2049 | sizeof(temp_event_data), |
| 2050 | (char *)&temp_event_data, |
| 2051 | SCSI_NL_VID_TYPE_PCI |
| 2052 | | PCI_VENDOR_ID_EMULEX); |
| 2053 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2054 | spin_lock_irq(&phba->hbalock); |
| 2055 | phba->over_temp_state = HBA_OVER_TEMP; |
| 2056 | spin_unlock_irq(&phba->hbalock); |
| 2057 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2058 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2059 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2060 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2061 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2062 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2063 | "3143 Port Down: Firmware Update " |
| 2064 | "Detected\n"); |
| 2065 | en_rn_msg = false; |
| 2066 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2067 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2068 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2069 | "3144 Port Down: Debug Dump\n"); |
| 2070 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 2071 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2072 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2073 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2074 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2075 | /* If resets are disabled then leave the HBA alone and return */ |
| 2076 | if (!phba->cfg_enable_hba_reset) |
| 2077 | return; |
| 2078 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2079 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2080 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 2081 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2082 | if (rc == 0) { |
| 2083 | /* don't report event on forced debug dump */ |
| 2084 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 2085 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 2086 | return; |
| 2087 | else |
| 2088 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2089 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2090 | /* fall through for not able to recover */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2091 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 2092 | "3152 Unrecoverable error\n"); |
| 2093 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2094 | break; |
| 2095 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 2096 | default: |
| 2097 | break; |
| 2098 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2099 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2100 | "3123 Report dump event to upper layer\n"); |
| 2101 | /* Send an internal error event to mgmt application */ |
| 2102 | lpfc_board_errevt_to_mgmt(phba); |
| 2103 | |
| 2104 | event_data = FC_REG_DUMP_EVENT; |
| 2105 | shost = lpfc_shost_from_vport(vport); |
| 2106 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2107 | sizeof(event_data), (char *) &event_data, |
| 2108 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | /** |
| 2112 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 2113 | * @phba: pointer to lpfc HBA data structure. |
| 2114 | * |
| 2115 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 2116 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 2117 | * |
| 2118 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2119 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2120 | * Any other value - error. |
| 2121 | **/ |
| 2122 | void |
| 2123 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 2124 | { |
| 2125 | (*phba->lpfc_handle_eratt)(phba); |
| 2126 | } |
| 2127 | |
| 2128 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2129 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2130 | * @phba: pointer to lpfc hba data structure. |
| 2131 | * |
| 2132 | * 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] | 2133 | * attention link event. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2134 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2136 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2137 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2138 | struct lpfc_vport *vport = phba->pport; |
| 2139 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2140 | LPFC_MBOXQ_t *pmb; |
| 2141 | volatile uint32_t control; |
| 2142 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2143 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2144 | |
| 2145 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2146 | if (!pmb) { |
| 2147 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2148 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2149 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | |
| 2151 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2152 | if (!mp) { |
| 2153 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2154 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2155 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2156 | |
| 2157 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2158 | if (!mp->virt) { |
| 2159 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2160 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2161 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2162 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 2163 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2164 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2165 | |
| 2166 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2167 | lpfc_read_topology(phba, pmb, mp); |
| 2168 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2169 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2170 | /* Block ELS IOCBs until we have processed this mbox command */ |
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 | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2172 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2173 | if (rc == MBX_NOT_FINISHED) { |
| 2174 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2175 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2176 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2177 | |
| 2178 | /* Clear Link Attention in HA REG */ |
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 | writel(HA_LATT, phba->HAregaddr); |
| 2181 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2182 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | |
| 2184 | return; |
| 2185 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2186 | lpfc_handle_latt_free_mbuf: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2187 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2188 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | lpfc_handle_latt_free_mp: |
| 2190 | kfree(mp); |
| 2191 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2192 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2193 | lpfc_handle_latt_err_exit: |
| 2194 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2195 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2196 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 2197 | control = readl(phba->HCregaddr); |
| 2198 | control |= HC_LAINT_ENA; |
| 2199 | writel(control, phba->HCregaddr); |
| 2200 | readl(phba->HCregaddr); /* flush */ |
| 2201 | |
| 2202 | /* Clear Link Attention in HA REG */ |
| 2203 | writel(HA_LATT, phba->HAregaddr); |
| 2204 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2205 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2206 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2207 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2208 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2209 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 2210 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2211 | |
| 2212 | return; |
| 2213 | } |
| 2214 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2215 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2216 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2217 | * @phba: pointer to lpfc hba data structure. |
| 2218 | * @vpd: pointer to the vital product data. |
| 2219 | * @len: length of the vital product data in bytes. |
| 2220 | * |
| 2221 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 2222 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 2223 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 2224 | * |
| 2225 | * Return codes |
| 2226 | * 0 - pointer to the VPD passed in is NULL |
| 2227 | * 1 - success |
| 2228 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2229 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2230 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2231 | { |
| 2232 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 2233 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2234 | int i, j; |
| 2235 | int finished = 0; |
| 2236 | int index = 0; |
| 2237 | |
| 2238 | if (!vpd) |
| 2239 | return 0; |
| 2240 | |
| 2241 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2242 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2243 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2244 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 2245 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2246 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | switch (vpd[index]) { |
| 2248 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2249 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2250 | index += 1; |
| 2251 | lenlo = vpd[index]; |
| 2252 | index += 1; |
| 2253 | lenhi = vpd[index]; |
| 2254 | index += 1; |
| 2255 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 2256 | index += i; |
| 2257 | break; |
| 2258 | case 0x90: |
| 2259 | index += 1; |
| 2260 | lenlo = vpd[index]; |
| 2261 | index += 1; |
| 2262 | lenhi = vpd[index]; |
| 2263 | index += 1; |
| 2264 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2265 | if (Length > len - index) |
| 2266 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2267 | while (Length > 0) { |
| 2268 | /* Look for Serial Number */ |
| 2269 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 2270 | index += 2; |
| 2271 | i = vpd[index]; |
| 2272 | index += 1; |
| 2273 | j = 0; |
| 2274 | Length -= (3+i); |
| 2275 | while(i--) { |
| 2276 | phba->SerialNumber[j++] = vpd[index++]; |
| 2277 | if (j == 31) |
| 2278 | break; |
| 2279 | } |
| 2280 | phba->SerialNumber[j] = 0; |
| 2281 | continue; |
| 2282 | } |
| 2283 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 2284 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 2285 | index += 2; |
| 2286 | i = vpd[index]; |
| 2287 | index += 1; |
| 2288 | j = 0; |
| 2289 | Length -= (3+i); |
| 2290 | while(i--) { |
| 2291 | phba->ModelDesc[j++] = vpd[index++]; |
| 2292 | if (j == 255) |
| 2293 | break; |
| 2294 | } |
| 2295 | phba->ModelDesc[j] = 0; |
| 2296 | continue; |
| 2297 | } |
| 2298 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 2299 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 2300 | index += 2; |
| 2301 | i = vpd[index]; |
| 2302 | index += 1; |
| 2303 | j = 0; |
| 2304 | Length -= (3+i); |
| 2305 | while(i--) { |
| 2306 | phba->ModelName[j++] = vpd[index++]; |
| 2307 | if (j == 79) |
| 2308 | break; |
| 2309 | } |
| 2310 | phba->ModelName[j] = 0; |
| 2311 | continue; |
| 2312 | } |
| 2313 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2314 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2315 | index += 2; |
| 2316 | i = vpd[index]; |
| 2317 | index += 1; |
| 2318 | j = 0; |
| 2319 | Length -= (3+i); |
| 2320 | while(i--) { |
| 2321 | phba->ProgramType[j++] = vpd[index++]; |
| 2322 | if (j == 255) |
| 2323 | break; |
| 2324 | } |
| 2325 | phba->ProgramType[j] = 0; |
| 2326 | continue; |
| 2327 | } |
| 2328 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2329 | phba->vpd_flag |= VPD_PORT; |
| 2330 | index += 2; |
| 2331 | i = vpd[index]; |
| 2332 | index += 1; |
| 2333 | j = 0; |
| 2334 | Length -= (3+i); |
| 2335 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2336 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2337 | (phba->sli4_hba.pport_name_sta == |
| 2338 | LPFC_SLI4_PPNAME_GET)) { |
| 2339 | j++; |
| 2340 | index++; |
| 2341 | } else |
| 2342 | phba->Port[j++] = vpd[index++]; |
| 2343 | if (j == 19) |
| 2344 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2345 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2346 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 2347 | (phba->sli4_hba.pport_name_sta == |
| 2348 | LPFC_SLI4_PPNAME_NON)) |
| 2349 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2350 | continue; |
| 2351 | } |
| 2352 | else { |
| 2353 | index += 2; |
| 2354 | i = vpd[index]; |
| 2355 | index += 1; |
| 2356 | index += i; |
| 2357 | Length -= (3 + i); |
| 2358 | } |
| 2359 | } |
| 2360 | finished = 0; |
| 2361 | break; |
| 2362 | case 0x78: |
| 2363 | finished = 1; |
| 2364 | break; |
| 2365 | default: |
| 2366 | index ++; |
| 2367 | break; |
| 2368 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2369 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2370 | |
| 2371 | return(1); |
| 2372 | } |
| 2373 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2374 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2375 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2376 | * @phba: pointer to lpfc hba data structure. |
| 2377 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2378 | * @descp: pointer to the data structure to hold the derived description. |
| 2379 | * |
| 2380 | * This routine retrieves HBA's description based on its registered PCI device |
| 2381 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2382 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2383 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2384 | * function returns, the @mdp will be filled with the model name. |
| 2385 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2387 | 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] | 2388 | { |
| 2389 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2390 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2391 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2392 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2393 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2394 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2395 | char *name; |
| 2396 | char *bus; |
| 2397 | char *function; |
| 2398 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2399 | |
| 2400 | if (mdp && mdp[0] != '\0' |
| 2401 | && descp && descp[0] != '\0') |
| 2402 | return; |
| 2403 | |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 2404 | if (phba->lmt & LMT_64Gb) |
| 2405 | max_speed = 64; |
| 2406 | else if (phba->lmt & LMT_32Gb) |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2407 | max_speed = 32; |
| 2408 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2409 | max_speed = 16; |
| 2410 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2411 | max_speed = 10; |
| 2412 | else if (phba->lmt & LMT_8Gb) |
| 2413 | max_speed = 8; |
| 2414 | else if (phba->lmt & LMT_4Gb) |
| 2415 | max_speed = 4; |
| 2416 | else if (phba->lmt & LMT_2Gb) |
| 2417 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2418 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2419 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2420 | else |
| 2421 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | |
| 2423 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2424 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2425 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2426 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2427 | m = (typeof(m)){"LP6000", "PCI", |
| 2428 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2429 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | case PCI_DEVICE_ID_SUPERFLY: |
| 2431 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2432 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2433 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2434 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2435 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2436 | break; |
| 2437 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2438 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2439 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2440 | break; |
| 2441 | case PCI_DEVICE_ID_CENTAUR: |
| 2442 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2443 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2445 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2446 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2447 | break; |
| 2448 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2449 | m = (typeof(m)){"LP952", "PCI", |
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_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2453 | m = (typeof(m)){"LP9802", "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_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2457 | m = (typeof(m)){"LP10000", "PCI-X", |
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; |
| 2460 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2461 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2462 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2463 | break; |
| 2464 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2465 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2466 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | break; |
| 2468 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2469 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2470 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2471 | break; |
| 2472 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2473 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2474 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2475 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2476 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2477 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2478 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2479 | break; |
| 2480 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2481 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2482 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2483 | break; |
| 2484 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2485 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2486 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2487 | break; |
| 2488 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2489 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2490 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2491 | break; |
| 2492 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2493 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2494 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2495 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2496 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2497 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2498 | break; |
| 2499 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2500 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2501 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2502 | break; |
| 2503 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2504 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2505 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2506 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2507 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2508 | break; |
| 2509 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2510 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2511 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2512 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2514 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2515 | break; |
| 2516 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2517 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2518 | break; |
| 2519 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2520 | m = (typeof(m)){"LP101", "PCI-X", |
| 2521 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2522 | break; |
| 2523 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2524 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2525 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2526 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2527 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2528 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2529 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2530 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2531 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2532 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2533 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2534 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2535 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2536 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2537 | break; |
| 2538 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2539 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2540 | break; |
| 2541 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2542 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2543 | break; |
| 2544 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2545 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2546 | break; |
| 2547 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2548 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2549 | break; |
| 2550 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2551 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2552 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2553 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2554 | m = (typeof(m)){"LP21000", "PCIe", |
| 2555 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2556 | GE = 1; |
| 2557 | break; |
| 2558 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2559 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2560 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2561 | break; |
| 2562 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2563 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2564 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2565 | break; |
| 2566 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2567 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2568 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2569 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2570 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2571 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2572 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2573 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2574 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2575 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2576 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2577 | break; |
| 2578 | case PCI_DEVICE_ID_FALCON: |
| 2579 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2580 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2581 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2582 | case PCI_DEVICE_ID_BALIUS: |
| 2583 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2584 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2585 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2586 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2587 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2588 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2589 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2590 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2591 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2592 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2593 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2594 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2595 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2596 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2597 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2598 | oneConnect = 1; |
| 2599 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2600 | "Obsolete, Unsupported FCoE"}; |
| 2601 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2602 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2603 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2604 | break; |
James Smart | c238b9b | 2018-02-22 08:18:44 -0800 | [diff] [blame] | 2605 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 2606 | m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"}; |
| 2607 | break; |
James Smart | f449a3d | 2021-07-22 15:17:16 -0700 | [diff] [blame] | 2608 | case PCI_DEVICE_ID_LANCER_G7P_FC: |
| 2609 | m = (typeof(m)){"LPe38000", "PCIe", "Fibre Channel Adapter"}; |
| 2610 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2611 | case PCI_DEVICE_ID_SKYHAWK: |
| 2612 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2613 | oneConnect = 1; |
| 2614 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2615 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2616 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2617 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2618 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2619 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2620 | |
| 2621 | if (mdp && mdp[0] == '\0') |
| 2622 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2623 | /* |
| 2624 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2625 | * and we put the port number on the end |
| 2626 | */ |
| 2627 | if (descp && descp[0] == '\0') { |
| 2628 | if (oneConnect) |
| 2629 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2630 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2631 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2632 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2633 | else if (max_speed == 0) |
| 2634 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2635 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2636 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2637 | else |
| 2638 | snprintf(descp, 255, |
| 2639 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2640 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2641 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2642 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2643 | } |
| 2644 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2645 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2646 | * 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] | 2647 | * @phba: pointer to lpfc hba data structure. |
| 2648 | * @pring: pointer to a IOCB ring. |
| 2649 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2650 | * |
| 2651 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2652 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2653 | * |
| 2654 | * Return codes |
| 2655 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2656 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2657 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2658 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2659 | { |
| 2660 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2661 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2662 | struct lpfc_dmabuf *mp1, *mp2; |
| 2663 | |
| 2664 | cnt += pring->missbufcnt; |
| 2665 | |
| 2666 | /* While there are buffers to post */ |
| 2667 | while (cnt > 0) { |
| 2668 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2669 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | if (iocb == NULL) { |
| 2671 | pring->missbufcnt = cnt; |
| 2672 | return cnt; |
| 2673 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2674 | icmd = &iocb->iocb; |
| 2675 | |
| 2676 | /* 2 buffers can be posted per command */ |
| 2677 | /* Allocate buffer to post */ |
| 2678 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2679 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2680 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2681 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2682 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2683 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2684 | pring->missbufcnt = cnt; |
| 2685 | return cnt; |
| 2686 | } |
| 2687 | |
| 2688 | INIT_LIST_HEAD(&mp1->list); |
| 2689 | /* Allocate buffer to post */ |
| 2690 | if (cnt > 1) { |
| 2691 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2692 | if (mp2) |
| 2693 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2694 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2695 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2696 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2697 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2698 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2699 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2700 | pring->missbufcnt = cnt; |
| 2701 | return cnt; |
| 2702 | } |
| 2703 | |
| 2704 | INIT_LIST_HEAD(&mp2->list); |
| 2705 | } else { |
| 2706 | mp2 = NULL; |
| 2707 | } |
| 2708 | |
| 2709 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2710 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2711 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2712 | icmd->ulpBdeCount = 1; |
| 2713 | cnt--; |
| 2714 | if (mp2) { |
| 2715 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2716 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2717 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2718 | cnt--; |
| 2719 | icmd->ulpBdeCount = 2; |
| 2720 | } |
| 2721 | |
| 2722 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2723 | icmd->ulpLe = 1; |
| 2724 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2725 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2726 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2727 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2728 | kfree(mp1); |
| 2729 | cnt++; |
| 2730 | if (mp2) { |
| 2731 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2732 | kfree(mp2); |
| 2733 | cnt++; |
| 2734 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2735 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2736 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2737 | return cnt; |
| 2738 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2740 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2741 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | } |
| 2743 | pring->missbufcnt = 0; |
| 2744 | return 0; |
| 2745 | } |
| 2746 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2747 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2748 | * 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] | 2749 | * @phba: pointer to lpfc hba data structure. |
| 2750 | * |
| 2751 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2752 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2753 | * set to 64 IOCBs. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2754 | * |
| 2755 | * Return codes |
| 2756 | * 0 - success (currently always success) |
| 2757 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2759 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2760 | { |
| 2761 | struct lpfc_sli *psli = &phba->sli; |
| 2762 | |
| 2763 | /* Ring 0, ELS / CT buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2764 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2765 | /* Ring 2 - FCP no buffers needed */ |
| 2766 | |
| 2767 | return 0; |
| 2768 | } |
| 2769 | |
| 2770 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2771 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2772 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2773 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2774 | * @HashResultPointer: pointer to an array as hash table. |
| 2775 | * |
| 2776 | * This routine sets up the initial values to the array of hash table entries |
| 2777 | * for the LC HBAs. |
| 2778 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2779 | static void |
| 2780 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2781 | { |
| 2782 | HashResultPointer[0] = 0x67452301; |
| 2783 | HashResultPointer[1] = 0xEFCDAB89; |
| 2784 | HashResultPointer[2] = 0x98BADCFE; |
| 2785 | HashResultPointer[3] = 0x10325476; |
| 2786 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2787 | } |
| 2788 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2789 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2790 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2791 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2792 | * @HashWorkingPointer: pointer to an working hash table. |
| 2793 | * |
| 2794 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2795 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2796 | * The results are putting back to the initial hash table, returned through |
| 2797 | * the @HashResultPointer as the result hash table. |
| 2798 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2799 | static void |
| 2800 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2801 | { |
| 2802 | int t; |
| 2803 | uint32_t TEMP; |
| 2804 | uint32_t A, B, C, D, E; |
| 2805 | t = 16; |
| 2806 | do { |
| 2807 | HashWorkingPointer[t] = |
| 2808 | S(1, |
| 2809 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2810 | 8] ^ |
| 2811 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2812 | } while (++t <= 79); |
| 2813 | t = 0; |
| 2814 | A = HashResultPointer[0]; |
| 2815 | B = HashResultPointer[1]; |
| 2816 | C = HashResultPointer[2]; |
| 2817 | D = HashResultPointer[3]; |
| 2818 | E = HashResultPointer[4]; |
| 2819 | |
| 2820 | do { |
| 2821 | if (t < 20) { |
| 2822 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2823 | } else if (t < 40) { |
| 2824 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2825 | } else if (t < 60) { |
| 2826 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2827 | } else { |
| 2828 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2829 | } |
| 2830 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2831 | E = D; |
| 2832 | D = C; |
| 2833 | C = S(30, B); |
| 2834 | B = A; |
| 2835 | A = TEMP; |
| 2836 | } while (++t <= 79); |
| 2837 | |
| 2838 | HashResultPointer[0] += A; |
| 2839 | HashResultPointer[1] += B; |
| 2840 | HashResultPointer[2] += C; |
| 2841 | HashResultPointer[3] += D; |
| 2842 | HashResultPointer[4] += E; |
| 2843 | |
| 2844 | } |
| 2845 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2846 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2847 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2848 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2849 | * @HashWorking: pointer to the entry of the working hash array. |
| 2850 | * |
| 2851 | * This routine calculates the working hash array referred by @HashWorking |
| 2852 | * from the challenge random numbers associated with the host, referred by |
| 2853 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2854 | * array and returned by reference through @HashWorking. |
| 2855 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2856 | static void |
| 2857 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2858 | { |
| 2859 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2860 | } |
| 2861 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2862 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2863 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2864 | * @phba: pointer to lpfc hba data structure. |
| 2865 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2866 | * |
| 2867 | * This routine performs the special handling for LC HBA initialization. |
| 2868 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2869 | void |
| 2870 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2871 | { |
| 2872 | int t; |
| 2873 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2874 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2875 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2876 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2877 | if (!HashWorking) |
| 2878 | return; |
| 2879 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2880 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2881 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2882 | |
| 2883 | for (t = 0; t < 7; t++) |
| 2884 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2885 | |
| 2886 | lpfc_sha_init(hbainit); |
| 2887 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2888 | kfree(HashWorking); |
| 2889 | } |
| 2890 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2891 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2892 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2893 | * @vport: pointer to a virtual N_Port data structure. |
| 2894 | * |
| 2895 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2896 | * It invokes the discovery state machine to perform necessary state |
| 2897 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2898 | * the physical port is treated as @vport 0. |
| 2899 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2900 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2901 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2902 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2903 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2904 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2905 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2906 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2907 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2908 | lpfc_port_link_failure(vport); |
| 2909 | |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 2910 | /* Clean up VMID resources */ |
| 2911 | if (lpfc_is_vmid_enabled(phba)) |
| 2912 | lpfc_vmid_vport_cleanup(vport); |
| 2913 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2914 | 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] | 2915 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2916 | ndlp->nlp_DID == Fabric_DID) { |
| 2917 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2918 | lpfc_nlp_put(ndlp); |
| 2919 | continue; |
| 2920 | } |
| 2921 | |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 2922 | if (ndlp->nlp_DID == Fabric_Cntl_DID && |
| 2923 | ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2924 | lpfc_nlp_put(ndlp); |
| 2925 | continue; |
| 2926 | } |
| 2927 | |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2928 | /* Fabric Ports not in UNMAPPED state are cleaned up in the |
| 2929 | * DEVICE_RM event. |
| 2930 | */ |
| 2931 | if (ndlp->nlp_type & NLP_FABRIC && |
| 2932 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2933 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2934 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2935 | |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2936 | if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD))) |
| 2937 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2938 | NLP_EVT_DEVICE_RM); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2939 | } |
| 2940 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2941 | /* At this point, ALL ndlp's should be gone |
| 2942 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2943 | * Lets wait for this to happen, if needed. |
| 2944 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2945 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2946 | if (i++ > 3000) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2947 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2948 | LOG_TRACE_EVENT, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2949 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2950 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2951 | &vport->fc_nodes, nlp_listp) { |
| 2952 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2953 | LOG_TRACE_EVENT, |
| 2954 | "0282 did:x%x ndlp:x%px " |
| 2955 | "refcnt:%d xflags x%x nflag x%x\n", |
| 2956 | ndlp->nlp_DID, (void *)ndlp, |
| 2957 | kref_read(&ndlp->kref), |
| 2958 | ndlp->fc4_xpt_flags, |
| 2959 | ndlp->nlp_flag); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2960 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2961 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2962 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2963 | |
| 2964 | /* Wait for any activity on ndlps to settle */ |
| 2965 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2966 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2967 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2968 | } |
| 2969 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2970 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2971 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2972 | * @vport: pointer to a virtual N_Port data structure. |
| 2973 | * |
| 2974 | * This routine stops all the timers associated with a @vport. This function |
| 2975 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2976 | * port is treated as @vport 0. |
| 2977 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2978 | void |
| 2979 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2980 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2981 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2982 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2983 | lpfc_can_disctmo(vport); |
| 2984 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2985 | } |
| 2986 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2987 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2988 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2989 | * @phba: pointer to lpfc hba data structure. |
| 2990 | * |
| 2991 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2992 | * caller of this routine should already hold the host lock. |
| 2993 | **/ |
| 2994 | void |
| 2995 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2996 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2997 | /* Clear pending FCF rediscovery wait flag */ |
| 2998 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2999 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3000 | /* Now, try to stop the timer */ |
| 3001 | del_timer(&phba->fcf.redisc_wait); |
| 3002 | } |
| 3003 | |
| 3004 | /** |
| 3005 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 3006 | * @phba: pointer to lpfc hba data structure. |
| 3007 | * |
| 3008 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 3009 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 3010 | * lock held before proceeding with disabling the timer and clearing the |
| 3011 | * wait timer pendig flag. |
| 3012 | **/ |
| 3013 | void |
| 3014 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 3015 | { |
| 3016 | spin_lock_irq(&phba->hbalock); |
| 3017 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 3018 | /* FCF rediscovery timer already fired or stopped */ |
| 3019 | spin_unlock_irq(&phba->hbalock); |
| 3020 | return; |
| 3021 | } |
| 3022 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 3023 | /* Clear failover in progress flags */ |
| 3024 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3025 | spin_unlock_irq(&phba->hbalock); |
| 3026 | } |
| 3027 | |
| 3028 | /** |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 3029 | * lpfc_cmf_stop - Stop CMF processing |
| 3030 | * @phba: pointer to lpfc hba data structure. |
| 3031 | * |
| 3032 | * This is called when the link goes down or if CMF mode is turned OFF. |
| 3033 | * It is also called when going offline or unloaded just before the |
| 3034 | * congestion info buffer is unregistered. |
| 3035 | **/ |
| 3036 | void |
| 3037 | lpfc_cmf_stop(struct lpfc_hba *phba) |
| 3038 | { |
| 3039 | int cpu; |
| 3040 | struct lpfc_cgn_stat *cgs; |
| 3041 | |
| 3042 | /* We only do something if CMF is enabled */ |
| 3043 | if (!phba->sli4_hba.pc_sli4_params.cmf) |
| 3044 | return; |
| 3045 | |
| 3046 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 3047 | "6221 Stop CMF / Cancel Timer\n"); |
| 3048 | |
| 3049 | /* Cancel the CMF timer */ |
| 3050 | hrtimer_cancel(&phba->cmf_timer); |
| 3051 | |
| 3052 | /* Zero CMF counters */ |
| 3053 | atomic_set(&phba->cmf_busy, 0); |
| 3054 | for_each_present_cpu(cpu) { |
| 3055 | cgs = per_cpu_ptr(phba->cmf_stat, cpu); |
| 3056 | atomic64_set(&cgs->total_bytes, 0); |
| 3057 | atomic64_set(&cgs->rcv_bytes, 0); |
| 3058 | atomic_set(&cgs->rx_io_cnt, 0); |
| 3059 | atomic64_set(&cgs->rx_latency, 0); |
| 3060 | } |
| 3061 | atomic_set(&phba->cmf_bw_wait, 0); |
| 3062 | |
| 3063 | /* Resume any blocked IO - Queue unblock on workqueue */ |
| 3064 | queue_work(phba->wq, &phba->unblock_request_work); |
| 3065 | } |
| 3066 | |
| 3067 | static inline uint64_t |
| 3068 | lpfc_get_max_line_rate(struct lpfc_hba *phba) |
| 3069 | { |
| 3070 | uint64_t rate = lpfc_sli_port_speed_get(phba); |
| 3071 | |
| 3072 | return ((((unsigned long)rate) * 1024 * 1024) / 10); |
| 3073 | } |
| 3074 | |
| 3075 | void |
| 3076 | lpfc_cmf_signal_init(struct lpfc_hba *phba) |
| 3077 | { |
| 3078 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 3079 | "6223 Signal CMF init\n"); |
| 3080 | |
| 3081 | /* Use the new fc_linkspeed to recalculate */ |
| 3082 | phba->cmf_interval_rate = LPFC_CMF_INTERVAL; |
| 3083 | phba->cmf_max_line_rate = lpfc_get_max_line_rate(phba); |
| 3084 | phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate * |
| 3085 | phba->cmf_interval_rate, 1000); |
| 3086 | phba->cmf_max_bytes_per_interval = phba->cmf_link_byte_count; |
| 3087 | |
| 3088 | /* This is a signal to firmware to sync up CMF BW with link speed */ |
| 3089 | lpfc_issue_cmf_sync_wqe(phba, 0, 0); |
| 3090 | } |
| 3091 | |
| 3092 | /** |
| 3093 | * lpfc_cmf_start - Start CMF processing |
| 3094 | * @phba: pointer to lpfc hba data structure. |
| 3095 | * |
| 3096 | * This is called when the link comes up or if CMF mode is turned OFF |
| 3097 | * to Monitor or Managed. |
| 3098 | **/ |
| 3099 | void |
| 3100 | lpfc_cmf_start(struct lpfc_hba *phba) |
| 3101 | { |
| 3102 | struct lpfc_cgn_stat *cgs; |
| 3103 | int cpu; |
| 3104 | |
| 3105 | /* We only do something if CMF is enabled */ |
| 3106 | if (!phba->sli4_hba.pc_sli4_params.cmf || |
| 3107 | phba->cmf_active_mode == LPFC_CFG_OFF) |
| 3108 | return; |
| 3109 | |
| 3110 | /* Reinitialize congestion buffer info */ |
| 3111 | lpfc_init_congestion_buf(phba); |
| 3112 | |
| 3113 | atomic_set(&phba->cgn_fabric_warn_cnt, 0); |
| 3114 | atomic_set(&phba->cgn_fabric_alarm_cnt, 0); |
| 3115 | atomic_set(&phba->cgn_sync_alarm_cnt, 0); |
| 3116 | atomic_set(&phba->cgn_sync_warn_cnt, 0); |
| 3117 | |
| 3118 | atomic_set(&phba->cmf_busy, 0); |
| 3119 | for_each_present_cpu(cpu) { |
| 3120 | cgs = per_cpu_ptr(phba->cmf_stat, cpu); |
| 3121 | atomic64_set(&cgs->total_bytes, 0); |
| 3122 | atomic64_set(&cgs->rcv_bytes, 0); |
| 3123 | atomic_set(&cgs->rx_io_cnt, 0); |
| 3124 | atomic64_set(&cgs->rx_latency, 0); |
| 3125 | } |
| 3126 | phba->cmf_latency.tv_sec = 0; |
| 3127 | phba->cmf_latency.tv_nsec = 0; |
| 3128 | |
| 3129 | lpfc_cmf_signal_init(phba); |
| 3130 | |
| 3131 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 3132 | "6222 Start CMF / Timer\n"); |
| 3133 | |
| 3134 | phba->cmf_timer_cnt = 0; |
| 3135 | hrtimer_start(&phba->cmf_timer, |
| 3136 | ktime_set(0, LPFC_CMF_INTERVAL * 1000000), |
| 3137 | HRTIMER_MODE_REL); |
| 3138 | /* Setup for latency check in IO cmpl routines */ |
| 3139 | ktime_get_real_ts64(&phba->cmf_latency); |
| 3140 | |
| 3141 | atomic_set(&phba->cmf_bw_wait, 0); |
| 3142 | atomic_set(&phba->cmf_stop_io, 0); |
| 3143 | } |
| 3144 | |
| 3145 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3146 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3147 | * @phba: pointer to lpfc hba data structure. |
| 3148 | * |
| 3149 | * This routine stops all the timers associated with a HBA. This function is |
| 3150 | * invoked before either putting a HBA offline or unloading the driver. |
| 3151 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3152 | void |
| 3153 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3154 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 3155 | if (phba->pport) |
| 3156 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 3157 | cancel_delayed_work_sync(&phba->eq_delay_work); |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 3158 | cancel_delayed_work_sync(&phba->idle_stat_delay_work); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3159 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3160 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3161 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3162 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 3163 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3164 | del_timer_sync(&phba->rrq_tmr); |
| 3165 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 3166 | } |
James Smart | a22d73b | 2021-01-04 10:02:38 -0800 | [diff] [blame] | 3167 | phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3168 | |
| 3169 | switch (phba->pci_dev_grp) { |
| 3170 | case LPFC_PCI_DEV_LP: |
| 3171 | /* Stop any LightPulse device specific driver timers */ |
| 3172 | del_timer_sync(&phba->fcp_poll_timer); |
| 3173 | break; |
| 3174 | case LPFC_PCI_DEV_OC: |
Paul Walmsley | cc0e5f1 | 2019-07-11 20:52:33 -0700 | [diff] [blame] | 3175 | /* Stop any OneConnect device specific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 3176 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3177 | break; |
| 3178 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3179 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 3180 | "0297 Invalid device group (x%x)\n", |
| 3181 | phba->pci_dev_grp); |
| 3182 | break; |
| 3183 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3184 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3185 | } |
| 3186 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3187 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3188 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3189 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 3190 | * @mbx_action: flag for mailbox no wait action. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3191 | * |
| 3192 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 3193 | * management interface is marked as blocked, all the user space access to |
| 3194 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 3195 | * all be blocked. The HBA is set to block the management interface when the |
| 3196 | * driver prepares the HBA interface for online or offline. |
| 3197 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3198 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3199 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3200 | { |
| 3201 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3202 | uint8_t actcmd = MBX_HEARTBEAT; |
| 3203 | unsigned long timeout; |
| 3204 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3205 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3206 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3207 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3208 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 3209 | return; |
| 3210 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 3211 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3212 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3213 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3214 | /* Determine how long we might wait for the active mailbox |
| 3215 | * command to be gracefully completed by firmware. |
| 3216 | */ |
| 3217 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3218 | phba->sli.mbox_active) * 1000) + jiffies; |
| 3219 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3220 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3221 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3222 | /* Wait for the outstnading mailbox command to complete */ |
| 3223 | while (phba->sli.mbox_active) { |
| 3224 | /* Check active mailbox complete status every 2ms */ |
| 3225 | msleep(2); |
| 3226 | if (time_after(jiffies, timeout)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3227 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 3228 | "2813 Mgmt IO is Blocked %x " |
| 3229 | "- mbox cmd %x still active\n", |
| 3230 | phba->sli.sli_flag, actcmd); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3231 | break; |
| 3232 | } |
| 3233 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3234 | } |
| 3235 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3236 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3237 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 3238 | * @phba: pointer to lpfc hba data structure. |
| 3239 | * |
| 3240 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 3241 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 3242 | * is to fixup the temporary rpi assignments. |
| 3243 | **/ |
| 3244 | void |
| 3245 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 3246 | { |
| 3247 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3248 | struct lpfc_vport **vports; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3249 | int i, rpi; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3250 | |
| 3251 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 3252 | return; |
| 3253 | |
| 3254 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3255 | if (vports == NULL) |
| 3256 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3257 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3258 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3259 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3260 | continue; |
| 3261 | |
| 3262 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3263 | &vports[i]->fc_nodes, |
| 3264 | nlp_listp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3265 | rpi = lpfc_sli4_alloc_rpi(phba); |
| 3266 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3267 | /* TODO print log? */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3268 | continue; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3269 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3270 | ndlp->nlp_rpi = rpi; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3271 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, |
| 3272 | LOG_NODE | LOG_DISCOVERY, |
| 3273 | "0009 Assign RPI x%x to ndlp x%px " |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3274 | "DID:x%06x flg:x%x\n", |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3275 | ndlp->nlp_rpi, ndlp, ndlp->nlp_DID, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3276 | ndlp->nlp_flag); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3277 | } |
| 3278 | } |
| 3279 | lpfc_destroy_vport_work_array(phba, vports); |
| 3280 | } |
| 3281 | |
| 3282 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3283 | * lpfc_create_expedite_pool - create expedite pool |
| 3284 | * @phba: pointer to lpfc hba data structure. |
| 3285 | * |
| 3286 | * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0 |
| 3287 | * to expedite pool. Mark them as expedite. |
| 3288 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3289 | static void lpfc_create_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3290 | { |
| 3291 | struct lpfc_sli4_hdw_queue *qp; |
| 3292 | struct lpfc_io_buf *lpfc_ncmd; |
| 3293 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3294 | struct lpfc_epd_pool *epd_pool; |
| 3295 | unsigned long iflag; |
| 3296 | |
| 3297 | epd_pool = &phba->epd_pool; |
| 3298 | qp = &phba->sli4_hba.hdwq[0]; |
| 3299 | |
| 3300 | spin_lock_init(&epd_pool->lock); |
| 3301 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3302 | spin_lock(&epd_pool->lock); |
| 3303 | INIT_LIST_HEAD(&epd_pool->list); |
| 3304 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3305 | &qp->lpfc_io_buf_list_put, list) { |
| 3306 | list_move_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 3307 | lpfc_ncmd->expedite = true; |
| 3308 | qp->put_io_bufs--; |
| 3309 | epd_pool->count++; |
| 3310 | if (epd_pool->count >= XRI_BATCH) |
| 3311 | break; |
| 3312 | } |
| 3313 | spin_unlock(&epd_pool->lock); |
| 3314 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3315 | } |
| 3316 | |
| 3317 | /** |
| 3318 | * lpfc_destroy_expedite_pool - destroy expedite pool |
| 3319 | * @phba: pointer to lpfc hba data structure. |
| 3320 | * |
| 3321 | * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put |
| 3322 | * of HWQ 0. Clear the mark. |
| 3323 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3324 | static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3325 | { |
| 3326 | struct lpfc_sli4_hdw_queue *qp; |
| 3327 | struct lpfc_io_buf *lpfc_ncmd; |
| 3328 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3329 | struct lpfc_epd_pool *epd_pool; |
| 3330 | unsigned long iflag; |
| 3331 | |
| 3332 | epd_pool = &phba->epd_pool; |
| 3333 | qp = &phba->sli4_hba.hdwq[0]; |
| 3334 | |
| 3335 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3336 | spin_lock(&epd_pool->lock); |
| 3337 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3338 | &epd_pool->list, list) { |
| 3339 | list_move_tail(&lpfc_ncmd->list, |
| 3340 | &qp->lpfc_io_buf_list_put); |
| 3341 | lpfc_ncmd->flags = false; |
| 3342 | qp->put_io_bufs++; |
| 3343 | epd_pool->count--; |
| 3344 | } |
| 3345 | spin_unlock(&epd_pool->lock); |
| 3346 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3347 | } |
| 3348 | |
| 3349 | /** |
| 3350 | * lpfc_create_multixri_pools - create multi-XRI pools |
| 3351 | * @phba: pointer to lpfc hba data structure. |
| 3352 | * |
| 3353 | * This routine initialize public, private per HWQ. Then, move XRIs from |
| 3354 | * lpfc_io_buf_list_put to public pool. High and low watermark are also |
| 3355 | * Initialized. |
| 3356 | **/ |
| 3357 | void lpfc_create_multixri_pools(struct lpfc_hba *phba) |
| 3358 | { |
| 3359 | u32 i, j; |
| 3360 | u32 hwq_count; |
| 3361 | u32 count_per_hwq; |
| 3362 | struct lpfc_io_buf *lpfc_ncmd; |
| 3363 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3364 | unsigned long iflag; |
| 3365 | struct lpfc_sli4_hdw_queue *qp; |
| 3366 | struct lpfc_multixri_pool *multixri_pool; |
| 3367 | struct lpfc_pbl_pool *pbl_pool; |
| 3368 | struct lpfc_pvt_pool *pvt_pool; |
| 3369 | |
| 3370 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3371 | "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n", |
| 3372 | phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu, |
| 3373 | phba->sli4_hba.io_xri_cnt); |
| 3374 | |
| 3375 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3376 | lpfc_create_expedite_pool(phba); |
| 3377 | |
| 3378 | hwq_count = phba->cfg_hdw_queue; |
| 3379 | count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count; |
| 3380 | |
| 3381 | for (i = 0; i < hwq_count; i++) { |
| 3382 | multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL); |
| 3383 | |
| 3384 | if (!multixri_pool) { |
| 3385 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3386 | "1238 Failed to allocate memory for " |
| 3387 | "multixri_pool\n"); |
| 3388 | |
| 3389 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3390 | lpfc_destroy_expedite_pool(phba); |
| 3391 | |
| 3392 | j = 0; |
| 3393 | while (j < i) { |
| 3394 | qp = &phba->sli4_hba.hdwq[j]; |
| 3395 | kfree(qp->p_multixri_pool); |
| 3396 | j++; |
| 3397 | } |
| 3398 | phba->cfg_xri_rebalancing = 0; |
| 3399 | return; |
| 3400 | } |
| 3401 | |
| 3402 | qp = &phba->sli4_hba.hdwq[i]; |
| 3403 | qp->p_multixri_pool = multixri_pool; |
| 3404 | |
| 3405 | multixri_pool->xri_limit = count_per_hwq; |
| 3406 | multixri_pool->rrb_next_hwqid = i; |
| 3407 | |
| 3408 | /* Deal with public free xri pool */ |
| 3409 | pbl_pool = &multixri_pool->pbl_pool; |
| 3410 | spin_lock_init(&pbl_pool->lock); |
| 3411 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3412 | spin_lock(&pbl_pool->lock); |
| 3413 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3414 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3415 | &qp->lpfc_io_buf_list_put, list) { |
| 3416 | list_move_tail(&lpfc_ncmd->list, &pbl_pool->list); |
| 3417 | qp->put_io_bufs--; |
| 3418 | pbl_pool->count++; |
| 3419 | } |
| 3420 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3421 | "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n", |
| 3422 | pbl_pool->count, i); |
| 3423 | spin_unlock(&pbl_pool->lock); |
| 3424 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3425 | |
| 3426 | /* Deal with private free xri pool */ |
| 3427 | pvt_pool = &multixri_pool->pvt_pool; |
| 3428 | pvt_pool->high_watermark = multixri_pool->xri_limit / 2; |
| 3429 | pvt_pool->low_watermark = XRI_BATCH; |
| 3430 | spin_lock_init(&pvt_pool->lock); |
| 3431 | spin_lock_irqsave(&pvt_pool->lock, iflag); |
| 3432 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3433 | pvt_pool->count = 0; |
| 3434 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | /** |
| 3439 | * lpfc_destroy_multixri_pools - destroy multi-XRI pools |
| 3440 | * @phba: pointer to lpfc hba data structure. |
| 3441 | * |
| 3442 | * This routine returns XRIs from public/private to lpfc_io_buf_list_put. |
| 3443 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3444 | static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3445 | { |
| 3446 | u32 i; |
| 3447 | u32 hwq_count; |
| 3448 | struct lpfc_io_buf *lpfc_ncmd; |
| 3449 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3450 | unsigned long iflag; |
| 3451 | struct lpfc_sli4_hdw_queue *qp; |
| 3452 | struct lpfc_multixri_pool *multixri_pool; |
| 3453 | struct lpfc_pbl_pool *pbl_pool; |
| 3454 | struct lpfc_pvt_pool *pvt_pool; |
| 3455 | |
| 3456 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3457 | lpfc_destroy_expedite_pool(phba); |
| 3458 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 3459 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3460 | lpfc_sli_flush_io_rings(phba); |
James Smart | c66a919 | 2019-03-12 16:30:19 -0700 | [diff] [blame] | 3461 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3462 | hwq_count = phba->cfg_hdw_queue; |
| 3463 | |
| 3464 | for (i = 0; i < hwq_count; i++) { |
| 3465 | qp = &phba->sli4_hba.hdwq[i]; |
| 3466 | multixri_pool = qp->p_multixri_pool; |
| 3467 | if (!multixri_pool) |
| 3468 | continue; |
| 3469 | |
| 3470 | qp->p_multixri_pool = NULL; |
| 3471 | |
| 3472 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3473 | |
| 3474 | /* Deal with public free xri pool */ |
| 3475 | pbl_pool = &multixri_pool->pbl_pool; |
| 3476 | spin_lock(&pbl_pool->lock); |
| 3477 | |
| 3478 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3479 | "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n", |
| 3480 | pbl_pool->count, i); |
| 3481 | |
| 3482 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3483 | &pbl_pool->list, list) { |
| 3484 | list_move_tail(&lpfc_ncmd->list, |
| 3485 | &qp->lpfc_io_buf_list_put); |
| 3486 | qp->put_io_bufs++; |
| 3487 | pbl_pool->count--; |
| 3488 | } |
| 3489 | |
| 3490 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3491 | pbl_pool->count = 0; |
| 3492 | |
| 3493 | spin_unlock(&pbl_pool->lock); |
| 3494 | |
| 3495 | /* Deal with private free xri pool */ |
| 3496 | pvt_pool = &multixri_pool->pvt_pool; |
| 3497 | spin_lock(&pvt_pool->lock); |
| 3498 | |
| 3499 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3500 | "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n", |
| 3501 | pvt_pool->count, i); |
| 3502 | |
| 3503 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3504 | &pvt_pool->list, list) { |
| 3505 | list_move_tail(&lpfc_ncmd->list, |
| 3506 | &qp->lpfc_io_buf_list_put); |
| 3507 | qp->put_io_bufs++; |
| 3508 | pvt_pool->count--; |
| 3509 | } |
| 3510 | |
| 3511 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3512 | pvt_pool->count = 0; |
| 3513 | |
| 3514 | spin_unlock(&pvt_pool->lock); |
| 3515 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3516 | |
| 3517 | kfree(multixri_pool); |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3522 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3523 | * @phba: pointer to lpfc hba data structure. |
| 3524 | * |
| 3525 | * This routine initializes the HBA and brings a HBA online. During this |
| 3526 | * process, the management interface is blocked to prevent user space access |
| 3527 | * to the HBA interfering with the driver initialization. |
| 3528 | * |
| 3529 | * Return codes |
| 3530 | * 0 - successful |
| 3531 | * 1 - failed |
| 3532 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3533 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3534 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3535 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3536 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3537 | struct lpfc_vport **vports; |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3538 | int i, error = 0; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3539 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3540 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3541 | if (!phba) |
| 3542 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3543 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3544 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3545 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3546 | return 0; |
| 3547 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3548 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3549 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3550 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3551 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3552 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3553 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3554 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 3555 | lpfc_unblock_mgmt_io(phba); |
| 3556 | return 1; |
| 3557 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3558 | spin_lock_irq(&phba->hbalock); |
| 3559 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 3560 | vpis_cleared = true; |
| 3561 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3562 | |
| 3563 | /* Reestablish the local initiator port. |
| 3564 | * The offline process destroyed the previous lport. |
| 3565 | */ |
| 3566 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
| 3567 | !phba->nvmet_support) { |
| 3568 | error = lpfc_nvme_create_localport(phba->pport); |
| 3569 | if (error) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3570 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3571 | "6132 NVME restore reg failed " |
| 3572 | "on nvmei error x%x\n", error); |
| 3573 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3574 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3575 | lpfc_sli_queue_init(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3576 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 3577 | lpfc_unblock_mgmt_io(phba); |
| 3578 | return 1; |
| 3579 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3580 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3581 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3582 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3583 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3584 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3585 | struct Scsi_Host *shost; |
| 3586 | shost = lpfc_shost_from_vport(vports[i]); |
| 3587 | spin_lock_irq(shost->host_lock); |
| 3588 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 3589 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3590 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3591 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3592 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3593 | if ((vpis_cleared) && |
| 3594 | (vports[i]->port_type != |
| 3595 | LPFC_PHYSICAL_PORT)) |
| 3596 | vports[i]->vpi = 0; |
| 3597 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3598 | spin_unlock_irq(shost->host_lock); |
| 3599 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3600 | } |
| 3601 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3602 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3603 | if (phba->cfg_xri_rebalancing) |
| 3604 | lpfc_create_multixri_pools(phba); |
| 3605 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 3606 | lpfc_cpuhp_add(phba); |
| 3607 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3608 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3609 | return 0; |
| 3610 | } |
| 3611 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3612 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3613 | * 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] | 3614 | * @phba: pointer to lpfc hba data structure. |
| 3615 | * |
| 3616 | * This routine marks a HBA's management interface as not blocked. Once the |
| 3617 | * HBA's management interface is marked as not blocked, all the user space |
| 3618 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 3619 | * interface will be allowed. The HBA is set to block the management interface |
| 3620 | * when the driver prepares the HBA interface for online or offline and then |
| 3621 | * set to unblock the management interface afterwards. |
| 3622 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3623 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3624 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 3625 | { |
| 3626 | unsigned long iflag; |
| 3627 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3628 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3629 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 3630 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3631 | } |
| 3632 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3633 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3634 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3635 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 3636 | * @mbx_action: flag for mailbox shutdown action. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3637 | * |
| 3638 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 3639 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 3640 | * queue to make it ready to be brought offline. |
| 3641 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3642 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3643 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3644 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3645 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3646 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3647 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3648 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3649 | int i; |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 3650 | int offline = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3651 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3652 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3653 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3654 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3655 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3656 | |
| 3657 | lpfc_linkdown(phba); |
| 3658 | |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 3659 | offline = pci_channel_offline(phba->pcidev); |
| 3660 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3661 | /* Issue an unreg_login to all nodes on all vports */ |
| 3662 | vports = lpfc_create_vport_work_array(phba); |
| 3663 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3664 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3665 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3666 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3667 | shost = lpfc_shost_from_vport(vports[i]); |
| 3668 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3669 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3670 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 3671 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3672 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3673 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3674 | shost = lpfc_shost_from_vport(vports[i]); |
| 3675 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3676 | &vports[i]->fc_nodes, |
| 3677 | nlp_listp) { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3678 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3679 | spin_lock_irq(&ndlp->lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3680 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3681 | spin_unlock_irq(&ndlp->lock); |
James Smart | affbe24 | 2021-07-07 11:43:42 -0700 | [diff] [blame] | 3682 | |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 3683 | if (offline) { |
| 3684 | spin_lock_irq(&ndlp->lock); |
| 3685 | ndlp->nlp_flag &= ~(NLP_UNREG_INP | |
| 3686 | NLP_RPI_REGISTERED); |
| 3687 | spin_unlock_irq(&ndlp->lock); |
| 3688 | } else { |
| 3689 | lpfc_unreg_rpi(vports[i], ndlp); |
| 3690 | } |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3691 | /* |
| 3692 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3693 | * RPI. Get a new RPI when the adapter port |
| 3694 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3695 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3696 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 3697 | lpfc_printf_vlog(vports[i], KERN_INFO, |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3698 | LOG_NODE | LOG_DISCOVERY, |
| 3699 | "0011 Free RPI x%x on " |
James Smart | f115612 | 2021-04-11 18:31:24 -0700 | [diff] [blame] | 3700 | "ndlp: x%px did x%x\n", |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3701 | ndlp->nlp_rpi, ndlp, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3702 | ndlp->nlp_DID); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3703 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3704 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3705 | } |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3706 | |
| 3707 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3708 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3709 | NULL, NLP_EVT_DEVICE_RECOVERY); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 3710 | |
| 3711 | /* Don't remove the node unless the |
| 3712 | * has been unregistered with the |
| 3713 | * transport. If so, let dev_loss |
| 3714 | * take care of the node. |
| 3715 | */ |
| 3716 | if (!(ndlp->fc4_xpt_flags & |
| 3717 | (NVME_XPT_REGD | SCSI_XPT_REGD))) |
| 3718 | lpfc_disc_state_machine |
| 3719 | (vports[i], ndlp, |
| 3720 | NULL, |
| 3721 | NLP_EVT_DEVICE_RM); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3722 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3723 | } |
| 3724 | } |
| 3725 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3726 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3727 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3728 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 3729 | |
| 3730 | if (phba->wq) |
| 3731 | flush_workqueue(phba->wq); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3732 | } |
| 3733 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3734 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3735 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3736 | * @phba: pointer to lpfc hba data structure. |
| 3737 | * |
| 3738 | * This routine actually brings a HBA offline. It stops all the timers |
| 3739 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3740 | * marks the HBA as in offline state for the upper layer protocol. |
| 3741 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3742 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3743 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3744 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3745 | struct Scsi_Host *shost; |
| 3746 | struct lpfc_vport **vports; |
| 3747 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3748 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3749 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3750 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3751 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3752 | /* stop port and all timers associated with this hba */ |
| 3753 | lpfc_stop_port(phba); |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 3754 | |
| 3755 | /* Tear down the local and target port registrations. The |
| 3756 | * nvme transports need to cleanup. |
| 3757 | */ |
| 3758 | lpfc_nvmet_destroy_targetport(phba); |
| 3759 | lpfc_nvme_destroy_localport(phba->pport); |
| 3760 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3761 | vports = lpfc_create_vport_work_array(phba); |
| 3762 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3763 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3764 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3765 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3766 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3767 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3768 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3769 | now. */ |
| 3770 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3771 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3772 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3773 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3774 | vports = lpfc_create_vport_work_array(phba); |
| 3775 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3776 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3777 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3778 | spin_lock_irq(shost->host_lock); |
| 3779 | vports[i]->work_port_events = 0; |
| 3780 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3781 | spin_unlock_irq(shost->host_lock); |
| 3782 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3783 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | f0871ab | 2021-01-04 10:02:32 -0800 | [diff] [blame] | 3784 | /* If OFFLINE flag is clear (i.e. unloading), cpuhp removal is handled |
| 3785 | * in hba_unset |
| 3786 | */ |
| 3787 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 3788 | __lpfc_cpuhp_remove(phba); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3789 | |
| 3790 | if (phba->cfg_xri_rebalancing) |
| 3791 | lpfc_destroy_multixri_pools(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3792 | } |
| 3793 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3794 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3795 | * 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] | 3796 | * @phba: pointer to lpfc hba data structure. |
| 3797 | * |
| 3798 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3799 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3800 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3801 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3802 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3803 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3804 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3805 | struct lpfc_io_buf *sb, *sb_next; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3806 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3807 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3808 | return; |
| 3809 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3810 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3811 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3812 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3813 | |
| 3814 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3815 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3816 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3817 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3818 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3819 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3820 | kfree(sb); |
| 3821 | phba->total_scsi_bufs--; |
| 3822 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3823 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3824 | |
| 3825 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3826 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3827 | list) { |
| 3828 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3829 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3830 | sb->dma_handle); |
| 3831 | kfree(sb); |
| 3832 | phba->total_scsi_bufs--; |
| 3833 | } |
| 3834 | spin_unlock(&phba->scsi_buf_list_get_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3835 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3836 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3837 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3838 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3839 | * 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] | 3840 | * @phba: pointer to lpfc hba data structure. |
| 3841 | * |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3842 | * 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] | 3843 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3844 | * the internal resources before the device is removed from the system. |
| 3845 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3846 | void |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3847 | lpfc_io_free(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3848 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3849 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3850 | struct lpfc_sli4_hdw_queue *qp; |
| 3851 | int idx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3852 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3853 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3854 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3855 | /* Release all the lpfc_nvme_bufs maintained by this host. */ |
| 3856 | spin_lock(&qp->io_buf_list_put_lock); |
| 3857 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3858 | &qp->lpfc_io_buf_list_put, |
| 3859 | list) { |
| 3860 | list_del(&lpfc_ncmd->list); |
| 3861 | qp->put_io_bufs--; |
| 3862 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3863 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3864 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 3865 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 3866 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3867 | kfree(lpfc_ncmd); |
| 3868 | qp->total_io_bufs--; |
| 3869 | } |
| 3870 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3871 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3872 | spin_lock(&qp->io_buf_list_get_lock); |
| 3873 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3874 | &qp->lpfc_io_buf_list_get, |
| 3875 | list) { |
| 3876 | list_del(&lpfc_ncmd->list); |
| 3877 | qp->get_io_bufs--; |
| 3878 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3879 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3880 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 3881 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 3882 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3883 | kfree(lpfc_ncmd); |
| 3884 | qp->total_io_bufs--; |
| 3885 | } |
| 3886 | spin_unlock(&qp->io_buf_list_get_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3887 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3888 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3889 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3890 | /** |
| 3891 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3892 | * @phba: pointer to lpfc hba data structure. |
| 3893 | * |
| 3894 | * This routine first calculates the sizes of the current els and allocated |
| 3895 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3896 | * XRIs assigned due to port function reset. During port initialization, the |
| 3897 | * current els and allocated scsi sgl lists are 0s. |
| 3898 | * |
| 3899 | * Return codes |
| 3900 | * 0 - successful (for now, it always returns 0) |
| 3901 | **/ |
| 3902 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3903 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3904 | { |
| 3905 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3906 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3907 | LIST_HEAD(els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3908 | int rc; |
| 3909 | |
| 3910 | /* |
| 3911 | * update on pci function's els xri-sgl list |
| 3912 | */ |
| 3913 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3914 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3915 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3916 | /* els xri-sgl expanded */ |
| 3917 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3918 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3919 | "3157 ELS xri-sgl count increased from " |
| 3920 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3921 | els_xri_cnt); |
| 3922 | /* allocate the additional els sgls */ |
| 3923 | for (i = 0; i < xri_cnt; i++) { |
| 3924 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3925 | GFP_KERNEL); |
| 3926 | if (sglq_entry == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3927 | lpfc_printf_log(phba, KERN_ERR, |
| 3928 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3929 | "2562 Failure to allocate an " |
| 3930 | "ELS sgl entry:%d\n", i); |
| 3931 | rc = -ENOMEM; |
| 3932 | goto out_free_mem; |
| 3933 | } |
| 3934 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3935 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3936 | &sglq_entry->phys); |
| 3937 | if (sglq_entry->virt == NULL) { |
| 3938 | kfree(sglq_entry); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3939 | lpfc_printf_log(phba, KERN_ERR, |
| 3940 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3941 | "2563 Failure to allocate an " |
| 3942 | "ELS mbuf:%d\n", i); |
| 3943 | rc = -ENOMEM; |
| 3944 | goto out_free_mem; |
| 3945 | } |
| 3946 | sglq_entry->sgl = sglq_entry->virt; |
| 3947 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3948 | sglq_entry->state = SGL_FREED; |
| 3949 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3950 | } |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3951 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3952 | list_splice_init(&els_sgl_list, |
| 3953 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3954 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3955 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3956 | /* els xri-sgl shrinked */ |
| 3957 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3958 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3959 | "3158 ELS xri-sgl count decreased from " |
| 3960 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3961 | els_xri_cnt); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3962 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3963 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, |
| 3964 | &els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3965 | /* release extra els sgls from list */ |
| 3966 | for (i = 0; i < xri_cnt; i++) { |
| 3967 | list_remove_head(&els_sgl_list, |
| 3968 | sglq_entry, struct lpfc_sglq, list); |
| 3969 | if (sglq_entry) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3970 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3971 | sglq_entry->phys); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3972 | kfree(sglq_entry); |
| 3973 | } |
| 3974 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3975 | list_splice_init(&els_sgl_list, |
| 3976 | &phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 3977 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3978 | } else |
| 3979 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3980 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3981 | els_xri_cnt); |
| 3982 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3983 | |
| 3984 | /* update xris to els sgls on the list */ |
| 3985 | sglq_entry = NULL; |
| 3986 | sglq_entry_next = NULL; |
| 3987 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3988 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3989 | lxri = lpfc_sli4_next_xritag(phba); |
| 3990 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3991 | lpfc_printf_log(phba, KERN_ERR, |
| 3992 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3993 | "2400 Failed to allocate xri for " |
| 3994 | "ELS sgl\n"); |
| 3995 | rc = -ENOMEM; |
| 3996 | goto out_free_mem; |
| 3997 | } |
| 3998 | sglq_entry->sli4_lxritag = lxri; |
| 3999 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 4000 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4001 | return 0; |
| 4002 | |
| 4003 | out_free_mem: |
| 4004 | lpfc_free_els_sgl_list(phba); |
| 4005 | return rc; |
| 4006 | } |
| 4007 | |
| 4008 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 4009 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping |
| 4010 | * @phba: pointer to lpfc hba data structure. |
| 4011 | * |
| 4012 | * This routine first calculates the sizes of the current els and allocated |
| 4013 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 4014 | * XRIs assigned due to port function reset. During port initialization, the |
| 4015 | * current els and allocated scsi sgl lists are 0s. |
| 4016 | * |
| 4017 | * Return codes |
| 4018 | * 0 - successful (for now, it always returns 0) |
| 4019 | **/ |
| 4020 | int |
| 4021 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) |
| 4022 | { |
| 4023 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 4024 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 4025 | uint16_t nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 4026 | LIST_HEAD(nvmet_sgl_list); |
| 4027 | int rc; |
| 4028 | |
| 4029 | /* |
| 4030 | * update on pci function's nvmet xri-sgl list |
| 4031 | */ |
| 4032 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 4033 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 4034 | /* For NVMET, ALL remaining XRIs are dedicated for IO processing */ |
| 4035 | 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] | 4036 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { |
| 4037 | /* els xri-sgl expanded */ |
| 4038 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; |
| 4039 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4040 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", |
| 4041 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); |
| 4042 | /* allocate the additional nvmet sgls */ |
| 4043 | for (i = 0; i < xri_cnt; i++) { |
| 4044 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 4045 | GFP_KERNEL); |
| 4046 | if (sglq_entry == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4047 | lpfc_printf_log(phba, KERN_ERR, |
| 4048 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 4049 | "6303 Failure to allocate an " |
| 4050 | "NVMET sgl entry:%d\n", i); |
| 4051 | rc = -ENOMEM; |
| 4052 | goto out_free_mem; |
| 4053 | } |
| 4054 | sglq_entry->buff_type = NVMET_BUFF_TYPE; |
| 4055 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, |
| 4056 | &sglq_entry->phys); |
| 4057 | if (sglq_entry->virt == NULL) { |
| 4058 | kfree(sglq_entry); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4059 | lpfc_printf_log(phba, KERN_ERR, |
| 4060 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 4061 | "6304 Failure to allocate an " |
| 4062 | "NVMET buf:%d\n", i); |
| 4063 | rc = -ENOMEM; |
| 4064 | goto out_free_mem; |
| 4065 | } |
| 4066 | sglq_entry->sgl = sglq_entry->virt; |
| 4067 | memset(sglq_entry->sgl, 0, |
| 4068 | phba->cfg_sg_dma_buf_size); |
| 4069 | sglq_entry->state = SGL_FREED; |
| 4070 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); |
| 4071 | } |
| 4072 | spin_lock_irq(&phba->hbalock); |
| 4073 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 4074 | list_splice_init(&nvmet_sgl_list, |
| 4075 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 4076 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 4077 | spin_unlock_irq(&phba->hbalock); |
| 4078 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { |
| 4079 | /* nvmet xri-sgl shrunk */ |
| 4080 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; |
| 4081 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4082 | "6305 NVMET xri-sgl count decreased from " |
| 4083 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, |
| 4084 | nvmet_xri_cnt); |
| 4085 | spin_lock_irq(&phba->hbalock); |
| 4086 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 4087 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 4088 | &nvmet_sgl_list); |
| 4089 | /* release extra nvmet sgls from list */ |
| 4090 | for (i = 0; i < xri_cnt; i++) { |
| 4091 | list_remove_head(&nvmet_sgl_list, |
| 4092 | sglq_entry, struct lpfc_sglq, list); |
| 4093 | if (sglq_entry) { |
| 4094 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, |
| 4095 | sglq_entry->phys); |
| 4096 | kfree(sglq_entry); |
| 4097 | } |
| 4098 | } |
| 4099 | list_splice_init(&nvmet_sgl_list, |
| 4100 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 4101 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 4102 | spin_unlock_irq(&phba->hbalock); |
| 4103 | } else |
| 4104 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 4105 | "6306 NVMET xri-sgl count unchanged: %d\n", |
| 4106 | nvmet_xri_cnt); |
| 4107 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; |
| 4108 | |
| 4109 | /* update xris to nvmet sgls on the list */ |
| 4110 | sglq_entry = NULL; |
| 4111 | sglq_entry_next = NULL; |
| 4112 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 4113 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { |
| 4114 | lxri = lpfc_sli4_next_xritag(phba); |
| 4115 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4116 | lpfc_printf_log(phba, KERN_ERR, |
| 4117 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 4118 | "6307 Failed to allocate xri for " |
| 4119 | "NVMET sgl\n"); |
| 4120 | rc = -ENOMEM; |
| 4121 | goto out_free_mem; |
| 4122 | } |
| 4123 | sglq_entry->sli4_lxritag = lxri; |
| 4124 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 4125 | } |
| 4126 | return 0; |
| 4127 | |
| 4128 | out_free_mem: |
| 4129 | lpfc_free_nvmet_sgl_list(phba); |
| 4130 | return rc; |
| 4131 | } |
| 4132 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4133 | int |
| 4134 | lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf) |
| 4135 | { |
| 4136 | LIST_HEAD(blist); |
| 4137 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4138 | struct lpfc_io_buf *lpfc_cmd; |
| 4139 | struct lpfc_io_buf *iobufp, *prev_iobufp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4140 | int idx, cnt, xri, inserted; |
| 4141 | |
| 4142 | cnt = 0; |
| 4143 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 4144 | qp = &phba->sli4_hba.hdwq[idx]; |
| 4145 | spin_lock_irq(&qp->io_buf_list_get_lock); |
| 4146 | spin_lock(&qp->io_buf_list_put_lock); |
| 4147 | |
| 4148 | /* Take everything off the get and put lists */ |
| 4149 | list_splice_init(&qp->lpfc_io_buf_list_get, &blist); |
| 4150 | list_splice(&qp->lpfc_io_buf_list_put, &blist); |
| 4151 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 4152 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 4153 | cnt += qp->get_io_bufs + qp->put_io_bufs; |
| 4154 | qp->get_io_bufs = 0; |
| 4155 | qp->put_io_bufs = 0; |
| 4156 | qp->total_io_bufs = 0; |
| 4157 | spin_unlock(&qp->io_buf_list_put_lock); |
| 4158 | spin_unlock_irq(&qp->io_buf_list_get_lock); |
| 4159 | } |
| 4160 | |
| 4161 | /* |
| 4162 | * Take IO buffers off blist and put on cbuf sorted by XRI. |
| 4163 | * This is because POST_SGL takes a sequential range of XRIs |
| 4164 | * to post to the firmware. |
| 4165 | */ |
| 4166 | for (idx = 0; idx < cnt; idx++) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4167 | list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4168 | if (!lpfc_cmd) |
| 4169 | return cnt; |
| 4170 | if (idx == 0) { |
| 4171 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 4172 | continue; |
| 4173 | } |
| 4174 | xri = lpfc_cmd->cur_iocbq.sli4_xritag; |
| 4175 | inserted = 0; |
| 4176 | prev_iobufp = NULL; |
| 4177 | list_for_each_entry(iobufp, cbuf, list) { |
| 4178 | if (xri < iobufp->cur_iocbq.sli4_xritag) { |
| 4179 | if (prev_iobufp) |
| 4180 | list_add(&lpfc_cmd->list, |
| 4181 | &prev_iobufp->list); |
| 4182 | else |
| 4183 | list_add(&lpfc_cmd->list, cbuf); |
| 4184 | inserted = 1; |
| 4185 | break; |
| 4186 | } |
| 4187 | prev_iobufp = iobufp; |
| 4188 | } |
| 4189 | if (!inserted) |
| 4190 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 4191 | } |
| 4192 | return cnt; |
| 4193 | } |
| 4194 | |
| 4195 | int |
| 4196 | lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf) |
| 4197 | { |
| 4198 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4199 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4200 | int idx, cnt; |
| 4201 | |
| 4202 | qp = phba->sli4_hba.hdwq; |
| 4203 | cnt = 0; |
| 4204 | while (!list_empty(cbuf)) { |
| 4205 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 4206 | list_remove_head(cbuf, lpfc_cmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4207 | struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4208 | if (!lpfc_cmd) |
| 4209 | return cnt; |
| 4210 | cnt++; |
| 4211 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 4212 | lpfc_cmd->hdwq_no = idx; |
| 4213 | lpfc_cmd->hdwq = qp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4214 | lpfc_cmd->cur_iocbq.wqe_cmpl = NULL; |
| 4215 | lpfc_cmd->cur_iocbq.iocb_cmpl = NULL; |
| 4216 | spin_lock(&qp->io_buf_list_put_lock); |
| 4217 | list_add_tail(&lpfc_cmd->list, |
| 4218 | &qp->lpfc_io_buf_list_put); |
| 4219 | qp->put_io_bufs++; |
| 4220 | qp->total_io_bufs++; |
| 4221 | spin_unlock(&qp->io_buf_list_put_lock); |
| 4222 | } |
| 4223 | } |
| 4224 | return cnt; |
| 4225 | } |
| 4226 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 4227 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4228 | * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4229 | * @phba: pointer to lpfc hba data structure. |
| 4230 | * |
| 4231 | * This routine first calculates the sizes of the current els and allocated |
| 4232 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 4233 | * XRIs assigned due to port function reset. During port initialization, the |
| 4234 | * current els and allocated scsi sgl lists are 0s. |
| 4235 | * |
| 4236 | * Return codes |
| 4237 | * 0 - successful (for now, it always returns 0) |
| 4238 | **/ |
| 4239 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4240 | lpfc_sli4_io_sgl_update(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4241 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4242 | struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4243 | uint16_t i, lxri, els_xri_cnt; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4244 | uint16_t io_xri_cnt, io_xri_max; |
| 4245 | LIST_HEAD(io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4246 | int rc, cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4247 | |
| 4248 | /* |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4249 | * update on pci function's allocated nvme xri-sgl list |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4250 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4251 | |
| 4252 | /* maximum number of xris available for nvme buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4253 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4254 | io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 4255 | phba->sli4_hba.io_xri_max = io_xri_max; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4256 | |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4257 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4258 | "6074 Current allocated XRI sgl count:%d, " |
| 4259 | "maximum XRI count:%d\n", |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4260 | phba->sli4_hba.io_xri_cnt, |
| 4261 | phba->sli4_hba.io_xri_max); |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4262 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4263 | cnt = lpfc_io_buf_flush(phba, &io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4264 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4265 | 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] | 4266 | /* max nvme xri shrunk below the allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4267 | io_xri_cnt = phba->sli4_hba.io_xri_cnt - |
| 4268 | phba->sli4_hba.io_xri_max; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4269 | /* release the extra allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4270 | for (i = 0; i < io_xri_cnt; i++) { |
| 4271 | list_remove_head(&io_sgl_list, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4272 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4273 | if (lpfc_ncmd) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 4274 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4275 | lpfc_ncmd->data, |
| 4276 | lpfc_ncmd->dma_handle); |
| 4277 | kfree(lpfc_ncmd); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 4278 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4279 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4280 | phba->sli4_hba.io_xri_cnt -= io_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4281 | } |
| 4282 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4283 | /* update xris associated to remaining allocated nvme buffers */ |
| 4284 | lpfc_ncmd = NULL; |
| 4285 | lpfc_ncmd_next = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4286 | phba->sli4_hba.io_xri_cnt = cnt; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4287 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4288 | &io_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4289 | lxri = lpfc_sli4_next_xritag(phba); |
| 4290 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4291 | lpfc_printf_log(phba, KERN_ERR, |
| 4292 | LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4293 | "6075 Failed to allocate xri for " |
| 4294 | "nvme buffer\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4295 | rc = -ENOMEM; |
| 4296 | goto out_free_mem; |
| 4297 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4298 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; |
| 4299 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4300 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4301 | cnt = lpfc_io_buf_replenish(phba, &io_sgl_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4302 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4303 | |
| 4304 | out_free_mem: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4305 | lpfc_io_free(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4306 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4307 | } |
| 4308 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4309 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4310 | * 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] | 4311 | * @phba: Pointer to lpfc hba data structure. |
| 4312 | * @num_to_alloc: The requested number of buffers to allocate. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4313 | * |
| 4314 | * This routine allocates nvme buffers for device with SLI-4 interface spec, |
| 4315 | * the nvme buffer contains all the necessary information needed to initiate |
| 4316 | * an I/O. After allocating up to @num_to_allocate IO buffers and put |
| 4317 | * them on a list, it post them to the port by using SGL block post. |
| 4318 | * |
| 4319 | * Return codes: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4320 | * int - number of IO buffers that were allocated and posted. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4321 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 4322 | **/ |
| 4323 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4324 | lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4325 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4326 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4327 | struct lpfc_iocbq *pwqeq; |
| 4328 | uint16_t iotag, lxri = 0; |
| 4329 | int bcnt, num_posted; |
| 4330 | LIST_HEAD(prep_nblist); |
| 4331 | LIST_HEAD(post_nblist); |
| 4332 | LIST_HEAD(nvme_nblist); |
| 4333 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4334 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4335 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
James Smart | 7f9989b | 2019-08-27 14:27:46 -0700 | [diff] [blame] | 4336 | lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4337 | if (!lpfc_ncmd) |
| 4338 | break; |
| 4339 | /* |
| 4340 | * Get memory from the pci pool to map the virt space to |
| 4341 | * pci bus space for an I/O. The DMA buffer includes the |
| 4342 | * number of SGE's necessary to support the sg_tablesize. |
| 4343 | */ |
Thomas Meyer | a5c990e | 2019-05-29 22:21:36 +0200 | [diff] [blame] | 4344 | lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
| 4345 | GFP_KERNEL, |
| 4346 | &lpfc_ncmd->dma_handle); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4347 | if (!lpfc_ncmd->data) { |
| 4348 | kfree(lpfc_ncmd); |
| 4349 | break; |
| 4350 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4351 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4352 | if (phba->cfg_xpsgl && !phba->nvmet_support) { |
| 4353 | INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list); |
| 4354 | } else { |
| 4355 | /* |
| 4356 | * 4K Page alignment is CRITICAL to BlockGuard, double |
| 4357 | * check to be sure. |
| 4358 | */ |
| 4359 | if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 4360 | (((unsigned long)(lpfc_ncmd->data) & |
| 4361 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4362 | lpfc_printf_log(phba, KERN_ERR, |
| 4363 | LOG_TRACE_EVENT, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4364 | "3369 Memory alignment err: " |
| 4365 | "addr=%lx\n", |
| 4366 | (unsigned long)lpfc_ncmd->data); |
| 4367 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4368 | lpfc_ncmd->data, |
| 4369 | lpfc_ncmd->dma_handle); |
| 4370 | kfree(lpfc_ncmd); |
| 4371 | break; |
| 4372 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4373 | } |
| 4374 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4375 | INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list); |
| 4376 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4377 | lxri = lpfc_sli4_next_xritag(phba); |
| 4378 | if (lxri == NO_XRI) { |
| 4379 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4380 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4381 | kfree(lpfc_ncmd); |
| 4382 | break; |
| 4383 | } |
| 4384 | pwqeq = &lpfc_ncmd->cur_iocbq; |
| 4385 | |
| 4386 | /* Allocate iotag for lpfc_ncmd->cur_iocbq. */ |
| 4387 | iotag = lpfc_sli_next_iotag(phba, pwqeq); |
| 4388 | if (iotag == 0) { |
| 4389 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4390 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4391 | kfree(lpfc_ncmd); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4392 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4393 | "6121 Failed to allocate IOTAG for" |
| 4394 | " XRI:0x%x\n", lxri); |
| 4395 | lpfc_sli4_free_xri(phba, lxri); |
| 4396 | break; |
| 4397 | } |
| 4398 | pwqeq->sli4_lxritag = lxri; |
| 4399 | pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 4400 | pwqeq->context1 = lpfc_ncmd; |
| 4401 | |
| 4402 | /* Initialize local short-hand pointers. */ |
| 4403 | lpfc_ncmd->dma_sgl = lpfc_ncmd->data; |
| 4404 | lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle; |
| 4405 | lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4406 | spin_lock_init(&lpfc_ncmd->buf_lock); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4407 | |
| 4408 | /* add the nvme buffer to a post list */ |
| 4409 | list_add_tail(&lpfc_ncmd->list, &post_nblist); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4410 | phba->sli4_hba.io_xri_cnt++; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4411 | } |
| 4412 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME, |
| 4413 | "6114 Allocate %d out of %d requested new NVME " |
| 4414 | "buffers\n", bcnt, num_to_alloc); |
| 4415 | |
| 4416 | /* post the list of nvme buffer sgls to port if available */ |
| 4417 | if (!list_empty(&post_nblist)) |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4418 | num_posted = lpfc_sli4_post_io_sgl_list( |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4419 | phba, &post_nblist, bcnt); |
| 4420 | else |
| 4421 | num_posted = 0; |
| 4422 | |
| 4423 | return num_posted; |
| 4424 | } |
| 4425 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4426 | static uint64_t |
| 4427 | lpfc_get_wwpn(struct lpfc_hba *phba) |
| 4428 | { |
| 4429 | uint64_t wwn; |
| 4430 | int rc; |
| 4431 | LPFC_MBOXQ_t *mboxq; |
| 4432 | MAILBOX_t *mb; |
| 4433 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4434 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4435 | GFP_KERNEL); |
| 4436 | if (!mboxq) |
| 4437 | return (uint64_t)-1; |
| 4438 | |
| 4439 | /* First get WWN of HBA instance */ |
| 4440 | lpfc_read_nv(phba, mboxq); |
| 4441 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4442 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4443 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4444 | "6019 Mailbox failed , mbxCmd x%x " |
| 4445 | "READ_NV, mbxStatus x%x\n", |
| 4446 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4447 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 4448 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4449 | return (uint64_t) -1; |
| 4450 | } |
| 4451 | mb = &mboxq->u.mb; |
| 4452 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t)); |
| 4453 | /* wwn is WWPN of HBA instance */ |
| 4454 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4455 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4456 | return be64_to_cpu(wwn); |
| 4457 | else |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 4458 | return rol64(wwn, 32); |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4459 | } |
| 4460 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4461 | /** |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 4462 | * lpfc_vmid_res_alloc - Allocates resources for VMID |
| 4463 | * @phba: pointer to lpfc hba data structure. |
| 4464 | * @vport: pointer to vport data structure |
| 4465 | * |
| 4466 | * This routine allocated the resources needed for the VMID. |
| 4467 | * |
| 4468 | * Return codes |
| 4469 | * 0 on Success |
| 4470 | * Non-0 on Failure |
| 4471 | */ |
| 4472 | static int |
| 4473 | lpfc_vmid_res_alloc(struct lpfc_hba *phba, struct lpfc_vport *vport) |
| 4474 | { |
| 4475 | /* VMID feature is supported only on SLI4 */ |
| 4476 | if (phba->sli_rev == LPFC_SLI_REV3) { |
| 4477 | phba->cfg_vmid_app_header = 0; |
| 4478 | phba->cfg_vmid_priority_tagging = 0; |
| 4479 | } |
| 4480 | |
| 4481 | if (lpfc_is_vmid_enabled(phba)) { |
| 4482 | vport->vmid = |
| 4483 | kcalloc(phba->cfg_max_vmid, sizeof(struct lpfc_vmid), |
| 4484 | GFP_KERNEL); |
| 4485 | if (!vport->vmid) |
| 4486 | return -ENOMEM; |
| 4487 | |
| 4488 | rwlock_init(&vport->vmid_lock); |
| 4489 | |
| 4490 | /* Set the VMID parameters for the vport */ |
| 4491 | vport->vmid_priority_tagging = phba->cfg_vmid_priority_tagging; |
| 4492 | vport->vmid_inactivity_timeout = |
| 4493 | phba->cfg_vmid_inactivity_timeout; |
| 4494 | vport->max_vmid = phba->cfg_max_vmid; |
| 4495 | vport->cur_vmid_cnt = 0; |
| 4496 | |
| 4497 | vport->vmid_priority_range = bitmap_zalloc |
| 4498 | (LPFC_VMID_MAX_PRIORITY_RANGE, GFP_KERNEL); |
| 4499 | |
| 4500 | if (!vport->vmid_priority_range) { |
| 4501 | kfree(vport->vmid); |
| 4502 | return -ENOMEM; |
| 4503 | } |
| 4504 | |
| 4505 | hash_init(vport->hash_table); |
| 4506 | } |
| 4507 | return 0; |
| 4508 | } |
| 4509 | |
| 4510 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4511 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4512 | * @phba: pointer to lpfc hba data structure. |
| 4513 | * @instance: a unique integer ID to this FC port. |
| 4514 | * @dev: pointer to the device data structure. |
| 4515 | * |
| 4516 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 4517 | * can be created on top of either a physical port or a virtual port provided |
| 4518 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 4519 | * and associates the FC port created before adding the shost into the SCSI |
| 4520 | * layer. |
| 4521 | * |
| 4522 | * Return codes |
| 4523 | * @vport - pointer to the virtual N_Port data structure. |
| 4524 | * NULL - port create failed. |
| 4525 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4526 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4527 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4528 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4529 | struct lpfc_vport *vport; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4530 | struct Scsi_Host *shost = NULL; |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4531 | struct scsi_host_template *template; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4532 | int error = 0; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4533 | int i; |
| 4534 | uint64_t wwn; |
| 4535 | bool use_no_reset_hba = false; |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4536 | int rc; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4537 | |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4538 | if (lpfc_no_hba_reset_cnt) { |
| 4539 | if (phba->sli_rev < LPFC_SLI_REV4 && |
| 4540 | dev == &phba->pcidev->dev) { |
| 4541 | /* Reset the port first */ |
| 4542 | lpfc_sli_brdrestart(phba); |
| 4543 | rc = lpfc_sli_chipset_init(phba); |
| 4544 | if (rc) |
| 4545 | return NULL; |
| 4546 | } |
| 4547 | wwn = lpfc_get_wwpn(phba); |
| 4548 | } |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4549 | |
| 4550 | for (i = 0; i < lpfc_no_hba_reset_cnt; i++) { |
| 4551 | if (wwn == lpfc_no_hba_reset[i]) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4552 | lpfc_printf_log(phba, KERN_ERR, |
| 4553 | LOG_TRACE_EVENT, |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4554 | "6020 Setting use_no_reset port=%llx\n", |
| 4555 | wwn); |
| 4556 | use_no_reset_hba = true; |
| 4557 | break; |
| 4558 | } |
| 4559 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4560 | |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4561 | /* Seed template for SCSI host registration */ |
| 4562 | if (dev == &phba->pcidev->dev) { |
| 4563 | template = &phba->port_template; |
| 4564 | |
| 4565 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 4566 | /* Seed physical port template */ |
| 4567 | memcpy(template, &lpfc_template, sizeof(*template)); |
| 4568 | |
James Smart | 7c30bb6 | 2020-10-20 13:27:16 -0700 | [diff] [blame] | 4569 | if (use_no_reset_hba) |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4570 | /* template is for a no reset SCSI Host */ |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4571 | template->eh_host_reset_handler = NULL; |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4572 | |
| 4573 | /* Template for all vports this physical port creates */ |
| 4574 | memcpy(&phba->vport_template, &lpfc_template, |
| 4575 | sizeof(*template)); |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4576 | phba->vport_template.shost_attrs = lpfc_vport_attrs; |
| 4577 | phba->vport_template.eh_bus_reset_handler = NULL; |
| 4578 | phba->vport_template.eh_host_reset_handler = NULL; |
| 4579 | phba->vport_template.vendor_id = 0; |
| 4580 | |
| 4581 | /* Initialize the host templates with updated value */ |
| 4582 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4583 | template->sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 4584 | phba->vport_template.sg_tablesize = |
| 4585 | phba->cfg_scsi_seg_cnt; |
| 4586 | } else { |
| 4587 | template->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4588 | phba->vport_template.sg_tablesize = |
| 4589 | phba->cfg_sg_seg_cnt; |
| 4590 | } |
| 4591 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4592 | } else { |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4593 | /* NVMET is for physical port only */ |
| 4594 | memcpy(template, &lpfc_template_nvme, |
| 4595 | sizeof(*template)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4596 | } |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4597 | } else { |
| 4598 | template = &phba->vport_template; |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 4599 | } |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4600 | |
| 4601 | shost = scsi_host_alloc(template, sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4602 | if (!shost) |
| 4603 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4604 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4605 | vport = (struct lpfc_vport *) shost->hostdata; |
| 4606 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4607 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4608 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4609 | vport->fc_rscn_flush = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4610 | lpfc_get_vport_cfgparam(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4611 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4612 | /* Adjust value in vport */ |
| 4613 | vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type; |
| 4614 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4615 | shost->unique_id = instance; |
| 4616 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4617 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4618 | shost->this_id = -1; |
| 4619 | shost->max_cmd_len = 16; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4620 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4621 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 77ffd34 | 2019-08-15 19:36:49 -0700 | [diff] [blame] | 4622 | if (!phba->cfg_fcp_mq_threshold || |
| 4623 | phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue) |
| 4624 | phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue; |
| 4625 | |
| 4626 | shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(), |
| 4627 | phba->cfg_fcp_mq_threshold); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4628 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4629 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4630 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4631 | |
| 4632 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 4633 | shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE; |
| 4634 | else |
| 4635 | shost->sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 4636 | } else |
| 4637 | /* SLI-3 has a limited number of hardware queues (3), |
| 4638 | * thus there is only one for FCP processing. |
| 4639 | */ |
| 4640 | shost->nr_hw_queues = 1; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 4641 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4642 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4643 | * Set initial can_queue value since 0 is no longer supported and |
| 4644 | * scsi_add_host will fail. This will be adjusted later based on the |
| 4645 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4646 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4647 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4648 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4649 | shost->transportt = lpfc_vport_transport_template; |
| 4650 | vport->port_type = LPFC_NPIV_PORT; |
| 4651 | } else { |
| 4652 | shost->transportt = lpfc_transport_template; |
| 4653 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 4654 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4655 | |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4656 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 4657 | "9081 CreatePort TMPLATE type %x TBLsize %d " |
| 4658 | "SEGcnt %d/%d\n", |
| 4659 | vport->port_type, shost->sg_tablesize, |
| 4660 | phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt); |
| 4661 | |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 4662 | /* Allocate the resources for VMID */ |
| 4663 | rc = lpfc_vmid_res_alloc(phba, vport); |
| 4664 | |
| 4665 | if (rc) |
| 4666 | goto out; |
| 4667 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4668 | /* Initialize all internally managed lists. */ |
| 4669 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4670 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4671 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4672 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4673 | timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4674 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4675 | timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4676 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4677 | timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4678 | |
James Smart | aa6ff30 | 2019-05-21 17:49:09 -0700 | [diff] [blame] | 4679 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 4680 | lpfc_setup_bg(phba, shost); |
| 4681 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 4682 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4683 | if (error) |
| 4684 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4685 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4686 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4687 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4688 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4689 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4690 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4691 | out_put_shost: |
Gaurav Srivastava | 5e63330 | 2021-06-08 10:05:49 +0530 | [diff] [blame] | 4692 | kfree(vport->vmid); |
| 4693 | bitmap_free(vport->vmid_priority_range); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4694 | scsi_host_put(shost); |
| 4695 | out: |
| 4696 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4697 | } |
| 4698 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4699 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4700 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4701 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 4702 | * |
| 4703 | * This routine destroys a FC port from the upper layer protocol. All the |
| 4704 | * resources associated with the port are released. |
| 4705 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4706 | void |
| 4707 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4708 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4709 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4710 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4711 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4712 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4713 | fc_remove_host(shost); |
| 4714 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4715 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4716 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4717 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4718 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4719 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4720 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4721 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4722 | } |
| 4723 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4724 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4725 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4726 | * |
| 4727 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 4728 | * uses the kernel idr facility to perform the task. |
| 4729 | * |
| 4730 | * Return codes: |
| 4731 | * instance - a unique integer ID allocated as the new instance. |
| 4732 | * -1 - lpfc get instance failed. |
| 4733 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4734 | int |
| 4735 | lpfc_get_instance(void) |
| 4736 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4737 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4738 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4739 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 4740 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4741 | } |
| 4742 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4743 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4744 | * 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] | 4745 | * @shost: pointer to SCSI host data structure. |
| 4746 | * @time: elapsed time of the scan in jiffies. |
| 4747 | * |
| 4748 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 4749 | * whether the scan host is finished. |
| 4750 | * |
| 4751 | * Note: there is no scan_start function as adapter initialization will have |
| 4752 | * asynchronously kicked off the link initialization. |
| 4753 | * |
| 4754 | * Return codes |
| 4755 | * 0 - SCSI host scan is not over yet. |
| 4756 | * 1 - SCSI host scan is over. |
| 4757 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4758 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 4759 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4760 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4761 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4762 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4763 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4764 | spin_lock_irq(shost->host_lock); |
| 4765 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4766 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4767 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4768 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4769 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4770 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4771 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4772 | "0461 Scanning longer than 30 " |
| 4773 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4774 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4775 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4776 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4777 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 4778 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4779 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4780 | "0465 Link down longer than 15 " |
| 4781 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4782 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4783 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4784 | } |
| 4785 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4786 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4787 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4788 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4789 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4790 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4791 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4792 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4793 | goto finished; |
| 4794 | |
| 4795 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4796 | |
| 4797 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4798 | spin_unlock_irq(shost->host_lock); |
| 4799 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4800 | } |
| 4801 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 4802 | static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost) |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4803 | { |
| 4804 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; |
| 4805 | struct lpfc_hba *phba = vport->phba; |
| 4806 | |
| 4807 | fc_host_supported_speeds(shost) = 0; |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 4808 | /* |
| 4809 | * Avoid reporting supported link speed for FCoE as it can't be |
| 4810 | * controlled via FCoE. |
| 4811 | */ |
| 4812 | if (phba->hba_flag & HBA_FCOE_MODE) |
| 4813 | return; |
| 4814 | |
James Smart | bfc4778 | 2021-07-22 15:17:19 -0700 | [diff] [blame] | 4815 | if (phba->lmt & LMT_256Gb) |
| 4816 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_256GBIT; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4817 | if (phba->lmt & LMT_128Gb) |
| 4818 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4819 | if (phba->lmt & LMT_64Gb) |
| 4820 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT; |
| 4821 | if (phba->lmt & LMT_32Gb) |
| 4822 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
| 4823 | if (phba->lmt & LMT_16Gb) |
| 4824 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
| 4825 | if (phba->lmt & LMT_10Gb) |
| 4826 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
| 4827 | if (phba->lmt & LMT_8Gb) |
| 4828 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
| 4829 | if (phba->lmt & LMT_4Gb) |
| 4830 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 4831 | if (phba->lmt & LMT_2Gb) |
| 4832 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 4833 | if (phba->lmt & LMT_1Gb) |
| 4834 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 4835 | } |
| 4836 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4837 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4838 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4839 | * @shost: pointer to SCSI host data structure. |
| 4840 | * |
| 4841 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 4842 | * SCSI host can be either on top of a physical port or a virtual port. |
| 4843 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4844 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 4845 | { |
| 4846 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4847 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4848 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4849 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4850 | */ |
| 4851 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4852 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 4853 | 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] | 4854 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 4855 | |
| 4856 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4857 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4858 | fc_host_supported_fc4s(shost)[2] = 1; |
| 4859 | fc_host_supported_fc4s(shost)[7] = 1; |
| 4860 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4861 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 4862 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4863 | |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4864 | lpfc_host_supported_speeds_set(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4865 | |
| 4866 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4867 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 4868 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4869 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 4870 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 4871 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4872 | /* This value is also unchanging */ |
| 4873 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4874 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4875 | fc_host_active_fc4s(shost)[2] = 1; |
| 4876 | fc_host_active_fc4s(shost)[7] = 1; |
| 4877 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4878 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4879 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4880 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4881 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4882 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4883 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4884 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4885 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4886 | * @phba: pointer to lpfc hba data structure. |
| 4887 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4888 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 4889 | * from generating interrupts and stops the device driver's timers for the |
| 4890 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4891 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4892 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4893 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4894 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4895 | /* Clear all interrupt enable conditions */ |
| 4896 | writel(0, phba->HCregaddr); |
| 4897 | readl(phba->HCregaddr); /* flush */ |
| 4898 | /* Clear all pending interrupts */ |
| 4899 | writel(0xffffffff, phba->HAregaddr); |
| 4900 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4901 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4902 | /* Reset some HBA SLI setup states */ |
| 4903 | lpfc_stop_hba_timers(phba); |
| 4904 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4905 | } |
| 4906 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4907 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4908 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4909 | * @phba: pointer to lpfc hba data structure. |
| 4910 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4911 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 4912 | * from generating interrupts and stops the device driver's timers for the |
| 4913 | * device. |
| 4914 | **/ |
| 4915 | static void |
| 4916 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 4917 | { |
| 4918 | /* Reset some HBA SLI4 setup states */ |
| 4919 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4920 | if (phba->pport) |
| 4921 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4922 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | /** |
| 4926 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 4927 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4928 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4929 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 4930 | * the API jump table function pointer from the lpfc_hba struct. |
| 4931 | **/ |
| 4932 | void |
| 4933 | lpfc_stop_port(struct lpfc_hba *phba) |
| 4934 | { |
| 4935 | phba->lpfc_stop_port(phba); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 4936 | |
| 4937 | if (phba->wq) |
| 4938 | flush_workqueue(phba->wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4939 | } |
| 4940 | |
| 4941 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4942 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 4943 | * @phba: Pointer to hba for which this call is being executed. |
| 4944 | * |
| 4945 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 4946 | **/ |
| 4947 | void |
| 4948 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 4949 | { |
| 4950 | unsigned long fcf_redisc_wait_tmo = |
| 4951 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 4952 | /* Start fcf rediscovery wait period timer */ |
| 4953 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 4954 | spin_lock_irq(&phba->hbalock); |
| 4955 | /* Allow action to new fcf asynchronous event */ |
| 4956 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 4957 | /* Mark the FCF rediscovery pending state */ |
| 4958 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 4959 | spin_unlock_irq(&phba->hbalock); |
| 4960 | } |
| 4961 | |
| 4962 | /** |
| 4963 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 4964 | * @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] | 4965 | * |
| 4966 | * This routine is invoked when waiting for FCF table rediscover has been |
| 4967 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 4968 | * wait period, a new FCF event shall be added to the FCOE async event |
| 4969 | * list, and then worker thread shall be waked up for processing from the |
| 4970 | * worker thread context. |
| 4971 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 4972 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4973 | lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4974 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4975 | struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4976 | |
| 4977 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 4978 | spin_lock_irq(&phba->hbalock); |
| 4979 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 4980 | spin_unlock_irq(&phba->hbalock); |
| 4981 | return; |
| 4982 | } |
| 4983 | /* Clear FCF rediscovery timer pending flag */ |
| 4984 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 4985 | /* FCF rediscovery event to worker thread */ |
| 4986 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 4987 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4988 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4989 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4990 | /* wake up worker thread */ |
| 4991 | lpfc_worker_wake_up(phba); |
| 4992 | } |
| 4993 | |
| 4994 | /** |
Gaurav Srivastava | 2039717 | 2021-06-08 10:05:54 +0530 | [diff] [blame] | 4995 | * lpfc_vmid_poll - VMID timeout detection |
James Smart | 50baa15 | 2021-07-07 11:43:35 -0700 | [diff] [blame] | 4996 | * @t: Timer context used to obtain the pointer to lpfc hba data structure. |
Gaurav Srivastava | 2039717 | 2021-06-08 10:05:54 +0530 | [diff] [blame] | 4997 | * |
| 4998 | * This routine is invoked when there is no I/O on by a VM for the specified |
| 4999 | * amount of time. When this situation is detected, the VMID has to be |
| 5000 | * deregistered from the switch and all the local resources freed. The VMID |
| 5001 | * will be reassigned to the VM once the I/O begins. |
| 5002 | **/ |
| 5003 | static void |
| 5004 | lpfc_vmid_poll(struct timer_list *t) |
| 5005 | { |
| 5006 | struct lpfc_hba *phba = from_timer(phba, t, inactive_vmid_poll); |
| 5007 | u32 wake_up = 0; |
| 5008 | |
| 5009 | /* check if there is a need to issue QFPA */ |
| 5010 | if (phba->pport->vmid_priority_tagging) { |
| 5011 | wake_up = 1; |
| 5012 | phba->pport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA; |
| 5013 | } |
| 5014 | |
| 5015 | /* Is the vmid inactivity timer enabled */ |
| 5016 | if (phba->pport->vmid_inactivity_timeout || |
| 5017 | phba->pport->load_flag & FC_DEREGISTER_ALL_APP_ID) { |
| 5018 | wake_up = 1; |
| 5019 | phba->pport->work_port_events |= WORKER_CHECK_INACTIVE_VMID; |
| 5020 | } |
| 5021 | |
| 5022 | if (wake_up) |
| 5023 | lpfc_worker_wake_up(phba); |
| 5024 | |
| 5025 | /* restart the timer for the next iteration */ |
| 5026 | mod_timer(&phba->inactive_vmid_poll, jiffies + msecs_to_jiffies(1000 * |
| 5027 | LPFC_VMID_TIMER)); |
| 5028 | } |
| 5029 | |
| 5030 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5031 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 5032 | * @phba: pointer to lpfc hba data structure. |
| 5033 | * @acqe_link: pointer to the async link completion queue entry. |
| 5034 | * |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5035 | * This routine is to parse the SLI4 link-attention link fault code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5036 | **/ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5037 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5038 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 5039 | struct lpfc_acqe_link *acqe_link) |
| 5040 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5041 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 5042 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 5043 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 5044 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5045 | case LPFC_ASYNC_LINK_FAULT_LR_LRR: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5046 | break; |
| 5047 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5048 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5049 | "0398 Unknown link fault code: x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5050 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5051 | break; |
| 5052 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5053 | } |
| 5054 | |
| 5055 | /** |
| 5056 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 5057 | * @phba: pointer to lpfc hba data structure. |
| 5058 | * @acqe_link: pointer to the async link completion queue entry. |
| 5059 | * |
| 5060 | * This routine is to parse the SLI4 link attention type and translate it |
| 5061 | * into the base driver's link attention type coding. |
| 5062 | * |
| 5063 | * Return: Link attention type in terms of base driver's coding. |
| 5064 | **/ |
| 5065 | static uint8_t |
| 5066 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 5067 | struct lpfc_acqe_link *acqe_link) |
| 5068 | { |
| 5069 | uint8_t att_type; |
| 5070 | |
| 5071 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 5072 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 5073 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5074 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5075 | break; |
| 5076 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 5077 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5078 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5079 | break; |
| 5080 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5081 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5082 | break; |
| 5083 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5084 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5085 | "0399 Invalid link attention type: x%x\n", |
| 5086 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5087 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5088 | break; |
| 5089 | } |
| 5090 | return att_type; |
| 5091 | } |
| 5092 | |
| 5093 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5094 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 5095 | * @phba: pointer to lpfc hba data structure. |
| 5096 | * |
| 5097 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 5098 | * |
| 5099 | * Return: link speed in terms of Mbps. |
| 5100 | **/ |
| 5101 | uint32_t |
| 5102 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 5103 | { |
| 5104 | uint32_t link_speed; |
| 5105 | |
| 5106 | if (!lpfc_is_link_up(phba)) |
| 5107 | return 0; |
| 5108 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5109 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 5110 | switch (phba->fc_linkspeed) { |
| 5111 | case LPFC_LINK_SPEED_1GHZ: |
| 5112 | link_speed = 1000; |
| 5113 | break; |
| 5114 | case LPFC_LINK_SPEED_2GHZ: |
| 5115 | link_speed = 2000; |
| 5116 | break; |
| 5117 | case LPFC_LINK_SPEED_4GHZ: |
| 5118 | link_speed = 4000; |
| 5119 | break; |
| 5120 | case LPFC_LINK_SPEED_8GHZ: |
| 5121 | link_speed = 8000; |
| 5122 | break; |
| 5123 | case LPFC_LINK_SPEED_10GHZ: |
| 5124 | link_speed = 10000; |
| 5125 | break; |
| 5126 | case LPFC_LINK_SPEED_16GHZ: |
| 5127 | link_speed = 16000; |
| 5128 | break; |
| 5129 | default: |
| 5130 | link_speed = 0; |
| 5131 | } |
| 5132 | } else { |
| 5133 | if (phba->sli4_hba.link_state.logical_speed) |
| 5134 | link_speed = |
| 5135 | phba->sli4_hba.link_state.logical_speed; |
| 5136 | else |
| 5137 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5138 | } |
| 5139 | return link_speed; |
| 5140 | } |
| 5141 | |
| 5142 | /** |
| 5143 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 5144 | * @phba: pointer to lpfc hba data structure. |
| 5145 | * @evt_code: asynchronous event code. |
| 5146 | * @speed_code: asynchronous event link speed code. |
| 5147 | * |
| 5148 | * This routine is to parse the giving SLI4 async event link speed code into |
| 5149 | * value of Mbps for the link speed. |
| 5150 | * |
| 5151 | * Return: link speed in terms of Mbps. |
| 5152 | **/ |
| 5153 | static uint32_t |
| 5154 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 5155 | uint8_t speed_code) |
| 5156 | { |
| 5157 | uint32_t port_speed; |
| 5158 | |
| 5159 | switch (evt_code) { |
| 5160 | case LPFC_TRAILER_CODE_LINK: |
| 5161 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5162 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5163 | port_speed = 0; |
| 5164 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5165 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5166 | port_speed = 10; |
| 5167 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5168 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5169 | port_speed = 100; |
| 5170 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5171 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5172 | port_speed = 1000; |
| 5173 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5174 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5175 | port_speed = 10000; |
| 5176 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5177 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 5178 | port_speed = 20000; |
| 5179 | break; |
| 5180 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 5181 | port_speed = 25000; |
| 5182 | break; |
| 5183 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 5184 | port_speed = 40000; |
| 5185 | break; |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 5186 | case LPFC_ASYNC_LINK_SPEED_100GBPS: |
| 5187 | port_speed = 100000; |
| 5188 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5189 | default: |
| 5190 | port_speed = 0; |
| 5191 | } |
| 5192 | break; |
| 5193 | case LPFC_TRAILER_CODE_FC: |
| 5194 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5195 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5196 | port_speed = 0; |
| 5197 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5198 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5199 | port_speed = 1000; |
| 5200 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5201 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5202 | port_speed = 2000; |
| 5203 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5204 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5205 | port_speed = 4000; |
| 5206 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5207 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5208 | port_speed = 8000; |
| 5209 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5210 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5211 | port_speed = 10000; |
| 5212 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 5213 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5214 | port_speed = 16000; |
| 5215 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 5216 | case LPFC_FC_LA_SPEED_32G: |
| 5217 | port_speed = 32000; |
| 5218 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 5219 | case LPFC_FC_LA_SPEED_64G: |
| 5220 | port_speed = 64000; |
| 5221 | break; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5222 | case LPFC_FC_LA_SPEED_128G: |
| 5223 | port_speed = 128000; |
| 5224 | break; |
James Smart | bfc4778 | 2021-07-22 15:17:19 -0700 | [diff] [blame] | 5225 | case LPFC_FC_LA_SPEED_256G: |
| 5226 | port_speed = 256000; |
| 5227 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5228 | default: |
| 5229 | port_speed = 0; |
| 5230 | } |
| 5231 | break; |
| 5232 | default: |
| 5233 | port_speed = 0; |
| 5234 | } |
| 5235 | return port_speed; |
| 5236 | } |
| 5237 | |
| 5238 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5239 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5240 | * @phba: pointer to lpfc hba data structure. |
| 5241 | * @acqe_link: pointer to the async link completion queue entry. |
| 5242 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5243 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5244 | **/ |
| 5245 | static void |
| 5246 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 5247 | struct lpfc_acqe_link *acqe_link) |
| 5248 | { |
| 5249 | struct lpfc_dmabuf *mp; |
| 5250 | LPFC_MBOXQ_t *pmb; |
| 5251 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5252 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5253 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5254 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5255 | |
| 5256 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5257 | 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] | 5258 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 5259 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5260 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5261 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5262 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5263 | "0395 The mboxq allocation failed\n"); |
| 5264 | return; |
| 5265 | } |
| 5266 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5267 | if (!mp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5268 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5269 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 5270 | goto out_free_pmb; |
| 5271 | } |
| 5272 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 5273 | if (!mp->virt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5274 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5275 | "0397 The mbuf allocation failed\n"); |
| 5276 | goto out_free_dmabuf; |
| 5277 | } |
| 5278 | |
| 5279 | /* Cleanup any outstanding ELS commands */ |
| 5280 | lpfc_els_flush_all_cmd(phba); |
| 5281 | |
| 5282 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5283 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5284 | |
| 5285 | /* Update link event statistics */ |
| 5286 | phba->sli.slistat.link_event++; |
| 5287 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5288 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5289 | lpfc_read_topology(phba, pmb, mp); |
| 5290 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5291 | pmb->vport = phba->pport; |
| 5292 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5293 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5294 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5295 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 5296 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5297 | phba->sli4_hba.link_state.duplex = |
| 5298 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 5299 | phba->sli4_hba.link_state.status = |
| 5300 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5301 | phba->sli4_hba.link_state.type = |
| 5302 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 5303 | phba->sli4_hba.link_state.number = |
| 5304 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5305 | phba->sli4_hba.link_state.fault = |
| 5306 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 5307 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5308 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 5309 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5310 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 5311 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 5312 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 5313 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5314 | phba->sli4_hba.link_state.speed, |
| 5315 | phba->sli4_hba.link_state.topology, |
| 5316 | phba->sli4_hba.link_state.status, |
| 5317 | phba->sli4_hba.link_state.type, |
| 5318 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5319 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5320 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5321 | /* |
| 5322 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 5323 | * topology info. Note: Optional for non FC-AL ports. |
| 5324 | */ |
| 5325 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 5326 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5327 | if (rc == MBX_NOT_FINISHED) |
| 5328 | goto out_free_dmabuf; |
| 5329 | return; |
| 5330 | } |
| 5331 | /* |
| 5332 | * For FCoE Mode: fill in all the topology information we need and call |
| 5333 | * the READ_TOPOLOGY completion routine to continue without actually |
| 5334 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 5335 | */ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5336 | /* Initialize completion status */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5337 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5338 | mb->mbxStatus = MBX_SUCCESS; |
| 5339 | |
| 5340 | /* Parse port fault information field */ |
| 5341 | lpfc_sli4_parse_latt_fault(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5342 | |
| 5343 | /* Parse and translate link attention fields */ |
| 5344 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 5345 | la->eventTag = acqe_link->event_tag; |
| 5346 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 5347 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5348 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5349 | |
| 5350 | /* Fake the the following irrelvant fields */ |
| 5351 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 5352 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 5353 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 5354 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 5355 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 5356 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5357 | |
| 5358 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5359 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5360 | |
| 5361 | return; |
| 5362 | |
| 5363 | out_free_dmabuf: |
| 5364 | kfree(mp); |
| 5365 | out_free_pmb: |
| 5366 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5367 | } |
| 5368 | |
| 5369 | /** |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5370 | * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read |
| 5371 | * topology. |
| 5372 | * @phba: pointer to lpfc hba data structure. |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5373 | * @speed_code: asynchronous event link speed code. |
| 5374 | * |
| 5375 | * This routine is to parse the giving SLI4 async event link speed code into |
| 5376 | * value of Read topology link speed. |
| 5377 | * |
| 5378 | * Return: link speed in terms of Read topology. |
| 5379 | **/ |
| 5380 | static uint8_t |
| 5381 | lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code) |
| 5382 | { |
| 5383 | uint8_t port_speed; |
| 5384 | |
| 5385 | switch (speed_code) { |
| 5386 | case LPFC_FC_LA_SPEED_1G: |
| 5387 | port_speed = LPFC_LINK_SPEED_1GHZ; |
| 5388 | break; |
| 5389 | case LPFC_FC_LA_SPEED_2G: |
| 5390 | port_speed = LPFC_LINK_SPEED_2GHZ; |
| 5391 | break; |
| 5392 | case LPFC_FC_LA_SPEED_4G: |
| 5393 | port_speed = LPFC_LINK_SPEED_4GHZ; |
| 5394 | break; |
| 5395 | case LPFC_FC_LA_SPEED_8G: |
| 5396 | port_speed = LPFC_LINK_SPEED_8GHZ; |
| 5397 | break; |
| 5398 | case LPFC_FC_LA_SPEED_16G: |
| 5399 | port_speed = LPFC_LINK_SPEED_16GHZ; |
| 5400 | break; |
| 5401 | case LPFC_FC_LA_SPEED_32G: |
| 5402 | port_speed = LPFC_LINK_SPEED_32GHZ; |
| 5403 | break; |
| 5404 | case LPFC_FC_LA_SPEED_64G: |
| 5405 | port_speed = LPFC_LINK_SPEED_64GHZ; |
| 5406 | break; |
| 5407 | case LPFC_FC_LA_SPEED_128G: |
| 5408 | port_speed = LPFC_LINK_SPEED_128GHZ; |
| 5409 | break; |
| 5410 | case LPFC_FC_LA_SPEED_256G: |
| 5411 | port_speed = LPFC_LINK_SPEED_256GHZ; |
| 5412 | break; |
| 5413 | default: |
| 5414 | port_speed = 0; |
| 5415 | break; |
| 5416 | } |
| 5417 | |
| 5418 | return port_speed; |
| 5419 | } |
| 5420 | |
James Smart | 74a7baa | 2021-08-16 09:28:58 -0700 | [diff] [blame] | 5421 | void |
| 5422 | lpfc_cgn_dump_rxmonitor(struct lpfc_hba *phba) |
| 5423 | { |
| 5424 | struct rxtable_entry *entry; |
| 5425 | int cnt = 0, head, tail, last, start; |
| 5426 | |
| 5427 | head = atomic_read(&phba->rxtable_idx_head); |
| 5428 | tail = atomic_read(&phba->rxtable_idx_tail); |
| 5429 | if (!phba->rxtable || head == tail) { |
| 5430 | lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT, |
| 5431 | "4411 Rxtable is empty\n"); |
| 5432 | return; |
| 5433 | } |
| 5434 | last = tail; |
| 5435 | start = head; |
| 5436 | |
| 5437 | /* Display the last LPFC_MAX_RXMONITOR_DUMP entries from the rxtable */ |
| 5438 | while (start != last) { |
| 5439 | if (start) |
| 5440 | start--; |
| 5441 | else |
| 5442 | start = LPFC_MAX_RXMONITOR_ENTRY - 1; |
| 5443 | entry = &phba->rxtable[start]; |
| 5444 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 5445 | "4410 %02d: MBPI %lld Xmit %lld Cmpl %lld " |
| 5446 | "Lat %lld ASz %lld Info %02d BWUtil %d " |
| 5447 | "Int %d slot %d\n", |
| 5448 | cnt, entry->max_bytes_per_interval, |
| 5449 | entry->total_bytes, entry->rcv_bytes, |
| 5450 | entry->avg_io_latency, entry->avg_io_size, |
| 5451 | entry->cmf_info, entry->timer_utilization, |
| 5452 | entry->timer_interval, start); |
| 5453 | cnt++; |
| 5454 | if (cnt >= LPFC_MAX_RXMONITOR_DUMP) |
| 5455 | return; |
| 5456 | } |
| 5457 | } |
| 5458 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 5459 | /** |
James Smart | 7481811c | 2021-08-16 09:28:56 -0700 | [diff] [blame] | 5460 | * lpfc_cgn_update_stat - Save data into congestion stats buffer |
| 5461 | * @phba: pointer to lpfc hba data structure. |
| 5462 | * @dtag: FPIN descriptor received |
| 5463 | * |
| 5464 | * Increment the FPIN received counter/time when it happens. |
| 5465 | */ |
| 5466 | void |
| 5467 | lpfc_cgn_update_stat(struct lpfc_hba *phba, uint32_t dtag) |
| 5468 | { |
| 5469 | struct lpfc_cgn_info *cp; |
| 5470 | struct tm broken; |
| 5471 | struct timespec64 cur_time; |
| 5472 | u32 cnt; |
| 5473 | u16 value; |
| 5474 | |
| 5475 | /* Make sure we have a congestion info buffer */ |
| 5476 | if (!phba->cgn_i) |
| 5477 | return; |
| 5478 | cp = (struct lpfc_cgn_info *)phba->cgn_i->virt; |
| 5479 | ktime_get_real_ts64(&cur_time); |
| 5480 | time64_to_tm(cur_time.tv_sec, 0, &broken); |
| 5481 | |
| 5482 | /* Update congestion statistics */ |
| 5483 | switch (dtag) { |
| 5484 | case ELS_DTAG_LNK_INTEGRITY: |
| 5485 | cnt = le32_to_cpu(cp->link_integ_notification); |
| 5486 | cnt++; |
| 5487 | cp->link_integ_notification = cpu_to_le32(cnt); |
| 5488 | |
| 5489 | cp->cgn_stat_lnk_month = broken.tm_mon + 1; |
| 5490 | cp->cgn_stat_lnk_day = broken.tm_mday; |
| 5491 | cp->cgn_stat_lnk_year = broken.tm_year - 100; |
| 5492 | cp->cgn_stat_lnk_hour = broken.tm_hour; |
| 5493 | cp->cgn_stat_lnk_min = broken.tm_min; |
| 5494 | cp->cgn_stat_lnk_sec = broken.tm_sec; |
| 5495 | break; |
| 5496 | case ELS_DTAG_DELIVERY: |
| 5497 | cnt = le32_to_cpu(cp->delivery_notification); |
| 5498 | cnt++; |
| 5499 | cp->delivery_notification = cpu_to_le32(cnt); |
| 5500 | |
| 5501 | cp->cgn_stat_del_month = broken.tm_mon + 1; |
| 5502 | cp->cgn_stat_del_day = broken.tm_mday; |
| 5503 | cp->cgn_stat_del_year = broken.tm_year - 100; |
| 5504 | cp->cgn_stat_del_hour = broken.tm_hour; |
| 5505 | cp->cgn_stat_del_min = broken.tm_min; |
| 5506 | cp->cgn_stat_del_sec = broken.tm_sec; |
| 5507 | break; |
| 5508 | case ELS_DTAG_PEER_CONGEST: |
| 5509 | cnt = le32_to_cpu(cp->cgn_peer_notification); |
| 5510 | cnt++; |
| 5511 | cp->cgn_peer_notification = cpu_to_le32(cnt); |
| 5512 | |
| 5513 | cp->cgn_stat_peer_month = broken.tm_mon + 1; |
| 5514 | cp->cgn_stat_peer_day = broken.tm_mday; |
| 5515 | cp->cgn_stat_peer_year = broken.tm_year - 100; |
| 5516 | cp->cgn_stat_peer_hour = broken.tm_hour; |
| 5517 | cp->cgn_stat_peer_min = broken.tm_min; |
| 5518 | cp->cgn_stat_peer_sec = broken.tm_sec; |
| 5519 | break; |
| 5520 | case ELS_DTAG_CONGESTION: |
| 5521 | cnt = le32_to_cpu(cp->cgn_notification); |
| 5522 | cnt++; |
| 5523 | cp->cgn_notification = cpu_to_le32(cnt); |
| 5524 | |
| 5525 | cp->cgn_stat_cgn_month = broken.tm_mon + 1; |
| 5526 | cp->cgn_stat_cgn_day = broken.tm_mday; |
| 5527 | cp->cgn_stat_cgn_year = broken.tm_year - 100; |
| 5528 | cp->cgn_stat_cgn_hour = broken.tm_hour; |
| 5529 | cp->cgn_stat_cgn_min = broken.tm_min; |
| 5530 | cp->cgn_stat_cgn_sec = broken.tm_sec; |
| 5531 | } |
| 5532 | if (phba->cgn_fpin_frequency && |
| 5533 | phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) { |
| 5534 | value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency; |
| 5535 | cp->cgn_stat_npm = cpu_to_le32(value); |
| 5536 | } |
| 5537 | value = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, |
| 5538 | LPFC_CGN_CRC32_SEED); |
| 5539 | cp->cgn_info_crc = cpu_to_le32(value); |
| 5540 | } |
| 5541 | |
| 5542 | /** |
| 5543 | * lpfc_cgn_save_evt_cnt - Save data into registered congestion buffer |
| 5544 | * @phba: pointer to lpfc hba data structure. |
| 5545 | * |
| 5546 | * Save the congestion event data every minute. |
| 5547 | * On the hour collapse all the minute data into hour data. Every day |
| 5548 | * collapse all the hour data into daily data. Separate driver |
| 5549 | * and fabrc congestion event counters that will be saved out |
| 5550 | * to the registered congestion buffer every minute. |
| 5551 | */ |
| 5552 | static void |
| 5553 | lpfc_cgn_save_evt_cnt(struct lpfc_hba *phba) |
| 5554 | { |
| 5555 | struct lpfc_cgn_info *cp; |
| 5556 | struct tm broken; |
| 5557 | struct timespec64 cur_time; |
| 5558 | uint32_t i, index; |
| 5559 | uint16_t value, mvalue; |
| 5560 | uint64_t bps; |
| 5561 | uint32_t mbps; |
| 5562 | uint32_t dvalue, wvalue, lvalue, avalue; |
| 5563 | uint64_t latsum; |
| 5564 | uint16_t *ptr; |
| 5565 | uint32_t *lptr; |
| 5566 | uint16_t *mptr; |
| 5567 | |
| 5568 | /* Make sure we have a congestion info buffer */ |
| 5569 | if (!phba->cgn_i) |
| 5570 | return; |
| 5571 | cp = (struct lpfc_cgn_info *)phba->cgn_i->virt; |
| 5572 | |
| 5573 | if (time_before(jiffies, phba->cgn_evt_timestamp)) |
| 5574 | return; |
| 5575 | phba->cgn_evt_timestamp = jiffies + |
| 5576 | msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN); |
| 5577 | phba->cgn_evt_minute++; |
| 5578 | |
| 5579 | /* We should get to this point in the routine on 1 minute intervals */ |
| 5580 | |
| 5581 | ktime_get_real_ts64(&cur_time); |
| 5582 | time64_to_tm(cur_time.tv_sec, 0, &broken); |
| 5583 | |
| 5584 | if (phba->cgn_fpin_frequency && |
| 5585 | phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ) { |
| 5586 | value = LPFC_CGN_TIMER_TO_MIN / phba->cgn_fpin_frequency; |
| 5587 | cp->cgn_stat_npm = cpu_to_le32(value); |
| 5588 | } |
| 5589 | |
| 5590 | /* Read and clear the latency counters for this minute */ |
| 5591 | lvalue = atomic_read(&phba->cgn_latency_evt_cnt); |
| 5592 | latsum = atomic64_read(&phba->cgn_latency_evt); |
| 5593 | atomic_set(&phba->cgn_latency_evt_cnt, 0); |
| 5594 | atomic64_set(&phba->cgn_latency_evt, 0); |
| 5595 | |
| 5596 | /* We need to store MB/sec bandwidth in the congestion information. |
| 5597 | * block_cnt is count of 512 byte blocks for the entire minute, |
| 5598 | * bps will get bytes per sec before finally converting to MB/sec. |
| 5599 | */ |
| 5600 | bps = div_u64(phba->rx_block_cnt, LPFC_SEC_MIN) * 512; |
| 5601 | phba->rx_block_cnt = 0; |
| 5602 | mvalue = bps / (1024 * 1024); /* convert to MB/sec */ |
| 5603 | |
| 5604 | /* Every minute */ |
| 5605 | /* cgn parameters */ |
| 5606 | cp->cgn_info_mode = phba->cgn_p.cgn_param_mode; |
| 5607 | cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0; |
| 5608 | cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1; |
| 5609 | cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2; |
| 5610 | |
| 5611 | /* Fill in default LUN qdepth */ |
| 5612 | value = (uint16_t)(phba->pport->cfg_lun_queue_depth); |
| 5613 | cp->cgn_lunq = cpu_to_le16(value); |
| 5614 | |
| 5615 | /* Record congestion buffer info - every minute |
| 5616 | * cgn_driver_evt_cnt (Driver events) |
| 5617 | * cgn_fabric_warn_cnt (Congestion Warnings) |
| 5618 | * cgn_latency_evt_cnt / cgn_latency_evt (IO Latency) |
| 5619 | * cgn_fabric_alarm_cnt (Congestion Alarms) |
| 5620 | */ |
| 5621 | index = ++cp->cgn_index_minute; |
| 5622 | if (cp->cgn_index_minute == LPFC_MIN_HOUR) { |
| 5623 | cp->cgn_index_minute = 0; |
| 5624 | index = 0; |
| 5625 | } |
| 5626 | |
| 5627 | /* Get the number of driver events in this sample and reset counter */ |
| 5628 | dvalue = atomic_read(&phba->cgn_driver_evt_cnt); |
| 5629 | atomic_set(&phba->cgn_driver_evt_cnt, 0); |
| 5630 | |
| 5631 | /* Get the number of warning events - FPIN and Signal for this minute */ |
| 5632 | wvalue = 0; |
| 5633 | if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) || |
| 5634 | phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY || |
| 5635 | phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) |
| 5636 | wvalue = atomic_read(&phba->cgn_fabric_warn_cnt); |
| 5637 | atomic_set(&phba->cgn_fabric_warn_cnt, 0); |
| 5638 | |
| 5639 | /* Get the number of alarm events - FPIN and Signal for this minute */ |
| 5640 | avalue = 0; |
| 5641 | if ((phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) || |
| 5642 | phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) |
| 5643 | avalue = atomic_read(&phba->cgn_fabric_alarm_cnt); |
| 5644 | atomic_set(&phba->cgn_fabric_alarm_cnt, 0); |
| 5645 | |
| 5646 | /* Collect the driver, warning, alarm and latency counts for this |
| 5647 | * minute into the driver congestion buffer. |
| 5648 | */ |
| 5649 | ptr = &cp->cgn_drvr_min[index]; |
| 5650 | value = (uint16_t)dvalue; |
| 5651 | *ptr = cpu_to_le16(value); |
| 5652 | |
| 5653 | ptr = &cp->cgn_warn_min[index]; |
| 5654 | value = (uint16_t)wvalue; |
| 5655 | *ptr = cpu_to_le16(value); |
| 5656 | |
| 5657 | ptr = &cp->cgn_alarm_min[index]; |
| 5658 | value = (uint16_t)avalue; |
| 5659 | *ptr = cpu_to_le16(value); |
| 5660 | |
| 5661 | lptr = &cp->cgn_latency_min[index]; |
| 5662 | if (lvalue) { |
| 5663 | lvalue = (uint32_t)div_u64(latsum, lvalue); |
| 5664 | *lptr = cpu_to_le32(lvalue); |
| 5665 | } else { |
| 5666 | *lptr = 0; |
| 5667 | } |
| 5668 | |
| 5669 | /* Collect the bandwidth value into the driver's congesion buffer. */ |
| 5670 | mptr = &cp->cgn_bw_min[index]; |
| 5671 | *mptr = cpu_to_le16(mvalue); |
| 5672 | |
| 5673 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 5674 | "2418 Congestion Info - minute (%d): %d %d %d %d %d\n", |
| 5675 | index, dvalue, wvalue, *lptr, mvalue, avalue); |
| 5676 | |
| 5677 | /* Every hour */ |
| 5678 | if ((phba->cgn_evt_minute % LPFC_MIN_HOUR) == 0) { |
| 5679 | /* Record congestion buffer info - every hour |
| 5680 | * Collapse all minutes into an hour |
| 5681 | */ |
| 5682 | index = ++cp->cgn_index_hour; |
| 5683 | if (cp->cgn_index_hour == LPFC_HOUR_DAY) { |
| 5684 | cp->cgn_index_hour = 0; |
| 5685 | index = 0; |
| 5686 | } |
| 5687 | |
| 5688 | dvalue = 0; |
| 5689 | wvalue = 0; |
| 5690 | lvalue = 0; |
| 5691 | avalue = 0; |
| 5692 | mvalue = 0; |
| 5693 | mbps = 0; |
| 5694 | for (i = 0; i < LPFC_MIN_HOUR; i++) { |
| 5695 | dvalue += le16_to_cpu(cp->cgn_drvr_min[i]); |
| 5696 | wvalue += le16_to_cpu(cp->cgn_warn_min[i]); |
| 5697 | lvalue += le32_to_cpu(cp->cgn_latency_min[i]); |
| 5698 | mbps += le16_to_cpu(cp->cgn_bw_min[i]); |
| 5699 | avalue += le16_to_cpu(cp->cgn_alarm_min[i]); |
| 5700 | } |
| 5701 | if (lvalue) /* Avg of latency averages */ |
| 5702 | lvalue /= LPFC_MIN_HOUR; |
| 5703 | if (mbps) /* Avg of Bandwidth averages */ |
| 5704 | mvalue = mbps / LPFC_MIN_HOUR; |
| 5705 | |
| 5706 | lptr = &cp->cgn_drvr_hr[index]; |
| 5707 | *lptr = cpu_to_le32(dvalue); |
| 5708 | lptr = &cp->cgn_warn_hr[index]; |
| 5709 | *lptr = cpu_to_le32(wvalue); |
| 5710 | lptr = &cp->cgn_latency_hr[index]; |
| 5711 | *lptr = cpu_to_le32(lvalue); |
| 5712 | mptr = &cp->cgn_bw_hr[index]; |
| 5713 | *mptr = cpu_to_le16(mvalue); |
| 5714 | lptr = &cp->cgn_alarm_hr[index]; |
| 5715 | *lptr = cpu_to_le32(avalue); |
| 5716 | |
| 5717 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 5718 | "2419 Congestion Info - hour " |
| 5719 | "(%d): %d %d %d %d %d\n", |
| 5720 | index, dvalue, wvalue, lvalue, mvalue, avalue); |
| 5721 | } |
| 5722 | |
| 5723 | /* Every day */ |
| 5724 | if ((phba->cgn_evt_minute % LPFC_MIN_DAY) == 0) { |
| 5725 | /* Record congestion buffer info - every hour |
| 5726 | * Collapse all hours into a day. Rotate days |
| 5727 | * after LPFC_MAX_CGN_DAYS. |
| 5728 | */ |
| 5729 | index = ++cp->cgn_index_day; |
| 5730 | if (cp->cgn_index_day == LPFC_MAX_CGN_DAYS) { |
| 5731 | cp->cgn_index_day = 0; |
| 5732 | index = 0; |
| 5733 | } |
| 5734 | |
| 5735 | /* Anytime we overwrite daily index 0, after we wrap, |
| 5736 | * we will be overwriting the oldest day, so we must |
| 5737 | * update the congestion data start time for that day. |
| 5738 | * That start time should have previously been saved after |
| 5739 | * we wrote the last days worth of data. |
| 5740 | */ |
| 5741 | if ((phba->hba_flag & HBA_CGN_DAY_WRAP) && index == 0) { |
| 5742 | time64_to_tm(phba->cgn_daily_ts.tv_sec, 0, &broken); |
| 5743 | |
| 5744 | cp->cgn_info_month = broken.tm_mon + 1; |
| 5745 | cp->cgn_info_day = broken.tm_mday; |
| 5746 | cp->cgn_info_year = broken.tm_year - 100; |
| 5747 | cp->cgn_info_hour = broken.tm_hour; |
| 5748 | cp->cgn_info_minute = broken.tm_min; |
| 5749 | cp->cgn_info_second = broken.tm_sec; |
| 5750 | |
| 5751 | lpfc_printf_log |
| 5752 | (phba, KERN_INFO, LOG_CGN_MGMT, |
| 5753 | "2646 CGNInfo idx0 Start Time: " |
| 5754 | "%d/%d/%d %d:%d:%d\n", |
| 5755 | cp->cgn_info_day, cp->cgn_info_month, |
| 5756 | cp->cgn_info_year, cp->cgn_info_hour, |
| 5757 | cp->cgn_info_minute, cp->cgn_info_second); |
| 5758 | } |
| 5759 | |
| 5760 | dvalue = 0; |
| 5761 | wvalue = 0; |
| 5762 | lvalue = 0; |
| 5763 | mvalue = 0; |
| 5764 | mbps = 0; |
| 5765 | avalue = 0; |
| 5766 | for (i = 0; i < LPFC_HOUR_DAY; i++) { |
| 5767 | dvalue += le32_to_cpu(cp->cgn_drvr_hr[i]); |
| 5768 | wvalue += le32_to_cpu(cp->cgn_warn_hr[i]); |
| 5769 | lvalue += le32_to_cpu(cp->cgn_latency_hr[i]); |
| 5770 | mbps += le32_to_cpu(cp->cgn_bw_hr[i]); |
| 5771 | avalue += le32_to_cpu(cp->cgn_alarm_hr[i]); |
| 5772 | } |
| 5773 | if (lvalue) /* Avg of latency averages */ |
| 5774 | lvalue /= LPFC_HOUR_DAY; |
| 5775 | if (mbps) /* Avg of Bandwidth averages */ |
| 5776 | mvalue = mbps / LPFC_HOUR_DAY; |
| 5777 | |
| 5778 | lptr = &cp->cgn_drvr_day[index]; |
| 5779 | *lptr = cpu_to_le32(dvalue); |
| 5780 | lptr = &cp->cgn_warn_day[index]; |
| 5781 | *lptr = cpu_to_le32(wvalue); |
| 5782 | lptr = &cp->cgn_latency_day[index]; |
| 5783 | *lptr = cpu_to_le32(lvalue); |
| 5784 | mptr = &cp->cgn_bw_day[index]; |
| 5785 | *mptr = cpu_to_le16(mvalue); |
| 5786 | lptr = &cp->cgn_alarm_day[index]; |
| 5787 | *lptr = cpu_to_le32(avalue); |
| 5788 | |
| 5789 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 5790 | "2420 Congestion Info - daily (%d): " |
| 5791 | "%d %d %d %d %d\n", |
| 5792 | index, dvalue, wvalue, lvalue, mvalue, avalue); |
| 5793 | |
| 5794 | /* We just wrote LPFC_MAX_CGN_DAYS of data, |
| 5795 | * so we are wrapped on any data after this. |
| 5796 | * Save this as the start time for the next day. |
| 5797 | */ |
| 5798 | if (index == (LPFC_MAX_CGN_DAYS - 1)) { |
| 5799 | phba->hba_flag |= HBA_CGN_DAY_WRAP; |
| 5800 | ktime_get_real_ts64(&phba->cgn_daily_ts); |
| 5801 | } |
| 5802 | } |
| 5803 | |
| 5804 | /* Use the frequency found in the last rcv'ed FPIN */ |
| 5805 | value = phba->cgn_fpin_frequency; |
| 5806 | if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_WARN) |
| 5807 | cp->cgn_warn_freq = cpu_to_le16(value); |
| 5808 | if (phba->cgn_reg_fpin & LPFC_CGN_FPIN_ALARM) |
| 5809 | cp->cgn_alarm_freq = cpu_to_le16(value); |
| 5810 | |
| 5811 | /* Frequency (in ms) Signal Warning/Signal Congestion Notifications |
| 5812 | * are received by the HBA |
| 5813 | */ |
| 5814 | value = phba->cgn_sig_freq; |
| 5815 | |
| 5816 | if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY || |
| 5817 | phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) |
| 5818 | cp->cgn_warn_freq = cpu_to_le16(value); |
| 5819 | if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) |
| 5820 | cp->cgn_alarm_freq = cpu_to_le16(value); |
| 5821 | |
| 5822 | lvalue = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, |
| 5823 | LPFC_CGN_CRC32_SEED); |
| 5824 | cp->cgn_info_crc = cpu_to_le32(lvalue); |
| 5825 | } |
| 5826 | |
| 5827 | /** |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 5828 | * lpfc_calc_cmf_latency - latency from start of rxate timer interval |
| 5829 | * @phba: The Hba for which this call is being executed. |
| 5830 | * |
| 5831 | * The routine calculates the latency from the beginning of the CMF timer |
| 5832 | * interval to the current point in time. It is called from IO completion |
| 5833 | * when we exceed our Bandwidth limitation for the time interval. |
| 5834 | */ |
| 5835 | uint32_t |
| 5836 | lpfc_calc_cmf_latency(struct lpfc_hba *phba) |
| 5837 | { |
| 5838 | struct timespec64 cmpl_time; |
| 5839 | uint32_t msec = 0; |
| 5840 | |
| 5841 | ktime_get_real_ts64(&cmpl_time); |
| 5842 | |
| 5843 | /* This routine works on a ms granularity so sec and usec are |
| 5844 | * converted accordingly. |
| 5845 | */ |
| 5846 | if (cmpl_time.tv_sec == phba->cmf_latency.tv_sec) { |
| 5847 | msec = (cmpl_time.tv_nsec - phba->cmf_latency.tv_nsec) / |
| 5848 | NSEC_PER_MSEC; |
| 5849 | } else { |
| 5850 | if (cmpl_time.tv_nsec >= phba->cmf_latency.tv_nsec) { |
| 5851 | msec = (cmpl_time.tv_sec - |
| 5852 | phba->cmf_latency.tv_sec) * MSEC_PER_SEC; |
| 5853 | msec += ((cmpl_time.tv_nsec - |
| 5854 | phba->cmf_latency.tv_nsec) / NSEC_PER_MSEC); |
| 5855 | } else { |
| 5856 | msec = (cmpl_time.tv_sec - phba->cmf_latency.tv_sec - |
| 5857 | 1) * MSEC_PER_SEC; |
| 5858 | msec += (((NSEC_PER_SEC - phba->cmf_latency.tv_nsec) + |
| 5859 | cmpl_time.tv_nsec) / NSEC_PER_MSEC); |
| 5860 | } |
| 5861 | } |
| 5862 | return msec; |
| 5863 | } |
| 5864 | |
| 5865 | /** |
| 5866 | * lpfc_cmf_timer - This is the timer function for one congestion |
| 5867 | * rate interval. |
| 5868 | * @timer: Pointer to the high resolution timer that expired |
| 5869 | */ |
| 5870 | static enum hrtimer_restart |
| 5871 | lpfc_cmf_timer(struct hrtimer *timer) |
| 5872 | { |
| 5873 | struct lpfc_hba *phba = container_of(timer, struct lpfc_hba, |
| 5874 | cmf_timer); |
James Smart | 17b27ac | 2021-08-16 09:28:55 -0700 | [diff] [blame] | 5875 | struct rxtable_entry *entry; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 5876 | uint32_t io_cnt; |
James Smart | 17b27ac | 2021-08-16 09:28:55 -0700 | [diff] [blame] | 5877 | uint32_t head, tail; |
| 5878 | uint32_t busy, max_read; |
James Smart | d5ac69b | 2021-09-10 16:31:55 -0700 | [diff] [blame^] | 5879 | uint64_t total, rcv, lat, mbpi, extra; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 5880 | int timer_interval = LPFC_CMF_INTERVAL; |
James Smart | 17b27ac | 2021-08-16 09:28:55 -0700 | [diff] [blame] | 5881 | uint32_t ms; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 5882 | struct lpfc_cgn_stat *cgs; |
| 5883 | int cpu; |
| 5884 | |
| 5885 | /* Only restart the timer if congestion mgmt is on */ |
| 5886 | if (phba->cmf_active_mode == LPFC_CFG_OFF || |
| 5887 | !phba->cmf_latency.tv_sec) { |
| 5888 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 5889 | "6224 CMF timer exit: %d %lld\n", |
| 5890 | phba->cmf_active_mode, |
| 5891 | (uint64_t)phba->cmf_latency.tv_sec); |
| 5892 | return HRTIMER_NORESTART; |
| 5893 | } |
| 5894 | |
| 5895 | /* If pport is not ready yet, just exit and wait for |
| 5896 | * the next timer cycle to hit. |
| 5897 | */ |
| 5898 | if (!phba->pport) |
| 5899 | goto skip; |
| 5900 | |
| 5901 | /* Do not block SCSI IO while in the timer routine since |
| 5902 | * total_bytes will be cleared |
| 5903 | */ |
| 5904 | atomic_set(&phba->cmf_stop_io, 1); |
| 5905 | |
James Smart | 17b27ac | 2021-08-16 09:28:55 -0700 | [diff] [blame] | 5906 | /* First we need to calculate the actual ms between |
| 5907 | * the last timer interrupt and this one. We ask for |
| 5908 | * LPFC_CMF_INTERVAL, however the actual time may |
| 5909 | * vary depending on system overhead. |
| 5910 | */ |
| 5911 | ms = lpfc_calc_cmf_latency(phba); |
| 5912 | |
| 5913 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 5914 | /* Immediately after we calculate the time since the last |
| 5915 | * timer interrupt, set the start time for the next |
| 5916 | * interrupt |
| 5917 | */ |
| 5918 | ktime_get_real_ts64(&phba->cmf_latency); |
| 5919 | |
| 5920 | phba->cmf_link_byte_count = |
| 5921 | div_u64(phba->cmf_max_line_rate * LPFC_CMF_INTERVAL, 1000); |
| 5922 | |
| 5923 | /* Collect all the stats from the prior timer interval */ |
| 5924 | total = 0; |
| 5925 | io_cnt = 0; |
| 5926 | lat = 0; |
| 5927 | rcv = 0; |
| 5928 | for_each_present_cpu(cpu) { |
| 5929 | cgs = per_cpu_ptr(phba->cmf_stat, cpu); |
| 5930 | total += atomic64_xchg(&cgs->total_bytes, 0); |
| 5931 | io_cnt += atomic_xchg(&cgs->rx_io_cnt, 0); |
| 5932 | lat += atomic64_xchg(&cgs->rx_latency, 0); |
| 5933 | rcv += atomic64_xchg(&cgs->rcv_bytes, 0); |
| 5934 | } |
| 5935 | |
| 5936 | /* Before we issue another CMF_SYNC_WQE, retrieve the BW |
| 5937 | * returned from the last CMF_SYNC_WQE issued, from |
| 5938 | * cmf_last_sync_bw. This will be the target BW for |
| 5939 | * this next timer interval. |
| 5940 | */ |
| 5941 | if (phba->cmf_active_mode == LPFC_CFG_MANAGED && |
| 5942 | phba->link_state != LPFC_LINK_DOWN && |
| 5943 | phba->hba_flag & HBA_SETUP) { |
| 5944 | mbpi = phba->cmf_last_sync_bw; |
| 5945 | phba->cmf_last_sync_bw = 0; |
James Smart | d5ac69b | 2021-09-10 16:31:55 -0700 | [diff] [blame^] | 5946 | extra = 0; |
| 5947 | |
| 5948 | /* Calculate any extra bytes needed to account for the |
| 5949 | * timer accuracy. If we are less than LPFC_CMF_INTERVAL |
| 5950 | * add an extra 3% slop factor, equal to LPFC_CMF_INTERVAL |
| 5951 | * add an extra 2%. The goal is to equalize total with a |
| 5952 | * time > LPFC_CMF_INTERVAL or <= LPFC_CMF_INTERVAL + 1 |
| 5953 | */ |
| 5954 | if (ms == LPFC_CMF_INTERVAL) |
| 5955 | extra = div_u64(total, 50); |
| 5956 | else if (ms < LPFC_CMF_INTERVAL) |
| 5957 | extra = div_u64(total, 33); |
| 5958 | lpfc_issue_cmf_sync_wqe(phba, LPFC_CMF_INTERVAL, total + extra); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 5959 | } else { |
| 5960 | /* For Monitor mode or link down we want mbpi |
| 5961 | * to be the full link speed |
| 5962 | */ |
| 5963 | mbpi = phba->cmf_link_byte_count; |
| 5964 | } |
| 5965 | phba->cmf_timer_cnt++; |
| 5966 | |
| 5967 | if (io_cnt) { |
| 5968 | /* Update congestion info buffer latency in us */ |
| 5969 | atomic_add(io_cnt, &phba->cgn_latency_evt_cnt); |
| 5970 | atomic64_add(lat, &phba->cgn_latency_evt); |
| 5971 | } |
James Smart | 17b27ac | 2021-08-16 09:28:55 -0700 | [diff] [blame] | 5972 | busy = atomic_xchg(&phba->cmf_busy, 0); |
| 5973 | max_read = atomic_xchg(&phba->rx_max_read_cnt, 0); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 5974 | |
| 5975 | /* Calculate MBPI for the next timer interval */ |
| 5976 | if (mbpi) { |
| 5977 | if (mbpi > phba->cmf_link_byte_count || |
| 5978 | phba->cmf_active_mode == LPFC_CFG_MONITOR) |
| 5979 | mbpi = phba->cmf_link_byte_count; |
| 5980 | |
| 5981 | /* Change max_bytes_per_interval to what the prior |
| 5982 | * CMF_SYNC_WQE cmpl indicated. |
| 5983 | */ |
| 5984 | if (mbpi != phba->cmf_max_bytes_per_interval) |
| 5985 | phba->cmf_max_bytes_per_interval = mbpi; |
| 5986 | } |
| 5987 | |
James Smart | 17b27ac | 2021-08-16 09:28:55 -0700 | [diff] [blame] | 5988 | /* Save rxmonitor information for debug */ |
| 5989 | if (phba->rxtable) { |
| 5990 | head = atomic_xchg(&phba->rxtable_idx_head, |
| 5991 | LPFC_RXMONITOR_TABLE_IN_USE); |
| 5992 | entry = &phba->rxtable[head]; |
| 5993 | entry->total_bytes = total; |
| 5994 | entry->rcv_bytes = rcv; |
| 5995 | entry->cmf_busy = busy; |
| 5996 | entry->cmf_info = phba->cmf_active_info; |
| 5997 | if (io_cnt) { |
| 5998 | entry->avg_io_latency = div_u64(lat, io_cnt); |
| 5999 | entry->avg_io_size = div_u64(rcv, io_cnt); |
| 6000 | } else { |
| 6001 | entry->avg_io_latency = 0; |
| 6002 | entry->avg_io_size = 0; |
| 6003 | } |
| 6004 | entry->max_read_cnt = max_read; |
| 6005 | entry->io_cnt = io_cnt; |
| 6006 | entry->max_bytes_per_interval = mbpi; |
| 6007 | if (phba->cmf_active_mode == LPFC_CFG_MANAGED) |
| 6008 | entry->timer_utilization = phba->cmf_last_ts; |
| 6009 | else |
| 6010 | entry->timer_utilization = ms; |
| 6011 | entry->timer_interval = ms; |
| 6012 | phba->cmf_last_ts = 0; |
| 6013 | |
| 6014 | /* Increment rxtable index */ |
| 6015 | head = (head + 1) % LPFC_MAX_RXMONITOR_ENTRY; |
| 6016 | tail = atomic_read(&phba->rxtable_idx_tail); |
| 6017 | if (head == tail) { |
| 6018 | tail = (tail + 1) % LPFC_MAX_RXMONITOR_ENTRY; |
| 6019 | atomic_set(&phba->rxtable_idx_tail, tail); |
| 6020 | } |
| 6021 | atomic_set(&phba->rxtable_idx_head, head); |
| 6022 | } |
| 6023 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 6024 | if (phba->cmf_active_mode == LPFC_CFG_MONITOR) { |
| 6025 | /* If Monitor mode, check if we are oversubscribed |
| 6026 | * against the full line rate. |
| 6027 | */ |
| 6028 | if (mbpi && total > mbpi) |
| 6029 | atomic_inc(&phba->cgn_driver_evt_cnt); |
| 6030 | } |
| 6031 | phba->rx_block_cnt += div_u64(rcv, 512); /* save 512 byte block cnt */ |
| 6032 | |
James Smart | 7481811c | 2021-08-16 09:28:56 -0700 | [diff] [blame] | 6033 | /* Each minute save Fabric and Driver congestion information */ |
| 6034 | lpfc_cgn_save_evt_cnt(phba); |
| 6035 | |
| 6036 | /* Since we need to call lpfc_cgn_save_evt_cnt every minute, on the |
| 6037 | * minute, adjust our next timer interval, if needed, to ensure a |
| 6038 | * 1 minute granularity when we get the next timer interrupt. |
| 6039 | */ |
| 6040 | if (time_after(jiffies + msecs_to_jiffies(LPFC_CMF_INTERVAL), |
| 6041 | phba->cgn_evt_timestamp)) { |
| 6042 | timer_interval = jiffies_to_msecs(phba->cgn_evt_timestamp - |
| 6043 | jiffies); |
| 6044 | if (timer_interval <= 0) |
| 6045 | timer_interval = LPFC_CMF_INTERVAL; |
| 6046 | |
| 6047 | /* If we adjust timer_interval, max_bytes_per_interval |
| 6048 | * needs to be adjusted as well. |
| 6049 | */ |
| 6050 | phba->cmf_link_byte_count = div_u64(phba->cmf_max_line_rate * |
| 6051 | timer_interval, 1000); |
| 6052 | if (phba->cmf_active_mode == LPFC_CFG_MONITOR) |
| 6053 | phba->cmf_max_bytes_per_interval = |
| 6054 | phba->cmf_link_byte_count; |
| 6055 | } |
| 6056 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 6057 | /* Since total_bytes has already been zero'ed, its okay to unblock |
| 6058 | * after max_bytes_per_interval is setup. |
| 6059 | */ |
| 6060 | if (atomic_xchg(&phba->cmf_bw_wait, 0)) |
| 6061 | queue_work(phba->wq, &phba->unblock_request_work); |
| 6062 | |
| 6063 | /* SCSI IO is now unblocked */ |
| 6064 | atomic_set(&phba->cmf_stop_io, 0); |
| 6065 | |
| 6066 | skip: |
| 6067 | hrtimer_forward_now(timer, |
| 6068 | ktime_set(0, timer_interval * NSEC_PER_MSEC)); |
| 6069 | return HRTIMER_RESTART; |
| 6070 | } |
| 6071 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 6072 | #define trunk_link_status(__idx)\ |
| 6073 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 6074 | ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\ |
| 6075 | "Link up" : "Link down") : "NA" |
| 6076 | /* Did port __idx reported an error */ |
| 6077 | #define trunk_port_fault(__idx)\ |
| 6078 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 6079 | (port_fault & (1 << __idx) ? "YES" : "NO") : "NA" |
| 6080 | |
| 6081 | static void |
| 6082 | lpfc_update_trunk_link_status(struct lpfc_hba *phba, |
| 6083 | struct lpfc_acqe_fc_la *acqe_fc) |
| 6084 | { |
| 6085 | uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc); |
| 6086 | uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc); |
| 6087 | |
| 6088 | phba->sli4_hba.link_state.speed = |
| 6089 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 6090 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 6091 | |
| 6092 | phba->sli4_hba.link_state.logical_speed = |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 6093 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 6094 | /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */ |
| 6095 | phba->fc_linkspeed = |
| 6096 | lpfc_async_link_speed_to_read_top( |
| 6097 | phba, |
| 6098 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 6099 | |
| 6100 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) { |
| 6101 | phba->trunk_link.link0.state = |
| 6102 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc) |
| 6103 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 6104 | phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 6105 | } |
| 6106 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) { |
| 6107 | phba->trunk_link.link1.state = |
| 6108 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc) |
| 6109 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 6110 | phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 6111 | } |
| 6112 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) { |
| 6113 | phba->trunk_link.link2.state = |
| 6114 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc) |
| 6115 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 6116 | phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 6117 | } |
| 6118 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) { |
| 6119 | phba->trunk_link.link3.state = |
| 6120 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc) |
| 6121 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 6122 | phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 6123 | } |
| 6124 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6125 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 6126 | "2910 Async FC Trunking Event - Speed:%d\n" |
| 6127 | "\tLogical speed:%d " |
| 6128 | "port0: %s port1: %s port2: %s port3: %s\n", |
| 6129 | phba->sli4_hba.link_state.speed, |
| 6130 | phba->sli4_hba.link_state.logical_speed, |
| 6131 | trunk_link_status(0), trunk_link_status(1), |
| 6132 | trunk_link_status(2), trunk_link_status(3)); |
| 6133 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 6134 | if (phba->cmf_active_mode != LPFC_CFG_OFF) |
| 6135 | lpfc_cmf_signal_init(phba); |
| 6136 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 6137 | if (port_fault) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6138 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 6139 | "3202 trunk error:0x%x (%s) seen on port0:%s " |
| 6140 | /* |
| 6141 | * SLI-4: We have only 0xA error codes |
| 6142 | * defined as of now. print an appropriate |
| 6143 | * message in case driver needs to be updated. |
| 6144 | */ |
| 6145 | "port1:%s port2:%s port3:%s\n", err, err > 0xA ? |
| 6146 | "UNDEFINED. update driver." : trunk_errmsg[err], |
| 6147 | trunk_port_fault(0), trunk_port_fault(1), |
| 6148 | trunk_port_fault(2), trunk_port_fault(3)); |
| 6149 | } |
| 6150 | |
| 6151 | |
| 6152 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6153 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 6154 | * @phba: pointer to lpfc hba data structure. |
| 6155 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 6156 | * |
| 6157 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 6158 | * that the event was received and then issue a read_topology mailbox command so |
| 6159 | * that the rest of the driver will treat it the same as SLI3. |
| 6160 | **/ |
| 6161 | static void |
| 6162 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 6163 | { |
| 6164 | struct lpfc_dmabuf *mp; |
| 6165 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6166 | MAILBOX_t *mb; |
| 6167 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6168 | int rc; |
| 6169 | |
| 6170 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 6171 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6172 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6173 | "2895 Non FC link Event detected.(%d)\n", |
| 6174 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 6175 | return; |
| 6176 | } |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 6177 | |
| 6178 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 6179 | LPFC_FC_LA_TYPE_TRUNKING_EVENT) { |
| 6180 | lpfc_update_trunk_link_status(phba, acqe_fc); |
| 6181 | return; |
| 6182 | } |
| 6183 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6184 | /* Keep the link status for extra SLI4 state machine reference */ |
| 6185 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 6186 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 6187 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6188 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 6189 | phba->sli4_hba.link_state.topology = |
| 6190 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 6191 | phba->sli4_hba.link_state.status = |
| 6192 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 6193 | phba->sli4_hba.link_state.type = |
| 6194 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 6195 | phba->sli4_hba.link_state.number = |
| 6196 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 6197 | phba->sli4_hba.link_state.fault = |
| 6198 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 6199 | |
| 6200 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 6201 | LPFC_FC_LA_TYPE_LINK_DOWN) |
| 6202 | phba->sli4_hba.link_state.logical_speed = 0; |
| 6203 | else if (!phba->sli4_hba.conf_trunk) |
| 6204 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 6205 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 6206 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6207 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6208 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 6209 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 6210 | "%dMbps Fault:%d\n", |
| 6211 | phba->sli4_hba.link_state.speed, |
| 6212 | phba->sli4_hba.link_state.topology, |
| 6213 | phba->sli4_hba.link_state.status, |
| 6214 | phba->sli4_hba.link_state.type, |
| 6215 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 6216 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6217 | phba->sli4_hba.link_state.fault); |
| 6218 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 6219 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6220 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6221 | "2897 The mboxq allocation failed\n"); |
| 6222 | return; |
| 6223 | } |
| 6224 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 6225 | if (!mp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6226 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6227 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 6228 | goto out_free_pmb; |
| 6229 | } |
| 6230 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 6231 | if (!mp->virt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6232 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6233 | "2899 The mbuf allocation failed\n"); |
| 6234 | goto out_free_dmabuf; |
| 6235 | } |
| 6236 | |
| 6237 | /* Cleanup any outstanding ELS commands */ |
| 6238 | lpfc_els_flush_all_cmd(phba); |
| 6239 | |
| 6240 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6241 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6242 | |
| 6243 | /* Update link event statistics */ |
| 6244 | phba->sli.slistat.link_event++; |
| 6245 | |
| 6246 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 6247 | lpfc_read_topology(phba, pmb, mp); |
| 6248 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 6249 | pmb->vport = phba->pport; |
| 6250 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6251 | 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] | 6252 | phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK); |
| 6253 | |
| 6254 | switch (phba->sli4_hba.link_state.status) { |
| 6255 | case LPFC_FC_LA_TYPE_MDS_LINK_DOWN: |
| 6256 | phba->link_flag |= LS_MDS_LINK_DOWN; |
| 6257 | break; |
| 6258 | case LPFC_FC_LA_TYPE_MDS_LOOPBACK: |
| 6259 | phba->link_flag |= LS_MDS_LOOPBACK; |
| 6260 | break; |
| 6261 | default: |
| 6262 | break; |
| 6263 | } |
| 6264 | |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 6265 | /* Initialize completion status */ |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6266 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 6267 | mb->mbxStatus = MBX_SUCCESS; |
| 6268 | |
| 6269 | /* Parse port fault information field */ |
| 6270 | lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6271 | |
| 6272 | /* Parse and translate link attention fields */ |
| 6273 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 6274 | la->eventTag = acqe_fc->event_tag; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6275 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 6276 | if (phba->sli4_hba.link_state.status == |
| 6277 | LPFC_FC_LA_TYPE_UNEXP_WWPN) { |
| 6278 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 6279 | LPFC_FC_LA_TYPE_UNEXP_WWPN); |
| 6280 | } else { |
| 6281 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 6282 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 6283 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 6284 | /* Invoke the mailbox command callback function */ |
| 6285 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 6286 | |
| 6287 | return; |
| 6288 | } |
| 6289 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6290 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 6291 | if (rc == MBX_NOT_FINISHED) |
| 6292 | goto out_free_dmabuf; |
| 6293 | return; |
| 6294 | |
| 6295 | out_free_dmabuf: |
| 6296 | kfree(mp); |
| 6297 | out_free_pmb: |
| 6298 | mempool_free(pmb, phba->mbox_mem_pool); |
| 6299 | } |
| 6300 | |
| 6301 | /** |
| 6302 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 6303 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 6304 | * @acqe_sli: pointer to the async SLI completion queue entry. |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6305 | * |
| 6306 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 6307 | **/ |
| 6308 | static void |
| 6309 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 6310 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6311 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 6312 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6313 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6314 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6315 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6316 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6317 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 6318 | struct lpfc_acqe_cgn_signal *cgn_signal; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6319 | struct Scsi_Host *shost; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 6320 | struct lpfc_vport **vports; |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 6321 | int rc, i, cnt; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6322 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6323 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 6324 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6325 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 6326 | "2901 Async SLI event - Type:%d, Event Data: x%08x " |
| 6327 | "x%08x x%08x x%08x\n", evt_type, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6328 | acqe_sli->event_data1, acqe_sli->event_data2, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 6329 | acqe_sli->reserved, acqe_sli->trailer); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6330 | |
| 6331 | port_name = phba->Port[0]; |
| 6332 | if (port_name == 0x00) |
| 6333 | port_name = '?'; /* get port name is empty */ |
| 6334 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6335 | switch (evt_type) { |
| 6336 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 6337 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 6338 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 6339 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 6340 | |
| 6341 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6342 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 6343 | acqe_sli->event_data1, port_name); |
| 6344 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 6345 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6346 | shost = lpfc_shost_from_vport(phba->pport); |
| 6347 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 6348 | sizeof(temp_event_data), |
| 6349 | (char *)&temp_event_data, |
| 6350 | SCSI_NL_VID_TYPE_PCI |
| 6351 | | PCI_VENDOR_ID_EMULEX); |
| 6352 | break; |
| 6353 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 6354 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 6355 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 6356 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 6357 | |
| 6358 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6359 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 6360 | acqe_sli->event_data1, port_name); |
| 6361 | |
| 6362 | shost = lpfc_shost_from_vport(phba->pport); |
| 6363 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 6364 | sizeof(temp_event_data), |
| 6365 | (char *)&temp_event_data, |
| 6366 | SCSI_NL_VID_TYPE_PCI |
| 6367 | | PCI_VENDOR_ID_EMULEX); |
| 6368 | break; |
| 6369 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 6370 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6371 | &acqe_sli->event_data1; |
| 6372 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6373 | /* fetch the status for this port */ |
| 6374 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 6375 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6376 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 6377 | &misconfigured->theEvent); |
| 6378 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6379 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6380 | break; |
| 6381 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6382 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 6383 | &misconfigured->theEvent); |
| 6384 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6385 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6386 | break; |
| 6387 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6388 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 6389 | &misconfigured->theEvent); |
| 6390 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6391 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6392 | break; |
| 6393 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6394 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 6395 | &misconfigured->theEvent); |
| 6396 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6397 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6398 | break; |
| 6399 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6400 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6401 | "3296 " |
| 6402 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 6403 | "event: Invalid link %d", |
| 6404 | phba->sli4_hba.lnk_info.lnk_no); |
| 6405 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6406 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6407 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6408 | /* Skip if optic state unchanged */ |
| 6409 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 6410 | return; |
| 6411 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6412 | switch (status) { |
| 6413 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6414 | sprintf(message, "Physical Link is functional"); |
| 6415 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6416 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 6417 | sprintf(message, "Optics faulted/incorrectly " |
| 6418 | "installed/not installed - Reseat optics, " |
| 6419 | "if issue not resolved, replace."); |
| 6420 | break; |
| 6421 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 6422 | sprintf(message, |
| 6423 | "Optics of two types installed - Remove one " |
| 6424 | "optic or install matching pair of optics."); |
| 6425 | break; |
| 6426 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 6427 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 6428 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6429 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6430 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 6431 | sprintf(message, "Unqualified optics - Replace with " |
| 6432 | "Avago optics for Warranty and Technical " |
| 6433 | "Support - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 6434 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6435 | break; |
| 6436 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 6437 | sprintf(message, "Uncertified optics - Replace with " |
| 6438 | "Avago-certified optics to enable link " |
| 6439 | "operation - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 6440 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6441 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6442 | default: |
| 6443 | /* firmware is reporting a status we don't know about */ |
| 6444 | sprintf(message, "Unknown event status x%02x", status); |
| 6445 | break; |
| 6446 | } |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 6447 | |
| 6448 | /* Issue READ_CONFIG mbox command to refresh supported speeds */ |
| 6449 | rc = lpfc_sli4_read_config(phba); |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 6450 | if (rc) { |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 6451 | phba->lmt = 0; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6452 | lpfc_printf_log(phba, KERN_ERR, |
| 6453 | LOG_TRACE_EVENT, |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 6454 | "3194 Unable to retrieve supported " |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 6455 | "speeds, rc = 0x%x\n", rc); |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 6456 | } |
| 6457 | vports = lpfc_create_vport_work_array(phba); |
| 6458 | if (vports != NULL) { |
| 6459 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 6460 | i++) { |
| 6461 | shost = lpfc_shost_from_vport(vports[i]); |
| 6462 | lpfc_host_supported_speeds_set(shost); |
| 6463 | } |
| 6464 | } |
| 6465 | lpfc_destroy_vport_work_array(phba, vports); |
| 6466 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6467 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6468 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6469 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6470 | break; |
| 6471 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 6472 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6473 | "3192 Remote DPort Test Initiated - " |
| 6474 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 6475 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6476 | break; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 6477 | case LPFC_SLI_EVENT_TYPE_PORT_PARAMS_CHG: |
| 6478 | /* Call FW to obtain active parms */ |
| 6479 | lpfc_sli4_cgn_parm_chg_evt(phba); |
| 6480 | break; |
James Smart | e7d8595 | 2019-10-18 14:18:29 -0700 | [diff] [blame] | 6481 | case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN: |
| 6482 | /* Misconfigured WWN. Reports that the SLI Port is configured |
| 6483 | * to use FA-WWN, but the attached device doesn’t support it. |
| 6484 | * No driver action is required. |
| 6485 | * Event Data1 - N.A, Event Data2 - N.A |
| 6486 | */ |
| 6487 | lpfc_log_msg(phba, KERN_WARNING, LOG_SLI, |
| 6488 | "2699 Misconfigured FA-WWN - Attached device does " |
| 6489 | "not support FA-WWN\n"); |
| 6490 | break; |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 6491 | case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE: |
| 6492 | /* EEPROM failure. No driver action is required */ |
| 6493 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 6494 | "2518 EEPROM failure - " |
| 6495 | "Event Data1: x%08x Event Data2: x%08x\n", |
| 6496 | acqe_sli->event_data1, acqe_sli->event_data2); |
| 6497 | break; |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 6498 | case LPFC_SLI_EVENT_TYPE_CGN_SIGNAL: |
| 6499 | if (phba->cmf_active_mode == LPFC_CFG_OFF) |
| 6500 | break; |
| 6501 | cgn_signal = (struct lpfc_acqe_cgn_signal *) |
| 6502 | &acqe_sli->event_data1; |
| 6503 | phba->cgn_acqe_cnt++; |
| 6504 | |
| 6505 | cnt = bf_get(lpfc_warn_acqe, cgn_signal); |
| 6506 | atomic64_add(cnt, &phba->cgn_acqe_stat.warn); |
| 6507 | atomic64_add(cgn_signal->alarm_cnt, &phba->cgn_acqe_stat.alarm); |
| 6508 | |
| 6509 | /* no threshold for CMF, even 1 signal will trigger an event */ |
| 6510 | |
| 6511 | /* Alarm overrides warning, so check that first */ |
| 6512 | if (cgn_signal->alarm_cnt) { |
| 6513 | if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) { |
| 6514 | /* Keep track of alarm cnt for cgn_info */ |
| 6515 | atomic_add(cgn_signal->alarm_cnt, |
| 6516 | &phba->cgn_fabric_alarm_cnt); |
| 6517 | /* Keep track of alarm cnt for CMF_SYNC_WQE */ |
| 6518 | atomic_add(cgn_signal->alarm_cnt, |
| 6519 | &phba->cgn_sync_alarm_cnt); |
| 6520 | } |
| 6521 | } else if (cnt) { |
| 6522 | /* signal action needs to be taken */ |
| 6523 | if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY || |
| 6524 | phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) { |
| 6525 | /* Keep track of warning cnt for cgn_info */ |
| 6526 | atomic_add(cnt, &phba->cgn_fabric_warn_cnt); |
| 6527 | /* Keep track of warning cnt for CMF_SYNC_WQE */ |
| 6528 | atomic_add(cnt, &phba->cgn_sync_warn_cnt); |
| 6529 | } |
| 6530 | } |
| 6531 | break; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6532 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6533 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 6534 | "3193 Unrecognized SLI event, type: 0x%x", |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6535 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 6536 | break; |
| 6537 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6541 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 6542 | * @vport: pointer to vport data structure. |
| 6543 | * |
| 6544 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 6545 | * response to a CVL event. |
| 6546 | * |
| 6547 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 6548 | * return NULL. |
| 6549 | **/ |
| 6550 | static struct lpfc_nodelist * |
| 6551 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 6552 | { |
| 6553 | struct lpfc_nodelist *ndlp; |
| 6554 | struct Scsi_Host *shost; |
| 6555 | struct lpfc_hba *phba; |
| 6556 | |
| 6557 | if (!vport) |
| 6558 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6559 | phba = vport->phba; |
| 6560 | if (!phba) |
| 6561 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6562 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 6563 | if (!ndlp) { |
| 6564 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 6565 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6566 | if (!ndlp) |
| 6567 | return 0; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6568 | /* Set the node type */ |
| 6569 | ndlp->nlp_type |= NLP_FABRIC; |
| 6570 | /* Put ndlp onto node list */ |
| 6571 | lpfc_enqueue_node(vport, ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 6572 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6573 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 6574 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6575 | return NULL; |
| 6576 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 6577 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 6578 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6579 | return NULL; |
| 6580 | shost = lpfc_shost_from_vport(vport); |
| 6581 | if (!shost) |
| 6582 | return NULL; |
| 6583 | lpfc_linkdown_port(vport); |
| 6584 | lpfc_cleanup_pending_mbox(vport); |
| 6585 | spin_lock_irq(shost->host_lock); |
| 6586 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 6587 | spin_unlock_irq(shost->host_lock); |
| 6588 | |
| 6589 | return ndlp; |
| 6590 | } |
| 6591 | |
| 6592 | /** |
| 6593 | * 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] | 6594 | * @phba: pointer to lpfc hba data structure. |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6595 | * |
| 6596 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 6597 | * response to a FCF dead event. |
| 6598 | **/ |
| 6599 | static void |
| 6600 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 6601 | { |
| 6602 | struct lpfc_vport **vports; |
| 6603 | int i; |
| 6604 | |
| 6605 | vports = lpfc_create_vport_work_array(phba); |
| 6606 | if (vports) |
| 6607 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 6608 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 6609 | lpfc_destroy_vport_work_array(phba, vports); |
| 6610 | } |
| 6611 | |
| 6612 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6613 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6614 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 6615 | * @acqe_fip: pointer to the async fcoe completion queue entry. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6616 | * |
| 6617 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 6618 | **/ |
| 6619 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 6620 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6621 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6622 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6623 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6624 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6625 | struct lpfc_vport *vport; |
| 6626 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6627 | int active_vlink_present; |
| 6628 | struct lpfc_vport **vports; |
| 6629 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6630 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6631 | phba->fc_eventTag = acqe_fip->event_tag; |
| 6632 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6633 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6634 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 6635 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 6636 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6637 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6638 | "2546 New FCF event, evt_tag:x%x, " |
| 6639 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6640 | acqe_fip->event_tag, |
| 6641 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 6642 | else |
| 6643 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 6644 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6645 | "2788 FCF param modified event, " |
| 6646 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6647 | acqe_fip->event_tag, |
| 6648 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6649 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6650 | /* |
| 6651 | * During period of FCF discovery, read the FCF |
| 6652 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6653 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6654 | */ |
| 6655 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 6656 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6657 | "2779 Read FCF (x%x) for updating " |
| 6658 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6659 | acqe_fip->index); |
| 6660 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6661 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6662 | |
| 6663 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6664 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6665 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6666 | spin_unlock_irq(&phba->hbalock); |
| 6667 | break; |
| 6668 | } |
| 6669 | /* If fast FCF failover rescan event is pending, do nothing */ |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 6670 | if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6671 | spin_unlock_irq(&phba->hbalock); |
| 6672 | break; |
| 6673 | } |
| 6674 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 6675 | /* If the FCF has been in discovered state, do nothing. */ |
| 6676 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 6677 | spin_unlock_irq(&phba->hbalock); |
| 6678 | break; |
| 6679 | } |
| 6680 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6681 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6682 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 6683 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6684 | "2770 Start FCF table scan per async FCF " |
| 6685 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6686 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6687 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 6688 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6689 | if (rc) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6690 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6691 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6692 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6693 | break; |
| 6694 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6695 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6696 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6697 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
| 6698 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 6699 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6700 | break; |
| 6701 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6702 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6703 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6704 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6705 | "2549 FCF (x%x) disconnected from network, " |
| 6706 | "tag:x%x\n", acqe_fip->index, |
| 6707 | acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6708 | /* |
| 6709 | * If we are in the middle of FCF failover process, clear |
| 6710 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6711 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6712 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame] | 6713 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 6714 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6715 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6716 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6717 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6718 | break; |
| 6719 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6720 | spin_unlock_irq(&phba->hbalock); |
| 6721 | |
| 6722 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6723 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6724 | break; |
| 6725 | |
| 6726 | /* |
| 6727 | * Otherwise, request the port to rediscover the entire FCF |
| 6728 | * table for a fast recovery from case that the current FCF |
| 6729 | * is no longer valid as we are not in the middle of FCF |
| 6730 | * failover process already. |
| 6731 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 6732 | spin_lock_irq(&phba->hbalock); |
| 6733 | /* Mark the fast failover process in progress */ |
| 6734 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 6735 | spin_unlock_irq(&phba->hbalock); |
| 6736 | |
| 6737 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 6738 | "2771 Start FCF fast failover process due to " |
| 6739 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 6740 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 6741 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 6742 | if (rc) { |
| 6743 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6744 | LOG_TRACE_EVENT, |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 6745 | "2772 Issue FCF rediscover mailbox " |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 6746 | "command failed, fail through to FCF " |
| 6747 | "dead event\n"); |
| 6748 | spin_lock_irq(&phba->hbalock); |
| 6749 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 6750 | spin_unlock_irq(&phba->hbalock); |
| 6751 | /* |
| 6752 | * Last resort will fail over by treating this |
| 6753 | * as a link down to FCF registration. |
| 6754 | */ |
| 6755 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 6756 | } else { |
| 6757 | /* Reset FCF roundrobin bmask for new discovery */ |
| 6758 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 6759 | /* |
| 6760 | * Handling fast FCF failover to a DEAD FCF event is |
| 6761 | * considered equalivant to receiving CVL to all vports. |
| 6762 | */ |
| 6763 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 6764 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6765 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6766 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 6767 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6768 | lpfc_printf_log(phba, KERN_ERR, |
| 6769 | LOG_TRACE_EVENT, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6770 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6771 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6772 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6773 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 6774 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6775 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6776 | if (!ndlp) |
| 6777 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6778 | active_vlink_present = 0; |
| 6779 | |
| 6780 | vports = lpfc_create_vport_work_array(phba); |
| 6781 | if (vports) { |
| 6782 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 6783 | i++) { |
| 6784 | if ((!(vports[i]->fc_flag & |
| 6785 | FC_VPORT_CVL_RCVD)) && |
| 6786 | (vports[i]->port_state > LPFC_FDISC)) { |
| 6787 | active_vlink_present = 1; |
| 6788 | break; |
| 6789 | } |
| 6790 | } |
| 6791 | lpfc_destroy_vport_work_array(phba, vports); |
| 6792 | } |
| 6793 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 6794 | /* |
| 6795 | * Don't re-instantiate if vport is marked for deletion. |
| 6796 | * If we are here first then vport_delete is going to wait |
| 6797 | * for discovery to complete. |
| 6798 | */ |
| 6799 | if (!(vport->load_flag & FC_UNLOADING) && |
| 6800 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6801 | /* |
| 6802 | * If there are other active VLinks present, |
| 6803 | * re-instantiate the Vlink using FDISC. |
| 6804 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 6805 | mod_timer(&ndlp->nlp_delayfunc, |
| 6806 | jiffies + msecs_to_jiffies(1000)); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6807 | spin_lock_irq(&ndlp->lock); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6808 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 6809 | spin_unlock_irq(&ndlp->lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 6810 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 6811 | vport->port_state = LPFC_FDISC; |
| 6812 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6813 | /* |
| 6814 | * Otherwise, we request port to rediscover |
| 6815 | * the entire FCF table for a fast recovery |
| 6816 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6817 | * is no longer valid if we are not already |
| 6818 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6819 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6820 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6821 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6822 | spin_unlock_irq(&phba->hbalock); |
| 6823 | break; |
| 6824 | } |
| 6825 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6826 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6827 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6828 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 6829 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6830 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 6831 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6832 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6833 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6834 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6835 | LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6836 | "2774 Issue FCF rediscover " |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 6837 | "mailbox command failed, " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6838 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6839 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6840 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 6841 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6842 | /* |
| 6843 | * Last resort will be re-try on the |
| 6844 | * the current registered FCF entry. |
| 6845 | */ |
| 6846 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 6847 | } else |
| 6848 | /* |
| 6849 | * Reset FCF roundrobin bmask for new |
| 6850 | * discovery. |
| 6851 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 6852 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 6853 | } |
| 6854 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6855 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6856 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6857 | "0288 Unknown FCoE event type 0x%x event tag " |
| 6858 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6859 | break; |
| 6860 | } |
| 6861 | } |
| 6862 | |
| 6863 | /** |
| 6864 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 6865 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 6866 | * @acqe_dcbx: pointer to the async dcbx completion queue entry. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6867 | * |
| 6868 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 6869 | **/ |
| 6870 | static void |
| 6871 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 6872 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 6873 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 6874 | phba->fc_eventTag = acqe_dcbx->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6875 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6876 | "0290 The SLI4 DCBX asynchronous event is not " |
| 6877 | "handled yet\n"); |
| 6878 | } |
| 6879 | |
| 6880 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 6881 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 6882 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 6883 | * @acqe_grp5: pointer to the async grp5 completion queue entry. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 6884 | * |
| 6885 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 6886 | * is an asynchronous notified of a logical link speed change. The Port |
| 6887 | * reports the logical link speed in units of 10Mbps. |
| 6888 | **/ |
| 6889 | static void |
| 6890 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 6891 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 6892 | { |
| 6893 | uint16_t prev_ll_spd; |
| 6894 | |
| 6895 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 6896 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 6897 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 6898 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 6899 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 6900 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 6901 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 6902 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 6903 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 6904 | } |
| 6905 | |
| 6906 | /** |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 6907 | * lpfc_sli4_async_cmstat_evt - Process the asynchronous cmstat event |
| 6908 | * @phba: pointer to lpfc hba data structure. |
| 6909 | * |
| 6910 | * This routine is to handle the SLI4 asynchronous cmstat event. A cmstat event |
| 6911 | * is an asynchronous notification of a request to reset CM stats. |
| 6912 | **/ |
| 6913 | static void |
| 6914 | lpfc_sli4_async_cmstat_evt(struct lpfc_hba *phba) |
| 6915 | { |
| 6916 | if (!phba->cgn_i) |
| 6917 | return; |
| 6918 | lpfc_init_congestion_stat(phba); |
| 6919 | } |
| 6920 | |
| 6921 | /** |
James Smart | 72df8a45 | 2021-08-16 09:28:52 -0700 | [diff] [blame] | 6922 | * lpfc_cgn_params_val - Validate FW congestion parameters. |
| 6923 | * @phba: pointer to lpfc hba data structure. |
| 6924 | * @p_cfg_param: pointer to FW provided congestion parameters. |
| 6925 | * |
| 6926 | * This routine validates the congestion parameters passed |
| 6927 | * by the FW to the driver via an ACQE event. |
| 6928 | **/ |
| 6929 | static void |
| 6930 | lpfc_cgn_params_val(struct lpfc_hba *phba, struct lpfc_cgn_param *p_cfg_param) |
| 6931 | { |
| 6932 | spin_lock_irq(&phba->hbalock); |
| 6933 | |
| 6934 | if (!lpfc_rangecheck(p_cfg_param->cgn_param_mode, LPFC_CFG_OFF, |
| 6935 | LPFC_CFG_MONITOR)) { |
| 6936 | lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT, |
| 6937 | "6225 CMF mode param out of range: %d\n", |
| 6938 | p_cfg_param->cgn_param_mode); |
| 6939 | p_cfg_param->cgn_param_mode = LPFC_CFG_OFF; |
| 6940 | } |
| 6941 | |
| 6942 | spin_unlock_irq(&phba->hbalock); |
| 6943 | } |
| 6944 | |
| 6945 | /** |
| 6946 | * lpfc_cgn_params_parse - Process a FW cong parm change event |
| 6947 | * @phba: pointer to lpfc hba data structure. |
| 6948 | * @p_cgn_param: pointer to a data buffer with the FW cong params. |
| 6949 | * @len: the size of pdata in bytes. |
| 6950 | * |
| 6951 | * This routine validates the congestion management buffer signature |
| 6952 | * from the FW, validates the contents and makes corrections for |
| 6953 | * valid, in-range values. If the signature magic is correct and |
| 6954 | * after parameter validation, the contents are copied to the driver's |
| 6955 | * @phba structure. If the magic is incorrect, an error message is |
| 6956 | * logged. |
| 6957 | **/ |
| 6958 | static void |
| 6959 | lpfc_cgn_params_parse(struct lpfc_hba *phba, |
| 6960 | struct lpfc_cgn_param *p_cgn_param, uint32_t len) |
| 6961 | { |
James Smart | 7481811c | 2021-08-16 09:28:56 -0700 | [diff] [blame] | 6962 | struct lpfc_cgn_info *cp; |
| 6963 | uint32_t crc, oldmode; |
James Smart | 72df8a45 | 2021-08-16 09:28:52 -0700 | [diff] [blame] | 6964 | |
| 6965 | /* Make sure the FW has encoded the correct magic number to |
| 6966 | * validate the congestion parameter in FW memory. |
| 6967 | */ |
| 6968 | if (p_cgn_param->cgn_param_magic == LPFC_CFG_PARAM_MAGIC_NUM) { |
| 6969 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT, |
| 6970 | "4668 FW cgn parm buffer data: " |
| 6971 | "magic 0x%x version %d mode %d " |
| 6972 | "level0 %d level1 %d " |
| 6973 | "level2 %d byte13 %d " |
| 6974 | "byte14 %d byte15 %d " |
| 6975 | "byte11 %d byte12 %d activeMode %d\n", |
| 6976 | p_cgn_param->cgn_param_magic, |
| 6977 | p_cgn_param->cgn_param_version, |
| 6978 | p_cgn_param->cgn_param_mode, |
| 6979 | p_cgn_param->cgn_param_level0, |
| 6980 | p_cgn_param->cgn_param_level1, |
| 6981 | p_cgn_param->cgn_param_level2, |
| 6982 | p_cgn_param->byte13, |
| 6983 | p_cgn_param->byte14, |
| 6984 | p_cgn_param->byte15, |
| 6985 | p_cgn_param->byte11, |
| 6986 | p_cgn_param->byte12, |
| 6987 | phba->cmf_active_mode); |
| 6988 | |
| 6989 | oldmode = phba->cmf_active_mode; |
| 6990 | |
| 6991 | /* Any parameters out of range are corrected to defaults |
| 6992 | * by this routine. No need to fail. |
| 6993 | */ |
| 6994 | lpfc_cgn_params_val(phba, p_cgn_param); |
| 6995 | |
| 6996 | /* Parameters are verified, move them into driver storage */ |
| 6997 | spin_lock_irq(&phba->hbalock); |
| 6998 | memcpy(&phba->cgn_p, p_cgn_param, |
| 6999 | sizeof(struct lpfc_cgn_param)); |
| 7000 | |
James Smart | 7481811c | 2021-08-16 09:28:56 -0700 | [diff] [blame] | 7001 | /* Update parameters in congestion info buffer now */ |
| 7002 | if (phba->cgn_i) { |
| 7003 | cp = (struct lpfc_cgn_info *)phba->cgn_i->virt; |
| 7004 | cp->cgn_info_mode = phba->cgn_p.cgn_param_mode; |
| 7005 | cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0; |
| 7006 | cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1; |
| 7007 | cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2; |
| 7008 | crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, |
| 7009 | LPFC_CGN_CRC32_SEED); |
| 7010 | cp->cgn_info_crc = cpu_to_le32(crc); |
| 7011 | } |
James Smart | 72df8a45 | 2021-08-16 09:28:52 -0700 | [diff] [blame] | 7012 | spin_unlock_irq(&phba->hbalock); |
| 7013 | |
| 7014 | phba->cmf_active_mode = phba->cgn_p.cgn_param_mode; |
| 7015 | |
| 7016 | switch (oldmode) { |
| 7017 | case LPFC_CFG_OFF: |
| 7018 | if (phba->cgn_p.cgn_param_mode != LPFC_CFG_OFF) { |
| 7019 | /* Turning CMF on */ |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 7020 | lpfc_cmf_start(phba); |
James Smart | 72df8a45 | 2021-08-16 09:28:52 -0700 | [diff] [blame] | 7021 | |
| 7022 | if (phba->link_state >= LPFC_LINK_UP) { |
| 7023 | phba->cgn_reg_fpin = |
| 7024 | phba->cgn_init_reg_fpin; |
| 7025 | phba->cgn_reg_signal = |
| 7026 | phba->cgn_init_reg_signal; |
| 7027 | lpfc_issue_els_edc(phba->pport, 0); |
| 7028 | } |
| 7029 | } |
| 7030 | break; |
| 7031 | case LPFC_CFG_MANAGED: |
| 7032 | switch (phba->cgn_p.cgn_param_mode) { |
| 7033 | case LPFC_CFG_OFF: |
| 7034 | /* Turning CMF off */ |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 7035 | lpfc_cmf_stop(phba); |
James Smart | 72df8a45 | 2021-08-16 09:28:52 -0700 | [diff] [blame] | 7036 | if (phba->link_state >= LPFC_LINK_UP) |
| 7037 | lpfc_issue_els_edc(phba->pport, 0); |
| 7038 | break; |
| 7039 | case LPFC_CFG_MONITOR: |
| 7040 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 7041 | "4661 Switch from MANAGED to " |
| 7042 | "`MONITOR mode\n"); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 7043 | phba->cmf_max_bytes_per_interval = |
| 7044 | phba->cmf_link_byte_count; |
| 7045 | |
| 7046 | /* Resume blocked IO - unblock on workqueue */ |
| 7047 | queue_work(phba->wq, |
| 7048 | &phba->unblock_request_work); |
James Smart | 72df8a45 | 2021-08-16 09:28:52 -0700 | [diff] [blame] | 7049 | break; |
| 7050 | } |
| 7051 | break; |
| 7052 | case LPFC_CFG_MONITOR: |
| 7053 | switch (phba->cgn_p.cgn_param_mode) { |
| 7054 | case LPFC_CFG_OFF: |
| 7055 | /* Turning CMF off */ |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 7056 | lpfc_cmf_stop(phba); |
James Smart | 72df8a45 | 2021-08-16 09:28:52 -0700 | [diff] [blame] | 7057 | if (phba->link_state >= LPFC_LINK_UP) |
| 7058 | lpfc_issue_els_edc(phba->pport, 0); |
| 7059 | break; |
| 7060 | case LPFC_CFG_MANAGED: |
| 7061 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 7062 | "4662 Switch from MONITOR to " |
| 7063 | "MANAGED mode\n"); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 7064 | lpfc_cmf_signal_init(phba); |
James Smart | 72df8a45 | 2021-08-16 09:28:52 -0700 | [diff] [blame] | 7065 | break; |
| 7066 | } |
| 7067 | break; |
| 7068 | } |
| 7069 | } else { |
| 7070 | lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT, |
| 7071 | "4669 FW cgn parm buf wrong magic 0x%x " |
| 7072 | "version %d\n", p_cgn_param->cgn_param_magic, |
| 7073 | p_cgn_param->cgn_param_version); |
| 7074 | } |
| 7075 | } |
| 7076 | |
| 7077 | /** |
| 7078 | * lpfc_sli4_cgn_params_read - Read and Validate FW congestion parameters. |
| 7079 | * @phba: pointer to lpfc hba data structure. |
| 7080 | * |
| 7081 | * This routine issues a read_object mailbox command to |
| 7082 | * get the congestion management parameters from the FW |
| 7083 | * parses it and updates the driver maintained values. |
| 7084 | * |
| 7085 | * Returns |
| 7086 | * 0 if the object was empty |
| 7087 | * -Eval if an error was encountered |
| 7088 | * Count if bytes were read from object |
| 7089 | **/ |
| 7090 | int |
| 7091 | lpfc_sli4_cgn_params_read(struct lpfc_hba *phba) |
| 7092 | { |
| 7093 | int ret = 0; |
| 7094 | struct lpfc_cgn_param *p_cgn_param = NULL; |
| 7095 | u32 *pdata = NULL; |
| 7096 | u32 len = 0; |
| 7097 | |
| 7098 | /* Find out if the FW has a new set of congestion parameters. */ |
| 7099 | len = sizeof(struct lpfc_cgn_param); |
| 7100 | pdata = kzalloc(len, GFP_KERNEL); |
| 7101 | ret = lpfc_read_object(phba, (char *)LPFC_PORT_CFG_NAME, |
| 7102 | pdata, len); |
| 7103 | |
| 7104 | /* 0 means no data. A negative means error. A positive means |
| 7105 | * bytes were copied. |
| 7106 | */ |
| 7107 | if (!ret) { |
| 7108 | lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT, |
| 7109 | "4670 CGN RD OBJ returns no data\n"); |
| 7110 | goto rd_obj_err; |
| 7111 | } else if (ret < 0) { |
| 7112 | /* Some error. Just exit and return it to the caller.*/ |
| 7113 | goto rd_obj_err; |
| 7114 | } |
| 7115 | |
| 7116 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT, |
| 7117 | "6234 READ CGN PARAMS Successful %d\n", len); |
| 7118 | |
| 7119 | /* Parse data pointer over len and update the phba congestion |
| 7120 | * parameters with values passed back. The receive rate values |
| 7121 | * may have been altered in FW, but take no action here. |
| 7122 | */ |
| 7123 | p_cgn_param = (struct lpfc_cgn_param *)pdata; |
| 7124 | lpfc_cgn_params_parse(phba, p_cgn_param, len); |
| 7125 | |
| 7126 | rd_obj_err: |
| 7127 | kfree(pdata); |
| 7128 | return ret; |
| 7129 | } |
| 7130 | |
| 7131 | /** |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 7132 | * lpfc_sli4_cgn_parm_chg_evt - Process a FW congestion param change event |
| 7133 | * @phba: pointer to lpfc hba data structure. |
| 7134 | * |
| 7135 | * The FW generated Async ACQE SLI event calls this routine when |
| 7136 | * the event type is an SLI Internal Port Event and the Event Code |
| 7137 | * indicates a change to the FW maintained congestion parameters. |
| 7138 | * |
| 7139 | * This routine executes a Read_Object mailbox call to obtain the |
| 7140 | * current congestion parameters maintained in FW and corrects |
| 7141 | * the driver's active congestion parameters. |
| 7142 | * |
| 7143 | * The acqe event is not passed because there is no further data |
| 7144 | * required. |
| 7145 | * |
| 7146 | * Returns nonzero error if event processing encountered an error. |
| 7147 | * Zero otherwise for success. |
| 7148 | **/ |
| 7149 | static int |
| 7150 | lpfc_sli4_cgn_parm_chg_evt(struct lpfc_hba *phba) |
| 7151 | { |
| 7152 | int ret = 0; |
| 7153 | |
| 7154 | if (!phba->sli4_hba.pc_sli4_params.cmf) { |
| 7155 | lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT, |
| 7156 | "4664 Cgn Evt when E2E off. Drop event\n"); |
| 7157 | return -EACCES; |
| 7158 | } |
| 7159 | |
| 7160 | /* If the event is claiming an empty object, it's ok. A write |
| 7161 | * could have cleared it. Only error is a negative return |
| 7162 | * status. |
| 7163 | */ |
| 7164 | ret = lpfc_sli4_cgn_params_read(phba); |
| 7165 | if (ret < 0) { |
| 7166 | lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT, |
| 7167 | "4667 Error reading Cgn Params (%d)\n", |
| 7168 | ret); |
| 7169 | } else if (!ret) { |
| 7170 | lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT, |
| 7171 | "4673 CGN Event empty object.\n"); |
| 7172 | } |
| 7173 | return ret; |
| 7174 | } |
| 7175 | |
| 7176 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7177 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 7178 | * @phba: pointer to lpfc hba data structure. |
| 7179 | * |
| 7180 | * This routine is invoked by the worker thread to process all the pending |
| 7181 | * SLI4 asynchronous events. |
| 7182 | **/ |
| 7183 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 7184 | { |
| 7185 | struct lpfc_cq_event *cq_event; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 7186 | unsigned long iflags; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7187 | |
| 7188 | /* First, declare the async event has been handled */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 7189 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7190 | phba->hba_flag &= ~ASYNC_EVENT; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 7191 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 7192 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7193 | /* Now, handle all the async events */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 7194 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7195 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7196 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 7197 | cq_event, struct lpfc_cq_event, list); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 7198 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, |
| 7199 | iflags); |
| 7200 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7201 | /* Process the asynchronous event */ |
| 7202 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 7203 | case LPFC_TRAILER_CODE_LINK: |
| 7204 | lpfc_sli4_async_link_evt(phba, |
| 7205 | &cq_event->cqe.acqe_link); |
| 7206 | break; |
| 7207 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 7208 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7209 | break; |
| 7210 | case LPFC_TRAILER_CODE_DCBX: |
| 7211 | lpfc_sli4_async_dcbx_evt(phba, |
| 7212 | &cq_event->cqe.acqe_dcbx); |
| 7213 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 7214 | case LPFC_TRAILER_CODE_GRP5: |
| 7215 | lpfc_sli4_async_grp5_evt(phba, |
| 7216 | &cq_event->cqe.acqe_grp5); |
| 7217 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 7218 | case LPFC_TRAILER_CODE_FC: |
| 7219 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 7220 | break; |
| 7221 | case LPFC_TRAILER_CODE_SLI: |
| 7222 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 7223 | break; |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 7224 | case LPFC_TRAILER_CODE_CMSTAT: |
| 7225 | lpfc_sli4_async_cmstat_evt(phba); |
| 7226 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7227 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7228 | lpfc_printf_log(phba, KERN_ERR, |
| 7229 | LOG_TRACE_EVENT, |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 7230 | "1804 Invalid asynchronous event code: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7231 | "x%x\n", bf_get(lpfc_trailer_code, |
| 7232 | &cq_event->cqe.mcqe_cmpl)); |
| 7233 | break; |
| 7234 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 7235 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7236 | /* Free the completion event processed to the free pool */ |
| 7237 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 7238 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7239 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 7240 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7241 | } |
| 7242 | |
| 7243 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 7244 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 7245 | * @phba: pointer to lpfc hba data structure. |
| 7246 | * |
| 7247 | * This routine is invoked by the worker thread to process FCF table |
| 7248 | * rediscovery pending completion event. |
| 7249 | **/ |
| 7250 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 7251 | { |
| 7252 | int rc; |
| 7253 | |
| 7254 | spin_lock_irq(&phba->hbalock); |
| 7255 | /* Clear FCF rediscovery timeout event */ |
| 7256 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 7257 | /* Clear driver fast failover FCF record flag */ |
| 7258 | phba->fcf.failover_rec.flag = 0; |
| 7259 | /* Set state for FCF fast failover */ |
| 7260 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 7261 | spin_unlock_irq(&phba->hbalock); |
| 7262 | |
| 7263 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7264 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 7265 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7266 | 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] | 7267 | if (rc) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7268 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7269 | "2747 Issue FCF scan read FCF mailbox " |
| 7270 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 7271 | } |
| 7272 | |
| 7273 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7274 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 7275 | * @phba: pointer to lpfc hba data structure. |
| 7276 | * @dev_grp: The HBA PCI-Device group number. |
| 7277 | * |
| 7278 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 7279 | * API jump table entries. |
| 7280 | * |
| 7281 | * Return: 0 if success, otherwise -ENODEV |
| 7282 | **/ |
| 7283 | int |
| 7284 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7285 | { |
| 7286 | int rc; |
| 7287 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7288 | /* Set up lpfc PCI-device group */ |
| 7289 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7290 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7291 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 7292 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 7293 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7294 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7295 | /* Set up device INIT API function jump table */ |
| 7296 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 7297 | if (rc) |
| 7298 | return -ENODEV; |
| 7299 | /* Set up SCSI API function jump table */ |
| 7300 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 7301 | if (rc) |
| 7302 | return -ENODEV; |
| 7303 | /* Set up SLI API function jump table */ |
| 7304 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 7305 | if (rc) |
| 7306 | return -ENODEV; |
| 7307 | /* Set up MBOX API function jump table */ |
| 7308 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 7309 | if (rc) |
| 7310 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7311 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7312 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7313 | } |
| 7314 | |
| 7315 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 7316 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7317 | * @phba: pointer to lpfc hba data structure. |
| 7318 | * @intr_mode: active interrupt mode adopted. |
| 7319 | * |
| 7320 | * This routine it invoked to log the currently used active interrupt mode |
| 7321 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7322 | **/ |
| 7323 | 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] | 7324 | { |
| 7325 | switch (intr_mode) { |
| 7326 | case 0: |
| 7327 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7328 | "0470 Enable INTx interrupt mode.\n"); |
| 7329 | break; |
| 7330 | case 1: |
| 7331 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7332 | "0481 Enabled MSI interrupt mode.\n"); |
| 7333 | break; |
| 7334 | case 2: |
| 7335 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7336 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 7337 | break; |
| 7338 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7339 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7340 | "0482 Illegal interrupt mode.\n"); |
| 7341 | break; |
| 7342 | } |
| 7343 | return; |
| 7344 | } |
| 7345 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7346 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7347 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7348 | * @phba: pointer to lpfc hba data structure. |
| 7349 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7350 | * This routine is invoked to enable the PCI device that is common to all |
| 7351 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7352 | * |
| 7353 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7354 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7355 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7356 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7357 | static int |
| 7358 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7359 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7360 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7361 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7362 | /* Obtain PCI device reference */ |
| 7363 | if (!phba->pcidev) |
| 7364 | goto out_error; |
| 7365 | else |
| 7366 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7367 | /* Enable PCI device */ |
| 7368 | if (pci_enable_device_mem(pdev)) |
| 7369 | goto out_error; |
| 7370 | /* Request PCI resource for the device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 7371 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7372 | goto out_disable_device; |
| 7373 | /* Set up device as PCI master and save state for EEH */ |
| 7374 | pci_set_master(pdev); |
| 7375 | pci_try_set_mwi(pdev); |
| 7376 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7377 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7378 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 7379 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 7380 | pdev->needs_freset = 1; |
| 7381 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7382 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7383 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7384 | out_disable_device: |
| 7385 | pci_disable_device(pdev); |
| 7386 | out_error: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7387 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 7388 | "1401 Failed to enable pci device\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7389 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7390 | } |
| 7391 | |
| 7392 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7393 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7394 | * @phba: pointer to lpfc hba data structure. |
| 7395 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7396 | * This routine is invoked to disable the PCI device that is common to all |
| 7397 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7398 | **/ |
| 7399 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7400 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7401 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7402 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7403 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7404 | /* Obtain PCI device reference */ |
| 7405 | if (!phba->pcidev) |
| 7406 | return; |
| 7407 | else |
| 7408 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7409 | /* Release PCI resource and disable PCI device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 7410 | pci_release_mem_regions(pdev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7411 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 7412 | |
| 7413 | return; |
| 7414 | } |
| 7415 | |
| 7416 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7417 | * lpfc_reset_hba - Reset a hba |
| 7418 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7419 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7420 | * This routine is invoked to reset a hba device. It brings the HBA |
| 7421 | * offline, performs a board restart, and then brings the board back |
| 7422 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 7423 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7424 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7425 | void |
| 7426 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7427 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7428 | /* If resets are disabled then set error state and return. */ |
| 7429 | if (!phba->cfg_enable_hba_reset) { |
| 7430 | phba->link_state = LPFC_HBA_ERROR; |
| 7431 | return; |
| 7432 | } |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 7433 | |
| 7434 | /* If not LPFC_SLI_ACTIVE, force all IO to be flushed */ |
| 7435 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) { |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 7436 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 7437 | } else { |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 7438 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 9ec58ec | 2021-01-04 10:02:35 -0800 | [diff] [blame] | 7439 | lpfc_sli_flush_io_rings(phba); |
| 7440 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7441 | lpfc_offline(phba); |
| 7442 | lpfc_sli_brdrestart(phba); |
| 7443 | lpfc_online(phba); |
| 7444 | lpfc_unblock_mgmt_io(phba); |
| 7445 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7446 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7447 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7448 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 7449 | * @phba: pointer to lpfc hba data structure. |
| 7450 | * |
| 7451 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 7452 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 7453 | * enable the number of virtual functions to the physical function. As |
| 7454 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 7455 | * API call does not considered as an error condition for most of the device. |
| 7456 | **/ |
| 7457 | uint16_t |
| 7458 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 7459 | { |
| 7460 | struct pci_dev *pdev = phba->pcidev; |
| 7461 | uint16_t nr_virtfn; |
| 7462 | int pos; |
| 7463 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7464 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 7465 | if (pos == 0) |
| 7466 | return 0; |
| 7467 | |
| 7468 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 7469 | return nr_virtfn; |
| 7470 | } |
| 7471 | |
| 7472 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7473 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 7474 | * @phba: pointer to lpfc hba data structure. |
| 7475 | * @nr_vfn: number of virtual functions to be enabled. |
| 7476 | * |
| 7477 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 7478 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 7479 | * enable the number of virtual functions to the physical function. As |
| 7480 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 7481 | * API call does not considered as an error condition for most of the device. |
| 7482 | **/ |
| 7483 | int |
| 7484 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 7485 | { |
| 7486 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7487 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7488 | int rc; |
| 7489 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7490 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 7491 | if (nr_vfn > max_nr_vfn) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7492 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 7493 | "3057 Requested vfs (%d) greater than " |
| 7494 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 7495 | return -EINVAL; |
| 7496 | } |
| 7497 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7498 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 7499 | if (rc) { |
| 7500 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7501 | "2806 Failed to enable sriov on this device " |
| 7502 | "with vfn number nr_vf:%d, rc:%d\n", |
| 7503 | nr_vfn, rc); |
| 7504 | } else |
| 7505 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7506 | "2807 Successful enable sriov on this device " |
| 7507 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 7508 | return rc; |
| 7509 | } |
| 7510 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 7511 | static void |
| 7512 | lpfc_unblock_requests_work(struct work_struct *work) |
| 7513 | { |
| 7514 | struct lpfc_hba *phba = container_of(work, struct lpfc_hba, |
| 7515 | unblock_request_work); |
| 7516 | |
| 7517 | lpfc_unblock_requests(phba); |
| 7518 | } |
| 7519 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7520 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7521 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7522 | * @phba: pointer to lpfc hba data structure. |
| 7523 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7524 | * This routine is invoked to set up the driver internal resources before the |
| 7525 | * device specific resource setup to support the HBA device it attached to. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7526 | * |
| 7527 | * Return codes |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7528 | * 0 - successful |
| 7529 | * other values - error |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7530 | **/ |
| 7531 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7532 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7533 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7534 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7535 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7536 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7537 | * Driver resources common to all SLI revisions |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7538 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7539 | atomic_set(&phba->fast_event_count, 0); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7540 | atomic_set(&phba->dbg_log_idx, 0); |
| 7541 | atomic_set(&phba->dbg_log_cnt, 0); |
| 7542 | atomic_set(&phba->dbg_log_dmping, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7543 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7544 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 7545 | /* Initialize port_list spinlock */ |
| 7546 | spin_lock_init(&phba->port_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7547 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 7548 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7549 | INIT_LIST_HEAD(&phba->work_list); |
| 7550 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| 7551 | |
| 7552 | /* Initialize the wait queue head for the kernel thread */ |
| 7553 | init_waitqueue_head(&phba->work_waitq); |
| 7554 | |
| 7555 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7556 | "1403 Protocols supported %s %s %s\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7557 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
| 7558 | "SCSI" : " "), |
| 7559 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7560 | "NVME" : " "), |
| 7561 | (phba->nvmet_support ? "NVMET" : " ")); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7562 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7563 | /* Initialize the IO buffer list used by driver for SLI3 SCSI */ |
| 7564 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 7565 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 7566 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 7567 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7568 | |
| 7569 | /* Initialize the fabric iocb list */ |
| 7570 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 7571 | |
| 7572 | /* Initialize list to save ELS buffers */ |
| 7573 | INIT_LIST_HEAD(&phba->elsbuf); |
| 7574 | |
| 7575 | /* Initialize FCF connection rec list */ |
| 7576 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| 7577 | |
| 7578 | /* Initialize OAS configuration list */ |
| 7579 | spin_lock_init(&phba->devicelock); |
| 7580 | INIT_LIST_HEAD(&phba->luns); |
| 7581 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7582 | /* MBOX heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7583 | timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7584 | /* Fabric block timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7585 | timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7586 | /* EA polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7587 | timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7588 | /* Heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7589 | timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7590 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7591 | INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work); |
| 7592 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7593 | INIT_DELAYED_WORK(&phba->idle_stat_delay_work, |
| 7594 | lpfc_idle_stat_delay_work); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 7595 | INIT_WORK(&phba->unblock_request_work, lpfc_unblock_requests_work); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7596 | return 0; |
| 7597 | } |
| 7598 | |
| 7599 | /** |
| 7600 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev |
| 7601 | * @phba: pointer to lpfc hba data structure. |
| 7602 | * |
| 7603 | * This routine is invoked to set up the driver internal resources specific to |
| 7604 | * support the SLI-3 HBA device it attached to. |
| 7605 | * |
| 7606 | * Return codes |
| 7607 | * 0 - successful |
| 7608 | * other values - error |
| 7609 | **/ |
| 7610 | static int |
| 7611 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 7612 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7613 | int rc, entry_sz; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7614 | |
| 7615 | /* |
| 7616 | * Initialize timers used by driver |
| 7617 | */ |
| 7618 | |
| 7619 | /* FCP polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7620 | timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7621 | |
| 7622 | /* Host attention work mask setup */ |
| 7623 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 7624 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 7625 | |
| 7626 | /* Get all the module params for configuring this host */ |
| 7627 | lpfc_get_cfgparam(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7628 | /* Set up phase-1 common device driver resources */ |
| 7629 | |
| 7630 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 7631 | if (rc) |
| 7632 | return -ENODEV; |
| 7633 | |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 7634 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 7635 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 7636 | /* check for menlo minimum sg count */ |
| 7637 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 7638 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 7639 | } |
| 7640 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7641 | if (!phba->sli.sli3_ring) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 7642 | phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING, |
| 7643 | sizeof(struct lpfc_sli_ring), |
| 7644 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7645 | if (!phba->sli.sli3_ring) |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7646 | return -ENOMEM; |
| 7647 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7648 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 7649 | * 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] | 7650 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7651 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7652 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7653 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7654 | entry_sz = sizeof(struct sli4_sge); |
| 7655 | else |
| 7656 | entry_sz = sizeof(struct ulp_bde64); |
| 7657 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 7658 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 7659 | if (phba->cfg_enable_bg) { |
| 7660 | /* |
| 7661 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 7662 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 7663 | * over how many protection data segments the SCSI Layer |
| 7664 | * will hand us (ie: there could be one for every block |
| 7665 | * in the IO), we just allocate enough BDEs to accomidate |
| 7666 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 7667 | * minimize the risk of running out. |
| 7668 | */ |
| 7669 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 7670 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7671 | (LPFC_MAX_SG_SEG_CNT * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 7672 | |
| 7673 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 7674 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 7675 | |
| 7676 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 7677 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 7678 | } else { |
| 7679 | /* |
| 7680 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 7681 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 7682 | * cfg_sg_seg_cnt data segments. |
| 7683 | */ |
| 7684 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 7685 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 7686 | ((phba->cfg_sg_seg_cnt + 2) * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 7687 | |
| 7688 | /* Total BDEs in BPL for scsi_sg_list */ |
| 7689 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 7690 | } |
| 7691 | |
| 7692 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 7693 | "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 7694 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 7695 | phba->cfg_total_seg_cnt); |
| 7696 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7697 | phba->max_vpi = LPFC_MAX_VPI; |
| 7698 | /* This will be set to correct value after config_port mbox */ |
| 7699 | phba->max_vports = 0; |
| 7700 | |
| 7701 | /* |
| 7702 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 7703 | */ |
| 7704 | lpfc_sli_setup(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7705 | lpfc_sli_queue_init(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7706 | |
| 7707 | /* Allocate device driver memory */ |
| 7708 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 7709 | return -ENOMEM; |
| 7710 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 7711 | phba->lpfc_sg_dma_buf_pool = |
| 7712 | dma_pool_create("lpfc_sg_dma_buf_pool", |
| 7713 | &phba->pcidev->dev, phba->cfg_sg_dma_buf_size, |
| 7714 | BPL_ALIGN_SZ, 0); |
| 7715 | |
| 7716 | if (!phba->lpfc_sg_dma_buf_pool) |
| 7717 | goto fail_free_mem; |
| 7718 | |
| 7719 | phba->lpfc_cmd_rsp_buf_pool = |
| 7720 | dma_pool_create("lpfc_cmd_rsp_buf_pool", |
| 7721 | &phba->pcidev->dev, |
| 7722 | sizeof(struct fcp_cmnd) + |
| 7723 | sizeof(struct fcp_rsp), |
| 7724 | BPL_ALIGN_SZ, 0); |
| 7725 | |
| 7726 | if (!phba->lpfc_cmd_rsp_buf_pool) |
| 7727 | goto fail_free_dma_buf_pool; |
| 7728 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7729 | /* |
| 7730 | * Enable sr-iov virtual functions if supported and configured |
| 7731 | * through the module parameter. |
| 7732 | */ |
| 7733 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 7734 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 7735 | phba->cfg_sriov_nr_virtfn); |
| 7736 | if (rc) { |
| 7737 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7738 | "2808 Requested number of SR-IOV " |
| 7739 | "virtual functions (%d) is not " |
| 7740 | "supported\n", |
| 7741 | phba->cfg_sriov_nr_virtfn); |
| 7742 | phba->cfg_sriov_nr_virtfn = 0; |
| 7743 | } |
| 7744 | } |
| 7745 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7746 | return 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 7747 | |
| 7748 | fail_free_dma_buf_pool: |
| 7749 | dma_pool_destroy(phba->lpfc_sg_dma_buf_pool); |
| 7750 | phba->lpfc_sg_dma_buf_pool = NULL; |
| 7751 | fail_free_mem: |
| 7752 | lpfc_mem_free(phba); |
| 7753 | return -ENOMEM; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7754 | } |
| 7755 | |
| 7756 | /** |
| 7757 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 7758 | * @phba: pointer to lpfc hba data structure. |
| 7759 | * |
| 7760 | * This routine is invoked to unset the driver internal resources set up |
| 7761 | * specific for supporting the SLI-3 HBA device it attached to. |
| 7762 | **/ |
| 7763 | static void |
| 7764 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 7765 | { |
| 7766 | /* Free device driver memory allocated */ |
| 7767 | lpfc_mem_free_all(phba); |
| 7768 | |
| 7769 | return; |
| 7770 | } |
| 7771 | |
| 7772 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7773 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 7774 | * @phba: pointer to lpfc hba data structure. |
| 7775 | * |
| 7776 | * This routine is invoked to set up the driver internal resources specific to |
| 7777 | * support the SLI-4 HBA device it attached to. |
| 7778 | * |
| 7779 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7780 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7781 | * other values - error |
| 7782 | **/ |
| 7783 | static int |
| 7784 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 7785 | { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 7786 | LPFC_MBOXQ_t *mboxq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7787 | MAILBOX_t *mb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7788 | int rc, i, max_buf_size; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 7789 | int longs; |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 7790 | int extra; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7791 | uint64_t wwn; |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 7792 | u32 if_type; |
| 7793 | u32 if_fam; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7794 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7795 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | eede497 | 2019-11-21 09:55:56 -0800 | [diff] [blame] | 7796 | phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7797 | phba->sli4_hba.curr_disp_cpu = 0; |
| 7798 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 7799 | /* Get all the module params for configuring this host */ |
| 7800 | lpfc_get_cfgparam(phba); |
| 7801 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7802 | /* Set up phase-1 common device driver resources */ |
| 7803 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 7804 | if (rc) |
| 7805 | return -ENODEV; |
| 7806 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7807 | /* Before proceed, wait for POST done and device ready */ |
| 7808 | rc = lpfc_sli4_post_status_check(phba); |
| 7809 | if (rc) |
| 7810 | return -ENODEV; |
| 7811 | |
James Smart | 3cee98d | 2019-08-14 16:56:34 -0700 | [diff] [blame] | 7812 | /* Allocate all driver workqueues here */ |
| 7813 | |
| 7814 | /* The lpfc_wq workqueue for deferred irq use */ |
| 7815 | phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); |
| 7816 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7817 | /* |
| 7818 | * Initialize timers used by driver |
| 7819 | */ |
| 7820 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7821 | timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7822 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 7823 | /* FCF rediscover timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 7824 | 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] | 7825 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 7826 | /* CMF congestion timer */ |
| 7827 | hrtimer_init(&phba->cmf_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 7828 | phba->cmf_timer.function = lpfc_cmf_timer; |
| 7829 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7830 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 7831 | * Control structure for handling external multi-buffer mailbox |
| 7832 | * command pass-through. |
| 7833 | */ |
| 7834 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 7835 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 7836 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 7837 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7838 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 7839 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7840 | /* This will be set to correct value after the read_config mbox */ |
| 7841 | phba->max_vports = 0; |
| 7842 | |
| 7843 | /* Program the default value of vlan_id and fc_map */ |
| 7844 | phba->valid_vlan = 0; |
| 7845 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 7846 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 7847 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 7848 | |
| 7849 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7850 | * 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] | 7851 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
| 7852 | * The WQ create will allocate the ring. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7853 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 7854 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7855 | /* Initialize buffer queue management fields */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7856 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7857 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 7858 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 7859 | |
Gaurav Srivastava | 2039717 | 2021-06-08 10:05:54 +0530 | [diff] [blame] | 7860 | /* for VMID idle timeout if VMID is enabled */ |
| 7861 | if (lpfc_is_vmid_enabled(phba)) |
| 7862 | timer_setup(&phba->inactive_vmid_poll, lpfc_vmid_poll, 0); |
| 7863 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7864 | /* |
| 7865 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 7866 | */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 7867 | /* Initialize the Abort buffer list used by driver */ |
| 7868 | spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock); |
| 7869 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7870 | |
| 7871 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 7872 | /* Initialize the Abort nvme buffer list used by driver */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7873 | spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 7874 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7875 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list); |
James Smart | 79d8c4c | 2019-05-21 17:48:56 -0700 | [diff] [blame] | 7876 | spin_lock_init(&phba->sli4_hba.t_active_list_lock); |
| 7877 | INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7878 | } |
| 7879 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7880 | /* This abort list used by worker thread */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7881 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 7882 | spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 7883 | spin_lock_init(&phba->sli4_hba.asynce_list_lock); |
| 7884 | spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7885 | |
| 7886 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7887 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7888 | */ |
| 7889 | |
| 7890 | /* Driver internel slow-path CQ Event pool */ |
| 7891 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 7892 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 7893 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7894 | /* Asynchronous event CQ Event work queue list */ |
| 7895 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7896 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 7897 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 7898 | /* Receive queue CQ Event work queue list */ |
| 7899 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 7900 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7901 | /* Initialize extent block lists. */ |
| 7902 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 7903 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 7904 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 7905 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 7906 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 7907 | /* Initialize mboxq lists. If the early init routines fail |
| 7908 | * these lists need to be correctly initialized. |
| 7909 | */ |
| 7910 | INIT_LIST_HEAD(&phba->sli.mboxq); |
| 7911 | INIT_LIST_HEAD(&phba->sli.mboxq_cmpl); |
| 7912 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 7913 | /* initialize optic_state to 0xFF */ |
| 7914 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 7915 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7916 | /* Allocate device driver memory */ |
| 7917 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 7918 | if (rc) |
| 7919 | return -ENOMEM; |
| 7920 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7921 | /* IF Type 2 ports get initialized now. */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 7922 | 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] | 7923 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 7924 | rc = lpfc_pci_function_reset(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7925 | if (unlikely(rc)) { |
| 7926 | rc = -ENODEV; |
| 7927 | goto out_free_mem; |
| 7928 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 7929 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7930 | } |
| 7931 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7932 | /* Create the bootstrap mailbox command */ |
| 7933 | rc = lpfc_create_bootstrap_mbox(phba); |
| 7934 | if (unlikely(rc)) |
| 7935 | goto out_free_mem; |
| 7936 | |
| 7937 | /* Set up the host's endian order with the device. */ |
| 7938 | rc = lpfc_setup_endian_order(phba); |
| 7939 | if (unlikely(rc)) |
| 7940 | goto out_free_bsmbx; |
| 7941 | |
| 7942 | /* Set up the hba's configuration parameters. */ |
| 7943 | rc = lpfc_sli4_read_config(phba); |
| 7944 | if (unlikely(rc)) |
| 7945 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 7946 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 7947 | if (unlikely(rc)) |
| 7948 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7949 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7950 | /* IF Type 0 ports get initialized now. */ |
| 7951 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 7952 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 7953 | rc = lpfc_pci_function_reset(phba); |
| 7954 | if (unlikely(rc)) |
| 7955 | goto out_free_bsmbx; |
| 7956 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7957 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 7958 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 7959 | GFP_KERNEL); |
| 7960 | if (!mboxq) { |
| 7961 | rc = -ENOMEM; |
| 7962 | goto out_free_bsmbx; |
| 7963 | } |
| 7964 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7965 | /* Check for NVMET being configured */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7966 | phba->nvmet_support = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7967 | if (lpfc_enable_nvmet_cnt) { |
| 7968 | |
| 7969 | /* First get WWN of HBA instance */ |
| 7970 | lpfc_read_nv(phba, mboxq); |
| 7971 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 7972 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7973 | lpfc_printf_log(phba, KERN_ERR, |
| 7974 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7975 | "6016 Mailbox failed , mbxCmd x%x " |
| 7976 | "READ_NV, mbxStatus x%x\n", |
| 7977 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 7978 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 7979 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7980 | rc = -EIO; |
| 7981 | goto out_free_bsmbx; |
| 7982 | } |
| 7983 | mb = &mboxq->u.mb; |
| 7984 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, |
| 7985 | sizeof(uint64_t)); |
| 7986 | wwn = cpu_to_be64(wwn); |
| 7987 | phba->sli4_hba.wwnn.u.name = wwn; |
| 7988 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, |
| 7989 | sizeof(uint64_t)); |
| 7990 | /* wwn is WWPN of HBA instance */ |
| 7991 | wwn = cpu_to_be64(wwn); |
| 7992 | phba->sli4_hba.wwpn.u.name = wwn; |
| 7993 | |
| 7994 | /* Check to see if it matches any module parameter */ |
| 7995 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { |
| 7996 | if (wwn == lpfc_enable_nvmet[i]) { |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 7997 | #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 7998 | if (lpfc_nvmet_mem_alloc(phba)) |
| 7999 | break; |
| 8000 | |
| 8001 | phba->nvmet_support = 1; /* a match */ |
| 8002 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8003 | lpfc_printf_log(phba, KERN_ERR, |
| 8004 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8005 | "6017 NVME Target %016llx\n", |
| 8006 | wwn); |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 8007 | #else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8008 | lpfc_printf_log(phba, KERN_ERR, |
| 8009 | LOG_TRACE_EVENT, |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 8010 | "6021 Can't enable NVME Target." |
| 8011 | " NVME_TARGET_FC infrastructure" |
| 8012 | " is not in kernel\n"); |
| 8013 | #endif |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 8014 | /* Not supported for NVMET */ |
| 8015 | phba->cfg_xri_rebalancing = 0; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 8016 | if (phba->irq_chann_mode == NHT_MODE) { |
| 8017 | phba->cfg_irq_chann = |
| 8018 | phba->sli4_hba.num_present_cpu; |
| 8019 | phba->cfg_hdw_queue = |
| 8020 | phba->sli4_hba.num_present_cpu; |
| 8021 | phba->irq_chann_mode = NORMAL_MODE; |
| 8022 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 8023 | break; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8024 | } |
| 8025 | } |
| 8026 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8027 | |
| 8028 | lpfc_nvme_mod_param_dep(phba); |
| 8029 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8030 | /* |
| 8031 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8032 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 8033 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 8034 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8035 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 8036 | if (rc) { |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 8037 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8038 | &phba->sli4_hba.sli_intf); |
| 8039 | if_fam = bf_get(lpfc_sli_intf_sli_family, |
| 8040 | &phba->sli4_hba.sli_intf); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8041 | if (phba->sli4_hba.extents_in_use && |
| 8042 | phba->sli4_hba.rpi_hdrs_in_use) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8043 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 8044 | "2999 Unsupported SLI4 Parameters " |
| 8045 | "Extents and RPI headers enabled.\n"); |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 8046 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 8047 | if_fam == LPFC_SLI_INTF_FAMILY_BE2) { |
| 8048 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8049 | rc = -EIO; |
| 8050 | goto out_free_bsmbx; |
| 8051 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8052 | } |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 8053 | if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 8054 | if_fam == LPFC_SLI_INTF_FAMILY_BE2)) { |
| 8055 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8056 | rc = -EIO; |
| 8057 | goto out_free_bsmbx; |
| 8058 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8059 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8060 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 8061 | /* |
| 8062 | * 1 for cmd, 1 for rsp, NVME adds an extra one |
| 8063 | * for boundary conditions in its max_sgl_segment template. |
| 8064 | */ |
| 8065 | extra = 2; |
| 8066 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 8067 | extra++; |
| 8068 | |
| 8069 | /* |
| 8070 | * It doesn't matter what family our adapter is in, we are |
| 8071 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 8072 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 8073 | */ |
| 8074 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
| 8075 | |
| 8076 | /* |
| 8077 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
| 8078 | * used to create the sg_dma_buf_pool must be calculated. |
| 8079 | */ |
| 8080 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 8081 | /* Both cfg_enable_bg and cfg_external_dif code paths */ |
| 8082 | |
| 8083 | /* |
| 8084 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
| 8085 | * the FCP rsp, and a SGE. Sice we have no control |
| 8086 | * over how many protection segments the SCSI Layer |
| 8087 | * will hand us (ie: there could be one for every block |
| 8088 | * in the IO), just allocate enough SGEs to accomidate |
| 8089 | * our max amount and we need to limit lpfc_sg_seg_cnt |
| 8090 | * to minimize the risk of running out. |
| 8091 | */ |
| 8092 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 8093 | sizeof(struct fcp_rsp) + max_buf_size; |
| 8094 | |
| 8095 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 8096 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 8097 | |
| 8098 | /* |
| 8099 | * If supporting DIF, reduce the seg count for scsi to |
| 8100 | * allow room for the DIF sges. |
| 8101 | */ |
| 8102 | if (phba->cfg_enable_bg && |
| 8103 | phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF) |
| 8104 | phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF; |
| 8105 | else |
| 8106 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 8107 | |
| 8108 | } else { |
| 8109 | /* |
| 8110 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
| 8111 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 8112 | * cfg_sg_seg_cnt data segments. |
| 8113 | */ |
| 8114 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 8115 | sizeof(struct fcp_rsp) + |
| 8116 | ((phba->cfg_sg_seg_cnt + extra) * |
| 8117 | sizeof(struct sli4_sge)); |
| 8118 | |
| 8119 | /* Total SGEs for scsi_sg_list */ |
| 8120 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra; |
| 8121 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 8122 | |
| 8123 | /* |
| 8124 | * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only |
| 8125 | * need to post 1 page for the SGL. |
| 8126 | */ |
| 8127 | } |
| 8128 | |
| 8129 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 8130 | phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE; |
| 8131 | else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 8132 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 8133 | else |
| 8134 | phba->cfg_sg_dma_buf_size = |
| 8135 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 8136 | |
| 8137 | phba->border_sge_num = phba->cfg_sg_dma_buf_size / |
| 8138 | sizeof(struct sli4_sge); |
| 8139 | |
| 8140 | /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */ |
| 8141 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 8142 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { |
| 8143 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, |
| 8144 | "6300 Reducing NVME sg segment " |
| 8145 | "cnt to %d\n", |
| 8146 | LPFC_MAX_NVME_SEG_CNT); |
| 8147 | phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
| 8148 | } else |
| 8149 | phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; |
| 8150 | } |
| 8151 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 8152 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 8153 | "9087 sg_seg_cnt:%d dmabuf_size:%d " |
| 8154 | "total:%d scsi:%d nvme:%d\n", |
| 8155 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 8156 | phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt, |
| 8157 | phba->cfg_nvme_seg_cnt); |
| 8158 | |
| 8159 | if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE) |
| 8160 | i = phba->cfg_sg_dma_buf_size; |
| 8161 | else |
| 8162 | i = SLI4_PAGE_SIZE; |
| 8163 | |
| 8164 | phba->lpfc_sg_dma_buf_pool = |
| 8165 | dma_pool_create("lpfc_sg_dma_buf_pool", |
| 8166 | &phba->pcidev->dev, |
| 8167 | phba->cfg_sg_dma_buf_size, |
| 8168 | i, 0); |
| 8169 | if (!phba->lpfc_sg_dma_buf_pool) |
| 8170 | goto out_free_bsmbx; |
| 8171 | |
| 8172 | phba->lpfc_cmd_rsp_buf_pool = |
| 8173 | dma_pool_create("lpfc_cmd_rsp_buf_pool", |
| 8174 | &phba->pcidev->dev, |
| 8175 | sizeof(struct fcp_cmnd) + |
| 8176 | sizeof(struct fcp_rsp), |
| 8177 | i, 0); |
| 8178 | if (!phba->lpfc_cmd_rsp_buf_pool) |
| 8179 | goto out_free_sg_dma_buf; |
| 8180 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 8181 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8182 | |
| 8183 | /* Verify OAS is supported */ |
| 8184 | lpfc_sli4_oas_verify(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 8185 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 8186 | /* Verify RAS support on adapter */ |
| 8187 | lpfc_sli4_ras_init(phba); |
| 8188 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8189 | /* Verify all the SLI4 queues */ |
| 8190 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8191 | if (rc) |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 8192 | goto out_free_cmd_rsp_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8193 | |
| 8194 | /* Create driver internal CQE event pool */ |
| 8195 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 8196 | if (rc) |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 8197 | goto out_free_cmd_rsp_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8198 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8199 | /* Initialize sgl lists per host */ |
| 8200 | lpfc_init_sgl_list(phba); |
| 8201 | |
| 8202 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8203 | rc = lpfc_init_active_sgl_array(phba); |
| 8204 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8205 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8206 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8207 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8208 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8209 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 8210 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8211 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8212 | "1432 Failed to initialize rpi headers.\n"); |
| 8213 | goto out_free_active_sgl; |
| 8214 | } |
| 8215 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 8216 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8217 | 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] | 8218 | phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8219 | GFP_KERNEL); |
| 8220 | if (!phba->fcf.fcf_rr_bmask) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8221 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8222 | "2759 Failed allocate memory for FCF round " |
| 8223 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8224 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8225 | goto out_remove_rpi_hdrs; |
| 8226 | } |
| 8227 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8228 | phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8229 | sizeof(struct lpfc_hba_eq_hdl), |
| 8230 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8231 | if (!phba->sli4_hba.hba_eq_hdl) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8232 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8233 | "2572 Failed allocate memory for " |
| 8234 | "fast-path per-EQ handle array\n"); |
| 8235 | rc = -ENOMEM; |
| 8236 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8237 | } |
| 8238 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 8239 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8240 | sizeof(struct lpfc_vector_map_info), |
| 8241 | GFP_KERNEL); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8242 | if (!phba->sli4_hba.cpu_map) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8243 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8244 | "3327 Failed allocate memory for msi-x " |
| 8245 | "interrupt vector mapping\n"); |
| 8246 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8247 | goto out_free_hba_eq_hdl; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8248 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 8249 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8250 | phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info); |
| 8251 | if (!phba->sli4_hba.eq_info) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8252 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8253 | "3321 Failed allocation for per_cpu stats\n"); |
| 8254 | rc = -ENOMEM; |
| 8255 | goto out_free_hba_cpu_map; |
| 8256 | } |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 8257 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 8258 | phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu, |
| 8259 | sizeof(*phba->sli4_hba.idle_stat), |
| 8260 | GFP_KERNEL); |
| 8261 | if (!phba->sli4_hba.idle_stat) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8262 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 8263 | "3390 Failed allocation for idle_stat\n"); |
| 8264 | rc = -ENOMEM; |
| 8265 | goto out_free_hba_eq_info; |
| 8266 | } |
| 8267 | |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 8268 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 8269 | phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat); |
| 8270 | if (!phba->sli4_hba.c_stat) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8271 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 8272 | "3332 Failed allocating per cpu hdwq stats\n"); |
| 8273 | rc = -ENOMEM; |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 8274 | goto out_free_hba_idle_stat; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 8275 | } |
| 8276 | #endif |
| 8277 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 8278 | phba->cmf_stat = alloc_percpu(struct lpfc_cgn_stat); |
| 8279 | if (!phba->cmf_stat) { |
| 8280 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 8281 | "3331 Failed allocating per cpu cgn stats\n"); |
| 8282 | rc = -ENOMEM; |
| 8283 | goto out_free_hba_hdwq_info; |
| 8284 | } |
| 8285 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8286 | /* |
| 8287 | * Enable sr-iov virtual functions if supported and configured |
| 8288 | * through the module parameter. |
| 8289 | */ |
| 8290 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 8291 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 8292 | phba->cfg_sriov_nr_virtfn); |
| 8293 | if (rc) { |
| 8294 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8295 | "3020 Requested number of SR-IOV " |
| 8296 | "virtual functions (%d) is not " |
| 8297 | "supported\n", |
| 8298 | phba->cfg_sriov_nr_virtfn); |
| 8299 | phba->cfg_sriov_nr_virtfn = 0; |
| 8300 | } |
| 8301 | } |
| 8302 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 8303 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8304 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 8305 | out_free_hba_hdwq_info: |
| 8306 | free_percpu(phba->sli4_hba.c_stat); |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 8307 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 8308 | out_free_hba_idle_stat: |
| 8309 | kfree(phba->sli4_hba.idle_stat); |
| 8310 | #endif |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 8311 | out_free_hba_eq_info: |
| 8312 | free_percpu(phba->sli4_hba.eq_info); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8313 | out_free_hba_cpu_map: |
| 8314 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8315 | out_free_hba_eq_hdl: |
| 8316 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8317 | out_free_fcf_rr_bmask: |
| 8318 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8319 | out_remove_rpi_hdrs: |
| 8320 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 8321 | out_free_active_sgl: |
| 8322 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8323 | out_destroy_cq_event_pool: |
| 8324 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 8325 | out_free_cmd_rsp_buf: |
| 8326 | dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool); |
| 8327 | phba->lpfc_cmd_rsp_buf_pool = NULL; |
| 8328 | out_free_sg_dma_buf: |
| 8329 | dma_pool_destroy(phba->lpfc_sg_dma_buf_pool); |
| 8330 | phba->lpfc_sg_dma_buf_pool = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8331 | out_free_bsmbx: |
| 8332 | lpfc_destroy_bootstrap_mbox(phba); |
| 8333 | out_free_mem: |
| 8334 | lpfc_mem_free(phba); |
| 8335 | return rc; |
| 8336 | } |
| 8337 | |
| 8338 | /** |
| 8339 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 8340 | * @phba: pointer to lpfc hba data structure. |
| 8341 | * |
| 8342 | * This routine is invoked to unset the driver internal resources set up |
| 8343 | * specific for supporting the SLI-4 HBA device it attached to. |
| 8344 | **/ |
| 8345 | static void |
| 8346 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 8347 | { |
| 8348 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 8349 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8350 | free_percpu(phba->sli4_hba.eq_info); |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 8351 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 8352 | free_percpu(phba->sli4_hba.c_stat); |
| 8353 | #endif |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 8354 | free_percpu(phba->cmf_stat); |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 8355 | kfree(phba->sli4_hba.idle_stat); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8356 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8357 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 8358 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 8359 | phba->sli4_hba.num_possible_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8360 | phba->sli4_hba.num_present_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 8361 | phba->sli4_hba.curr_disp_cpu = 0; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 8362 | cpumask_clear(&phba->sli4_hba.irq_aff_mask); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 8363 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8364 | /* Free memory allocated for fast-path work queue handles */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8365 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8366 | |
| 8367 | /* Free the allocated rpi headers. */ |
| 8368 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 8369 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8370 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 8371 | /* Free eligible FCF index bmask */ |
| 8372 | kfree(phba->fcf.fcf_rr_bmask); |
| 8373 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8374 | /* Free the ELS sgl list */ |
| 8375 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8376 | lpfc_free_els_sgl_list(phba); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8377 | lpfc_free_nvmet_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8378 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8379 | /* Free the completion queue EQ event pool */ |
| 8380 | lpfc_sli4_cq_event_release_all(phba); |
| 8381 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 8382 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8383 | /* Release resource identifiers. */ |
| 8384 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 8385 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8386 | /* Free the bsmbx region. */ |
| 8387 | lpfc_destroy_bootstrap_mbox(phba); |
| 8388 | |
| 8389 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 8390 | lpfc_mem_free_all(phba); |
| 8391 | |
| 8392 | /* Free the current connect table */ |
| 8393 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 8394 | &phba->fcf_conn_rec_list, list) { |
| 8395 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8396 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 8397 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8398 | |
| 8399 | return; |
| 8400 | } |
| 8401 | |
| 8402 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8403 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8404 | * @phba: The hba struct for which this call is being executed. |
| 8405 | * @dev_grp: The HBA PCI-Device group number. |
| 8406 | * |
| 8407 | * This routine sets up the device INIT interface API function jump table |
| 8408 | * in @phba struct. |
| 8409 | * |
| 8410 | * Returns: 0 - success, -ENODEV - failure. |
| 8411 | **/ |
| 8412 | int |
| 8413 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 8414 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 8415 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 8416 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 8417 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8418 | switch (dev_grp) { |
| 8419 | case LPFC_PCI_DEV_LP: |
| 8420 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 8421 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 8422 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 8423 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8424 | case LPFC_PCI_DEV_OC: |
| 8425 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 8426 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 8427 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 8428 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8429 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8430 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8431 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 8432 | dev_grp); |
| 8433 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8434 | } |
| 8435 | return 0; |
| 8436 | } |
| 8437 | |
| 8438 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8439 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 8440 | * @phba: pointer to lpfc hba data structure. |
| 8441 | * |
| 8442 | * This routine is invoked to set up the driver internal resources after the |
| 8443 | * device specific resource setup to support the HBA device it attached to. |
| 8444 | * |
| 8445 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8446 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8447 | * other values - error |
| 8448 | **/ |
| 8449 | static int |
| 8450 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 8451 | { |
| 8452 | int error; |
| 8453 | |
| 8454 | /* Startup the kernel thread for this host adapter. */ |
| 8455 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 8456 | "lpfc_worker_%d", phba->brd_no); |
| 8457 | if (IS_ERR(phba->worker_thread)) { |
| 8458 | error = PTR_ERR(phba->worker_thread); |
| 8459 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 8460 | } |
| 8461 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8462 | return 0; |
| 8463 | } |
| 8464 | |
| 8465 | /** |
| 8466 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 8467 | * @phba: pointer to lpfc hba data structure. |
| 8468 | * |
| 8469 | * This routine is invoked to unset the driver internal resources set up after |
| 8470 | * the device specific resource setup for supporting the HBA device it |
| 8471 | * attached to. |
| 8472 | **/ |
| 8473 | static void |
| 8474 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 8475 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 8476 | if (phba->wq) { |
| 8477 | flush_workqueue(phba->wq); |
| 8478 | destroy_workqueue(phba->wq); |
| 8479 | phba->wq = NULL; |
| 8480 | } |
| 8481 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8482 | /* Stop kernel worker thread */ |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 8483 | if (phba->worker_thread) |
| 8484 | kthread_stop(phba->worker_thread); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8485 | } |
| 8486 | |
| 8487 | /** |
| 8488 | * lpfc_free_iocb_list - Free iocb list. |
| 8489 | * @phba: pointer to lpfc hba data structure. |
| 8490 | * |
| 8491 | * This routine is invoked to free the driver's IOCB list and memory. |
| 8492 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 8493 | void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8494 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 8495 | { |
| 8496 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 8497 | |
| 8498 | spin_lock_irq(&phba->hbalock); |
| 8499 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 8500 | &phba->lpfc_iocb_list, list) { |
| 8501 | list_del(&iocbq_entry->list); |
| 8502 | kfree(iocbq_entry); |
| 8503 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 8504 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8505 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8506 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8507 | return; |
| 8508 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8509 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8510 | /** |
| 8511 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 8512 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 8513 | * @iocb_count: number of requested iocbs |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8514 | * |
| 8515 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 8516 | * list and set up the IOCB tag array accordingly. |
| 8517 | * |
| 8518 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8519 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8520 | * other values - error |
| 8521 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 8522 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8523 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 8524 | { |
| 8525 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 8526 | uint16_t iotag; |
| 8527 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8528 | |
| 8529 | /* Initialize and populate the iocb list per host. */ |
| 8530 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8531 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 8532 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8533 | if (iocbq_entry == NULL) { |
| 8534 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 8535 | "expected %d count. Unloading driver.\n", |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 8536 | __func__, i, iocb_count); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8537 | goto out_free_iocbq; |
| 8538 | } |
| 8539 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8540 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 8541 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8542 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8543 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8544 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 8545 | goto out_free_iocbq; |
| 8546 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8547 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8548 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8549 | |
| 8550 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8551 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 8552 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8553 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8554 | } |
| 8555 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8556 | return 0; |
| 8557 | |
| 8558 | out_free_iocbq: |
| 8559 | lpfc_free_iocb_list(phba); |
| 8560 | |
| 8561 | return -ENOMEM; |
| 8562 | } |
| 8563 | |
| 8564 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8565 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8566 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8567 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8568 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8569 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8570 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8571 | void |
| 8572 | 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] | 8573 | { |
| 8574 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8575 | |
| 8576 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 8577 | list_del(&sglq_entry->list); |
| 8578 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 8579 | kfree(sglq_entry); |
| 8580 | } |
| 8581 | } |
| 8582 | |
| 8583 | /** |
| 8584 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 8585 | * @phba: pointer to lpfc hba data structure. |
| 8586 | * |
| 8587 | * This routine is invoked to free the driver's els sgl list and memory. |
| 8588 | **/ |
| 8589 | static void |
| 8590 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 8591 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8592 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8593 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8594 | /* Retrieve all els sgls from driver list */ |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 8595 | spin_lock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8596 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); |
James Smart | a789241 | 2021-04-11 18:31:15 -0700 | [diff] [blame] | 8597 | spin_unlock_irq(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8598 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8599 | /* Now free the sgl list */ |
| 8600 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8601 | } |
| 8602 | |
| 8603 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8604 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. |
| 8605 | * @phba: pointer to lpfc hba data structure. |
| 8606 | * |
| 8607 | * This routine is invoked to free the driver's nvmet sgl list and memory. |
| 8608 | **/ |
| 8609 | static void |
| 8610 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) |
| 8611 | { |
| 8612 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 8613 | LIST_HEAD(sglq_list); |
| 8614 | |
| 8615 | /* Retrieve all nvmet sgls from driver list */ |
| 8616 | spin_lock_irq(&phba->hbalock); |
| 8617 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 8618 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); |
| 8619 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 8620 | spin_unlock_irq(&phba->hbalock); |
| 8621 | |
| 8622 | /* Now free the sgl list */ |
| 8623 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { |
| 8624 | list_del(&sglq_entry->list); |
| 8625 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 8626 | kfree(sglq_entry); |
| 8627 | } |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 8628 | |
| 8629 | /* Update the nvmet_xri_cnt to reflect no current sgls. |
| 8630 | * The next initialization cycle sets the count and allocates |
| 8631 | * the sgls over again. |
| 8632 | */ |
| 8633 | phba->sli4_hba.nvmet_xri_cnt = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8634 | } |
| 8635 | |
| 8636 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8637 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 8638 | * @phba: pointer to lpfc hba data structure. |
| 8639 | * |
| 8640 | * This routine is invoked to allocate the driver's active sgl memory. |
| 8641 | * This array will hold the sglq_entry's for active IOs. |
| 8642 | **/ |
| 8643 | static int |
| 8644 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 8645 | { |
| 8646 | int size; |
| 8647 | size = sizeof(struct lpfc_sglq *); |
| 8648 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 8649 | |
| 8650 | phba->sli4_hba.lpfc_sglq_active_list = |
| 8651 | kzalloc(size, GFP_KERNEL); |
| 8652 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 8653 | return -ENOMEM; |
| 8654 | return 0; |
| 8655 | } |
| 8656 | |
| 8657 | /** |
| 8658 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 8659 | * @phba: pointer to lpfc hba data structure. |
| 8660 | * |
| 8661 | * This routine is invoked to walk through the array of active sglq entries |
| 8662 | * and free all of the resources. |
| 8663 | * This is just a place holder for now. |
| 8664 | **/ |
| 8665 | static void |
| 8666 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 8667 | { |
| 8668 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 8669 | } |
| 8670 | |
| 8671 | /** |
| 8672 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 8673 | * @phba: pointer to lpfc hba data structure. |
| 8674 | * |
| 8675 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 8676 | * list and set up the sgl xritag tag array accordingly. |
| 8677 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8678 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8679 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8680 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 8681 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8682 | /* Initialize and populate the sglq list per host/VF. */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8683 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8684 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8685 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 8686 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8687 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 8688 | /* els xri-sgl book keeping */ |
| 8689 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8690 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8691 | /* nvme xri-buffer book keeping */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8692 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8693 | } |
| 8694 | |
| 8695 | /** |
| 8696 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 8697 | * @phba: pointer to lpfc hba data structure. |
| 8698 | * |
| 8699 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8700 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8701 | * 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] | 8702 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 8703 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8704 | * |
| 8705 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8706 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8707 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8708 | **/ |
| 8709 | int |
| 8710 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 8711 | { |
| 8712 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8713 | struct lpfc_rpi_hdr *rpi_hdr; |
| 8714 | |
| 8715 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8716 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8717 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8718 | if (phba->sli4_hba.extents_in_use) |
| 8719 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8720 | |
| 8721 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 8722 | if (!rpi_hdr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8723 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8724 | "0391 Error during rpi post operation\n"); |
| 8725 | lpfc_sli4_remove_rpis(phba); |
| 8726 | rc = -ENODEV; |
| 8727 | } |
| 8728 | |
| 8729 | return rc; |
| 8730 | } |
| 8731 | |
| 8732 | /** |
| 8733 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 8734 | * @phba: pointer to lpfc hba data structure. |
| 8735 | * |
| 8736 | * This routine is invoked to allocate a single 4KB memory region to |
| 8737 | * support rpis and stores them in the phba. This single region |
| 8738 | * provides support for up to 64 rpis. The region is used globally |
| 8739 | * by the device. |
| 8740 | * |
| 8741 | * Returns: |
| 8742 | * A valid rpi hdr on success. |
| 8743 | * A NULL pointer on any failure. |
| 8744 | **/ |
| 8745 | struct lpfc_rpi_hdr * |
| 8746 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 8747 | { |
| 8748 | uint16_t rpi_limit, curr_rpi_range; |
| 8749 | struct lpfc_dmabuf *dmabuf; |
| 8750 | struct lpfc_rpi_hdr *rpi_hdr; |
| 8751 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8752 | /* |
| 8753 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 8754 | * required. Set the expected maximum count and let the actual value |
| 8755 | * get set when extents are fully allocated. |
| 8756 | */ |
| 8757 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 8758 | return NULL; |
| 8759 | if (phba->sli4_hba.extents_in_use) |
| 8760 | return NULL; |
| 8761 | |
| 8762 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 8763 | rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8764 | |
| 8765 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8766 | /* |
| 8767 | * Establish the starting RPI in this header block. The starting |
| 8768 | * rpi is normalized to a zero base because the physical rpi is |
| 8769 | * port based. |
| 8770 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 8771 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8772 | spin_unlock_irq(&phba->hbalock); |
| 8773 | |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 8774 | /* Reached full RPI range */ |
| 8775 | if (curr_rpi_range == rpi_limit) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8776 | return NULL; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 8777 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8778 | /* |
| 8779 | * First allocate the protocol header region for the port. The |
| 8780 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 8781 | */ |
| 8782 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 8783 | if (!dmabuf) |
| 8784 | return NULL; |
| 8785 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 8786 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 8787 | LPFC_HDR_TEMPLATE_SIZE, |
| 8788 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8789 | if (!dmabuf->virt) { |
| 8790 | rpi_hdr = NULL; |
| 8791 | goto err_free_dmabuf; |
| 8792 | } |
| 8793 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8794 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 8795 | rpi_hdr = NULL; |
| 8796 | goto err_free_coherent; |
| 8797 | } |
| 8798 | |
| 8799 | /* Save the rpi header data for cleanup later. */ |
| 8800 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 8801 | if (!rpi_hdr) |
| 8802 | goto err_free_coherent; |
| 8803 | |
| 8804 | rpi_hdr->dmabuf = dmabuf; |
| 8805 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 8806 | rpi_hdr->page_count = 1; |
| 8807 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8808 | |
| 8809 | /* The rpi_hdr stores the logical index only. */ |
| 8810 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 8811 | 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] | 8812 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 8813 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8814 | spin_unlock_irq(&phba->hbalock); |
| 8815 | return rpi_hdr; |
| 8816 | |
| 8817 | err_free_coherent: |
| 8818 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 8819 | dmabuf->virt, dmabuf->phys); |
| 8820 | err_free_dmabuf: |
| 8821 | kfree(dmabuf); |
| 8822 | return NULL; |
| 8823 | } |
| 8824 | |
| 8825 | /** |
| 8826 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 8827 | * @phba: pointer to lpfc hba data structure. |
| 8828 | * |
| 8829 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8830 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 8831 | * presumes the caller has released all rpis consumed by fabric or port |
| 8832 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8833 | **/ |
| 8834 | void |
| 8835 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 8836 | { |
| 8837 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 8838 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8839 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 8840 | goto exit; |
| 8841 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8842 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 8843 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 8844 | list_del(&rpi_hdr->list); |
| 8845 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 8846 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 8847 | kfree(rpi_hdr->dmabuf); |
| 8848 | kfree(rpi_hdr); |
| 8849 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8850 | exit: |
| 8851 | /* There are no rpis available to the port now. */ |
| 8852 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8853 | } |
| 8854 | |
| 8855 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8856 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 8857 | * @pdev: pointer to pci device data structure. |
| 8858 | * |
| 8859 | * This routine is invoked to allocate the driver hba data structure for an |
| 8860 | * HBA device. If the allocation is successful, the phba reference to the |
| 8861 | * PCI device data structure is set. |
| 8862 | * |
| 8863 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8864 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8865 | * NULL - error |
| 8866 | **/ |
| 8867 | static struct lpfc_hba * |
| 8868 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 8869 | { |
| 8870 | struct lpfc_hba *phba; |
| 8871 | |
| 8872 | /* Allocate memory for HBA structure */ |
| 8873 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 8874 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 8875 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8876 | return NULL; |
| 8877 | } |
| 8878 | |
| 8879 | /* Set reference to PCI device in HBA structure */ |
| 8880 | phba->pcidev = pdev; |
| 8881 | |
| 8882 | /* Assign an unused board number */ |
| 8883 | phba->brd_no = lpfc_get_instance(); |
| 8884 | if (phba->brd_no < 0) { |
| 8885 | kfree(phba); |
| 8886 | return NULL; |
| 8887 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 8888 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8889 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 8890 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 8891 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 8892 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8893 | return phba; |
| 8894 | } |
| 8895 | |
| 8896 | /** |
| 8897 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 8898 | * @phba: pointer to lpfc hba data structure. |
| 8899 | * |
| 8900 | * This routine is invoked to free the driver hba data structure with an |
| 8901 | * HBA device. |
| 8902 | **/ |
| 8903 | static void |
| 8904 | lpfc_hba_free(struct lpfc_hba *phba) |
| 8905 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8906 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 8907 | kfree(phba->sli4_hba.hdwq); |
| 8908 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8909 | /* Release the driver assigned board number */ |
| 8910 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 8911 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8912 | /* Free memory allocated with sli3 rings */ |
| 8913 | kfree(phba->sli.sli3_ring); |
| 8914 | phba->sli.sli3_ring = NULL; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 8915 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8916 | kfree(phba); |
| 8917 | return; |
| 8918 | } |
| 8919 | |
| 8920 | /** |
| 8921 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 8922 | * @phba: pointer to lpfc hba data structure. |
| 8923 | * |
| 8924 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 8925 | * host with it. |
| 8926 | * |
| 8927 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8928 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8929 | * other values - error |
| 8930 | **/ |
| 8931 | static int |
| 8932 | lpfc_create_shost(struct lpfc_hba *phba) |
| 8933 | { |
| 8934 | struct lpfc_vport *vport; |
| 8935 | struct Scsi_Host *shost; |
| 8936 | |
| 8937 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8938 | phba->fc_edtov = FF_DEF_EDTOV; |
| 8939 | phba->fc_ratov = FF_DEF_RATOV; |
| 8940 | phba->fc_altov = FF_DEF_ALTOV; |
| 8941 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 8942 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 8943 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 8944 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8945 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8946 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8947 | |
| 8948 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8949 | phba->pport = vport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8950 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8951 | if (phba->nvmet_support) { |
| 8952 | /* Only 1 vport (pport) will support NVME target */ |
James Smart | ea85a20 | 2019-10-18 14:18:25 -0700 | [diff] [blame] | 8953 | phba->targetport = NULL; |
| 8954 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; |
| 8955 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC, |
| 8956 | "6076 NVME Target Found\n"); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 8957 | } |
| 8958 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 8959 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8960 | /* Put reference to SCSI host to driver's device private data */ |
| 8961 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 8962 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8963 | /* |
| 8964 | * At this point we are fully registered with PSA. In addition, |
| 8965 | * any initial discovery should be completed. |
| 8966 | */ |
| 8967 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 8968 | if (phba->cfg_enable_SmartSAN || |
| 8969 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8970 | |
| 8971 | /* Setup appropriate attribute masks */ |
| 8972 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 8973 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 8974 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 8975 | else |
| 8976 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 8977 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8978 | return 0; |
| 8979 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8980 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8981 | /** |
| 8982 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 8983 | * @phba: pointer to lpfc hba data structure. |
| 8984 | * |
| 8985 | * This routine is invoked to destroy HBA physical port and the associated |
| 8986 | * SCSI host. |
| 8987 | **/ |
| 8988 | static void |
| 8989 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 8990 | { |
| 8991 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 8992 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 8993 | /* Destroy physical port that associated with the SCSI host */ |
| 8994 | destroy_port(vport); |
| 8995 | |
| 8996 | return; |
| 8997 | } |
| 8998 | |
| 8999 | /** |
| 9000 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 9001 | * @phba: pointer to lpfc hba data structure. |
| 9002 | * @shost: the shost to be used to detect Block guard settings. |
| 9003 | * |
| 9004 | * This routine sets up the local Block guard protocol settings for @shost. |
| 9005 | * This routine also allocates memory for debugging bg buffers. |
| 9006 | **/ |
| 9007 | static void |
| 9008 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 9009 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 9010 | uint32_t old_mask; |
| 9011 | uint32_t old_guard; |
| 9012 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 9013 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9014 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9015 | "1478 Registering BlockGuard with the " |
| 9016 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 9017 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 9018 | old_mask = phba->cfg_prot_mask; |
| 9019 | old_guard = phba->cfg_prot_guard; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 9020 | |
| 9021 | /* Only allow supported values */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 9022 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 9023 | SHOST_DIX_TYPE0_PROTECTION | |
| 9024 | SHOST_DIX_TYPE1_PROTECTION); |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 9025 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
| 9026 | SHOST_DIX_GUARD_CRC); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 9027 | |
| 9028 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 9029 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 9030 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 9031 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 9032 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
| 9033 | if ((old_mask != phba->cfg_prot_mask) || |
| 9034 | (old_guard != phba->cfg_prot_guard)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9035 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 9036 | "1475 Registering BlockGuard with the " |
| 9037 | "SCSI layer: mask %d guard %d\n", |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 9038 | phba->cfg_prot_mask, |
| 9039 | phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 9040 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 9041 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
| 9042 | scsi_host_set_guard(shost, phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 9043 | } else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9044 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 9045 | "1479 Not Registering BlockGuard with the SCSI " |
| 9046 | "layer, Bad protection parameters: %d %d\n", |
| 9047 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 9048 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9049 | } |
| 9050 | |
| 9051 | /** |
| 9052 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 9053 | * @phba: pointer to lpfc hba data structure. |
| 9054 | * |
| 9055 | * This routine is invoked to perform all the necessary post initialization |
| 9056 | * setup for the device. |
| 9057 | **/ |
| 9058 | static void |
| 9059 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 9060 | { |
| 9061 | struct Scsi_Host *shost; |
| 9062 | struct lpfc_adapter_event_header adapter_event; |
| 9063 | |
| 9064 | /* Get the default values for Model Name and Description */ |
| 9065 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 9066 | |
| 9067 | /* |
| 9068 | * hba setup may have changed the hba_queue_depth so we need to |
| 9069 | * adjust the value of can_queue. |
| 9070 | */ |
| 9071 | shost = pci_get_drvdata(phba->pcidev); |
| 9072 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 9073 | |
| 9074 | lpfc_host_attrib_init(shost); |
| 9075 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 9076 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 9077 | spin_lock_irq(shost->host_lock); |
| 9078 | lpfc_poll_start_timer(phba); |
| 9079 | spin_unlock_irq(shost->host_lock); |
| 9080 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 9081 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 9082 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9083 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 9084 | /* Send board arrival event to upper layer */ |
| 9085 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 9086 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 9087 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9088 | sizeof(adapter_event), |
| 9089 | (char *) &adapter_event, |
| 9090 | LPFC_NL_VENDOR_ID); |
| 9091 | return; |
| 9092 | } |
| 9093 | |
| 9094 | /** |
| 9095 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 9096 | * @phba: pointer to lpfc hba data structure. |
| 9097 | * |
| 9098 | * This routine is invoked to set up the PCI device memory space for device |
| 9099 | * with SLI-3 interface spec. |
| 9100 | * |
| 9101 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9102 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9103 | * other values - error |
| 9104 | **/ |
| 9105 | static int |
| 9106 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 9107 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 9108 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9109 | unsigned long bar0map_len, bar2map_len; |
| 9110 | int i, hbq_count; |
| 9111 | void *ptr; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 9112 | int error; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9113 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 9114 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 9115 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9116 | |
| 9117 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 9118 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 9119 | if (error) |
| 9120 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 9121 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 9122 | return error; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 9123 | error = -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9124 | |
| 9125 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 9126 | * required by each mapping. |
| 9127 | */ |
| 9128 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 9129 | bar0map_len = pci_resource_len(pdev, 0); |
| 9130 | |
| 9131 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 9132 | bar2map_len = pci_resource_len(pdev, 2); |
| 9133 | |
| 9134 | /* Map HBA SLIM to a kernel virtual address. */ |
| 9135 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 9136 | if (!phba->slim_memmap_p) { |
| 9137 | dev_printk(KERN_ERR, &pdev->dev, |
| 9138 | "ioremap failed for SLIM memory.\n"); |
| 9139 | goto out; |
| 9140 | } |
| 9141 | |
| 9142 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 9143 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 9144 | if (!phba->ctrl_regs_memmap_p) { |
| 9145 | dev_printk(KERN_ERR, &pdev->dev, |
| 9146 | "ioremap failed for HBA control registers.\n"); |
| 9147 | goto out_iounmap_slim; |
| 9148 | } |
| 9149 | |
| 9150 | /* Allocate memory for SLI-2 structures */ |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 9151 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 9152 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9153 | if (!phba->slim2p.virt) |
| 9154 | goto out_iounmap; |
| 9155 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9156 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 9157 | phba->mbox_ext = (phba->slim2p.virt + |
| 9158 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9159 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 9160 | phba->IOCBs = (phba->slim2p.virt + |
| 9161 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 9162 | |
| 9163 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 9164 | lpfc_sli_hbq_size(), |
| 9165 | &phba->hbqslimp.phys, |
| 9166 | GFP_KERNEL); |
| 9167 | if (!phba->hbqslimp.virt) |
| 9168 | goto out_free_slim; |
| 9169 | |
| 9170 | hbq_count = lpfc_sli_hbq_count(); |
| 9171 | ptr = phba->hbqslimp.virt; |
| 9172 | for (i = 0; i < hbq_count; ++i) { |
| 9173 | phba->hbqs[i].hbq_virt = ptr; |
| 9174 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 9175 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 9176 | sizeof(struct lpfc_hbq_entry)); |
| 9177 | } |
| 9178 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 9179 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 9180 | |
| 9181 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 9182 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9183 | phba->MBslimaddr = phba->slim_memmap_p; |
| 9184 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 9185 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 9186 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 9187 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 9188 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9189 | return 0; |
| 9190 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9191 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 9192 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 9193 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9194 | out_iounmap: |
| 9195 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 9196 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9197 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 9198 | out: |
| 9199 | return error; |
| 9200 | } |
| 9201 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 9202 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 9203 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 9204 | * @phba: pointer to lpfc hba data structure. |
| 9205 | * |
| 9206 | * This routine is invoked to unset the PCI device memory space for device |
| 9207 | * with SLI-3 interface spec. |
| 9208 | **/ |
| 9209 | static void |
| 9210 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 9211 | { |
| 9212 | struct pci_dev *pdev; |
| 9213 | |
| 9214 | /* Obtain PCI device reference */ |
| 9215 | if (!phba->pcidev) |
| 9216 | return; |
| 9217 | else |
| 9218 | pdev = phba->pcidev; |
| 9219 | |
| 9220 | /* Free coherent DMA memory allocated */ |
| 9221 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 9222 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 9223 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 9224 | phba->slim2p.virt, phba->slim2p.phys); |
| 9225 | |
| 9226 | /* I/O memory unmap */ |
| 9227 | iounmap(phba->ctrl_regs_memmap_p); |
| 9228 | iounmap(phba->slim_memmap_p); |
| 9229 | |
| 9230 | return; |
| 9231 | } |
| 9232 | |
| 9233 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9234 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 9235 | * @phba: pointer to lpfc hba data structure. |
| 9236 | * |
| 9237 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 9238 | * done and check status. |
| 9239 | * |
| 9240 | * Return 0 if successful, otherwise -ENODEV. |
| 9241 | **/ |
| 9242 | int |
| 9243 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 9244 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9245 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 9246 | struct lpfc_register reg_data; |
| 9247 | int i, port_error = 0; |
| 9248 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9249 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9250 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 9251 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9252 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9253 | return -ENODEV; |
| 9254 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9255 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 9256 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9257 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 9258 | &portsmphr_reg.word0) || |
| 9259 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9260 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9261 | port_error = -ENODEV; |
| 9262 | break; |
| 9263 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9264 | if (LPFC_POST_STAGE_PORT_READY == |
| 9265 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9266 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9267 | msleep(10); |
| 9268 | } |
| 9269 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9270 | /* |
| 9271 | * If there was a port error during POST, then don't proceed with |
| 9272 | * other register reads as the data may not be valid. Just exit. |
| 9273 | */ |
| 9274 | if (port_error) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9275 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9276 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 9277 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 9278 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 9279 | portsmphr_reg.word0, |
| 9280 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 9281 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 9282 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 9283 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 9284 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 9285 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 9286 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 9287 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 9288 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9289 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9290 | "2534 Device Info: SLIFamily=0x%x, " |
| 9291 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 9292 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9293 | bf_get(lpfc_sli_intf_sli_family, |
| 9294 | &phba->sli4_hba.sli_intf), |
| 9295 | bf_get(lpfc_sli_intf_slirev, |
| 9296 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 9297 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9298 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 9299 | bf_get(lpfc_sli_intf_sli_hint1, |
| 9300 | &phba->sli4_hba.sli_intf), |
| 9301 | bf_get(lpfc_sli_intf_sli_hint2, |
| 9302 | &phba->sli4_hba.sli_intf), |
| 9303 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9304 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9305 | /* |
| 9306 | * Check for other Port errors during the initialization |
| 9307 | * process. Fail the load if the port did not come up |
| 9308 | * correctly. |
| 9309 | */ |
| 9310 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 9311 | &phba->sli4_hba.sli_intf); |
| 9312 | switch (if_type) { |
| 9313 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 9314 | phba->sli4_hba.ue_mask_lo = |
| 9315 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 9316 | phba->sli4_hba.ue_mask_hi = |
| 9317 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 9318 | uerrlo_reg.word0 = |
| 9319 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 9320 | uerrhi_reg.word0 = |
| 9321 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 9322 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 9323 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9324 | lpfc_printf_log(phba, KERN_ERR, |
| 9325 | LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9326 | "1422 Unrecoverable Error " |
| 9327 | "Detected during POST " |
| 9328 | "uerr_lo_reg=0x%x, " |
| 9329 | "uerr_hi_reg=0x%x, " |
| 9330 | "ue_mask_lo_reg=0x%x, " |
| 9331 | "ue_mask_hi_reg=0x%x\n", |
| 9332 | uerrlo_reg.word0, |
| 9333 | uerrhi_reg.word0, |
| 9334 | phba->sli4_hba.ue_mask_lo, |
| 9335 | phba->sli4_hba.ue_mask_hi); |
| 9336 | port_error = -ENODEV; |
| 9337 | } |
| 9338 | break; |
| 9339 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9340 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9341 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 9342 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 9343 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 9344 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 9345 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9346 | phba->work_status[0] = |
| 9347 | readl(phba->sli4_hba.u.if_type2. |
| 9348 | ERR1regaddr); |
| 9349 | phba->work_status[1] = |
| 9350 | readl(phba->sli4_hba.u.if_type2. |
| 9351 | ERR2regaddr); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9352 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 9353 | "2888 Unrecoverable port error " |
| 9354 | "following POST: port status reg " |
| 9355 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9356 | "error 1=0x%x, error 2=0x%x\n", |
| 9357 | reg_data.word0, |
| 9358 | portsmphr_reg.word0, |
| 9359 | phba->work_status[0], |
| 9360 | phba->work_status[1]); |
| 9361 | port_error = -ENODEV; |
| 9362 | } |
| 9363 | break; |
| 9364 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 9365 | default: |
| 9366 | break; |
| 9367 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 9368 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9369 | return port_error; |
| 9370 | } |
| 9371 | |
| 9372 | /** |
| 9373 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 9374 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9375 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9376 | * |
| 9377 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 9378 | * memory map. |
| 9379 | **/ |
| 9380 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9381 | 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] | 9382 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9383 | switch (if_type) { |
| 9384 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 9385 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 9386 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 9387 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 9388 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 9389 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 9390 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 9391 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 9392 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 9393 | phba->sli4_hba.SLIINTFregaddr = |
| 9394 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 9395 | break; |
| 9396 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 9397 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 9398 | phba->sli4_hba.conf_regs_memmap_p + |
| 9399 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9400 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9401 | phba->sli4_hba.conf_regs_memmap_p + |
| 9402 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9403 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9404 | phba->sli4_hba.conf_regs_memmap_p + |
| 9405 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9406 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9407 | phba->sli4_hba.conf_regs_memmap_p + |
| 9408 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9409 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9410 | phba->sli4_hba.conf_regs_memmap_p + |
| 9411 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9412 | phba->sli4_hba.SLIINTFregaddr = |
| 9413 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 9414 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 9415 | phba->sli4_hba.conf_regs_memmap_p + |
| 9416 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9417 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9418 | phba->sli4_hba.conf_regs_memmap_p + |
| 9419 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9420 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9421 | phba->sli4_hba.conf_regs_memmap_p + |
| 9422 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 9423 | phba->sli4_hba.CQDBregaddr = |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9424 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 9425 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9426 | phba->sli4_hba.MQDBregaddr = |
| 9427 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 9428 | phba->sli4_hba.BMBXregaddr = |
| 9429 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 9430 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9431 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 9432 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 9433 | phba->sli4_hba.conf_regs_memmap_p + |
| 9434 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
| 9435 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
| 9436 | phba->sli4_hba.conf_regs_memmap_p + |
| 9437 | LPFC_CTL_PORT_ER1_OFFSET; |
| 9438 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
| 9439 | phba->sli4_hba.conf_regs_memmap_p + |
| 9440 | LPFC_CTL_PORT_ER2_OFFSET; |
| 9441 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
| 9442 | phba->sli4_hba.conf_regs_memmap_p + |
| 9443 | LPFC_CTL_PORT_CTL_OFFSET; |
| 9444 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
| 9445 | phba->sli4_hba.conf_regs_memmap_p + |
| 9446 | LPFC_CTL_PORT_STA_OFFSET; |
| 9447 | phba->sli4_hba.PSMPHRregaddr = |
| 9448 | phba->sli4_hba.conf_regs_memmap_p + |
| 9449 | LPFC_CTL_PORT_SEM_OFFSET; |
| 9450 | phba->sli4_hba.BMBXregaddr = |
| 9451 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 9452 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 9453 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 9454 | default: |
| 9455 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 9456 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 9457 | if_type); |
| 9458 | break; |
| 9459 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9460 | } |
| 9461 | |
| 9462 | /** |
| 9463 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 9464 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 9465 | * @if_type: sli if type to operate on. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9466 | * |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9467 | * This routine is invoked to set up SLI4 BAR1 register memory map. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9468 | **/ |
| 9469 | static void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9470 | 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] | 9471 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 9472 | switch (if_type) { |
| 9473 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 9474 | phba->sli4_hba.PSMPHRregaddr = |
| 9475 | phba->sli4_hba.ctrl_regs_memmap_p + |
| 9476 | LPFC_SLIPORT_IF0_SMPHR; |
| 9477 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 9478 | LPFC_HST_ISR0; |
| 9479 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 9480 | LPFC_HST_IMR0; |
| 9481 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 9482 | LPFC_HST_ISCR0; |
| 9483 | break; |
| 9484 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 9485 | phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 9486 | LPFC_IF6_RQ_DOORBELL; |
| 9487 | phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 9488 | LPFC_IF6_WQ_DOORBELL; |
| 9489 | phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 9490 | LPFC_IF6_CQ_DOORBELL; |
| 9491 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 9492 | LPFC_IF6_EQ_DOORBELL; |
| 9493 | phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 9494 | LPFC_IF6_MQ_DOORBELL; |
| 9495 | break; |
| 9496 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 9497 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 9498 | default: |
| 9499 | dev_err(&phba->pcidev->dev, |
| 9500 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 9501 | if_type); |
| 9502 | break; |
| 9503 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9504 | } |
| 9505 | |
| 9506 | /** |
| 9507 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 9508 | * @phba: pointer to lpfc hba data structure. |
| 9509 | * @vf: virtual function number |
| 9510 | * |
| 9511 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 9512 | * based on the given viftual function number, @vf. |
| 9513 | * |
| 9514 | * Return 0 if successful, otherwise -ENODEV. |
| 9515 | **/ |
| 9516 | static int |
| 9517 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 9518 | { |
| 9519 | if (vf > LPFC_VIR_FUNC_MAX) |
| 9520 | return -ENODEV; |
| 9521 | |
| 9522 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9523 | vf * LPFC_VFR_PAGE_SIZE + |
| 9524 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9525 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9526 | vf * LPFC_VFR_PAGE_SIZE + |
| 9527 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 9528 | phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 9529 | vf * LPFC_VFR_PAGE_SIZE + |
| 9530 | LPFC_EQCQ_DOORBELL); |
| 9531 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9532 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 9533 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 9534 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 9535 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 9536 | return 0; |
| 9537 | } |
| 9538 | |
| 9539 | /** |
| 9540 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 9541 | * @phba: pointer to lpfc hba data structure. |
| 9542 | * |
| 9543 | * This routine is invoked to create the bootstrap mailbox |
| 9544 | * region consistent with the SLI-4 interface spec. This |
| 9545 | * routine allocates all memory necessary to communicate |
| 9546 | * mailbox commands to the port and sets up all alignment |
| 9547 | * needs. No locks are expected to be held when calling |
| 9548 | * this routine. |
| 9549 | * |
| 9550 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9551 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9552 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9553 | **/ |
| 9554 | static int |
| 9555 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 9556 | { |
| 9557 | uint32_t bmbx_size; |
| 9558 | struct lpfc_dmabuf *dmabuf; |
| 9559 | struct dma_address *dma_address; |
| 9560 | uint32_t pa_addr; |
| 9561 | uint64_t phys_addr; |
| 9562 | |
| 9563 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 9564 | if (!dmabuf) |
| 9565 | return -ENOMEM; |
| 9566 | |
| 9567 | /* |
| 9568 | * The bootstrap mailbox region is comprised of 2 parts |
| 9569 | * plus an alignment restriction of 16 bytes. |
| 9570 | */ |
| 9571 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 9572 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 9573 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9574 | if (!dmabuf->virt) { |
| 9575 | kfree(dmabuf); |
| 9576 | return -ENOMEM; |
| 9577 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9578 | |
| 9579 | /* |
| 9580 | * Initialize the bootstrap mailbox pointers now so that the register |
| 9581 | * operations are simple later. The mailbox dma address is required |
| 9582 | * to be 16-byte aligned. Also align the virtual memory as each |
| 9583 | * maibox is copied into the bmbx mailbox region before issuing the |
| 9584 | * command to the port. |
| 9585 | */ |
| 9586 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 9587 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 9588 | |
| 9589 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 9590 | LPFC_ALIGN_16_BYTE); |
| 9591 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 9592 | LPFC_ALIGN_16_BYTE); |
| 9593 | |
| 9594 | /* |
| 9595 | * Set the high and low physical addresses now. The SLI4 alignment |
| 9596 | * requirement is 16 bytes and the mailbox is posted to the port |
| 9597 | * as two 30-bit addresses. The other data is a bit marking whether |
| 9598 | * the 30-bit address is the high or low address. |
| 9599 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 9600 | * clean on 32 bit machines. |
| 9601 | */ |
| 9602 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 9603 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 9604 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 9605 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 9606 | LPFC_BMBX_BIT1_ADDR_HI); |
| 9607 | |
| 9608 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 9609 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 9610 | LPFC_BMBX_BIT1_ADDR_LO); |
| 9611 | return 0; |
| 9612 | } |
| 9613 | |
| 9614 | /** |
| 9615 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 9616 | * @phba: pointer to lpfc hba data structure. |
| 9617 | * |
| 9618 | * This routine is invoked to teardown the bootstrap mailbox |
| 9619 | * region and release all host resources. This routine requires |
| 9620 | * the caller to ensure all mailbox commands recovered, no |
| 9621 | * additional mailbox comands are sent, and interrupts are disabled |
| 9622 | * before calling this routine. |
| 9623 | * |
| 9624 | **/ |
| 9625 | static void |
| 9626 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 9627 | { |
| 9628 | dma_free_coherent(&phba->pcidev->dev, |
| 9629 | phba->sli4_hba.bmbx.bmbx_size, |
| 9630 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 9631 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 9632 | |
| 9633 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 9634 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 9635 | } |
| 9636 | |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 9637 | static const char * const lpfc_topo_to_str[] = { |
| 9638 | "Loop then P2P", |
| 9639 | "Loopback", |
| 9640 | "P2P Only", |
| 9641 | "Unsupported", |
| 9642 | "Loop Only", |
| 9643 | "Unsupported", |
| 9644 | "P2P then Loop", |
| 9645 | }; |
| 9646 | |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 9647 | #define LINK_FLAGS_DEF 0x0 |
| 9648 | #define LINK_FLAGS_P2P 0x1 |
| 9649 | #define LINK_FLAGS_LOOP 0x2 |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 9650 | /** |
| 9651 | * lpfc_map_topology - Map the topology read from READ_CONFIG |
| 9652 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 9653 | * @rd_config: pointer to read config data |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 9654 | * |
| 9655 | * This routine is invoked to map the topology values as read |
| 9656 | * from the read config mailbox command. If the persistent |
| 9657 | * topology feature is supported, the firmware will provide the |
| 9658 | * saved topology information to be used in INIT_LINK |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 9659 | **/ |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 9660 | static void |
| 9661 | lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config) |
| 9662 | { |
| 9663 | u8 ptv, tf, pt; |
| 9664 | |
| 9665 | ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config); |
| 9666 | tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config); |
| 9667 | pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config); |
| 9668 | |
| 9669 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9670 | "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x", |
| 9671 | ptv, tf, pt); |
| 9672 | if (!ptv) { |
| 9673 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9674 | "2019 FW does not support persistent topology " |
| 9675 | "Using driver parameter defined value [%s]", |
| 9676 | lpfc_topo_to_str[phba->cfg_topology]); |
| 9677 | return; |
| 9678 | } |
| 9679 | /* FW supports persistent topology - override module parameter value */ |
| 9680 | phba->hba_flag |= HBA_PERSISTENT_TOPO; |
James Smart | f6c5e6c | 2021-07-22 15:17:18 -0700 | [diff] [blame] | 9681 | |
| 9682 | /* if ASIC_GEN_NUM >= 0xC) */ |
| 9683 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 9684 | LPFC_SLI_INTF_IF_TYPE_6) || |
| 9685 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
| 9686 | LPFC_SLI_INTF_FAMILY_G6)) { |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 9687 | if (!tf) { |
| 9688 | phba->cfg_topology = ((pt == LINK_FLAGS_LOOP) |
| 9689 | ? FLAGS_TOPOLOGY_MODE_LOOP |
| 9690 | : FLAGS_TOPOLOGY_MODE_PT_PT); |
| 9691 | } else { |
| 9692 | phba->hba_flag &= ~HBA_PERSISTENT_TOPO; |
| 9693 | } |
James Smart | f6c5e6c | 2021-07-22 15:17:18 -0700 | [diff] [blame] | 9694 | } else { /* G5 */ |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 9695 | if (tf) { |
| 9696 | /* If topology failover set - pt is '0' or '1' */ |
| 9697 | phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP : |
| 9698 | FLAGS_TOPOLOGY_MODE_LOOP_PT); |
| 9699 | } else { |
| 9700 | phba->cfg_topology = ((pt == LINK_FLAGS_P2P) |
| 9701 | ? FLAGS_TOPOLOGY_MODE_PT_PT |
| 9702 | : FLAGS_TOPOLOGY_MODE_LOOP); |
| 9703 | } |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 9704 | } |
| 9705 | if (phba->hba_flag & HBA_PERSISTENT_TOPO) { |
| 9706 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9707 | "2020 Using persistent topology value [%s]", |
| 9708 | lpfc_topo_to_str[phba->cfg_topology]); |
| 9709 | } else { |
| 9710 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9711 | "2021 Invalid topology values from FW " |
| 9712 | "Using driver parameter defined value [%s]", |
| 9713 | lpfc_topo_to_str[phba->cfg_topology]); |
| 9714 | } |
| 9715 | } |
| 9716 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9717 | /** |
| 9718 | * lpfc_sli4_read_config - Get the config parameters. |
| 9719 | * @phba: pointer to lpfc hba data structure. |
| 9720 | * |
| 9721 | * This routine is invoked to read the configuration parameters from the HBA. |
| 9722 | * The configuration parameters are used to set the base and maximum values |
| 9723 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 9724 | * allocation for the port. |
| 9725 | * |
| 9726 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9727 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9728 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9729 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9730 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9731 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9732 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 9733 | { |
| 9734 | LPFC_MBOXQ_t *pmb; |
| 9735 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9736 | union lpfc_sli4_cfg_shdr *shdr; |
| 9737 | uint32_t shdr_status, shdr_add_status; |
| 9738 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 9739 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 9740 | char *pdesc_0; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 9741 | uint16_t forced_link_speed; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9742 | uint32_t if_type, qmin; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 9743 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9744 | |
| 9745 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9746 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9747 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9748 | "2011 Unable to allocate memory for issuing " |
| 9749 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 9750 | return -ENOMEM; |
| 9751 | } |
| 9752 | |
| 9753 | lpfc_read_config(phba, pmb); |
| 9754 | |
| 9755 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 9756 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9757 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 9758 | "2012 Mailbox failed , mbxCmd x%x " |
| 9759 | "READ_CONFIG, mbxStatus x%x\n", |
| 9760 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 9761 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9762 | rc = -EIO; |
| 9763 | } else { |
| 9764 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 9765 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 9766 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 9767 | phba->sli4_hba.lnk_info.lnk_tp = |
| 9768 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 9769 | phba->sli4_hba.lnk_info.lnk_no = |
| 9770 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 9771 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 9772 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 9773 | phba->sli4_hba.lnk_info.lnk_tp, |
| 9774 | phba->sli4_hba.lnk_info.lnk_no); |
| 9775 | } else |
| 9776 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 9777 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 9778 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 9779 | if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) { |
| 9780 | phba->bbcredit_support = 1; |
| 9781 | phba->sli4_hba.bbscn_params.word0 = rd_config->word8; |
| 9782 | } |
| 9783 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 9784 | phba->sli4_hba.conf_trunk = |
| 9785 | bf_get(lpfc_mbx_rd_conf_trunk, rd_config); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9786 | phba->sli4_hba.extents_in_use = |
| 9787 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9788 | phba->sli4_hba.max_cfg_param.max_xri = |
| 9789 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
James Smart | 31f06d2 | 2019-08-14 16:56:31 -0700 | [diff] [blame] | 9790 | /* Reduce resource usage in kdump environment */ |
| 9791 | if (is_kdump_kernel() && |
| 9792 | phba->sli4_hba.max_cfg_param.max_xri > 512) |
| 9793 | phba->sli4_hba.max_cfg_param.max_xri = 512; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9794 | phba->sli4_hba.max_cfg_param.xri_base = |
| 9795 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 9796 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 9797 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
James Smart | 8b47ae6 | 2018-11-29 16:09:33 -0800 | [diff] [blame] | 9798 | /* Limit the max we support */ |
| 9799 | if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS) |
| 9800 | phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9801 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 9802 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 9803 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 9804 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 9805 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 9806 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 9807 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 9808 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 9809 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 9810 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 9811 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 9812 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9813 | phba->sli4_hba.max_cfg_param.max_eq = |
| 9814 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 9815 | phba->sli4_hba.max_cfg_param.max_rq = |
| 9816 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 9817 | phba->sli4_hba.max_cfg_param.max_wq = |
| 9818 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 9819 | phba->sli4_hba.max_cfg_param.max_cq = |
| 9820 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 9821 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 9822 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 9823 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 9824 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 9825 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 9826 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9827 | phba->max_vports = phba->max_vpi; |
James Smart | 9064aeb | 2021-08-16 09:28:50 -0700 | [diff] [blame] | 9828 | |
| 9829 | /* Next decide on FPIN or Signal E2E CGN support |
| 9830 | * For congestion alarms and warnings valid combination are: |
| 9831 | * 1. FPIN alarms / FPIN warnings |
| 9832 | * 2. Signal alarms / Signal warnings |
| 9833 | * 3. FPIN alarms / Signal warnings |
| 9834 | * 4. Signal alarms / FPIN warnings |
| 9835 | * |
| 9836 | * Initialize the adapter frequency to 100 mSecs |
| 9837 | */ |
| 9838 | phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH; |
| 9839 | phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED; |
| 9840 | phba->cgn_sig_freq = lpfc_fabric_cgn_frequency; |
| 9841 | |
| 9842 | if (lpfc_use_cgn_signal) { |
| 9843 | if (bf_get(lpfc_mbx_rd_conf_wcs, rd_config)) { |
| 9844 | phba->cgn_reg_signal = EDC_CG_SIG_WARN_ONLY; |
| 9845 | phba->cgn_reg_fpin &= ~LPFC_CGN_FPIN_WARN; |
| 9846 | } |
| 9847 | if (bf_get(lpfc_mbx_rd_conf_acs, rd_config)) { |
| 9848 | /* MUST support both alarm and warning |
| 9849 | * because EDC does not support alarm alone. |
| 9850 | */ |
| 9851 | if (phba->cgn_reg_signal != |
| 9852 | EDC_CG_SIG_WARN_ONLY) { |
| 9853 | /* Must support both or none */ |
| 9854 | phba->cgn_reg_fpin = LPFC_CGN_FPIN_BOTH; |
| 9855 | phba->cgn_reg_signal = |
| 9856 | EDC_CG_SIG_NOTSUPPORTED; |
| 9857 | } else { |
| 9858 | phba->cgn_reg_signal = |
| 9859 | EDC_CG_SIG_WARN_ALARM; |
| 9860 | phba->cgn_reg_fpin = |
| 9861 | LPFC_CGN_FPIN_NONE; |
| 9862 | } |
| 9863 | } |
| 9864 | } |
| 9865 | |
| 9866 | /* Set the congestion initial signal and fpin values. */ |
| 9867 | phba->cgn_init_reg_fpin = phba->cgn_reg_fpin; |
| 9868 | phba->cgn_init_reg_signal = phba->cgn_reg_signal; |
| 9869 | |
| 9870 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 9871 | "6446 READ_CONFIG reg_sig x%x reg_fpin:x%x\n", |
| 9872 | phba->cgn_reg_signal, phba->cgn_reg_fpin); |
| 9873 | |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 9874 | lpfc_map_topology(phba, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9875 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 9876 | "2003 cfg params Extents? %d " |
| 9877 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9878 | "VPI(B:%d M:%d) " |
| 9879 | "VFI(B:%d M:%d) " |
| 9880 | "RPI(B:%d M:%d) " |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 9881 | "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] | 9882 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9883 | phba->sli4_hba.max_cfg_param.xri_base, |
| 9884 | phba->sli4_hba.max_cfg_param.max_xri, |
| 9885 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 9886 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 9887 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 9888 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 9889 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 9890 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9891 | phba->sli4_hba.max_cfg_param.max_fcfi, |
| 9892 | phba->sli4_hba.max_cfg_param.max_eq, |
| 9893 | phba->sli4_hba.max_cfg_param.max_cq, |
| 9894 | phba->sli4_hba.max_cfg_param.max_wq, |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 9895 | phba->sli4_hba.max_cfg_param.max_rq, |
| 9896 | phba->lmt); |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 9897 | |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 9898 | /* |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9899 | * Calculate queue resources based on how |
| 9900 | * many WQ/CQ/EQs are available. |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 9901 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9902 | qmin = phba->sli4_hba.max_cfg_param.max_wq; |
| 9903 | if (phba->sli4_hba.max_cfg_param.max_cq < qmin) |
| 9904 | qmin = phba->sli4_hba.max_cfg_param.max_cq; |
| 9905 | if (phba->sli4_hba.max_cfg_param.max_eq < qmin) |
| 9906 | qmin = phba->sli4_hba.max_cfg_param.max_eq; |
| 9907 | /* |
| 9908 | * Whats left after this can go toward NVME / FCP. |
| 9909 | * The minus 4 accounts for ELS, NVME LS, MBOX |
| 9910 | * plus one extra. When configured for |
| 9911 | * NVMET, FCP io channel WQs are not created. |
| 9912 | */ |
| 9913 | qmin -= 4; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 9914 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9915 | /* Check to see if there is enough for NVME */ |
| 9916 | if ((phba->cfg_irq_chann > qmin) || |
| 9917 | (phba->cfg_hdw_queue > qmin)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9918 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 9e3e365 | 2020-08-03 14:02:23 -0700 | [diff] [blame] | 9919 | "2005 Reducing Queues - " |
| 9920 | "FW resource limitation: " |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9921 | "WQ %d CQ %d EQ %d: min %d: " |
| 9922 | "IRQ %d HDWQ %d\n", |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 9923 | phba->sli4_hba.max_cfg_param.max_wq, |
| 9924 | phba->sli4_hba.max_cfg_param.max_cq, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9925 | phba->sli4_hba.max_cfg_param.max_eq, |
| 9926 | qmin, phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9927 | phba->cfg_hdw_queue); |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 9928 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9929 | if (phba->cfg_irq_chann > qmin) |
| 9930 | phba->cfg_irq_chann = qmin; |
| 9931 | if (phba->cfg_hdw_queue > qmin) |
| 9932 | phba->cfg_hdw_queue = qmin; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 9933 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9934 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 9935 | |
| 9936 | if (rc) |
| 9937 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9938 | |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 9939 | /* Update link speed if forced link speed is supported */ |
| 9940 | 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] | 9941 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 9942 | forced_link_speed = |
| 9943 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); |
| 9944 | if (forced_link_speed) { |
| 9945 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; |
| 9946 | |
| 9947 | switch (forced_link_speed) { |
| 9948 | case LINK_SPEED_1G: |
| 9949 | phba->cfg_link_speed = |
| 9950 | LPFC_USER_LINK_SPEED_1G; |
| 9951 | break; |
| 9952 | case LINK_SPEED_2G: |
| 9953 | phba->cfg_link_speed = |
| 9954 | LPFC_USER_LINK_SPEED_2G; |
| 9955 | break; |
| 9956 | case LINK_SPEED_4G: |
| 9957 | phba->cfg_link_speed = |
| 9958 | LPFC_USER_LINK_SPEED_4G; |
| 9959 | break; |
| 9960 | case LINK_SPEED_8G: |
| 9961 | phba->cfg_link_speed = |
| 9962 | LPFC_USER_LINK_SPEED_8G; |
| 9963 | break; |
| 9964 | case LINK_SPEED_10G: |
| 9965 | phba->cfg_link_speed = |
| 9966 | LPFC_USER_LINK_SPEED_10G; |
| 9967 | break; |
| 9968 | case LINK_SPEED_16G: |
| 9969 | phba->cfg_link_speed = |
| 9970 | LPFC_USER_LINK_SPEED_16G; |
| 9971 | break; |
| 9972 | case LINK_SPEED_32G: |
| 9973 | phba->cfg_link_speed = |
| 9974 | LPFC_USER_LINK_SPEED_32G; |
| 9975 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 9976 | case LINK_SPEED_64G: |
| 9977 | phba->cfg_link_speed = |
| 9978 | LPFC_USER_LINK_SPEED_64G; |
| 9979 | break; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 9980 | case 0xffff: |
| 9981 | phba->cfg_link_speed = |
| 9982 | LPFC_USER_LINK_SPEED_AUTO; |
| 9983 | break; |
| 9984 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9985 | lpfc_printf_log(phba, KERN_ERR, |
| 9986 | LOG_TRACE_EVENT, |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 9987 | "0047 Unrecognized link " |
| 9988 | "speed : %d\n", |
| 9989 | forced_link_speed); |
| 9990 | phba->cfg_link_speed = |
| 9991 | LPFC_USER_LINK_SPEED_AUTO; |
| 9992 | } |
| 9993 | } |
| 9994 | } |
| 9995 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9996 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 9997 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 9998 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 9999 | if (phba->cfg_hba_queue_depth > length) { |
| 10000 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10001 | "3361 HBA queue depth changed from %d to %d\n", |
| 10002 | phba->cfg_hba_queue_depth, length); |
| 10003 | phba->cfg_hba_queue_depth = length; |
| 10004 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10005 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10006 | 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] | 10007 | LPFC_SLI_INTF_IF_TYPE_2) |
| 10008 | goto read_cfg_out; |
| 10009 | |
| 10010 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 10011 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 10012 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 10013 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10014 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 10015 | length, LPFC_SLI4_MBX_EMBED); |
| 10016 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 10017 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10018 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 10019 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 10020 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 10021 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 10022 | if (rc2 || shdr_status || shdr_add_status) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10023 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10024 | "3026 Mailbox failed , mbxCmd x%x " |
| 10025 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 10026 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 10027 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10028 | goto read_cfg_out; |
| 10029 | } |
| 10030 | |
| 10031 | /* search for fc_fcoe resrouce descriptor */ |
| 10032 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10033 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 10034 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 10035 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 10036 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 10037 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 10038 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 10039 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 10040 | goto read_cfg_out; |
| 10041 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10042 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 10043 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10044 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 10045 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10046 | phba->sli4_hba.iov.pf_number = |
| 10047 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 10048 | phba->sli4_hba.iov.vf_number = |
| 10049 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 10050 | break; |
| 10051 | } |
| 10052 | } |
| 10053 | |
| 10054 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 10055 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 10056 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 10057 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 10058 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 10059 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10060 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10061 | "3028 GET_FUNCTION_CONFIG: failed to find " |
Colin Ian King | c4dba18 | 2018-10-16 18:28:53 +0100 | [diff] [blame] | 10062 | "Resource Descriptor:x%x\n", |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10063 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 10064 | |
| 10065 | read_cfg_out: |
| 10066 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10067 | return rc; |
| 10068 | } |
| 10069 | |
| 10070 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10071 | * 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] | 10072 | * @phba: pointer to lpfc hba data structure. |
| 10073 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10074 | * This routine is invoked to setup the port-side endian order when |
| 10075 | * the port if_type is 0. This routine has no function for other |
| 10076 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10077 | * |
| 10078 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10079 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10080 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10081 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10082 | **/ |
| 10083 | static int |
| 10084 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 10085 | { |
| 10086 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10087 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10088 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 10089 | HOST_ENDIAN_HIGH_WORD1}; |
| 10090 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10091 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10092 | switch (if_type) { |
| 10093 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10094 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 10095 | GFP_KERNEL); |
| 10096 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10097 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10098 | "0492 Unable to allocate memory for " |
| 10099 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 10100 | "command\n"); |
| 10101 | return -ENOMEM; |
| 10102 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10103 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10104 | /* |
| 10105 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 10106 | * two words to contain special data values and no other data. |
| 10107 | */ |
| 10108 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 10109 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 10110 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10111 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10112 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10113 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 10114 | "failed with status x%x\n", |
| 10115 | rc); |
| 10116 | rc = -EIO; |
| 10117 | } |
| 10118 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 10119 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10120 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10121 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 10122 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10123 | default: |
| 10124 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10125 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10126 | return rc; |
| 10127 | } |
| 10128 | |
| 10129 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10130 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10131 | * @phba: pointer to lpfc hba data structure. |
| 10132 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10133 | * This routine is invoked to check the user settable queue counts for EQs. |
| 10134 | * 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] | 10135 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 10136 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10137 | * |
| 10138 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10139 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10140 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10141 | **/ |
| 10142 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10143 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10144 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10145 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10146 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10147 | * device parameters |
| 10148 | */ |
| 10149 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 10150 | if (phba->nvmet_support) { |
James Smart | 97a9ed3 | 2019-10-18 14:18:17 -0700 | [diff] [blame] | 10151 | if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq) |
| 10152 | phba->cfg_nvmet_mrq = phba->cfg_hdw_queue; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 10153 | if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) |
| 10154 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 10155 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10156 | |
| 10157 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10158 | "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n", |
| 10159 | phba->cfg_hdw_queue, phba->cfg_irq_chann, |
| 10160 | phba->cfg_nvmet_mrq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10161 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10162 | /* Get EQ depth from module parameter, fake the default for now */ |
| 10163 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 10164 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 10165 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10166 | /* Get CQ depth from module parameter, fake the default for now */ |
| 10167 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 10168 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10169 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10170 | } |
| 10171 | |
| 10172 | static int |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10173 | lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10174 | { |
| 10175 | struct lpfc_queue *qdesc; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10176 | u32 wqesize; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10177 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10178 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10179 | cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ); |
| 10180 | /* Create Fast Path IO CQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10181 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 10182 | /* Increase the CQ size when WQEs contain an embedded cdb */ |
| 10183 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 10184 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10185 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 10186 | |
| 10187 | else |
| 10188 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10189 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10190 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10191 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10192 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 10193 | "0499 Failed allocate fast-path IO CQ (%d)\n", |
| 10194 | idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10195 | return 1; |
| 10196 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 10197 | qdesc->qe_valid = 1; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10198 | qdesc->hdwq = idx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10199 | qdesc->chann = cpu; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10200 | phba->sli4_hba.hdwq[idx].io_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10201 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10202 | /* Create Fast Path IO WQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10203 | if (phba->enab_exp_wqcq_pages) { |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 10204 | /* Increase the WQ size when WQEs contain an embedded cdb */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10205 | wqesize = (phba->fcp_embed_io) ? |
| 10206 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 10207 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10208 | wqesize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10209 | LPFC_WQE_EXP_COUNT, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10210 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 10211 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10212 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10213 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 10214 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10215 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10216 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10217 | "0503 Failed allocate fast-path IO WQ (%d)\n", |
| 10218 | idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10219 | return 1; |
| 10220 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10221 | qdesc->hdwq = idx; |
| 10222 | qdesc->chann = cpu; |
| 10223 | phba->sli4_hba.hdwq[idx].io_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10224 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 10225 | return 0; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10226 | } |
| 10227 | |
| 10228 | /** |
| 10229 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 10230 | * @phba: pointer to lpfc hba data structure. |
| 10231 | * |
| 10232 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 10233 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 10234 | * count (queue depth) shall be taken from the module parameter. For now, |
| 10235 | * we just use some constant number as place holder. |
| 10236 | * |
| 10237 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 10238 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10239 | * -ENOMEM - No availble memory |
| 10240 | * -EIO - The mailbox failed to complete successfully. |
| 10241 | **/ |
| 10242 | int |
| 10243 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 10244 | { |
| 10245 | struct lpfc_queue *qdesc; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10246 | int idx, cpu, eqcpu; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10247 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10248 | struct lpfc_vector_map_info *cpup; |
| 10249 | struct lpfc_vector_map_info *eqcpup; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10250 | struct lpfc_eq_intr_info *eqi; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10251 | |
| 10252 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10253 | * Create HBA Record arrays. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10254 | * Both NVME and FCP will share that same vectors / EQs |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10255 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10256 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 10257 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 10258 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 10259 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 10260 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 10261 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10262 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 10263 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 10264 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 10265 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10266 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10267 | if (!phba->sli4_hba.hdwq) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10268 | phba->sli4_hba.hdwq = kcalloc( |
| 10269 | phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue), |
| 10270 | GFP_KERNEL); |
| 10271 | if (!phba->sli4_hba.hdwq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10272 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10273 | "6427 Failed allocate memory for " |
| 10274 | "fast-path Hardware Queue array\n"); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10275 | goto out_error; |
| 10276 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10277 | /* Prepare hardware queues to take IO buffers */ |
| 10278 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 10279 | qp = &phba->sli4_hba.hdwq[idx]; |
| 10280 | spin_lock_init(&qp->io_buf_list_get_lock); |
| 10281 | spin_lock_init(&qp->io_buf_list_put_lock); |
| 10282 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 10283 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 10284 | qp->get_io_bufs = 0; |
| 10285 | qp->put_io_bufs = 0; |
| 10286 | qp->total_io_bufs = 0; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10287 | spin_lock_init(&qp->abts_io_buf_list_lock); |
| 10288 | INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10289 | qp->abts_scsi_io_bufs = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10290 | qp->abts_nvme_io_bufs = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 10291 | INIT_LIST_HEAD(&qp->sgl_list); |
| 10292 | INIT_LIST_HEAD(&qp->cmd_rsp_buf_list); |
| 10293 | spin_lock_init(&qp->hdwq_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10294 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10295 | } |
| 10296 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10297 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10298 | if (phba->nvmet_support) { |
| 10299 | phba->sli4_hba.nvmet_cqset = kcalloc( |
| 10300 | phba->cfg_nvmet_mrq, |
| 10301 | sizeof(struct lpfc_queue *), |
| 10302 | GFP_KERNEL); |
| 10303 | if (!phba->sli4_hba.nvmet_cqset) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10304 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10305 | "3121 Fail allocate memory for " |
| 10306 | "fast-path CQ set array\n"); |
| 10307 | goto out_error; |
| 10308 | } |
| 10309 | phba->sli4_hba.nvmet_mrq_hdr = kcalloc( |
| 10310 | phba->cfg_nvmet_mrq, |
| 10311 | sizeof(struct lpfc_queue *), |
| 10312 | GFP_KERNEL); |
| 10313 | if (!phba->sli4_hba.nvmet_mrq_hdr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10314 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10315 | "3122 Fail allocate memory for " |
| 10316 | "fast-path RQ set hdr array\n"); |
| 10317 | goto out_error; |
| 10318 | } |
| 10319 | phba->sli4_hba.nvmet_mrq_data = kcalloc( |
| 10320 | phba->cfg_nvmet_mrq, |
| 10321 | sizeof(struct lpfc_queue *), |
| 10322 | GFP_KERNEL); |
| 10323 | if (!phba->sli4_hba.nvmet_mrq_data) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10324 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10325 | "3124 Fail allocate memory for " |
| 10326 | "fast-path RQ set data array\n"); |
| 10327 | goto out_error; |
| 10328 | } |
| 10329 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10330 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10331 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10332 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10333 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10334 | /* Create HBA Event Queues (EQs) */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10335 | for_each_present_cpu(cpu) { |
| 10336 | /* We only want to create 1 EQ per vector, even though |
| 10337 | * multiple CPUs might be using that vector. so only |
| 10338 | * selects the CPUs that are LPFC_CPU_FIRST_IRQ. |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10339 | */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10340 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10341 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10342 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10343 | |
| 10344 | /* Get a ptr to the Hardware Queue associated with this CPU */ |
| 10345 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 10346 | |
| 10347 | /* Allocate an EQ */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10348 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10349 | phba->sli4_hba.eq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10350 | phba->sli4_hba.eq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10351 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10352 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10353 | "0497 Failed allocate EQ (%d)\n", |
| 10354 | cpup->hdwq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10355 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10356 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 10357 | qdesc->qe_valid = 1; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10358 | qdesc->hdwq = cpup->hdwq; |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 10359 | qdesc->chann = cpu; /* First CPU this EQ is affinitized to */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10360 | qdesc->last_cpu = qdesc->chann; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10361 | |
| 10362 | /* Save the allocated EQ in the Hardware Queue */ |
| 10363 | qp->hba_eq = qdesc; |
| 10364 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10365 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu); |
| 10366 | list_add(&qdesc->cpu_list, &eqi->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10367 | } |
| 10368 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10369 | /* Now we need to populate the other Hardware Queues, that share |
| 10370 | * an IRQ vector, with the associated EQ ptr. |
| 10371 | */ |
| 10372 | for_each_present_cpu(cpu) { |
| 10373 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10374 | |
| 10375 | /* Check for EQ already allocated in previous loop */ |
| 10376 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 10377 | continue; |
| 10378 | |
| 10379 | /* Check for multiple CPUs per hdwq */ |
| 10380 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 10381 | if (qp->hba_eq) |
| 10382 | continue; |
| 10383 | |
| 10384 | /* We need to share an EQ for this hdwq */ |
| 10385 | eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ); |
| 10386 | eqcpup = &phba->sli4_hba.cpu_map[eqcpu]; |
| 10387 | qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq; |
| 10388 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10389 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10390 | /* Allocate IO Path SLI4 CQ/WQs */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10391 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10392 | if (lpfc_alloc_io_wq_cq(phba, idx)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10393 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10394 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10395 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10396 | if (phba->nvmet_support) { |
| 10397 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
| 10398 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 10399 | LPFC_FIND_BY_HDWQ); |
| 10400 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10401 | LPFC_DEFAULT_PAGE_SIZE, |
| 10402 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10403 | phba->sli4_hba.cq_ecount, |
| 10404 | cpu); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10405 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10406 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10407 | "3142 Failed allocate NVME " |
| 10408 | "CQ Set (%d)\n", idx); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10409 | goto out_error; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10410 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10411 | qdesc->qe_valid = 1; |
| 10412 | qdesc->hdwq = idx; |
| 10413 | qdesc->chann = cpu; |
| 10414 | phba->sli4_hba.nvmet_cqset[idx] = qdesc; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10415 | } |
| 10416 | } |
| 10417 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10418 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10419 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10420 | */ |
| 10421 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10422 | cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10423 | /* Create slow-path Mailbox Command Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10424 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10425 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10426 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10427 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10428 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10429 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10430 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10431 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 10432 | qdesc->qe_valid = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10433 | phba->sli4_hba.mbx_cq = qdesc; |
| 10434 | |
| 10435 | /* Create slow-path ELS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10436 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10437 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10438 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10439 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10440 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10441 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10442 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10443 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 10444 | qdesc->qe_valid = 1; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10445 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10446 | phba->sli4_hba.els_cq = qdesc; |
| 10447 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10448 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10449 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10450 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10451 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10452 | |
| 10453 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10454 | |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10455 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10456 | phba->sli4_hba.mq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10457 | phba->sli4_hba.mq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10458 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10459 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10460 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10461 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10462 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10463 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10464 | phba->sli4_hba.mbx_wq = qdesc; |
| 10465 | |
| 10466 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10467 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10468 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10469 | |
| 10470 | /* Create slow-path ELS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10471 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10472 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10473 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10474 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10475 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10476 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10477 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10478 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10479 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10480 | phba->sli4_hba.els_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10481 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 10482 | |
| 10483 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 10484 | /* Create NVME LS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10485 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10486 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10487 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10488 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10489 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10490 | "6079 Failed allocate NVME LS CQ\n"); |
| 10491 | goto out_error; |
| 10492 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10493 | qdesc->chann = cpu; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 10494 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10495 | phba->sli4_hba.nvmels_cq = qdesc; |
| 10496 | |
| 10497 | /* Create NVME LS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10498 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10499 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10500 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10501 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10502 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10503 | "6080 Failed allocate NVME LS WQ\n"); |
| 10504 | goto out_error; |
| 10505 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10506 | qdesc->chann = cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10507 | phba->sli4_hba.nvmels_wq = qdesc; |
| 10508 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 10509 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10510 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10511 | /* |
| 10512 | * Create Receive Queue (RQ) |
| 10513 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10514 | |
| 10515 | /* Create Receive Queue for header */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10516 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10517 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10518 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10519 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10520 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10521 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10522 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10523 | } |
| 10524 | phba->sli4_hba.hdr_rq = qdesc; |
| 10525 | |
| 10526 | /* Create Receive Queue for data */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10527 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 10528 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10529 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10530 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10531 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10532 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10533 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10534 | } |
| 10535 | phba->sli4_hba.dat_rq = qdesc; |
| 10536 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10537 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 10538 | phba->nvmet_support) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10539 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10540 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 10541 | LPFC_FIND_BY_HDWQ); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10542 | /* Create NVMET Receive Queue for header */ |
| 10543 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10544 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10545 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10546 | LPFC_NVMET_RQE_DEF_COUNT, |
| 10547 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10548 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10549 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10550 | "3146 Failed allocate " |
| 10551 | "receive HRQ\n"); |
| 10552 | goto out_error; |
| 10553 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10554 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10555 | phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc; |
| 10556 | |
| 10557 | /* Only needed for header of RQ pair */ |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10558 | qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp), |
| 10559 | GFP_KERNEL, |
| 10560 | cpu_to_node(cpu)); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10561 | if (qdesc->rqbp == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10562 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10563 | "6131 Failed allocate " |
| 10564 | "Header RQBP\n"); |
| 10565 | goto out_error; |
| 10566 | } |
| 10567 | |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 10568 | /* Put list in known state in case driver load fails. */ |
| 10569 | INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list); |
| 10570 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10571 | /* Create NVMET Receive Queue for data */ |
| 10572 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 10573 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10574 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 10575 | LPFC_NVMET_RQE_DEF_COUNT, |
| 10576 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10577 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10578 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10579 | "3156 Failed allocate " |
| 10580 | "receive DRQ\n"); |
| 10581 | goto out_error; |
| 10582 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 10583 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10584 | phba->sli4_hba.nvmet_mrq_data[idx] = qdesc; |
| 10585 | } |
| 10586 | } |
| 10587 | |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 10588 | /* Clear NVME stats */ |
| 10589 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 10590 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 10591 | memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0, |
| 10592 | sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat)); |
| 10593 | } |
| 10594 | } |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 10595 | |
| 10596 | /* Clear SCSI stats */ |
| 10597 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 10598 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 10599 | memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0, |
| 10600 | sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat)); |
| 10601 | } |
| 10602 | } |
| 10603 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10604 | return 0; |
| 10605 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10606 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10607 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10608 | return -ENOMEM; |
| 10609 | } |
| 10610 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10611 | static inline void |
| 10612 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) |
| 10613 | { |
| 10614 | if (*qp != NULL) { |
| 10615 | lpfc_sli4_queue_free(*qp); |
| 10616 | *qp = NULL; |
| 10617 | } |
| 10618 | } |
| 10619 | |
| 10620 | static inline void |
| 10621 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) |
| 10622 | { |
| 10623 | int idx; |
| 10624 | |
| 10625 | if (*qs == NULL) |
| 10626 | return; |
| 10627 | |
| 10628 | for (idx = 0; idx < max; idx++) |
| 10629 | __lpfc_sli4_release_queue(&(*qs)[idx]); |
| 10630 | |
| 10631 | kfree(*qs); |
| 10632 | *qs = NULL; |
| 10633 | } |
| 10634 | |
| 10635 | static inline void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10636 | lpfc_sli4_release_hdwq(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10637 | { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10638 | struct lpfc_sli4_hdw_queue *hdwq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10639 | struct lpfc_queue *eq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10640 | uint32_t idx; |
| 10641 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10642 | hdwq = phba->sli4_hba.hdwq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10643 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10644 | /* Loop thru all Hardware Queues */ |
| 10645 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 10646 | /* Free the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10647 | lpfc_sli4_queue_free(hdwq[idx].io_cq); |
| 10648 | lpfc_sli4_queue_free(hdwq[idx].io_wq); |
James Smart | 821bc88 | 2020-01-27 16:23:05 -0800 | [diff] [blame] | 10649 | hdwq[idx].hba_eq = NULL; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10650 | hdwq[idx].io_cq = NULL; |
| 10651 | hdwq[idx].io_wq = NULL; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 10652 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 10653 | lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]); |
| 10654 | lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10655 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10656 | /* Loop thru all IRQ vectors */ |
| 10657 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 10658 | /* Free the EQ corresponding to the IRQ vector */ |
| 10659 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 10660 | lpfc_sli4_queue_free(eq); |
| 10661 | phba->sli4_hba.hba_eq_hdl[idx].eq = NULL; |
| 10662 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10663 | } |
| 10664 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10665 | /** |
| 10666 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 10667 | * @phba: pointer to lpfc hba data structure. |
| 10668 | * |
| 10669 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 10670 | * operation. |
| 10671 | * |
| 10672 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10673 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10674 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10675 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10676 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 10677 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10678 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 10679 | { |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 10680 | /* |
| 10681 | * Set FREE_INIT before beginning to free the queues. |
| 10682 | * Wait until the users of queues to acknowledge to |
| 10683 | * release queues by clearing FREE_WAIT. |
| 10684 | */ |
| 10685 | spin_lock_irq(&phba->hbalock); |
| 10686 | phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT; |
| 10687 | while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) { |
| 10688 | spin_unlock_irq(&phba->hbalock); |
| 10689 | msleep(20); |
| 10690 | spin_lock_irq(&phba->hbalock); |
| 10691 | } |
| 10692 | spin_unlock_irq(&phba->hbalock); |
| 10693 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 10694 | lpfc_sli4_cleanup_poll_list(phba); |
| 10695 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10696 | /* Release HBA eqs */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10697 | if (phba->sli4_hba.hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10698 | lpfc_sli4_release_hdwq(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10699 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 10700 | if (phba->nvmet_support) { |
| 10701 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset, |
| 10702 | phba->cfg_nvmet_mrq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10703 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 10704 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr, |
| 10705 | phba->cfg_nvmet_mrq); |
| 10706 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data, |
| 10707 | phba->cfg_nvmet_mrq); |
| 10708 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 10709 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10710 | /* Release mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10711 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10712 | |
| 10713 | /* Release ELS work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10714 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); |
| 10715 | |
| 10716 | /* Release ELS work queue */ |
| 10717 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10718 | |
| 10719 | /* Release unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10720 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); |
| 10721 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10722 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10723 | /* Release ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10724 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); |
| 10725 | |
| 10726 | /* Release NVME LS complete queue */ |
| 10727 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10728 | |
| 10729 | /* Release mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10730 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); |
| 10731 | |
| 10732 | /* Everything on this list has been freed */ |
| 10733 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 10734 | |
| 10735 | /* Done with freeing the queues */ |
| 10736 | spin_lock_irq(&phba->hbalock); |
| 10737 | phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT; |
| 10738 | spin_unlock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10739 | } |
| 10740 | |
| 10741 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10742 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) |
| 10743 | { |
| 10744 | struct lpfc_rqb *rqbp; |
| 10745 | struct lpfc_dmabuf *h_buf; |
| 10746 | struct rqb_dmabuf *rqb_buffer; |
| 10747 | |
| 10748 | rqbp = rq->rqbp; |
| 10749 | while (!list_empty(&rqbp->rqb_buffer_list)) { |
| 10750 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 10751 | struct lpfc_dmabuf, list); |
| 10752 | |
| 10753 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 10754 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); |
| 10755 | rqbp->buffer_count--; |
| 10756 | } |
| 10757 | return 1; |
| 10758 | } |
| 10759 | |
| 10760 | static int |
| 10761 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 10762 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, |
| 10763 | int qidx, uint32_t qtype) |
| 10764 | { |
| 10765 | struct lpfc_sli_ring *pring; |
| 10766 | int rc; |
| 10767 | |
| 10768 | if (!eq || !cq || !wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10769 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10770 | "6085 Fast-path %s (%d) not allocated\n", |
| 10771 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); |
| 10772 | return -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10773 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10774 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10775 | /* create the Cq first */ |
| 10776 | rc = lpfc_cq_create(phba, cq, eq, |
| 10777 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); |
| 10778 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10779 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 10780 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", |
| 10781 | qidx, (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10782 | return rc; |
| 10783 | } |
| 10784 | |
| 10785 | if (qtype != LPFC_MBOX) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10786 | /* Setup cq_map for fast lookup */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10787 | if (cq_map) |
| 10788 | *cq_map = cq->queue_id; |
| 10789 | |
| 10790 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10791 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", |
| 10792 | qidx, cq->queue_id, qidx, eq->queue_id); |
| 10793 | |
| 10794 | /* create the wq */ |
| 10795 | rc = lpfc_wq_create(phba, wq, cq, qtype); |
| 10796 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10797 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c835c08 | 2019-03-12 16:30:30 -0700 | [diff] [blame] | 10798 | "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10799 | qidx, (uint32_t)rc); |
| 10800 | /* no need to tear down cq - caller will do so */ |
| 10801 | return rc; |
| 10802 | } |
| 10803 | |
| 10804 | /* Bind this CQ/WQ to the NVME ring */ |
| 10805 | pring = wq->pring; |
| 10806 | pring->sli.sli4.wqp = (void *)wq; |
| 10807 | cq->pring = pring; |
| 10808 | |
| 10809 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10810 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", |
| 10811 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); |
| 10812 | } else { |
| 10813 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); |
| 10814 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10815 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 10816 | "0539 Failed setup of slow-path MQ: " |
| 10817 | "rc = 0x%x\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10818 | /* no need to tear down cq - caller will do so */ |
| 10819 | return rc; |
| 10820 | } |
| 10821 | |
| 10822 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10823 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 10824 | phba->sli4_hba.mbx_wq->queue_id, |
| 10825 | phba->sli4_hba.mbx_cq->queue_id); |
| 10826 | } |
| 10827 | |
| 10828 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10829 | } |
| 10830 | |
| 10831 | /** |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10832 | * lpfc_setup_cq_lookup - Setup the CQ lookup table |
| 10833 | * @phba: pointer to lpfc hba data structure. |
| 10834 | * |
| 10835 | * This routine will populate the cq_lookup table by all |
| 10836 | * available CQ queue_id's. |
| 10837 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 10838 | static void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10839 | lpfc_setup_cq_lookup(struct lpfc_hba *phba) |
| 10840 | { |
| 10841 | struct lpfc_queue *eq, *childq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10842 | int qidx; |
| 10843 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10844 | memset(phba->sli4_hba.cq_lookup, 0, |
| 10845 | (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1))); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10846 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10847 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10848 | /* Get the EQ corresponding to the IRQ vector */ |
| 10849 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10850 | if (!eq) |
| 10851 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10852 | /* Loop through all CQs associated with that EQ */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10853 | list_for_each_entry(childq, &eq->child_list, list) { |
| 10854 | if (childq->queue_id > phba->sli4_hba.cq_max) |
| 10855 | continue; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10856 | if (childq->subtype == LPFC_IO) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10857 | phba->sli4_hba.cq_lookup[childq->queue_id] = |
| 10858 | childq; |
| 10859 | } |
| 10860 | } |
| 10861 | } |
| 10862 | |
| 10863 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10864 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 10865 | * @phba: pointer to lpfc hba data structure. |
| 10866 | * |
| 10867 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 10868 | * operation. |
| 10869 | * |
| 10870 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10871 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10872 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10873 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10874 | **/ |
| 10875 | int |
| 10876 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 10877 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 10878 | uint32_t shdr_status, shdr_add_status; |
| 10879 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10880 | struct lpfc_vector_map_info *cpup; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10881 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 10882 | LPFC_MBOXQ_t *mboxq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10883 | int qidx, cpu; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 10884 | uint32_t length, usdelay; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10885 | int rc = -ENOMEM; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 10886 | |
| 10887 | /* Check for dual-ULP support */ |
| 10888 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 10889 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10890 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 10891 | "3249 Unable to allocate memory for " |
| 10892 | "QUERY_FW_CFG mailbox command\n"); |
| 10893 | return -ENOMEM; |
| 10894 | } |
| 10895 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 10896 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 10897 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10898 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 10899 | length, LPFC_SLI4_MBX_EMBED); |
| 10900 | |
| 10901 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10902 | |
| 10903 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 10904 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 10905 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 10906 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 10907 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10908 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 10909 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 10910 | "x%x add_status x%x, mbx status x%x\n", |
| 10911 | shdr_status, shdr_add_status, rc); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 10912 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 10913 | rc = -ENXIO; |
| 10914 | goto out_error; |
| 10915 | } |
| 10916 | |
| 10917 | phba->sli4_hba.fw_func_mode = |
| 10918 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 10919 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 10920 | 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] | 10921 | phba->sli4_hba.physical_port = |
| 10922 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 10923 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10924 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 10925 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 10926 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 10927 | |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 10928 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10929 | |
| 10930 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10931 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10932 | */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10933 | qp = phba->sli4_hba.hdwq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10934 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10935 | /* Set up HBA event queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10936 | if (!qp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10937 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10938 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 10939 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10940 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10941 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10942 | |
| 10943 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10944 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10945 | /* Create HBA Event Queues (EQs) in order */ |
| 10946 | for_each_present_cpu(cpu) { |
| 10947 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10948 | |
| 10949 | /* Look for the CPU thats using that vector with |
| 10950 | * LPFC_CPU_FIRST_IRQ set. |
| 10951 | */ |
| 10952 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 10953 | continue; |
| 10954 | if (qidx != cpup->eq) |
| 10955 | continue; |
| 10956 | |
| 10957 | /* Create an EQ for that vector */ |
| 10958 | rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq, |
| 10959 | phba->cfg_fcp_imax); |
| 10960 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10961 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10962 | "0523 Failed setup of fast-path" |
| 10963 | " EQ (%d), rc = 0x%x\n", |
| 10964 | cpup->eq, (uint32_t)rc); |
| 10965 | goto out_destroy; |
| 10966 | } |
| 10967 | |
| 10968 | /* Save the EQ for that vector in the hba_eq_hdl */ |
| 10969 | phba->sli4_hba.hba_eq_hdl[cpup->eq].eq = |
| 10970 | qp[cpup->hdwq].hba_eq; |
| 10971 | |
| 10972 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10973 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
| 10974 | cpup->eq, |
| 10975 | qp[cpup->hdwq].hba_eq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10976 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10977 | } |
| 10978 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10979 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10980 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10981 | cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ); |
| 10982 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10983 | |
| 10984 | /* Create the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10985 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10986 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10987 | qp[qidx].io_cq, |
| 10988 | qp[qidx].io_wq, |
| 10989 | &phba->sli4_hba.hdwq[qidx].io_cq_map, |
| 10990 | qidx, |
| 10991 | LPFC_IO); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10992 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10993 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10994 | "0535 Failed to setup fastpath " |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 10995 | "IO WQ/CQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10996 | qidx, (uint32_t)rc); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10997 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10998 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 10999 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11000 | |
| 11001 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11002 | * Set up Slow Path Complete Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11003 | */ |
| 11004 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11005 | /* Set up slow-path MBOX CQ/MQ */ |
| 11006 | |
| 11007 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11008 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11009 | "0528 %s not allocated\n", |
| 11010 | phba->sli4_hba.mbx_cq ? |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11011 | "Mailbox WQ" : "Mailbox CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 11012 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11013 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11014 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11015 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11016 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 11017 | phba->sli4_hba.mbx_cq, |
| 11018 | phba->sli4_hba.mbx_wq, |
| 11019 | NULL, 0, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11020 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11021 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11022 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
| 11023 | (uint32_t)rc); |
| 11024 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11025 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11026 | if (phba->nvmet_support) { |
| 11027 | if (!phba->sli4_hba.nvmet_cqset) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11028 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11029 | "3165 Fast-path NVME CQ Set " |
| 11030 | "array not allocated\n"); |
| 11031 | rc = -ENOMEM; |
| 11032 | goto out_destroy; |
| 11033 | } |
| 11034 | if (phba->cfg_nvmet_mrq > 1) { |
| 11035 | rc = lpfc_cq_create_set(phba, |
| 11036 | phba->sli4_hba.nvmet_cqset, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11037 | qp, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11038 | LPFC_WCQ, LPFC_NVMET); |
| 11039 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11040 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11041 | "3164 Failed setup of NVME CQ " |
| 11042 | "Set, rc = 0x%x\n", |
| 11043 | (uint32_t)rc); |
| 11044 | goto out_destroy; |
| 11045 | } |
| 11046 | } else { |
| 11047 | /* Set up NVMET Receive Complete Queue */ |
| 11048 | rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0], |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11049 | qp[0].hba_eq, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11050 | LPFC_WCQ, LPFC_NVMET); |
| 11051 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11052 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11053 | "6089 Failed setup NVMET CQ: " |
| 11054 | "rc = 0x%x\n", (uint32_t)rc); |
| 11055 | goto out_destroy; |
| 11056 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 11057 | phba->sli4_hba.nvmet_cqset[0]->chann = 0; |
| 11058 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11059 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11060 | "6090 NVMET CQ setup: cq-id=%d, " |
| 11061 | "parent eq-id=%d\n", |
| 11062 | phba->sli4_hba.nvmet_cqset[0]->queue_id, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11063 | qp[0].hba_eq->queue_id); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11064 | } |
| 11065 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11066 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11067 | /* Set up slow-path ELS WQ/CQ */ |
| 11068 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11069 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11070 | "0530 ELS %s not allocated\n", |
| 11071 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 11072 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11073 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11074 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11075 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 11076 | phba->sli4_hba.els_cq, |
| 11077 | phba->sli4_hba.els_wq, |
| 11078 | NULL, 0, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11079 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11080 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11081 | "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
| 11082 | (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11083 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11084 | } |
| 11085 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11086 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 11087 | phba->sli4_hba.els_wq->queue_id, |
| 11088 | phba->sli4_hba.els_cq->queue_id); |
| 11089 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11090 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11091 | /* Set up NVME LS Complete Queue */ |
| 11092 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11093 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11094 | "6091 LS %s not allocated\n", |
| 11095 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); |
| 11096 | rc = -ENOMEM; |
| 11097 | goto out_destroy; |
| 11098 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11099 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 11100 | phba->sli4_hba.nvmels_cq, |
| 11101 | phba->sli4_hba.nvmels_wq, |
| 11102 | NULL, 0, LPFC_NVME_LS); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11103 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11104 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11105 | "0526 Failed setup of NVVME LS WQ/CQ: " |
| 11106 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11107 | goto out_destroy; |
| 11108 | } |
| 11109 | |
| 11110 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11111 | "6096 ELS WQ setup: wq-id=%d, " |
| 11112 | "parent cq-id=%d\n", |
| 11113 | phba->sli4_hba.nvmels_wq->queue_id, |
| 11114 | phba->sli4_hba.nvmels_cq->queue_id); |
| 11115 | } |
| 11116 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11117 | /* |
| 11118 | * Create NVMET Receive Queue (RQ) |
| 11119 | */ |
| 11120 | if (phba->nvmet_support) { |
| 11121 | if ((!phba->sli4_hba.nvmet_cqset) || |
| 11122 | (!phba->sli4_hba.nvmet_mrq_hdr) || |
| 11123 | (!phba->sli4_hba.nvmet_mrq_data)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11124 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11125 | "6130 MRQ CQ Queues not " |
| 11126 | "allocated\n"); |
| 11127 | rc = -ENOMEM; |
| 11128 | goto out_destroy; |
| 11129 | } |
| 11130 | if (phba->cfg_nvmet_mrq > 1) { |
| 11131 | rc = lpfc_mrq_create(phba, |
| 11132 | phba->sli4_hba.nvmet_mrq_hdr, |
| 11133 | phba->sli4_hba.nvmet_mrq_data, |
| 11134 | phba->sli4_hba.nvmet_cqset, |
| 11135 | LPFC_NVMET); |
| 11136 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11137 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11138 | "6098 Failed setup of NVMET " |
| 11139 | "MRQ: rc = 0x%x\n", |
| 11140 | (uint32_t)rc); |
| 11141 | goto out_destroy; |
| 11142 | } |
| 11143 | |
| 11144 | } else { |
| 11145 | rc = lpfc_rq_create(phba, |
| 11146 | phba->sli4_hba.nvmet_mrq_hdr[0], |
| 11147 | phba->sli4_hba.nvmet_mrq_data[0], |
| 11148 | phba->sli4_hba.nvmet_cqset[0], |
| 11149 | LPFC_NVMET); |
| 11150 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11151 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11152 | "6057 Failed setup of NVMET " |
| 11153 | "Receive Queue: rc = 0x%x\n", |
| 11154 | (uint32_t)rc); |
| 11155 | goto out_destroy; |
| 11156 | } |
| 11157 | |
| 11158 | lpfc_printf_log( |
| 11159 | phba, KERN_INFO, LOG_INIT, |
| 11160 | "6099 NVMET RQ setup: hdr-rq-id=%d, " |
| 11161 | "dat-rq-id=%d parent cq-id=%d\n", |
| 11162 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id, |
| 11163 | phba->sli4_hba.nvmet_mrq_data[0]->queue_id, |
| 11164 | phba->sli4_hba.nvmet_cqset[0]->queue_id); |
| 11165 | |
| 11166 | } |
| 11167 | } |
| 11168 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11169 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11170 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11171 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 11172 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11173 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11174 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11175 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11176 | 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] | 11177 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11178 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11179 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11180 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 11181 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11182 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11183 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11184 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11185 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11186 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 11187 | "parent cq-id=%d\n", |
| 11188 | phba->sli4_hba.hdr_rq->queue_id, |
| 11189 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 11190 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11191 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 11192 | if (phba->cfg_fcp_imax) |
| 11193 | usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax; |
| 11194 | else |
| 11195 | usdelay = 0; |
| 11196 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11197 | for (qidx = 0; qidx < phba->cfg_irq_chann; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11198 | qidx += LPFC_MAX_EQ_DELAY_EQID_CNT) |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 11199 | 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] | 11200 | usdelay); |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 11201 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11202 | if (phba->sli4_hba.cq_max) { |
| 11203 | kfree(phba->sli4_hba.cq_lookup); |
| 11204 | phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1), |
| 11205 | sizeof(struct lpfc_queue *), GFP_KERNEL); |
| 11206 | if (!phba->sli4_hba.cq_lookup) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11207 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11208 | "0549 Failed setup of CQ Lookup table: " |
| 11209 | "size 0x%x\n", phba->sli4_hba.cq_max); |
Dan Carpenter | fad28e3 | 2019-02-11 21:43:00 +0300 | [diff] [blame] | 11210 | rc = -ENOMEM; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11211 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11212 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11213 | lpfc_setup_cq_lookup(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11214 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11215 | return 0; |
| 11216 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11217 | out_destroy: |
| 11218 | lpfc_sli4_queue_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11219 | out_error: |
| 11220 | return rc; |
| 11221 | } |
| 11222 | |
| 11223 | /** |
| 11224 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 11225 | * @phba: pointer to lpfc hba data structure. |
| 11226 | * |
| 11227 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 11228 | * operation. |
| 11229 | * |
| 11230 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11231 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11232 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 11233 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11234 | **/ |
| 11235 | void |
| 11236 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 11237 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11238 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11239 | struct lpfc_queue *eq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11240 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11241 | |
| 11242 | /* Unset mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11243 | if (phba->sli4_hba.mbx_wq) |
| 11244 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 11245 | |
| 11246 | /* Unset NVME LS work queue */ |
| 11247 | if (phba->sli4_hba.nvmels_wq) |
| 11248 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); |
| 11249 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11250 | /* Unset ELS work queue */ |
Colin Ian King | 019c0d6 | 2017-05-06 23:13:55 +0100 | [diff] [blame] | 11251 | if (phba->sli4_hba.els_wq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11252 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 11253 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11254 | /* Unset unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11255 | if (phba->sli4_hba.hdr_rq) |
| 11256 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, |
| 11257 | phba->sli4_hba.dat_rq); |
| 11258 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11259 | /* Unset mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11260 | if (phba->sli4_hba.mbx_cq) |
| 11261 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 11262 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11263 | /* Unset ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11264 | if (phba->sli4_hba.els_cq) |
| 11265 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 11266 | |
| 11267 | /* Unset NVME LS complete queue */ |
| 11268 | if (phba->sli4_hba.nvmels_cq) |
| 11269 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); |
| 11270 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 11271 | if (phba->nvmet_support) { |
| 11272 | /* Unset NVMET MRQ queue */ |
| 11273 | if (phba->sli4_hba.nvmet_mrq_hdr) { |
| 11274 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 11275 | lpfc_rq_destroy( |
| 11276 | phba, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11277 | phba->sli4_hba.nvmet_mrq_hdr[qidx], |
| 11278 | phba->sli4_hba.nvmet_mrq_data[qidx]); |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 11279 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11280 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 11281 | /* Unset NVMET CQ Set complete queue */ |
| 11282 | if (phba->sli4_hba.nvmet_cqset) { |
| 11283 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 11284 | lpfc_cq_destroy( |
| 11285 | phba, phba->sli4_hba.nvmet_cqset[qidx]); |
| 11286 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 11287 | } |
| 11288 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11289 | /* Unset fast-path SLI4 queues */ |
| 11290 | if (phba->sli4_hba.hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11291 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11292 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11293 | /* Destroy the CQ/WQ corresponding to Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11294 | qp = &phba->sli4_hba.hdwq[qidx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11295 | lpfc_wq_destroy(phba, qp->io_wq); |
| 11296 | lpfc_cq_destroy(phba, qp->io_cq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11297 | } |
| 11298 | /* Loop thru all IRQ vectors */ |
| 11299 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 11300 | /* Destroy the EQ corresponding to the IRQ vector */ |
| 11301 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
| 11302 | lpfc_eq_destroy(phba, eq); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11303 | } |
| 11304 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11305 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11306 | kfree(phba->sli4_hba.cq_lookup); |
| 11307 | phba->sli4_hba.cq_lookup = NULL; |
| 11308 | phba->sli4_hba.cq_max = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11309 | } |
| 11310 | |
| 11311 | /** |
| 11312 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 11313 | * @phba: pointer to lpfc hba data structure. |
| 11314 | * |
| 11315 | * This routine is invoked to allocate and set up a pool of completion queue |
| 11316 | * events. The body of the completion queue event is a completion queue entry |
| 11317 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 11318 | * the following HBA completion queue events for the worker thread to process: |
| 11319 | * - Mailbox asynchronous events |
| 11320 | * - Receive queue completion unsolicited events |
| 11321 | * Later, this can be used for all the slow-path events. |
| 11322 | * |
| 11323 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11324 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11325 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11326 | **/ |
| 11327 | static int |
| 11328 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 11329 | { |
| 11330 | struct lpfc_cq_event *cq_event; |
| 11331 | int i; |
| 11332 | |
| 11333 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 11334 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 11335 | if (!cq_event) |
| 11336 | goto out_pool_create_fail; |
| 11337 | list_add_tail(&cq_event->list, |
| 11338 | &phba->sli4_hba.sp_cqe_event_pool); |
| 11339 | } |
| 11340 | return 0; |
| 11341 | |
| 11342 | out_pool_create_fail: |
| 11343 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 11344 | return -ENOMEM; |
| 11345 | } |
| 11346 | |
| 11347 | /** |
| 11348 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 11349 | * @phba: pointer to lpfc hba data structure. |
| 11350 | * |
| 11351 | * This routine is invoked to free the pool of completion queue events at |
| 11352 | * driver unload time. Note that, it is the responsibility of the driver |
| 11353 | * cleanup routine to free all the outstanding completion-queue events |
| 11354 | * allocated from this pool back into the pool before invoking this routine |
| 11355 | * to destroy the pool. |
| 11356 | **/ |
| 11357 | static void |
| 11358 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 11359 | { |
| 11360 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 11361 | |
| 11362 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 11363 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 11364 | list_del(&cq_event->list); |
| 11365 | kfree(cq_event); |
| 11366 | } |
| 11367 | } |
| 11368 | |
| 11369 | /** |
| 11370 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 11371 | * @phba: pointer to lpfc hba data structure. |
| 11372 | * |
| 11373 | * This routine is the lock free version of the API invoked to allocate a |
| 11374 | * completion-queue event from the free pool. |
| 11375 | * |
| 11376 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 11377 | * NULL otherwise. |
| 11378 | **/ |
| 11379 | struct lpfc_cq_event * |
| 11380 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 11381 | { |
| 11382 | struct lpfc_cq_event *cq_event = NULL; |
| 11383 | |
| 11384 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 11385 | struct lpfc_cq_event, list); |
| 11386 | return cq_event; |
| 11387 | } |
| 11388 | |
| 11389 | /** |
| 11390 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 11391 | * @phba: pointer to lpfc hba data structure. |
| 11392 | * |
| 11393 | * This routine is the lock version of the API invoked to allocate a |
| 11394 | * completion-queue event from the free pool. |
| 11395 | * |
| 11396 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 11397 | * NULL otherwise. |
| 11398 | **/ |
| 11399 | struct lpfc_cq_event * |
| 11400 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 11401 | { |
| 11402 | struct lpfc_cq_event *cq_event; |
| 11403 | unsigned long iflags; |
| 11404 | |
| 11405 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11406 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 11407 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11408 | return cq_event; |
| 11409 | } |
| 11410 | |
| 11411 | /** |
| 11412 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 11413 | * @phba: pointer to lpfc hba data structure. |
| 11414 | * @cq_event: pointer to the completion queue event to be freed. |
| 11415 | * |
| 11416 | * This routine is the lock free version of the API invoked to release a |
| 11417 | * completion-queue event back into the free pool. |
| 11418 | **/ |
| 11419 | void |
| 11420 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 11421 | struct lpfc_cq_event *cq_event) |
| 11422 | { |
| 11423 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 11424 | } |
| 11425 | |
| 11426 | /** |
| 11427 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 11428 | * @phba: pointer to lpfc hba data structure. |
| 11429 | * @cq_event: pointer to the completion queue event to be freed. |
| 11430 | * |
| 11431 | * This routine is the lock version of the API invoked to release a |
| 11432 | * completion-queue event back into the free pool. |
| 11433 | **/ |
| 11434 | void |
| 11435 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 11436 | struct lpfc_cq_event *cq_event) |
| 11437 | { |
| 11438 | unsigned long iflags; |
| 11439 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 11440 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 11441 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 11442 | } |
| 11443 | |
| 11444 | /** |
| 11445 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 11446 | * @phba: pointer to lpfc hba data structure. |
| 11447 | * |
| 11448 | * This routine is to free all the pending completion-queue events to the |
| 11449 | * back into the free pool for device reset. |
| 11450 | **/ |
| 11451 | static void |
| 11452 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 11453 | { |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 11454 | LIST_HEAD(cq_event_list); |
| 11455 | struct lpfc_cq_event *cq_event; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11456 | unsigned long iflags; |
| 11457 | |
| 11458 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11459 | |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 11460 | /* Pending ELS XRI abort events */ |
| 11461 | spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
| 11462 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 11463 | &cq_event_list); |
| 11464 | spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
| 11465 | |
| 11466 | /* Pending asynnc events */ |
| 11467 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
| 11468 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 11469 | &cq_event_list); |
| 11470 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags); |
| 11471 | |
| 11472 | while (!list_empty(&cq_event_list)) { |
| 11473 | list_remove_head(&cq_event_list, cq_event, |
| 11474 | struct lpfc_cq_event, list); |
| 11475 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11476 | } |
| 11477 | } |
| 11478 | |
| 11479 | /** |
| 11480 | * lpfc_pci_function_reset - Reset pci function. |
| 11481 | * @phba: pointer to lpfc hba data structure. |
| 11482 | * |
| 11483 | * This routine is invoked to request a PCI function reset. It will destroys |
| 11484 | * all resources assigned to the PCI function which originates this request. |
| 11485 | * |
| 11486 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11487 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 11488 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 11489 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11490 | **/ |
| 11491 | int |
| 11492 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 11493 | { |
| 11494 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11495 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11496 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 11497 | uint32_t rdy_chk; |
| 11498 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11499 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11500 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 11501 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11502 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11503 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 11504 | switch (if_type) { |
| 11505 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 11506 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 11507 | GFP_KERNEL); |
| 11508 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11509 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11510 | "0494 Unable to allocate memory for " |
| 11511 | "issuing SLI_FUNCTION_RESET mailbox " |
| 11512 | "command\n"); |
| 11513 | return -ENOMEM; |
| 11514 | } |
| 11515 | |
| 11516 | /* Setup PCI function reset mailbox-ioctl command */ |
| 11517 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 11518 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 11519 | LPFC_SLI4_MBX_EMBED); |
| 11520 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 11521 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 11522 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 11523 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 11524 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 11525 | &shdr->response); |
James Smart | 304ee43 | 2021-04-11 18:31:17 -0700 | [diff] [blame] | 11526 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11527 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11528 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11529 | "0495 SLI_FUNCTION_RESET mailbox " |
| 11530 | "failed with status x%x add_status x%x," |
| 11531 | " mbx status x%x\n", |
| 11532 | shdr_status, shdr_add_status, rc); |
| 11533 | rc = -ENXIO; |
| 11534 | } |
| 11535 | break; |
| 11536 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11537 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 11538 | wait: |
| 11539 | /* |
| 11540 | * Poll the Port Status Register and wait for RDY for |
| 11541 | * up to 30 seconds. If the port doesn't respond, treat |
| 11542 | * it as an error. |
| 11543 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 11544 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 11545 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 11546 | STATUSregaddr, ®_data.word0)) { |
| 11547 | rc = -ENODEV; |
| 11548 | goto out; |
| 11549 | } |
| 11550 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 11551 | break; |
| 11552 | msleep(20); |
| 11553 | } |
| 11554 | |
| 11555 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 11556 | phba->work_status[0] = readl( |
| 11557 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 11558 | phba->work_status[1] = readl( |
| 11559 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11560 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 11561 | "2890 Port not ready, port status reg " |
| 11562 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 11563 | reg_data.word0, |
| 11564 | phba->work_status[0], |
| 11565 | phba->work_status[1]); |
| 11566 | rc = -ENODEV; |
| 11567 | goto out; |
| 11568 | } |
| 11569 | |
| 11570 | if (!port_reset) { |
| 11571 | /* |
| 11572 | * Reset the port now |
| 11573 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11574 | reg_data.word0 = 0; |
| 11575 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 11576 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 11577 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 11578 | LPFC_SLIPORT_INIT_PORT); |
| 11579 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 11580 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 11581 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 11582 | pci_read_config_word(phba->pcidev, |
| 11583 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11584 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 11585 | port_reset = 1; |
| 11586 | msleep(20); |
| 11587 | goto wait; |
| 11588 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 11589 | rc = -ENODEV; |
| 11590 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11591 | } |
| 11592 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 11593 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11594 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 11595 | default: |
| 11596 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11597 | } |
| 11598 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 11599 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11600 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 11601 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11602 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 11603 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 11604 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11605 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 11606 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11607 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11608 | return rc; |
| 11609 | } |
| 11610 | |
| 11611 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11612 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 11613 | * @phba: pointer to lpfc hba data structure. |
| 11614 | * |
| 11615 | * This routine is invoked to set up the PCI device memory space for device |
| 11616 | * with SLI-4 interface spec. |
| 11617 | * |
| 11618 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11619 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11620 | * other values - error |
| 11621 | **/ |
| 11622 | static int |
| 11623 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 11624 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 11625 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11626 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 11627 | int error; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11628 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11629 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 11630 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 11631 | return -ENODEV; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11632 | |
| 11633 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 11634 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 11635 | if (error) |
| 11636 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 11637 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 11638 | return error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11639 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11640 | /* |
| 11641 | * The BARs and register set definitions and offset locations are |
| 11642 | * dependent on the if_type. |
| 11643 | */ |
| 11644 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 11645 | &phba->sli4_hba.sli_intf.word0)) { |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 11646 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11647 | } |
| 11648 | |
| 11649 | /* There is no SLI3 failback for SLI4 devices. */ |
| 11650 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 11651 | LPFC_SLI_INTF_VALID) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11652 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11653 | "2894 SLI_INTF reg contents invalid " |
| 11654 | "sli_intf reg 0x%x\n", |
| 11655 | phba->sli4_hba.sli_intf.word0); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 11656 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11657 | } |
| 11658 | |
| 11659 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 11660 | /* |
| 11661 | * Get the bus address of SLI4 device Bar regions and the |
| 11662 | * number of bytes required by each mapping. The mapping of the |
| 11663 | * particular PCI BARs regions is dependent on the type of |
| 11664 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11665 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 11666 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 11667 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 11668 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11669 | |
| 11670 | /* |
| 11671 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 11672 | * addr |
| 11673 | */ |
| 11674 | phba->sli4_hba.conf_regs_memmap_p = |
| 11675 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 11676 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 11677 | dev_printk(KERN_ERR, &pdev->dev, |
| 11678 | "ioremap failed for SLI4 PCI config " |
| 11679 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 11680 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11681 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 11682 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11683 | /* Set up BAR0 PCI config space register memory map */ |
| 11684 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 11685 | } else { |
| 11686 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 11687 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11688 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11689 | dev_printk(KERN_ERR, &pdev->dev, |
| 11690 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 11691 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11692 | } |
| 11693 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11694 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11695 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 11696 | dev_printk(KERN_ERR, &pdev->dev, |
| 11697 | "ioremap failed for SLI4 PCI config " |
| 11698 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 11699 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11700 | } |
| 11701 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11702 | } |
| 11703 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 11704 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 11705 | if (pci_resource_start(pdev, PCI_64BIT_BAR2)) { |
| 11706 | /* |
| 11707 | * Map SLI4 if type 0 HBA Control Register base to a |
| 11708 | * kernel virtual address and setup the registers. |
| 11709 | */ |
| 11710 | phba->pci_bar1_map = pci_resource_start(pdev, |
| 11711 | PCI_64BIT_BAR2); |
| 11712 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 11713 | phba->sli4_hba.ctrl_regs_memmap_p = |
| 11714 | ioremap(phba->pci_bar1_map, |
| 11715 | bar1map_len); |
| 11716 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 11717 | dev_err(&pdev->dev, |
| 11718 | "ioremap failed for SLI4 HBA " |
| 11719 | "control registers.\n"); |
| 11720 | error = -ENOMEM; |
| 11721 | goto out_iounmap_conf; |
| 11722 | } |
| 11723 | phba->pci_bar2_memmap_p = |
| 11724 | phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11725 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 11726 | } else { |
| 11727 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11728 | goto out_iounmap_conf; |
| 11729 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11730 | } |
| 11731 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11732 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) && |
| 11733 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
| 11734 | /* |
| 11735 | * Map SLI4 if type 6 HBA Doorbell Register base to a kernel |
| 11736 | * virtual address and setup the registers. |
| 11737 | */ |
| 11738 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 11739 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 11740 | phba->sli4_hba.drbl_regs_memmap_p = |
| 11741 | ioremap(phba->pci_bar1_map, bar1map_len); |
| 11742 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 11743 | dev_err(&pdev->dev, |
| 11744 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 11745 | error = -ENOMEM; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11746 | goto out_iounmap_conf; |
| 11747 | } |
| 11748 | phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
| 11749 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
| 11750 | } |
| 11751 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 11752 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 11753 | if (pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 11754 | /* |
| 11755 | * Map SLI4 if type 0 HBA Doorbell Register base to |
| 11756 | * a kernel virtual address and setup the registers. |
| 11757 | */ |
| 11758 | phba->pci_bar2_map = pci_resource_start(pdev, |
| 11759 | PCI_64BIT_BAR4); |
| 11760 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 11761 | phba->sli4_hba.drbl_regs_memmap_p = |
| 11762 | ioremap(phba->pci_bar2_map, |
| 11763 | bar2map_len); |
| 11764 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 11765 | dev_err(&pdev->dev, |
| 11766 | "ioremap failed for SLI4 HBA" |
| 11767 | " doorbell registers.\n"); |
| 11768 | error = -ENOMEM; |
| 11769 | goto out_iounmap_ctrl; |
| 11770 | } |
| 11771 | phba->pci_bar4_memmap_p = |
| 11772 | phba->sli4_hba.drbl_regs_memmap_p; |
| 11773 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 11774 | if (error) |
| 11775 | goto out_iounmap_all; |
| 11776 | } else { |
| 11777 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 11778 | goto out_iounmap_all; |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 11779 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11780 | } |
| 11781 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 11782 | if (if_type == LPFC_SLI_INTF_IF_TYPE_6 && |
| 11783 | pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 11784 | /* |
| 11785 | * Map SLI4 if type 6 HBA DPP Register base to a kernel |
| 11786 | * virtual address and setup the registers. |
| 11787 | */ |
| 11788 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 11789 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 11790 | phba->sli4_hba.dpp_regs_memmap_p = |
| 11791 | ioremap(phba->pci_bar2_map, bar2map_len); |
| 11792 | if (!phba->sli4_hba.dpp_regs_memmap_p) { |
| 11793 | dev_err(&pdev->dev, |
| 11794 | "ioremap failed for SLI4 HBA dpp registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 11795 | error = -ENOMEM; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 11796 | goto out_iounmap_ctrl; |
| 11797 | } |
| 11798 | phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; |
| 11799 | } |
| 11800 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 11801 | /* Set up the EQ/CQ register handeling functions now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11802 | switch (if_type) { |
| 11803 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 11804 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 11805 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 11806 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db; |
| 11807 | phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11808 | break; |
| 11809 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 11810 | 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] | 11811 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db; |
| 11812 | 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] | 11813 | break; |
| 11814 | default: |
| 11815 | break; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 11816 | } |
| 11817 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11818 | return 0; |
| 11819 | |
| 11820 | out_iounmap_all: |
| 11821 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 11822 | out_iounmap_ctrl: |
| 11823 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 11824 | out_iounmap_conf: |
| 11825 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 11826 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11827 | return error; |
| 11828 | } |
| 11829 | |
| 11830 | /** |
| 11831 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 11832 | * @phba: pointer to lpfc hba data structure. |
| 11833 | * |
| 11834 | * This routine is invoked to unset the PCI device memory space for device |
| 11835 | * with SLI-4 interface spec. |
| 11836 | **/ |
| 11837 | static void |
| 11838 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 11839 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11840 | uint32_t if_type; |
| 11841 | 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] | 11842 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11843 | switch (if_type) { |
| 11844 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 11845 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 11846 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 11847 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 11848 | break; |
| 11849 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 11850 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 11851 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11852 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 11853 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 11854 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
James Smart | 0b43919 | 2019-12-18 15:58:05 -0800 | [diff] [blame] | 11855 | if (phba->sli4_hba.dpp_regs_memmap_p) |
| 11856 | iounmap(phba->sli4_hba.dpp_regs_memmap_p); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 11857 | break; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 11858 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 11859 | default: |
| 11860 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 11861 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 11862 | if_type); |
| 11863 | break; |
| 11864 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11865 | } |
| 11866 | |
| 11867 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11868 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 11869 | * @phba: pointer to lpfc hba data structure. |
| 11870 | * |
| 11871 | * 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] | 11872 | * with SLI-3 interface specs. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11873 | * |
| 11874 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11875 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11876 | * other values - error |
| 11877 | **/ |
| 11878 | static int |
| 11879 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 11880 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11881 | int rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11882 | LPFC_MBOXQ_t *pmb; |
| 11883 | |
| 11884 | /* Set up MSI-X multi-message vectors */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11885 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 11886 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); |
| 11887 | if (rc < 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11888 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11889 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11890 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11891 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11892 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11893 | /* |
| 11894 | * Assign MSI-X vectors to interrupt handlers |
| 11895 | */ |
| 11896 | |
| 11897 | /* vector-0 is associated to slow-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11898 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 11899 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11900 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 11901 | if (rc) { |
| 11902 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11903 | "0421 MSI-X slow-path request_irq failed " |
| 11904 | "(%d)\n", rc); |
| 11905 | goto msi_fail_out; |
| 11906 | } |
| 11907 | |
| 11908 | /* vector-1 is associated to fast-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11909 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 11910 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11911 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 11912 | |
| 11913 | if (rc) { |
| 11914 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11915 | "0429 MSI-X fast-path request_irq failed " |
| 11916 | "(%d)\n", rc); |
| 11917 | goto irq_fail_out; |
| 11918 | } |
| 11919 | |
| 11920 | /* |
| 11921 | * Configure HBA MSI-X attention conditions to messages |
| 11922 | */ |
| 11923 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 11924 | |
| 11925 | if (!pmb) { |
| 11926 | rc = -ENOMEM; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11927 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11928 | "0474 Unable to allocate memory for issuing " |
| 11929 | "MBOX_CONFIG_MSI command\n"); |
| 11930 | goto mem_fail_out; |
| 11931 | } |
| 11932 | rc = lpfc_config_msi(phba, pmb); |
| 11933 | if (rc) |
| 11934 | goto mbx_fail_out; |
| 11935 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 11936 | if (rc != MBX_SUCCESS) { |
| 11937 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 11938 | "0351 Config MSI mailbox command failed, " |
| 11939 | "mbxCmd x%x, mbxStatus x%x\n", |
| 11940 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 11941 | goto mbx_fail_out; |
| 11942 | } |
| 11943 | |
| 11944 | /* Free memory allocated for mailbox command */ |
| 11945 | mempool_free(pmb, phba->mbox_mem_pool); |
| 11946 | return rc; |
| 11947 | |
| 11948 | mbx_fail_out: |
| 11949 | /* Free memory allocated for mailbox command */ |
| 11950 | mempool_free(pmb, phba->mbox_mem_pool); |
| 11951 | |
| 11952 | mem_fail_out: |
| 11953 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11954 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11955 | |
| 11956 | irq_fail_out: |
| 11957 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11958 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11959 | |
| 11960 | msi_fail_out: |
| 11961 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11962 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11963 | |
| 11964 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11965 | return rc; |
| 11966 | } |
| 11967 | |
| 11968 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11969 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 11970 | * @phba: pointer to lpfc hba data structure. |
| 11971 | * |
| 11972 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 11973 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 11974 | * enable the MSI vector. The device driver is responsible for calling the |
| 11975 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 11976 | * is done in this function. |
| 11977 | * |
| 11978 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11979 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11980 | * other values - error |
| 11981 | */ |
| 11982 | static int |
| 11983 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 11984 | { |
| 11985 | int rc; |
| 11986 | |
| 11987 | rc = pci_enable_msi(phba->pcidev); |
| 11988 | if (!rc) |
| 11989 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11990 | "0462 PCI enable MSI mode success.\n"); |
| 11991 | else { |
| 11992 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11993 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 11994 | return rc; |
| 11995 | } |
| 11996 | |
| 11997 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 11998 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11999 | if (rc) { |
| 12000 | pci_disable_msi(phba->pcidev); |
| 12001 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 12002 | "0478 MSI request_irq failed (%d)\n", rc); |
| 12003 | } |
| 12004 | return rc; |
| 12005 | } |
| 12006 | |
| 12007 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12008 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 12009 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 12010 | * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X). |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12011 | * |
| 12012 | * This routine is invoked to enable device interrupt and associate driver's |
| 12013 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 12014 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 12015 | * will try to fallback from the configured interrupt mode to an interrupt |
| 12016 | * mode which is supported by the platform, kernel, and device in the order |
| 12017 | * of: |
| 12018 | * MSI-X -> MSI -> IRQ. |
| 12019 | * |
| 12020 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 12021 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12022 | * other values - error |
| 12023 | **/ |
| 12024 | static uint32_t |
| 12025 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 12026 | { |
| 12027 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 12028 | int retval; |
| 12029 | |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 12030 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 12031 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 12032 | if (retval) |
| 12033 | return intr_mode; |
| 12034 | phba->hba_flag &= ~HBA_NEEDS_CFG_PORT; |
| 12035 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12036 | if (cfg_mode == 2) { |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 12037 | /* Now, try to enable MSI-X interrupt mode */ |
| 12038 | retval = lpfc_sli_enable_msix(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12039 | if (!retval) { |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame] | 12040 | /* Indicate initialization to MSI-X mode */ |
| 12041 | phba->intr_type = MSIX; |
| 12042 | intr_mode = 2; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12043 | } |
| 12044 | } |
| 12045 | |
| 12046 | /* Fallback to MSI if MSI-X initialization failed */ |
| 12047 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 12048 | retval = lpfc_sli_enable_msi(phba); |
| 12049 | if (!retval) { |
| 12050 | /* Indicate initialization to MSI mode */ |
| 12051 | phba->intr_type = MSI; |
| 12052 | intr_mode = 1; |
| 12053 | } |
| 12054 | } |
| 12055 | |
| 12056 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 12057 | if (phba->intr_type == NONE) { |
| 12058 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 12059 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 12060 | if (!retval) { |
| 12061 | /* Indicate initialization to INTx mode */ |
| 12062 | phba->intr_type = INTx; |
| 12063 | intr_mode = 0; |
| 12064 | } |
| 12065 | } |
| 12066 | return intr_mode; |
| 12067 | } |
| 12068 | |
| 12069 | /** |
| 12070 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 12071 | * @phba: pointer to lpfc hba data structure. |
| 12072 | * |
| 12073 | * This routine is invoked to disable device interrupt and disassociate the |
| 12074 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 12075 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 12076 | * release the interrupt vector(s) for the message signaled interrupt. |
| 12077 | **/ |
| 12078 | static void |
| 12079 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 12080 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 12081 | int nr_irqs, i; |
| 12082 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12083 | if (phba->intr_type == MSIX) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 12084 | nr_irqs = LPFC_MSIX_VECTORS; |
| 12085 | else |
| 12086 | nr_irqs = 1; |
| 12087 | |
| 12088 | for (i = 0; i < nr_irqs; i++) |
| 12089 | free_irq(pci_irq_vector(phba->pcidev, i), phba); |
| 12090 | pci_free_irq_vectors(phba->pcidev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12091 | |
| 12092 | /* Reset interrupt management states */ |
| 12093 | phba->intr_type = NONE; |
| 12094 | phba->sli.slistat.sli_intr = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12095 | } |
| 12096 | |
| 12097 | /** |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12098 | * 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] | 12099 | * @phba: pointer to lpfc hba data structure. |
| 12100 | * @id: EQ vector index or Hardware Queue index |
| 12101 | * @match: LPFC_FIND_BY_EQ = match by EQ |
| 12102 | * LPFC_FIND_BY_HDWQ = match by Hardware Queue |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12103 | * Return the CPU that matches the selection criteria |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12104 | */ |
| 12105 | static uint16_t |
| 12106 | lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match) |
| 12107 | { |
| 12108 | struct lpfc_vector_map_info *cpup; |
| 12109 | int cpu; |
| 12110 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12111 | /* Loop through all CPUs */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 12112 | for_each_present_cpu(cpu) { |
| 12113 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12114 | |
| 12115 | /* If we are matching by EQ, there may be multiple CPUs using |
| 12116 | * using the same vector, so select the one with |
| 12117 | * LPFC_CPU_FIRST_IRQ set. |
| 12118 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12119 | if ((match == LPFC_FIND_BY_EQ) && |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12120 | (cpup->flag & LPFC_CPU_FIRST_IRQ) && |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12121 | (cpup->eq == id)) |
| 12122 | return cpu; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12123 | |
| 12124 | /* If matching by HDWQ, select the first CPU that matches */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12125 | if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id)) |
| 12126 | return cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12127 | } |
| 12128 | return 0; |
| 12129 | } |
| 12130 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12131 | #ifdef CONFIG_X86 |
| 12132 | /** |
| 12133 | * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded |
| 12134 | * @phba: pointer to lpfc hba data structure. |
| 12135 | * @cpu: CPU map index |
| 12136 | * @phys_id: CPU package physical id |
| 12137 | * @core_id: CPU core id |
| 12138 | */ |
| 12139 | static int |
| 12140 | lpfc_find_hyper(struct lpfc_hba *phba, int cpu, |
| 12141 | uint16_t phys_id, uint16_t core_id) |
| 12142 | { |
| 12143 | struct lpfc_vector_map_info *cpup; |
| 12144 | int idx; |
| 12145 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 12146 | for_each_present_cpu(idx) { |
| 12147 | cpup = &phba->sli4_hba.cpu_map[idx]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12148 | /* Does the cpup match the one we are looking for */ |
| 12149 | if ((cpup->phys_id == phys_id) && |
| 12150 | (cpup->core_id == core_id) && |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 12151 | (cpu != idx)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12152 | return 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12153 | } |
| 12154 | return 0; |
| 12155 | } |
| 12156 | #endif |
| 12157 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12158 | /* |
| 12159 | * lpfc_assign_eq_map_info - Assigns eq for vector_map structure |
| 12160 | * @phba: pointer to lpfc hba data structure. |
| 12161 | * @eqidx: index for eq and irq vector |
| 12162 | * @flag: flags to set for vector_map structure |
| 12163 | * @cpu: cpu used to index vector_map structure |
| 12164 | * |
| 12165 | * The routine assigns eq info into vector_map structure |
| 12166 | */ |
| 12167 | static inline void |
| 12168 | lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag, |
| 12169 | unsigned int cpu) |
| 12170 | { |
| 12171 | struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 12172 | struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx); |
| 12173 | |
| 12174 | cpup->eq = eqidx; |
| 12175 | cpup->flag |= flag; |
| 12176 | |
| 12177 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12178 | "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n", |
| 12179 | cpu, eqhdl->irq, cpup->eq, cpup->flag); |
| 12180 | } |
| 12181 | |
| 12182 | /** |
| 12183 | * lpfc_cpu_map_array_init - Initialize cpu_map structure |
| 12184 | * @phba: pointer to lpfc hba data structure. |
| 12185 | * |
| 12186 | * The routine initializes the cpu_map array structure |
| 12187 | */ |
| 12188 | static void |
| 12189 | lpfc_cpu_map_array_init(struct lpfc_hba *phba) |
| 12190 | { |
| 12191 | struct lpfc_vector_map_info *cpup; |
| 12192 | struct lpfc_eq_intr_info *eqi; |
| 12193 | int cpu; |
| 12194 | |
| 12195 | for_each_possible_cpu(cpu) { |
| 12196 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 12197 | cpup->phys_id = LPFC_VECTOR_MAP_EMPTY; |
| 12198 | cpup->core_id = LPFC_VECTOR_MAP_EMPTY; |
| 12199 | cpup->hdwq = LPFC_VECTOR_MAP_EMPTY; |
| 12200 | cpup->eq = LPFC_VECTOR_MAP_EMPTY; |
| 12201 | cpup->flag = 0; |
| 12202 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu); |
| 12203 | INIT_LIST_HEAD(&eqi->list); |
| 12204 | eqi->icnt = 0; |
| 12205 | } |
| 12206 | } |
| 12207 | |
| 12208 | /** |
| 12209 | * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure |
| 12210 | * @phba: pointer to lpfc hba data structure. |
| 12211 | * |
| 12212 | * The routine initializes the hba_eq_hdl array structure |
| 12213 | */ |
| 12214 | static void |
| 12215 | lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba) |
| 12216 | { |
| 12217 | struct lpfc_hba_eq_hdl *eqhdl; |
| 12218 | int i; |
| 12219 | |
| 12220 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 12221 | eqhdl = lpfc_get_eq_hdl(i); |
| 12222 | eqhdl->irq = LPFC_VECTOR_MAP_EMPTY; |
| 12223 | eqhdl->phba = phba; |
| 12224 | } |
| 12225 | } |
| 12226 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12227 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12228 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12229 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12230 | * @vectors: number of msix vectors allocated. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12231 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12232 | * The routine will figure out the CPU affinity assignment for every |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12233 | * MSI-X vector allocated for the HBA. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12234 | * In addition, the CPU to IO channel mapping will be calculated |
| 12235 | * and the phba->sli4_hba.cpu_map array will reflect this. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12236 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12237 | static void |
| 12238 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12239 | { |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12240 | int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12241 | int max_phys_id, min_phys_id; |
| 12242 | int max_core_id, min_core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12243 | struct lpfc_vector_map_info *cpup; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12244 | struct lpfc_vector_map_info *new_cpup; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12245 | #ifdef CONFIG_X86 |
| 12246 | struct cpuinfo_x86 *cpuinfo; |
| 12247 | #endif |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 12248 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 12249 | struct lpfc_hdwq_stat *c_stat; |
| 12250 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12251 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12252 | max_phys_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12253 | min_phys_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12254 | max_core_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12255 | min_core_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12256 | |
| 12257 | /* Update CPU map with physical id and core id of each CPU */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 12258 | for_each_present_cpu(cpu) { |
| 12259 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12260 | #ifdef CONFIG_X86 |
| 12261 | cpuinfo = &cpu_data(cpu); |
| 12262 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 12263 | cpup->core_id = cpuinfo->cpu_core_id; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12264 | if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) |
| 12265 | cpup->flag |= LPFC_CPU_MAP_HYPER; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12266 | #else |
| 12267 | /* No distinction between CPUs for other platforms */ |
| 12268 | cpup->phys_id = 0; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12269 | cpup->core_id = cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12270 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12271 | |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 12272 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12273 | "3328 CPU %d physid %d coreid %d flag x%x\n", |
| 12274 | cpu, cpup->phys_id, cpup->core_id, cpup->flag); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12275 | |
| 12276 | if (cpup->phys_id > max_phys_id) |
| 12277 | max_phys_id = cpup->phys_id; |
| 12278 | if (cpup->phys_id < min_phys_id) |
| 12279 | min_phys_id = cpup->phys_id; |
| 12280 | |
| 12281 | if (cpup->core_id > max_core_id) |
| 12282 | max_core_id = cpup->core_id; |
| 12283 | if (cpup->core_id < min_core_id) |
| 12284 | min_core_id = cpup->core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12285 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 12286 | |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12287 | /* After looking at each irq vector assigned to this pcidev, its |
| 12288 | * possible to see that not ALL CPUs have been accounted for. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12289 | * Next we will set any unassigned (unaffinitized) cpu map |
| 12290 | * entries to a IRQ on the same phys_id. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12291 | */ |
| 12292 | first_cpu = cpumask_first(cpu_present_mask); |
| 12293 | start_cpu = first_cpu; |
| 12294 | |
| 12295 | for_each_present_cpu(cpu) { |
| 12296 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 12297 | |
| 12298 | /* Is this CPU entry unassigned */ |
| 12299 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 12300 | /* Mark CPU as IRQ not assigned by the kernel */ |
| 12301 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 12302 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12303 | /* If so, find a new_cpup thats on the the SAME |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12304 | * phys_id as cpup. start_cpu will start where we |
| 12305 | * left off so all unassigned entries don't get assgined |
| 12306 | * the IRQ of the first entry. |
| 12307 | */ |
| 12308 | new_cpu = start_cpu; |
| 12309 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 12310 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 12311 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12312 | (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) && |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12313 | (new_cpup->phys_id == cpup->phys_id)) |
| 12314 | goto found_same; |
| 12315 | new_cpu = cpumask_next( |
| 12316 | new_cpu, cpu_present_mask); |
| 12317 | if (new_cpu == nr_cpumask_bits) |
| 12318 | new_cpu = first_cpu; |
| 12319 | } |
| 12320 | /* At this point, we leave the CPU as unassigned */ |
| 12321 | continue; |
| 12322 | found_same: |
| 12323 | /* We found a matching phys_id, so copy the IRQ info */ |
| 12324 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12325 | |
| 12326 | /* Bump start_cpu to the next slot to minmize the |
| 12327 | * chance of having multiple unassigned CPU entries |
| 12328 | * selecting the same IRQ. |
| 12329 | */ |
| 12330 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 12331 | if (start_cpu == nr_cpumask_bits) |
| 12332 | start_cpu = first_cpu; |
| 12333 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12334 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12335 | "3337 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12336 | "eq %d from peer cpu %d same " |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12337 | "phys_id (%d)\n", |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12338 | cpu, cpup->eq, new_cpu, |
| 12339 | cpup->phys_id); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12340 | } |
| 12341 | } |
| 12342 | |
| 12343 | /* Set any unassigned cpu map entries to a IRQ on any phys_id */ |
| 12344 | start_cpu = first_cpu; |
| 12345 | |
| 12346 | for_each_present_cpu(cpu) { |
| 12347 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 12348 | |
| 12349 | /* Is this entry unassigned */ |
| 12350 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 12351 | /* Mark it as IRQ not assigned by the kernel */ |
| 12352 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 12353 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12354 | /* If so, find a new_cpup thats on ANY phys_id |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12355 | * as the cpup. start_cpu will start where we |
| 12356 | * left off so all unassigned entries don't get |
| 12357 | * assigned the IRQ of the first entry. |
| 12358 | */ |
| 12359 | new_cpu = start_cpu; |
| 12360 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 12361 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 12362 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12363 | (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY)) |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12364 | goto found_any; |
| 12365 | new_cpu = cpumask_next( |
| 12366 | new_cpu, cpu_present_mask); |
| 12367 | if (new_cpu == nr_cpumask_bits) |
| 12368 | new_cpu = first_cpu; |
| 12369 | } |
| 12370 | /* We should never leave an entry unassigned */ |
| 12371 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12372 | "3339 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12373 | "eq %d UNASSIGNED\n", |
| 12374 | cpup->hdwq, cpup->eq); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12375 | continue; |
| 12376 | found_any: |
| 12377 | /* We found an available entry, copy the IRQ info */ |
| 12378 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12379 | |
| 12380 | /* Bump start_cpu to the next slot to minmize the |
| 12381 | * chance of having multiple unassigned CPU entries |
| 12382 | * selecting the same IRQ. |
| 12383 | */ |
| 12384 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 12385 | if (start_cpu == nr_cpumask_bits) |
| 12386 | start_cpu = first_cpu; |
| 12387 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12388 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12389 | "3338 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12390 | "eq %d from peer cpu %d (%d/%d)\n", |
| 12391 | cpu, cpup->eq, new_cpu, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 12392 | new_cpup->phys_id, new_cpup->core_id); |
| 12393 | } |
| 12394 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12395 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12396 | /* Assign hdwq indices that are unique across all cpus in the map |
| 12397 | * that are also FIRST_CPUs. |
| 12398 | */ |
| 12399 | idx = 0; |
| 12400 | for_each_present_cpu(cpu) { |
| 12401 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 12402 | |
| 12403 | /* Only FIRST IRQs get a hdwq index assignment. */ |
| 12404 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 12405 | continue; |
| 12406 | |
| 12407 | /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */ |
| 12408 | cpup->hdwq = idx; |
| 12409 | idx++; |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 12410 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12411 | "3333 Set Affinity: CPU %d (phys %d core %d): " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12412 | "hdwq %d eq %d flg x%x\n", |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12413 | cpu, cpup->phys_id, cpup->core_id, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12414 | cpup->hdwq, cpup->eq, cpup->flag); |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12415 | } |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 12416 | /* Associate a hdwq with each cpu_map entry |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12417 | * This will be 1 to 1 - hdwq to cpu, unless there are less |
| 12418 | * hardware queues then CPUs. For that case we will just round-robin |
| 12419 | * the available hardware queues as they get assigned to CPUs. |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12420 | * The next_idx is the idx from the FIRST_CPU loop above to account |
| 12421 | * for irq_chann < hdwq. The idx is used for round-robin assignments |
| 12422 | * and needs to start at 0. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12423 | */ |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12424 | next_idx = idx; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12425 | start_cpu = 0; |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12426 | idx = 0; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12427 | for_each_present_cpu(cpu) { |
| 12428 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12429 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12430 | /* FIRST cpus are already mapped. */ |
| 12431 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 12432 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12433 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12434 | /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq |
| 12435 | * of the unassigned cpus to the next idx so that all |
| 12436 | * hdw queues are fully utilized. |
| 12437 | */ |
| 12438 | if (next_idx < phba->cfg_hdw_queue) { |
| 12439 | cpup->hdwq = next_idx; |
| 12440 | next_idx++; |
| 12441 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12442 | } |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 12443 | |
| 12444 | /* Not a First CPU and all hdw_queues are used. Reuse a |
| 12445 | * Hardware Queue for another CPU, so be smart about it |
| 12446 | * and pick one that has its IRQ/EQ mapped to the same phys_id |
| 12447 | * (CPU package) and core_id. |
| 12448 | */ |
| 12449 | new_cpu = start_cpu; |
| 12450 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 12451 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 12452 | if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && |
| 12453 | new_cpup->phys_id == cpup->phys_id && |
| 12454 | new_cpup->core_id == cpup->core_id) { |
| 12455 | goto found_hdwq; |
| 12456 | } |
| 12457 | new_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 12458 | if (new_cpu == nr_cpumask_bits) |
| 12459 | new_cpu = first_cpu; |
| 12460 | } |
| 12461 | |
| 12462 | /* If we can't match both phys_id and core_id, |
| 12463 | * settle for just a phys_id match. |
| 12464 | */ |
| 12465 | new_cpu = start_cpu; |
| 12466 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 12467 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 12468 | if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && |
| 12469 | new_cpup->phys_id == cpup->phys_id) |
| 12470 | goto found_hdwq; |
| 12471 | |
| 12472 | new_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 12473 | if (new_cpu == nr_cpumask_bits) |
| 12474 | new_cpu = first_cpu; |
| 12475 | } |
| 12476 | |
| 12477 | /* Otherwise just round robin on cfg_hdw_queue */ |
| 12478 | cpup->hdwq = idx % phba->cfg_hdw_queue; |
| 12479 | idx++; |
| 12480 | goto logit; |
| 12481 | found_hdwq: |
| 12482 | /* We found an available entry, copy the IRQ info */ |
| 12483 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 12484 | if (start_cpu == nr_cpumask_bits) |
| 12485 | start_cpu = first_cpu; |
| 12486 | cpup->hdwq = new_cpup->hdwq; |
| 12487 | logit: |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 12488 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12489 | "3335 Set Affinity: CPU %d (phys %d core %d): " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12490 | "hdwq %d eq %d flg x%x\n", |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12491 | cpu, cpup->phys_id, cpup->core_id, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12492 | cpup->hdwq, cpup->eq, cpup->flag); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12493 | } |
| 12494 | |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 12495 | /* |
| 12496 | * Initialize the cpu_map slots for not-present cpus in case |
| 12497 | * a cpu is hot-added. Perform a simple hdwq round robin assignment. |
| 12498 | */ |
| 12499 | idx = 0; |
| 12500 | for_each_possible_cpu(cpu) { |
| 12501 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 12502 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 12503 | c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu); |
| 12504 | c_stat->hdwq_no = cpup->hdwq; |
| 12505 | #endif |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 12506 | if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) |
| 12507 | continue; |
| 12508 | |
| 12509 | cpup->hdwq = idx++ % phba->cfg_hdw_queue; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 12510 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 12511 | c_stat->hdwq_no = cpup->hdwq; |
| 12512 | #endif |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 12513 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12514 | "3340 Set Affinity: not present " |
| 12515 | "CPU %d hdwq %d\n", |
| 12516 | cpu, cpup->hdwq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 12517 | } |
| 12518 | |
| 12519 | /* The cpu_map array will be used later during initialization |
| 12520 | * when EQ / CQ / WQs are allocated and configured. |
| 12521 | */ |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 12522 | return; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12523 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12524 | |
| 12525 | /** |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12526 | * lpfc_cpuhp_get_eq |
| 12527 | * |
| 12528 | * @phba: pointer to lpfc hba data structure. |
| 12529 | * @cpu: cpu going offline |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 12530 | * @eqlist: eq list to append to |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12531 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 12532 | static int |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12533 | lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu, |
| 12534 | struct list_head *eqlist) |
| 12535 | { |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12536 | const struct cpumask *maskp; |
| 12537 | struct lpfc_queue *eq; |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 12538 | struct cpumask *tmp; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12539 | u16 idx; |
| 12540 | |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 12541 | tmp = kzalloc(cpumask_size(), GFP_KERNEL); |
| 12542 | if (!tmp) |
| 12543 | return -ENOMEM; |
| 12544 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12545 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 12546 | maskp = pci_irq_get_affinity(phba->pcidev, idx); |
| 12547 | if (!maskp) |
| 12548 | continue; |
| 12549 | /* |
| 12550 | * if irq is not affinitized to the cpu going |
| 12551 | * then we don't need to poll the eq attached |
| 12552 | * to it. |
| 12553 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 12554 | if (!cpumask_and(tmp, maskp, cpumask_of(cpu))) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12555 | continue; |
| 12556 | /* get the cpus that are online and are affini- |
| 12557 | * tized to this irq vector. If the count is |
| 12558 | * more than 1 then cpuhp is not going to shut- |
| 12559 | * down this vector. Since this cpu has not |
| 12560 | * gone offline yet, we need >1. |
| 12561 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 12562 | cpumask_and(tmp, maskp, cpu_online_mask); |
| 12563 | if (cpumask_weight(tmp) > 1) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12564 | continue; |
| 12565 | |
| 12566 | /* Now that we have an irq to shutdown, get the eq |
| 12567 | * mapped to this irq. Note: multiple hdwq's in |
| 12568 | * the software can share an eq, but eventually |
| 12569 | * only eq will be mapped to this vector |
| 12570 | */ |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12571 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 12572 | list_add(&eq->_poll_list, eqlist); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12573 | } |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 12574 | kfree(tmp); |
| 12575 | return 0; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12576 | } |
| 12577 | |
| 12578 | static void __lpfc_cpuhp_remove(struct lpfc_hba *phba) |
| 12579 | { |
| 12580 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 12581 | return; |
| 12582 | |
| 12583 | cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state, |
| 12584 | &phba->cpuhp); |
| 12585 | /* |
| 12586 | * unregistering the instance doesn't stop the polling |
| 12587 | * timer. Wait for the poll timer to retire. |
| 12588 | */ |
| 12589 | synchronize_rcu(); |
| 12590 | del_timer_sync(&phba->cpuhp_poll_timer); |
| 12591 | } |
| 12592 | |
| 12593 | static void lpfc_cpuhp_remove(struct lpfc_hba *phba) |
| 12594 | { |
| 12595 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 12596 | return; |
| 12597 | |
| 12598 | __lpfc_cpuhp_remove(phba); |
| 12599 | } |
| 12600 | |
| 12601 | static void lpfc_cpuhp_add(struct lpfc_hba *phba) |
| 12602 | { |
| 12603 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 12604 | return; |
| 12605 | |
| 12606 | rcu_read_lock(); |
| 12607 | |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 12608 | if (!list_empty(&phba->poll_list)) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12609 | mod_timer(&phba->cpuhp_poll_timer, |
| 12610 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12611 | |
| 12612 | rcu_read_unlock(); |
| 12613 | |
| 12614 | cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, |
| 12615 | &phba->cpuhp); |
| 12616 | } |
| 12617 | |
| 12618 | static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval) |
| 12619 | { |
| 12620 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 12621 | *retval = -EAGAIN; |
| 12622 | return true; |
| 12623 | } |
| 12624 | |
| 12625 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 12626 | *retval = 0; |
| 12627 | return true; |
| 12628 | } |
| 12629 | |
| 12630 | /* proceed with the hotplug */ |
| 12631 | return false; |
| 12632 | } |
| 12633 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12634 | /** |
| 12635 | * lpfc_irq_set_aff - set IRQ affinity |
| 12636 | * @eqhdl: EQ handle |
| 12637 | * @cpu: cpu to set affinity |
| 12638 | * |
| 12639 | **/ |
| 12640 | static inline void |
| 12641 | lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu) |
| 12642 | { |
| 12643 | cpumask_clear(&eqhdl->aff_mask); |
| 12644 | cpumask_set_cpu(cpu, &eqhdl->aff_mask); |
| 12645 | irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING); |
| 12646 | irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask); |
| 12647 | } |
| 12648 | |
| 12649 | /** |
| 12650 | * lpfc_irq_clear_aff - clear IRQ affinity |
| 12651 | * @eqhdl: EQ handle |
| 12652 | * |
| 12653 | **/ |
| 12654 | static inline void |
| 12655 | lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl) |
| 12656 | { |
| 12657 | cpumask_clear(&eqhdl->aff_mask); |
| 12658 | irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12659 | } |
| 12660 | |
| 12661 | /** |
| 12662 | * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event |
| 12663 | * @phba: pointer to HBA context object. |
| 12664 | * @cpu: cpu going offline/online |
| 12665 | * @offline: true, cpu is going offline. false, cpu is coming online. |
| 12666 | * |
| 12667 | * 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] | 12668 | * online cpu on the phba's original_mask and migrate all offlining IRQ |
| 12669 | * affinities. |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12670 | * |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12671 | * 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] | 12672 | * |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12673 | * 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] | 12674 | * PCI_IRQ_AFFINITY to auto-manage IRQ affinity. |
| 12675 | * |
| 12676 | **/ |
| 12677 | static void |
| 12678 | lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline) |
| 12679 | { |
| 12680 | struct lpfc_vector_map_info *cpup; |
| 12681 | struct cpumask *aff_mask; |
| 12682 | unsigned int cpu_select, cpu_next, idx; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12683 | const struct cpumask *orig_mask; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12684 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12685 | if (phba->irq_chann_mode == NORMAL_MODE) |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12686 | return; |
| 12687 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12688 | orig_mask = &phba->sli4_hba.irq_aff_mask; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12689 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12690 | if (!cpumask_test_cpu(cpu, orig_mask)) |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12691 | return; |
| 12692 | |
| 12693 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 12694 | |
| 12695 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 12696 | return; |
| 12697 | |
| 12698 | if (offline) { |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12699 | /* Find next online CPU on original mask */ |
| 12700 | cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true); |
| 12701 | cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12702 | |
| 12703 | /* Found a valid CPU */ |
| 12704 | if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) { |
| 12705 | /* Go through each eqhdl and ensure offlining |
| 12706 | * cpu aff_mask is migrated |
| 12707 | */ |
| 12708 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 12709 | aff_mask = lpfc_get_aff_mask(idx); |
| 12710 | |
| 12711 | /* Migrate affinity */ |
| 12712 | if (cpumask_test_cpu(cpu, aff_mask)) |
| 12713 | lpfc_irq_set_aff(lpfc_get_eq_hdl(idx), |
| 12714 | cpu_select); |
| 12715 | } |
| 12716 | } else { |
| 12717 | /* Rely on irqbalance if no online CPUs left on NUMA */ |
| 12718 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) |
| 12719 | lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx)); |
| 12720 | } |
| 12721 | } else { |
| 12722 | /* Migrate affinity back to this CPU */ |
| 12723 | lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu); |
| 12724 | } |
| 12725 | } |
| 12726 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12727 | static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node) |
| 12728 | { |
| 12729 | struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp); |
| 12730 | struct lpfc_queue *eq, *next; |
| 12731 | LIST_HEAD(eqlist); |
| 12732 | int retval; |
| 12733 | |
| 12734 | if (!phba) { |
| 12735 | WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id()); |
| 12736 | return 0; |
| 12737 | } |
| 12738 | |
| 12739 | if (__lpfc_cpuhp_checks(phba, &retval)) |
| 12740 | return retval; |
| 12741 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12742 | lpfc_irq_rebalance(phba, cpu, true); |
| 12743 | |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 12744 | retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist); |
| 12745 | if (retval) |
| 12746 | return retval; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12747 | |
| 12748 | /* start polling on these eq's */ |
| 12749 | list_for_each_entry_safe(eq, next, &eqlist, _poll_list) { |
| 12750 | list_del_init(&eq->_poll_list); |
| 12751 | lpfc_sli4_start_polling(eq); |
| 12752 | } |
| 12753 | |
| 12754 | return 0; |
| 12755 | } |
| 12756 | |
| 12757 | static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node) |
| 12758 | { |
| 12759 | struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp); |
| 12760 | struct lpfc_queue *eq, *next; |
| 12761 | unsigned int n; |
| 12762 | int retval; |
| 12763 | |
| 12764 | if (!phba) { |
| 12765 | WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id()); |
| 12766 | return 0; |
| 12767 | } |
| 12768 | |
| 12769 | if (__lpfc_cpuhp_checks(phba, &retval)) |
| 12770 | return retval; |
| 12771 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12772 | lpfc_irq_rebalance(phba, cpu, false); |
| 12773 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 12774 | list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) { |
| 12775 | n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ); |
| 12776 | if (n == cpu) |
| 12777 | lpfc_sli4_stop_polling(eq); |
| 12778 | } |
| 12779 | |
| 12780 | return 0; |
| 12781 | } |
| 12782 | |
| 12783 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12784 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 12785 | * @phba: pointer to lpfc hba data structure. |
| 12786 | * |
| 12787 | * 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] | 12788 | * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them |
| 12789 | * to cpus on the system. |
| 12790 | * |
| 12791 | * When cfg_irq_numa is enabled, the adapter will only allocate vectors for |
| 12792 | * the number of cpus on the same numa node as this adapter. The vectors are |
| 12793 | * allocated without requesting OS affinity mapping. A vector will be |
| 12794 | * allocated and assigned to each online and offline cpu. If the cpu is |
| 12795 | * online, then affinity will be set to that cpu. If the cpu is offline, then |
| 12796 | * affinity will be set to the nearest peer cpu within the numa node that is |
| 12797 | * online. If there are no online cpus within the numa node, affinity is not |
| 12798 | * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping |
| 12799 | * is consistent with the way cpu online/offline is handled when cfg_irq_numa is |
| 12800 | * configured. |
| 12801 | * |
| 12802 | * If numa mode is not enabled and there is more than 1 vector allocated, then |
| 12803 | * the driver relies on the managed irq interface where the OS assigns vector to |
| 12804 | * cpu affinity. The driver will then use that affinity mapping to setup its |
| 12805 | * cpu mapping table. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12806 | * |
| 12807 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 12808 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12809 | * other values - error |
| 12810 | **/ |
| 12811 | static int |
| 12812 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 12813 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12814 | int vectors, rc, index; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 12815 | char *name; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12816 | const struct cpumask *aff_mask = NULL; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12817 | unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids; |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 12818 | struct lpfc_vector_map_info *cpup; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12819 | struct lpfc_hba_eq_hdl *eqhdl; |
| 12820 | const struct cpumask *maskp; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12821 | unsigned int flags = PCI_IRQ_MSIX; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12822 | |
| 12823 | /* Set up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12824 | vectors = phba->cfg_irq_chann; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 12825 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12826 | if (phba->irq_chann_mode != NORMAL_MODE) |
| 12827 | aff_mask = &phba->sli4_hba.irq_aff_mask; |
| 12828 | |
| 12829 | if (aff_mask) { |
| 12830 | cpu_cnt = cpumask_weight(aff_mask); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12831 | vectors = min(phba->cfg_irq_chann, cpu_cnt); |
| 12832 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12833 | /* cpu: iterates over aff_mask including offline or online |
| 12834 | * cpu_select: iterates over online aff_mask to set affinity |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12835 | */ |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12836 | cpu = cpumask_first(aff_mask); |
| 12837 | cpu_select = lpfc_next_online_cpu(aff_mask, cpu); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12838 | } else { |
| 12839 | flags |= PCI_IRQ_AFFINITY; |
| 12840 | } |
| 12841 | |
| 12842 | rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags); |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 12843 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12844 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12845 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 12846 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12847 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 12848 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12849 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12850 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 12851 | for (index = 0; index < vectors; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12852 | eqhdl = lpfc_get_eq_hdl(index); |
| 12853 | name = eqhdl->handler_name; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 12854 | memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ); |
| 12855 | snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 12856 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12857 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12858 | eqhdl->idx = index; |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 12859 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
| 12860 | &lpfc_sli4_hba_intr_handler, 0, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12861 | name, eqhdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12862 | if (rc) { |
| 12863 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 12864 | "0486 MSI-X fast-path (%d) " |
| 12865 | "request_irq failed (%d)\n", index, rc); |
| 12866 | goto cfg_fail_out; |
| 12867 | } |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12868 | |
| 12869 | eqhdl->irq = pci_irq_vector(phba->pcidev, index); |
| 12870 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12871 | if (aff_mask) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12872 | /* If found a neighboring online cpu, set affinity */ |
| 12873 | if (cpu_select < nr_cpu_ids) |
| 12874 | lpfc_irq_set_aff(eqhdl, cpu_select); |
| 12875 | |
| 12876 | /* Assign EQ to cpu_map */ |
| 12877 | lpfc_assign_eq_map_info(phba, index, |
| 12878 | LPFC_CPU_FIRST_IRQ, |
| 12879 | cpu); |
| 12880 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12881 | /* Iterate to next offline or online cpu in aff_mask */ |
| 12882 | cpu = cpumask_next(cpu, aff_mask); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12883 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 12884 | /* Find next online cpu in aff_mask to set affinity */ |
| 12885 | cpu_select = lpfc_next_online_cpu(aff_mask, cpu); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12886 | } else if (vectors == 1) { |
| 12887 | cpu = cpumask_first(cpu_present_mask); |
| 12888 | lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ, |
| 12889 | cpu); |
| 12890 | } else { |
| 12891 | maskp = pci_irq_get_affinity(phba->pcidev, index); |
| 12892 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12893 | /* Loop through all CPUs associated with vector index */ |
| 12894 | for_each_cpu_and(cpu, maskp, cpu_present_mask) { |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 12895 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 12896 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12897 | /* If this is the first CPU thats assigned to |
| 12898 | * this vector, set LPFC_CPU_FIRST_IRQ. |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 12899 | * |
| 12900 | * With certain platforms its possible that irq |
| 12901 | * vectors are affinitized to all the cpu's. |
| 12902 | * This can result in each cpu_map.eq to be set |
| 12903 | * to the last vector, resulting in overwrite |
| 12904 | * of all the previous cpu_map.eq. Ensure that |
| 12905 | * each vector receives a place in cpu_map. |
| 12906 | * Later call to lpfc_cpu_affinity_check will |
| 12907 | * ensure we are nicely balanced out. |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12908 | */ |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 12909 | if (cpup->eq != LPFC_VECTOR_MAP_EMPTY) |
| 12910 | continue; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12911 | lpfc_assign_eq_map_info(phba, index, |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 12912 | LPFC_CPU_FIRST_IRQ, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12913 | cpu); |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 12914 | break; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12915 | } |
| 12916 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12917 | } |
| 12918 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12919 | if (vectors != phba->cfg_irq_chann) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12920 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 12921 | "3238 Reducing IO channels to match number of " |
| 12922 | "MSI-X vectors, requested %d got %d\n", |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12923 | phba->cfg_irq_chann, vectors); |
| 12924 | if (phba->cfg_irq_chann > vectors) |
| 12925 | phba->cfg_irq_chann = vectors; |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 12926 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 12927 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12928 | return rc; |
| 12929 | |
| 12930 | cfg_fail_out: |
| 12931 | /* free the irq already requested */ |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12932 | for (--index; index >= 0; index--) { |
| 12933 | eqhdl = lpfc_get_eq_hdl(index); |
| 12934 | lpfc_irq_clear_aff(eqhdl); |
| 12935 | irq_set_affinity_hint(eqhdl->irq, NULL); |
| 12936 | free_irq(eqhdl->irq, eqhdl); |
| 12937 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12938 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12939 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 12940 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 12941 | |
| 12942 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12943 | return rc; |
| 12944 | } |
| 12945 | |
| 12946 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12947 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 12948 | * @phba: pointer to lpfc hba data structure. |
| 12949 | * |
| 12950 | * 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] | 12951 | * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is |
| 12952 | * called to enable the MSI vector. The device driver is responsible for |
| 12953 | * calling the request_irq() to register MSI vector with a interrupt the |
| 12954 | * handler, which is done in this function. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12955 | * |
| 12956 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 12957 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12958 | * other values - error |
| 12959 | **/ |
| 12960 | static int |
| 12961 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 12962 | { |
| 12963 | int rc, index; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12964 | unsigned int cpu; |
| 12965 | struct lpfc_hba_eq_hdl *eqhdl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12966 | |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 12967 | rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1, |
| 12968 | PCI_IRQ_MSI | PCI_IRQ_AFFINITY); |
| 12969 | if (rc > 0) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12970 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12971 | "0487 PCI enable MSI mode success.\n"); |
| 12972 | else { |
| 12973 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12974 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 12975 | return rc ? rc : -1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12976 | } |
| 12977 | |
| 12978 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 12979 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12980 | if (rc) { |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 12981 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12982 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 12983 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12984 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12985 | } |
| 12986 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12987 | eqhdl = lpfc_get_eq_hdl(0); |
| 12988 | eqhdl->irq = pci_irq_vector(phba->pcidev, 0); |
| 12989 | |
| 12990 | cpu = cpumask_first(cpu_present_mask); |
| 12991 | lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu); |
| 12992 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 12993 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 12994 | eqhdl = lpfc_get_eq_hdl(index); |
| 12995 | eqhdl->idx = index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12996 | } |
| 12997 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12998 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12999 | } |
| 13000 | |
| 13001 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13002 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 13003 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 13004 | * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X). |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13005 | * |
| 13006 | * This routine is invoked to enable device interrupt and associate driver's |
| 13007 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 13008 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 13009 | * the driver will try to fallback from the configured interrupt mode to an |
| 13010 | * interrupt mode which is supported by the platform, kernel, and device in |
| 13011 | * the order of: |
| 13012 | * MSI-X -> MSI -> IRQ. |
| 13013 | * |
| 13014 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 13015 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13016 | * other values - error |
| 13017 | **/ |
| 13018 | static uint32_t |
| 13019 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 13020 | { |
| 13021 | uint32_t intr_mode = LPFC_INTR_ERROR; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13022 | int retval, idx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13023 | |
| 13024 | if (cfg_mode == 2) { |
| 13025 | /* Preparation before conf_msi mbox cmd */ |
| 13026 | retval = 0; |
| 13027 | if (!retval) { |
| 13028 | /* Now, try to enable MSI-X interrupt mode */ |
| 13029 | retval = lpfc_sli4_enable_msix(phba); |
| 13030 | if (!retval) { |
| 13031 | /* Indicate initialization to MSI-X mode */ |
| 13032 | phba->intr_type = MSIX; |
| 13033 | intr_mode = 2; |
| 13034 | } |
| 13035 | } |
| 13036 | } |
| 13037 | |
| 13038 | /* Fallback to MSI if MSI-X initialization failed */ |
| 13039 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 13040 | retval = lpfc_sli4_enable_msi(phba); |
| 13041 | if (!retval) { |
| 13042 | /* Indicate initialization to MSI mode */ |
| 13043 | phba->intr_type = MSI; |
| 13044 | intr_mode = 1; |
| 13045 | } |
| 13046 | } |
| 13047 | |
| 13048 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 13049 | if (phba->intr_type == NONE) { |
| 13050 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 13051 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 13052 | if (!retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13053 | struct lpfc_hba_eq_hdl *eqhdl; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 13054 | unsigned int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13055 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13056 | /* Indicate initialization to INTx mode */ |
| 13057 | phba->intr_type = INTx; |
| 13058 | intr_mode = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13059 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 13060 | eqhdl = lpfc_get_eq_hdl(0); |
| 13061 | eqhdl->irq = pci_irq_vector(phba->pcidev, 0); |
| 13062 | |
| 13063 | cpu = cpumask_first(cpu_present_mask); |
| 13064 | lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, |
| 13065 | cpu); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13066 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 13067 | eqhdl = lpfc_get_eq_hdl(idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13068 | eqhdl->idx = idx; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13069 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13070 | } |
| 13071 | } |
| 13072 | return intr_mode; |
| 13073 | } |
| 13074 | |
| 13075 | /** |
| 13076 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 13077 | * @phba: pointer to lpfc hba data structure. |
| 13078 | * |
| 13079 | * This routine is invoked to disable device interrupt and disassociate |
| 13080 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 13081 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 13082 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 13083 | **/ |
| 13084 | static void |
| 13085 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 13086 | { |
| 13087 | /* Disable the currently initialized interrupt mode */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 13088 | if (phba->intr_type == MSIX) { |
| 13089 | int index; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 13090 | struct lpfc_hba_eq_hdl *eqhdl; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 13091 | |
| 13092 | /* Free up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13093 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 13094 | eqhdl = lpfc_get_eq_hdl(index); |
| 13095 | lpfc_irq_clear_aff(eqhdl); |
| 13096 | irq_set_affinity_hint(eqhdl->irq, NULL); |
| 13097 | free_irq(eqhdl->irq, eqhdl); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 13098 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 13099 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13100 | free_irq(phba->pcidev->irq, phba); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 13101 | } |
| 13102 | |
| 13103 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13104 | |
| 13105 | /* Reset interrupt management states */ |
| 13106 | phba->intr_type = NONE; |
| 13107 | phba->sli.slistat.sli_intr = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13108 | } |
| 13109 | |
| 13110 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13111 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 13112 | * @phba: pointer to lpfc hba data structure. |
| 13113 | * |
| 13114 | * This routine is invoked to unset the HBA device initialization steps to |
| 13115 | * a device with SLI-3 interface spec. |
| 13116 | **/ |
| 13117 | static void |
| 13118 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 13119 | { |
| 13120 | struct lpfc_vport *vport = phba->pport; |
| 13121 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 13122 | |
| 13123 | spin_lock_irq(shost->host_lock); |
| 13124 | vport->load_flag |= FC_UNLOADING; |
| 13125 | spin_unlock_irq(shost->host_lock); |
| 13126 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 13127 | kfree(phba->vpi_bmask); |
| 13128 | kfree(phba->vpi_ids); |
| 13129 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13130 | lpfc_stop_hba_timers(phba); |
| 13131 | |
| 13132 | phba->pport->work_port_events = 0; |
| 13133 | |
| 13134 | lpfc_sli_hba_down(phba); |
| 13135 | |
| 13136 | lpfc_sli_brdrestart(phba); |
| 13137 | |
| 13138 | lpfc_sli_disable_intr(phba); |
| 13139 | |
| 13140 | return; |
| 13141 | } |
| 13142 | |
| 13143 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 13144 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 13145 | * @phba: Pointer to HBA context object. |
| 13146 | * |
| 13147 | * This function is called in the SLI4 code path to wait for completion |
| 13148 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 13149 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 13150 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 13151 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 13152 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 13153 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 13154 | * the rest of the driver unload resource release. |
| 13155 | **/ |
| 13156 | static void |
| 13157 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 13158 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13159 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13160 | int idx, ccnt; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 13161 | int wait_time = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13162 | int io_xri_cmpl = 1; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 13163 | int nvmet_xri_cmpl = 1; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 13164 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 13165 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 13166 | /* Driver just aborted IOs during the hba_unset process. Pause |
| 13167 | * here to give the HBA time to complete the IO and get entries |
| 13168 | * into the abts lists. |
| 13169 | */ |
| 13170 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5); |
| 13171 | |
| 13172 | /* Wait for NVME pending IO to flush back to transport. */ |
| 13173 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 13174 | lpfc_nvme_wait_for_io_drain(phba); |
| 13175 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13176 | ccnt = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13177 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 13178 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13179 | io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list); |
| 13180 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 13181 | ccnt++; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13182 | } |
| 13183 | if (ccnt) |
| 13184 | io_xri_cmpl = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13185 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 13186 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 13187 | nvmet_xri_cmpl = |
| 13188 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 13189 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13190 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13191 | while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 13192 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 13193 | if (!nvmet_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13194 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 13195 | "6424 NVMET XRI exchange busy " |
| 13196 | "wait time: %d seconds.\n", |
| 13197 | wait_time/1000); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13198 | if (!io_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13199 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13200 | "6100 IO XRI exchange busy " |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 13201 | "wait time: %d seconds.\n", |
| 13202 | wait_time/1000); |
| 13203 | if (!els_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13204 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 13205 | "2878 ELS XRI exchange busy " |
| 13206 | "wait time: %d seconds.\n", |
| 13207 | wait_time/1000); |
| 13208 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 13209 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 13210 | } else { |
| 13211 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 13212 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 13213 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13214 | |
| 13215 | ccnt = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13216 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 13217 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13218 | io_xri_cmpl = list_empty( |
| 13219 | &qp->lpfc_abts_io_buf_list); |
| 13220 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 13221 | ccnt++; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13222 | } |
| 13223 | if (ccnt) |
| 13224 | io_xri_cmpl = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13225 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 13226 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 13227 | nvmet_xri_cmpl = list_empty( |
| 13228 | &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 13229 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 13230 | els_xri_cmpl = |
| 13231 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 13232 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 13233 | } |
| 13234 | } |
| 13235 | |
| 13236 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13237 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 13238 | * @phba: Pointer to HBA context object. |
| 13239 | * |
| 13240 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 13241 | * function. The caller is not required to hold any lock. This routine |
| 13242 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 13243 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 13244 | * free any pending commands. |
| 13245 | **/ |
| 13246 | static void |
| 13247 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 13248 | { |
| 13249 | int wait_cnt = 0; |
| 13250 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 13251 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13252 | |
| 13253 | lpfc_stop_hba_timers(phba); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 13254 | hrtimer_cancel(&phba->cmf_timer); |
| 13255 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13256 | if (phba->pport) |
| 13257 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13258 | |
| 13259 | /* |
| 13260 | * Gracefully wait out the potential current outstanding asynchronous |
| 13261 | * mailbox command. |
| 13262 | */ |
| 13263 | |
| 13264 | /* First, block any pending async mailbox command from posted */ |
| 13265 | spin_lock_irq(&phba->hbalock); |
| 13266 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 13267 | spin_unlock_irq(&phba->hbalock); |
| 13268 | /* Now, trying to wait it out if we can */ |
| 13269 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 13270 | msleep(10); |
| 13271 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 13272 | break; |
| 13273 | } |
| 13274 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 13275 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 13276 | spin_lock_irq(&phba->hbalock); |
| 13277 | mboxq = phba->sli.mbox_active; |
| 13278 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 13279 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 13280 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 13281 | phba->sli.mbox_active = NULL; |
| 13282 | spin_unlock_irq(&phba->hbalock); |
| 13283 | } |
| 13284 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 13285 | /* Abort all iocbs associated with the hba */ |
| 13286 | lpfc_sli_hba_iocb_abort(phba); |
| 13287 | |
| 13288 | /* Wait for completion of device XRI exchange busy */ |
| 13289 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 13290 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13291 | /* per-phba callback de-registration for hotplug event */ |
SeongJae Park | 46da547 | 2020-06-23 10:41:22 +0200 | [diff] [blame] | 13292 | if (phba->pport) |
| 13293 | lpfc_cpuhp_remove(phba); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13294 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13295 | /* Disable PCI subsystem interrupt */ |
| 13296 | lpfc_sli4_disable_intr(phba); |
| 13297 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 13298 | /* Disable SR-IOV if enabled */ |
| 13299 | if (phba->cfg_sriov_nr_virtfn) |
| 13300 | pci_disable_sriov(pdev); |
| 13301 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13302 | /* Stop kthread signal shall trigger work_done one more time */ |
| 13303 | kthread_stop(phba->worker_thread); |
| 13304 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13305 | /* Disable FW logging to host memory */ |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 13306 | lpfc_ras_stop_fwlog(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13307 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 13308 | /* Unset the queues shared with the hardware then release all |
| 13309 | * allocated resources. |
| 13310 | */ |
| 13311 | lpfc_sli4_queue_unset(phba); |
| 13312 | lpfc_sli4_queue_destroy(phba); |
| 13313 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 13314 | /* Reset SLI4 HBA FCoE function */ |
| 13315 | lpfc_pci_function_reset(phba); |
| 13316 | |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 13317 | /* Free RAS DMA memory */ |
| 13318 | if (phba->ras_fwlog.ras_enabled) |
| 13319 | lpfc_sli4_ras_dma_free(phba); |
| 13320 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13321 | /* Stop the SLI4 device port */ |
James Smart | 1ffdd2c | 2019-03-04 15:27:51 -0800 | [diff] [blame] | 13322 | if (phba->pport) |
| 13323 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13324 | } |
| 13325 | |
James Smart | 7481811c | 2021-08-16 09:28:56 -0700 | [diff] [blame] | 13326 | static uint32_t |
| 13327 | lpfc_cgn_crc32(uint32_t crc, u8 byte) |
| 13328 | { |
| 13329 | uint32_t msb = 0; |
| 13330 | uint32_t bit; |
| 13331 | |
| 13332 | for (bit = 0; bit < 8; bit++) { |
| 13333 | msb = (crc >> 31) & 1; |
| 13334 | crc <<= 1; |
| 13335 | |
| 13336 | if (msb ^ (byte & 1)) { |
| 13337 | crc ^= LPFC_CGN_CRC32_MAGIC_NUMBER; |
| 13338 | crc |= 1; |
| 13339 | } |
| 13340 | byte >>= 1; |
| 13341 | } |
| 13342 | return crc; |
| 13343 | } |
| 13344 | |
| 13345 | static uint32_t |
| 13346 | lpfc_cgn_reverse_bits(uint32_t wd) |
| 13347 | { |
| 13348 | uint32_t result = 0; |
| 13349 | uint32_t i; |
| 13350 | |
| 13351 | for (i = 0; i < 32; i++) { |
| 13352 | result <<= 1; |
| 13353 | result |= (1 & (wd >> i)); |
| 13354 | } |
| 13355 | return result; |
| 13356 | } |
| 13357 | |
| 13358 | /* |
| 13359 | * The routine corresponds with the algorithm the HBA firmware |
| 13360 | * uses to validate the data integrity. |
| 13361 | */ |
| 13362 | uint32_t |
| 13363 | lpfc_cgn_calc_crc32(void *ptr, uint32_t byteLen, uint32_t crc) |
| 13364 | { |
| 13365 | uint32_t i; |
| 13366 | uint32_t result; |
| 13367 | uint8_t *data = (uint8_t *)ptr; |
| 13368 | |
| 13369 | for (i = 0; i < byteLen; ++i) |
| 13370 | crc = lpfc_cgn_crc32(crc, data[i]); |
| 13371 | |
| 13372 | result = ~lpfc_cgn_reverse_bits(crc); |
| 13373 | return result; |
| 13374 | } |
| 13375 | |
James Smart | 8c42a65 | 2021-08-16 09:28:51 -0700 | [diff] [blame] | 13376 | void |
| 13377 | lpfc_init_congestion_buf(struct lpfc_hba *phba) |
| 13378 | { |
James Smart | 7481811c | 2021-08-16 09:28:56 -0700 | [diff] [blame] | 13379 | struct lpfc_cgn_info *cp; |
| 13380 | struct timespec64 cmpl_time; |
| 13381 | struct tm broken; |
| 13382 | uint16_t size; |
| 13383 | uint32_t crc; |
| 13384 | |
James Smart | 8c42a65 | 2021-08-16 09:28:51 -0700 | [diff] [blame] | 13385 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 13386 | "6235 INIT Congestion Buffer %p\n", phba->cgn_i); |
| 13387 | |
| 13388 | if (!phba->cgn_i) |
| 13389 | return; |
James Smart | 7481811c | 2021-08-16 09:28:56 -0700 | [diff] [blame] | 13390 | cp = (struct lpfc_cgn_info *)phba->cgn_i->virt; |
James Smart | 8c42a65 | 2021-08-16 09:28:51 -0700 | [diff] [blame] | 13391 | |
| 13392 | atomic_set(&phba->cgn_fabric_warn_cnt, 0); |
| 13393 | atomic_set(&phba->cgn_fabric_alarm_cnt, 0); |
| 13394 | atomic_set(&phba->cgn_sync_alarm_cnt, 0); |
| 13395 | atomic_set(&phba->cgn_sync_warn_cnt, 0); |
| 13396 | |
| 13397 | atomic64_set(&phba->cgn_acqe_stat.alarm, 0); |
| 13398 | atomic64_set(&phba->cgn_acqe_stat.warn, 0); |
| 13399 | atomic_set(&phba->cgn_driver_evt_cnt, 0); |
| 13400 | atomic_set(&phba->cgn_latency_evt_cnt, 0); |
| 13401 | atomic64_set(&phba->cgn_latency_evt, 0); |
| 13402 | phba->cgn_evt_minute = 0; |
James Smart | 7481811c | 2021-08-16 09:28:56 -0700 | [diff] [blame] | 13403 | phba->hba_flag &= ~HBA_CGN_DAY_WRAP; |
| 13404 | |
| 13405 | memset(cp, 0xff, LPFC_CGN_DATA_SIZE); |
| 13406 | cp->cgn_info_size = cpu_to_le16(LPFC_CGN_INFO_SZ); |
| 13407 | cp->cgn_info_version = LPFC_CGN_INFO_V3; |
| 13408 | |
| 13409 | /* cgn parameters */ |
| 13410 | cp->cgn_info_mode = phba->cgn_p.cgn_param_mode; |
| 13411 | cp->cgn_info_level0 = phba->cgn_p.cgn_param_level0; |
| 13412 | cp->cgn_info_level1 = phba->cgn_p.cgn_param_level1; |
| 13413 | cp->cgn_info_level2 = phba->cgn_p.cgn_param_level2; |
| 13414 | |
| 13415 | ktime_get_real_ts64(&cmpl_time); |
| 13416 | time64_to_tm(cmpl_time.tv_sec, 0, &broken); |
| 13417 | |
| 13418 | cp->cgn_info_month = broken.tm_mon + 1; |
| 13419 | cp->cgn_info_day = broken.tm_mday; |
| 13420 | cp->cgn_info_year = broken.tm_year - 100; /* relative to 2000 */ |
| 13421 | cp->cgn_info_hour = broken.tm_hour; |
| 13422 | cp->cgn_info_minute = broken.tm_min; |
| 13423 | cp->cgn_info_second = broken.tm_sec; |
| 13424 | |
| 13425 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT, |
| 13426 | "2643 CGNInfo Init: Start Time " |
| 13427 | "%d/%d/%d %d:%d:%d\n", |
| 13428 | cp->cgn_info_day, cp->cgn_info_month, |
| 13429 | cp->cgn_info_year, cp->cgn_info_hour, |
| 13430 | cp->cgn_info_minute, cp->cgn_info_second); |
| 13431 | |
| 13432 | /* Fill in default LUN qdepth */ |
| 13433 | if (phba->pport) { |
| 13434 | size = (uint16_t)(phba->pport->cfg_lun_queue_depth); |
| 13435 | cp->cgn_lunq = cpu_to_le16(size); |
| 13436 | } |
| 13437 | |
| 13438 | /* last used Index initialized to 0xff already */ |
| 13439 | |
| 13440 | cp->cgn_warn_freq = LPFC_FPIN_INIT_FREQ; |
| 13441 | cp->cgn_alarm_freq = LPFC_FPIN_INIT_FREQ; |
| 13442 | crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED); |
| 13443 | cp->cgn_info_crc = cpu_to_le32(crc); |
James Smart | 8c42a65 | 2021-08-16 09:28:51 -0700 | [diff] [blame] | 13444 | |
| 13445 | phba->cgn_evt_timestamp = jiffies + |
| 13446 | msecs_to_jiffies(LPFC_CGN_TIMER_TO_MIN); |
| 13447 | } |
| 13448 | |
| 13449 | void |
| 13450 | lpfc_init_congestion_stat(struct lpfc_hba *phba) |
| 13451 | { |
James Smart | 7481811c | 2021-08-16 09:28:56 -0700 | [diff] [blame] | 13452 | struct lpfc_cgn_info *cp; |
| 13453 | struct timespec64 cmpl_time; |
| 13454 | struct tm broken; |
| 13455 | uint32_t crc; |
| 13456 | |
James Smart | 8c42a65 | 2021-08-16 09:28:51 -0700 | [diff] [blame] | 13457 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT, |
| 13458 | "6236 INIT Congestion Stat %p\n", phba->cgn_i); |
| 13459 | |
| 13460 | if (!phba->cgn_i) |
| 13461 | return; |
James Smart | 7481811c | 2021-08-16 09:28:56 -0700 | [diff] [blame] | 13462 | |
| 13463 | cp = (struct lpfc_cgn_info *)phba->cgn_i->virt; |
| 13464 | memset(&cp->cgn_stat_npm, 0, LPFC_CGN_STAT_SIZE); |
| 13465 | |
| 13466 | ktime_get_real_ts64(&cmpl_time); |
| 13467 | time64_to_tm(cmpl_time.tv_sec, 0, &broken); |
| 13468 | |
| 13469 | cp->cgn_stat_month = broken.tm_mon + 1; |
| 13470 | cp->cgn_stat_day = broken.tm_mday; |
| 13471 | cp->cgn_stat_year = broken.tm_year - 100; /* relative to 2000 */ |
| 13472 | cp->cgn_stat_hour = broken.tm_hour; |
| 13473 | cp->cgn_stat_minute = broken.tm_min; |
| 13474 | |
| 13475 | lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT | LOG_INIT, |
| 13476 | "2647 CGNstat Init: Start Time " |
| 13477 | "%d/%d/%d %d:%d\n", |
| 13478 | cp->cgn_stat_day, cp->cgn_stat_month, |
| 13479 | cp->cgn_stat_year, cp->cgn_stat_hour, |
| 13480 | cp->cgn_stat_minute); |
| 13481 | |
| 13482 | crc = lpfc_cgn_calc_crc32(cp, LPFC_CGN_INFO_SZ, LPFC_CGN_CRC32_SEED); |
| 13483 | cp->cgn_info_crc = cpu_to_le32(crc); |
James Smart | 8c42a65 | 2021-08-16 09:28:51 -0700 | [diff] [blame] | 13484 | } |
| 13485 | |
| 13486 | /** |
| 13487 | * __lpfc_reg_congestion_buf - register congestion info buffer with HBA |
| 13488 | * @phba: Pointer to hba context object. |
| 13489 | * @reg: flag to determine register or unregister. |
| 13490 | */ |
| 13491 | static int |
| 13492 | __lpfc_reg_congestion_buf(struct lpfc_hba *phba, int reg) |
| 13493 | { |
| 13494 | struct lpfc_mbx_reg_congestion_buf *reg_congestion_buf; |
| 13495 | union lpfc_sli4_cfg_shdr *shdr; |
| 13496 | uint32_t shdr_status, shdr_add_status; |
| 13497 | LPFC_MBOXQ_t *mboxq; |
| 13498 | int length, rc; |
| 13499 | |
| 13500 | if (!phba->cgn_i) |
| 13501 | return -ENXIO; |
| 13502 | |
| 13503 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 13504 | if (!mboxq) { |
| 13505 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 13506 | "2641 REG_CONGESTION_BUF mbox allocation fail: " |
| 13507 | "HBA state x%x reg %d\n", |
| 13508 | phba->pport->port_state, reg); |
| 13509 | return -ENOMEM; |
| 13510 | } |
| 13511 | |
| 13512 | length = (sizeof(struct lpfc_mbx_reg_congestion_buf) - |
| 13513 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13514 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13515 | LPFC_MBOX_OPCODE_REG_CONGESTION_BUF, length, |
| 13516 | LPFC_SLI4_MBX_EMBED); |
| 13517 | reg_congestion_buf = &mboxq->u.mqe.un.reg_congestion_buf; |
| 13518 | bf_set(lpfc_mbx_reg_cgn_buf_type, reg_congestion_buf, 1); |
| 13519 | if (reg > 0) |
| 13520 | bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 1); |
| 13521 | else |
| 13522 | bf_set(lpfc_mbx_reg_cgn_buf_cnt, reg_congestion_buf, 0); |
| 13523 | reg_congestion_buf->length = sizeof(struct lpfc_cgn_info); |
| 13524 | reg_congestion_buf->addr_lo = |
| 13525 | putPaddrLow(phba->cgn_i->phys); |
| 13526 | reg_congestion_buf->addr_hi = |
| 13527 | putPaddrHigh(phba->cgn_i->phys); |
| 13528 | |
| 13529 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 13530 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 13531 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 13532 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 13533 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 13534 | &shdr->response); |
| 13535 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 13536 | if (shdr_status || shdr_add_status || rc) { |
| 13537 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13538 | "2642 REG_CONGESTION_BUF mailbox " |
| 13539 | "failed with status x%x add_status x%x," |
| 13540 | " mbx status x%x reg %d\n", |
| 13541 | shdr_status, shdr_add_status, rc, reg); |
| 13542 | return -ENXIO; |
| 13543 | } |
| 13544 | return 0; |
| 13545 | } |
| 13546 | |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 13547 | int |
James Smart | 8c42a65 | 2021-08-16 09:28:51 -0700 | [diff] [blame] | 13548 | lpfc_unreg_congestion_buf(struct lpfc_hba *phba) |
| 13549 | { |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 13550 | lpfc_cmf_stop(phba); |
James Smart | 8c42a65 | 2021-08-16 09:28:51 -0700 | [diff] [blame] | 13551 | return __lpfc_reg_congestion_buf(phba, 0); |
| 13552 | } |
| 13553 | |
| 13554 | int |
| 13555 | lpfc_reg_congestion_buf(struct lpfc_hba *phba) |
| 13556 | { |
| 13557 | return __lpfc_reg_congestion_buf(phba, 1); |
| 13558 | } |
| 13559 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13560 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13561 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 13562 | * @phba: Pointer to HBA context object. |
| 13563 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 13564 | * |
| 13565 | * This function is called in the SLI4 code path to read the port's |
| 13566 | * sli4 capabilities. |
| 13567 | * |
| 13568 | * This function may be be called from any context that can block-wait |
| 13569 | * for the completion. The expectation is that this routine is called |
| 13570 | * typically from probe_one or from the online routine. |
| 13571 | **/ |
| 13572 | int |
| 13573 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 13574 | { |
| 13575 | int rc; |
| 13576 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 13577 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13578 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13579 | int length; |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 13580 | bool exp_wqcq_pages = true; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13581 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 13582 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13583 | /* |
| 13584 | * By default, the driver assumes the SLI4 port requires RPI |
| 13585 | * header postings. The SLI4_PARAM response will correct this |
| 13586 | * assumption. |
| 13587 | */ |
| 13588 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 13589 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13590 | /* Read the port's SLI4 Config Parameters */ |
| 13591 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 13592 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 13593 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 13594 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 13595 | length, LPFC_SLI4_MBX_EMBED); |
| 13596 | if (!phba->sli4_hba.intr_enable) |
| 13597 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 13598 | else { |
| 13599 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 13600 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 13601 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13602 | if (unlikely(rc)) |
| 13603 | return rc; |
| 13604 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 13605 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 13606 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 13607 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 13608 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 13609 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 13610 | mbx_sli4_parameters); |
| 13611 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 13612 | mbx_sli4_parameters); |
| 13613 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 13614 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 13615 | else |
| 13616 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 13617 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
James Smart | b62232b | 2021-04-11 18:31:22 -0700 | [diff] [blame] | 13618 | sli4_params->loopbk_scope = bf_get(cfg_loopbk_scope, |
| 13619 | mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13620 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13621 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 13622 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 13623 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 13624 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 13625 | sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters); |
| 13626 | sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 13627 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 13628 | sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters); |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 13629 | sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13630 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 13631 | mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13632 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13633 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 13634 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 13635 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 13636 | 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] | 13637 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 13638 | /* Check for Extended Pre-Registered SGL support */ |
| 13639 | phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters); |
| 13640 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 13641 | /* Check for firmware nvme support */ |
| 13642 | rc = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
| 13643 | bf_get(cfg_xib, mbx_sli4_parameters)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13644 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 13645 | if (rc) { |
| 13646 | /* Save this to indicate the Firmware supports NVME */ |
| 13647 | sli4_params->nvme = 1; |
| 13648 | |
| 13649 | /* Firmware NVME support, check driver FC4 NVME support */ |
| 13650 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) { |
| 13651 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
| 13652 | "6133 Disabling NVME support: " |
| 13653 | "FC4 type not supported: x%x\n", |
| 13654 | phba->cfg_enable_fc4_type); |
| 13655 | goto fcponly; |
| 13656 | } |
| 13657 | } else { |
| 13658 | /* No firmware NVME support, check driver FC4 NVME support */ |
| 13659 | sli4_params->nvme = 0; |
| 13660 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13661 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, |
| 13662 | "6101 Disabling NVME support: Not " |
| 13663 | "supported by firmware (%d %d) x%x\n", |
| 13664 | bf_get(cfg_nvme, mbx_sli4_parameters), |
| 13665 | bf_get(cfg_xib, mbx_sli4_parameters), |
| 13666 | phba->cfg_enable_fc4_type); |
| 13667 | fcponly: |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 13668 | phba->nvmet_support = 0; |
| 13669 | phba->cfg_nvmet_mrq = 0; |
James Smart | 6a224b4 | 2019-08-14 16:56:57 -0700 | [diff] [blame] | 13670 | phba->cfg_nvme_seg_cnt = 0; |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 13671 | |
| 13672 | /* If no FC4 type support, move to just SCSI support */ |
| 13673 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 13674 | return -ENODEV; |
| 13675 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; |
| 13676 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13677 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13678 | |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 13679 | /* 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] | 13680 | * accommodate 512K and 1M IOs in a single nvme buf. |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 13681 | */ |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 13682 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 13683 | phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 13684 | |
James Smart | 137ddf0 | 2021-07-07 11:43:44 -0700 | [diff] [blame] | 13685 | /* Enable embedded Payload BDE if support is indicated */ |
| 13686 | if (bf_get(cfg_pbde, mbx_sli4_parameters)) |
| 13687 | phba->cfg_enable_pbde = 1; |
| 13688 | else |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 13689 | phba->cfg_enable_pbde = 0; |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 13690 | |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 13691 | /* |
| 13692 | * To support Suppress Response feature we must satisfy 3 conditions. |
| 13693 | * lpfc_suppress_rsp module parameter must be set (default). |
| 13694 | * In SLI4-Parameters Descriptor: |
| 13695 | * Extended Inline Buffers (XIB) must be supported. |
| 13696 | * Suppress Response IU Not Supported (SRIUNS) must NOT be supported |
| 13697 | * (double negative). |
| 13698 | */ |
| 13699 | if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) && |
| 13700 | !(bf_get(cfg_nosr, mbx_sli4_parameters))) |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 13701 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 13702 | else |
| 13703 | phba->cfg_suppress_rsp = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 13704 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 13705 | if (bf_get(cfg_eqdr, mbx_sli4_parameters)) |
| 13706 | phba->sli.sli_flag |= LPFC_SLI_USE_EQDR; |
| 13707 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 13708 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 13709 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 13710 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 13711 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 13712 | /* |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 13713 | * Check whether the adapter supports an embedded copy of the |
| 13714 | * FCP CMD IU within the WQE for FCP_Ixxx commands. In order |
| 13715 | * to use this option, 128-byte WQEs must be used. |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 13716 | */ |
| 13717 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 13718 | phba->fcp_embed_io = 1; |
| 13719 | else |
| 13720 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 13721 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 13722 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 13723 | "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n", |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 13724 | bf_get(cfg_xib, mbx_sli4_parameters), |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 13725 | phba->cfg_enable_pbde, |
James Smart | ae463b6 | 2021-07-07 11:43:32 -0700 | [diff] [blame] | 13726 | phba->fcp_embed_io, sli4_params->nvme, |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 13727 | phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp); |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 13728 | |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 13729 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 13730 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 13731 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
James Smart | c221768 | 2018-05-24 21:09:00 -0700 | [diff] [blame] | 13732 | LPFC_SLI_INTF_FAMILY_LNCR_A0)) |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 13733 | exp_wqcq_pages = false; |
| 13734 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 13735 | if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) && |
| 13736 | (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) && |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 13737 | exp_wqcq_pages && |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 13738 | (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT)) |
| 13739 | phba->enab_exp_wqcq_pages = 1; |
| 13740 | else |
| 13741 | phba->enab_exp_wqcq_pages = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 13742 | /* |
| 13743 | * Check if the SLI port supports MDS Diagnostics |
| 13744 | */ |
| 13745 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 13746 | phba->mds_diags_support = 1; |
| 13747 | else |
| 13748 | phba->mds_diags_support = 0; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13749 | |
James Smart | 0d8af09 | 2019-08-14 16:57:10 -0700 | [diff] [blame] | 13750 | /* |
| 13751 | * Check if the SLI port supports NSLER |
| 13752 | */ |
| 13753 | if (bf_get(cfg_nsler, mbx_sli4_parameters)) |
| 13754 | phba->nsler = 1; |
| 13755 | else |
| 13756 | phba->nsler = 0; |
| 13757 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 13758 | return 0; |
| 13759 | } |
| 13760 | |
| 13761 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13762 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 13763 | * @pdev: pointer to PCI device |
| 13764 | * @pid: pointer to PCI device identifier |
| 13765 | * |
| 13766 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 13767 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 13768 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 13769 | * information of the device and driver to see if the driver state that it can |
| 13770 | * support this kind of device. If the match is successful, the driver core |
| 13771 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 13772 | * does all the initialization that it needs to do to handle the HBA properly. |
| 13773 | * |
| 13774 | * Return code |
| 13775 | * 0 - driver can claim the device |
| 13776 | * negative value - driver can not claim the device |
| 13777 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13778 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13779 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13780 | { |
| 13781 | struct lpfc_hba *phba; |
| 13782 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13783 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13784 | int error; |
| 13785 | uint32_t cfg_mode, intr_mode; |
| 13786 | |
| 13787 | /* Allocate memory for HBA structure */ |
| 13788 | phba = lpfc_hba_alloc(pdev); |
| 13789 | if (!phba) |
| 13790 | return -ENOMEM; |
| 13791 | |
| 13792 | /* Perform generic PCI device enabling operation */ |
| 13793 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13794 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13795 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13796 | |
| 13797 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 13798 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 13799 | if (error) |
| 13800 | goto out_disable_pci_dev; |
| 13801 | |
| 13802 | /* Set up SLI-3 specific device PCI memory space */ |
| 13803 | error = lpfc_sli_pci_mem_setup(phba); |
| 13804 | if (error) { |
| 13805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13806 | "1402 Failed to set up pci memory space.\n"); |
| 13807 | goto out_disable_pci_dev; |
| 13808 | } |
| 13809 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13810 | /* Set up SLI-3 specific device driver resources */ |
| 13811 | error = lpfc_sli_driver_resource_setup(phba); |
| 13812 | if (error) { |
| 13813 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13814 | "1404 Failed to set up driver resource.\n"); |
| 13815 | goto out_unset_pci_mem_s3; |
| 13816 | } |
| 13817 | |
| 13818 | /* Initialize and populate the iocb list per host */ |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 13819 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13820 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 13821 | if (error) { |
| 13822 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13823 | "1405 Failed to initialize iocb list.\n"); |
| 13824 | goto out_unset_driver_resource_s3; |
| 13825 | } |
| 13826 | |
| 13827 | /* Set up common device driver resources */ |
| 13828 | error = lpfc_setup_driver_resource_phase2(phba); |
| 13829 | if (error) { |
| 13830 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13831 | "1406 Failed to set up driver resource.\n"); |
| 13832 | goto out_free_iocb_list; |
| 13833 | } |
| 13834 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13835 | /* Get the default values for Model Name and Description */ |
| 13836 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 13837 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13838 | /* Create SCSI host to the physical port */ |
| 13839 | error = lpfc_create_shost(phba); |
| 13840 | if (error) { |
| 13841 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13842 | "1407 Failed to create scsi host.\n"); |
| 13843 | goto out_unset_driver_resource; |
| 13844 | } |
| 13845 | |
| 13846 | /* Configure sysfs attributes */ |
| 13847 | vport = phba->pport; |
| 13848 | error = lpfc_alloc_sysfs_attr(vport); |
| 13849 | if (error) { |
| 13850 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13851 | "1476 Failed to allocate sysfs attr\n"); |
| 13852 | goto out_destroy_shost; |
| 13853 | } |
| 13854 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13855 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13856 | /* Now, trying to enable interrupt and bring up the device */ |
| 13857 | cfg_mode = phba->cfg_use_msi; |
| 13858 | while (true) { |
| 13859 | /* Put device to a known state before enabling interrupt */ |
| 13860 | lpfc_stop_port(phba); |
| 13861 | /* Configure and enable interrupt */ |
| 13862 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 13863 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13864 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13865 | "0431 Failed to enable interrupt.\n"); |
| 13866 | error = -ENODEV; |
| 13867 | goto out_free_sysfs_attr; |
| 13868 | } |
| 13869 | /* SLI-3 HBA setup */ |
| 13870 | if (lpfc_sli_hba_setup(phba)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13871 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13872 | "1477 Failed to set up hba\n"); |
| 13873 | error = -ENODEV; |
| 13874 | goto out_remove_device; |
| 13875 | } |
| 13876 | |
| 13877 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 13878 | msleep(50); |
| 13879 | /* Check active interrupts on message signaled interrupts */ |
| 13880 | if (intr_mode == 0 || |
| 13881 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 13882 | /* Log the current active interrupt mode */ |
| 13883 | phba->intr_mode = intr_mode; |
| 13884 | lpfc_log_intr_mode(phba, intr_mode); |
| 13885 | break; |
| 13886 | } else { |
| 13887 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13888 | "0447 Configure interrupt mode (%d) " |
| 13889 | "failed active interrupt test.\n", |
| 13890 | intr_mode); |
| 13891 | /* Disable the current interrupt mode */ |
| 13892 | lpfc_sli_disable_intr(phba); |
| 13893 | /* Try next level of interrupt mode */ |
| 13894 | cfg_mode = --intr_mode; |
| 13895 | } |
| 13896 | } |
| 13897 | |
| 13898 | /* Perform post initialization setup */ |
| 13899 | lpfc_post_init_setup(phba); |
| 13900 | |
| 13901 | /* Check if there are static vports to be created. */ |
| 13902 | lpfc_create_static_vport(phba); |
| 13903 | |
| 13904 | return 0; |
| 13905 | |
| 13906 | out_remove_device: |
| 13907 | lpfc_unset_hba(phba); |
| 13908 | out_free_sysfs_attr: |
| 13909 | lpfc_free_sysfs_attr(vport); |
| 13910 | out_destroy_shost: |
| 13911 | lpfc_destroy_shost(phba); |
| 13912 | out_unset_driver_resource: |
| 13913 | lpfc_unset_driver_resource_phase2(phba); |
| 13914 | out_free_iocb_list: |
| 13915 | lpfc_free_iocb_list(phba); |
| 13916 | out_unset_driver_resource_s3: |
| 13917 | lpfc_sli_driver_resource_unset(phba); |
| 13918 | out_unset_pci_mem_s3: |
| 13919 | lpfc_sli_pci_mem_unset(phba); |
| 13920 | out_disable_pci_dev: |
| 13921 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13922 | if (shost) |
| 13923 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13924 | out_free_phba: |
| 13925 | lpfc_hba_free(phba); |
| 13926 | return error; |
| 13927 | } |
| 13928 | |
| 13929 | /** |
| 13930 | * 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] | 13931 | * @pdev: pointer to PCI device |
| 13932 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13933 | * This routine is to be called to disattach a device with SLI-3 interface |
| 13934 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 13935 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 13936 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 13937 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13938 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13939 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13940 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13941 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13942 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 13943 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13944 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 13945 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 13946 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 13947 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 13948 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 13949 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13950 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13951 | lpfc_free_sysfs_attr(vport); |
| 13952 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 13953 | /* Release all the vports against this physical port */ |
| 13954 | vports = lpfc_create_vport_work_array(phba); |
| 13955 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 13956 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 13957 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 13958 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 13959 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 13960 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 13961 | lpfc_destroy_vport_work_array(phba, vports); |
| 13962 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 13963 | /* Remove FC host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13964 | fc_remove_host(shost); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 13965 | scsi_remove_host(shost); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 13966 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 13967 | /* Clean up all nodes, mailboxes and IOs. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 13968 | lpfc_cleanup(vport); |
| 13969 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13970 | /* |
| 13971 | * Bring down the SLI Layer. This step disable all interrupts, |
| 13972 | * clears the rings, discards all mailbox commands, and resets |
| 13973 | * the HBA. |
| 13974 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13975 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 13976 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13977 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 13978 | /* Stop kthread signal shall trigger work_done one more time */ |
| 13979 | kthread_stop(phba->worker_thread); |
| 13980 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13981 | lpfc_sli_brdrestart(phba); |
| 13982 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 13983 | kfree(phba->vpi_bmask); |
| 13984 | kfree(phba->vpi_ids); |
| 13985 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13986 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13987 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13988 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13989 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13990 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 13991 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 13992 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 13993 | /* Disable SR-IOV if enabled */ |
| 13994 | if (phba->cfg_sriov_nr_virtfn) |
| 13995 | pci_disable_sriov(pdev); |
| 13996 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 13997 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13998 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 13999 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 14000 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 14001 | |
| 14002 | /* |
| 14003 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 14004 | * corresponding pools here. |
| 14005 | */ |
| 14006 | lpfc_scsi_free(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 14007 | lpfc_free_iocb_list(phba); |
| 14008 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14009 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 14010 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 14011 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 14012 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 14013 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 14014 | /* Free resources associated with SLI2 interface */ |
| 14015 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 14016 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 14017 | |
| 14018 | /* unmap adapter SLIM and Control Registers */ |
| 14019 | iounmap(phba->ctrl_regs_memmap_p); |
| 14020 | iounmap(phba->slim_memmap_p); |
| 14021 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14022 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 14023 | |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 14024 | pci_release_mem_regions(pdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 14025 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14026 | } |
| 14027 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14028 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14029 | * 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] | 14030 | * @dev_d: pointer to device |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14031 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14032 | * This routine is to be called from the kernel's PCI subsystem to support |
| 14033 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 14034 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 14035 | * worker thread for the device, turning off device's interrupt and DMA, |
| 14036 | * and bring the device offline. Note that as the driver implements the |
| 14037 | * minimum PM requirements to a power-aware driver's PM support for the |
| 14038 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 14039 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 14040 | * fully reinitialize its device during resume() method call, the driver will |
| 14041 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 14042 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14043 | * |
| 14044 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14045 | * 0 - driver suspended the device |
| 14046 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14047 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14048 | static int __maybe_unused |
| 14049 | lpfc_pci_suspend_one_s3(struct device *dev_d) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14050 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14051 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14052 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 14053 | |
| 14054 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 14055 | "0473 PCI device Power Management suspend.\n"); |
| 14056 | |
| 14057 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 14058 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14059 | lpfc_offline(phba); |
| 14060 | kthread_stop(phba->worker_thread); |
| 14061 | |
| 14062 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14063 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14064 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14065 | return 0; |
| 14066 | } |
| 14067 | |
| 14068 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14069 | * 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] | 14070 | * @dev_d: pointer to device |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14071 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14072 | * This routine is to be called from the kernel's PCI subsystem to support |
| 14073 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 14074 | * invokes this method, it restores the device's PCI config space state and |
| 14075 | * fully reinitializes the device and brings it online. Note that as the |
| 14076 | * driver implements the minimum PM requirements to a power-aware driver's |
| 14077 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 14078 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 14079 | * driver will fully reinitialize its device during resume() method call, |
| 14080 | * the device will be set to PCI_D0 directly in PCI config space before |
| 14081 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14082 | * |
| 14083 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14084 | * 0 - driver suspended the device |
| 14085 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14086 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14087 | static int __maybe_unused |
| 14088 | lpfc_pci_resume_one_s3(struct device *dev_d) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14089 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14090 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14091 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 14092 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14093 | int error; |
| 14094 | |
| 14095 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 14096 | "0452 PCI device Power Management resume.\n"); |
| 14097 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14098 | /* Startup the kernel thread for this host adapter. */ |
| 14099 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 14100 | "lpfc_worker_%d", phba->brd_no); |
| 14101 | if (IS_ERR(phba->worker_thread)) { |
| 14102 | error = PTR_ERR(phba->worker_thread); |
| 14103 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14104 | "0434 PM resume failed to start worker " |
| 14105 | "thread: error=x%x.\n", error); |
| 14106 | return error; |
| 14107 | } |
| 14108 | |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 14109 | /* Init cpu_map array */ |
| 14110 | lpfc_cpu_map_array_init(phba); |
| 14111 | /* Init hba_eq_hdl array */ |
| 14112 | lpfc_hba_eq_hdl_array_init(phba); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 14113 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14114 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 14115 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14116 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 14117 | "0430 PM resume Failed to enable interrupt\n"); |
| 14118 | return -EIO; |
| 14119 | } else |
| 14120 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14121 | |
| 14122 | /* Restart HBA and bring it online */ |
| 14123 | lpfc_sli_brdrestart(phba); |
| 14124 | lpfc_online(phba); |
| 14125 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 14126 | /* Log the current active interrupt mode */ |
| 14127 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 14128 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 14129 | return 0; |
| 14130 | } |
| 14131 | |
| 14132 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 14133 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 14134 | * @phba: pointer to lpfc hba data structure. |
| 14135 | * |
| 14136 | * 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] | 14137 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 14138 | **/ |
| 14139 | static void |
| 14140 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 14141 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14142 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 14143 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 14144 | |
| 14145 | /* |
| 14146 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 14147 | * and let the SCSI mid-layer to retry them to recover. |
| 14148 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 14149 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 14150 | } |
| 14151 | |
| 14152 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14153 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 14154 | * @phba: pointer to lpfc hba data structure. |
| 14155 | * |
| 14156 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 14157 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 14158 | * pending I/Os. |
| 14159 | **/ |
| 14160 | static void |
| 14161 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 14162 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14163 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 14164 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 14165 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14166 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 14167 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14168 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 14169 | /* Block all SCSI devices' I/Os on the host */ |
| 14170 | lpfc_scsi_dev_block(phba); |
| 14171 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 14172 | /* 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] | 14173 | lpfc_sli_flush_io_rings(phba); |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 14174 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 14175 | /* stop all timers */ |
| 14176 | lpfc_stop_hba_timers(phba); |
| 14177 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14178 | /* Disable interrupt and pci device */ |
| 14179 | lpfc_sli_disable_intr(phba); |
| 14180 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14181 | } |
| 14182 | |
| 14183 | /** |
| 14184 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 14185 | * @phba: pointer to lpfc hba data structure. |
| 14186 | * |
| 14187 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 14188 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 14189 | * pending I/Os. |
| 14190 | **/ |
| 14191 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14192 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14193 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14194 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 14195 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 14196 | /* Block all SCSI devices' I/Os on the host */ |
| 14197 | lpfc_scsi_dev_block(phba); |
| 14198 | |
| 14199 | /* stop all timers */ |
| 14200 | lpfc_stop_hba_timers(phba); |
| 14201 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14202 | /* Clean up all driver's outstanding SCSI I/Os */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 14203 | lpfc_sli_flush_io_rings(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14204 | } |
| 14205 | |
| 14206 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14207 | * 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] | 14208 | * @pdev: pointer to PCI device. |
| 14209 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14210 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14211 | * This routine is called from the PCI subsystem for I/O error handling to |
| 14212 | * device with SLI-3 interface spec. This function is called by the PCI |
| 14213 | * subsystem after a PCI bus error affecting this device has been detected. |
| 14214 | * When this function is invoked, it will need to stop all the I/Os and |
| 14215 | * interrupt(s) to the device. Once that is done, it will return |
| 14216 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 14217 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14218 | * |
| 14219 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14220 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14221 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 14222 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14223 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14224 | static pci_ers_result_t |
| 14225 | 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] | 14226 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 14227 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 14228 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14229 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14230 | switch (state) { |
| 14231 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 14232 | /* Non-fatal error, prepare for recovery */ |
| 14233 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14234 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 14235 | case pci_channel_io_frozen: |
| 14236 | /* Fatal error, prepare for slot reset */ |
| 14237 | lpfc_sli_prep_dev_for_reset(phba); |
| 14238 | return PCI_ERS_RESULT_NEED_RESET; |
| 14239 | case pci_channel_io_perm_failure: |
| 14240 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14241 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14242 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14243 | default: |
| 14244 | /* Unknown state, prepare and request slot reset */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14245 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 14246 | "0472 Unknown PCI error state: x%x\n", state); |
| 14247 | lpfc_sli_prep_dev_for_reset(phba); |
| 14248 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 14249 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14250 | } |
| 14251 | |
| 14252 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14253 | * 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] | 14254 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14255 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14256 | * This routine is called from the PCI subsystem for error handling to |
| 14257 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 14258 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 14259 | * During the PCI subsystem error recovery, after driver returns |
| 14260 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 14261 | * recovery and then call this routine before calling the .resume method |
| 14262 | * to recover the device. This function will initialize the HBA device, |
| 14263 | * enable the interrupt, but it will just put the HBA to offline state |
| 14264 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14265 | * |
| 14266 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14267 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 14268 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14269 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14270 | static pci_ers_result_t |
| 14271 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14272 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 14273 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 14274 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14275 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 14276 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14277 | |
| 14278 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 14279 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14280 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 14281 | "PCI device after reset.\n"); |
| 14282 | return PCI_ERS_RESULT_DISCONNECT; |
| 14283 | } |
| 14284 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 14285 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 14286 | |
| 14287 | /* |
| 14288 | * As the new kernel behavior of pci_restore_state() API call clears |
| 14289 | * device saved_state flag, need to save the restored state again. |
| 14290 | */ |
| 14291 | pci_save_state(pdev); |
| 14292 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 14293 | if (pdev->is_busmaster) |
| 14294 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14295 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 14296 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14297 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 14298 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14299 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 14300 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14301 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 14302 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14303 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 14304 | "0427 Cannot re-enable interrupt after " |
| 14305 | "slot reset.\n"); |
| 14306 | return PCI_ERS_RESULT_DISCONNECT; |
| 14307 | } else |
| 14308 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14309 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14310 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 14311 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14312 | lpfc_offline(phba); |
| 14313 | lpfc_sli_brdrestart(phba); |
| 14314 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 14315 | /* Log the current active interrupt mode */ |
| 14316 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 14317 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14318 | return PCI_ERS_RESULT_RECOVERED; |
| 14319 | } |
| 14320 | |
| 14321 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14322 | * 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] | 14323 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14324 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14325 | * This routine is called from the PCI subsystem for error handling to device |
| 14326 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 14327 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 14328 | * error recovery. After this call, traffic can start to flow from this device |
| 14329 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14330 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14331 | static void |
| 14332 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14333 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 14334 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 14335 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14336 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 14337 | /* 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] | 14338 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14339 | } |
| 14340 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 14341 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14342 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 14343 | * @phba: pointer to lpfc hba data structure. |
| 14344 | * |
| 14345 | * returns the number of ELS/CT IOCBs to reserve |
| 14346 | **/ |
| 14347 | int |
| 14348 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 14349 | { |
| 14350 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 14351 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14352 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 14353 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14354 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14355 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14356 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14357 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14358 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14359 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14360 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14361 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 14362 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 14363 | else if (max_xri <= 2048) |
| 14364 | return 200; |
| 14365 | else |
| 14366 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 14367 | } else |
| 14368 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14369 | } |
| 14370 | |
| 14371 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14372 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve |
| 14373 | * @phba: pointer to lpfc hba data structure. |
| 14374 | * |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 14375 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14376 | **/ |
| 14377 | int |
| 14378 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) |
| 14379 | { |
| 14380 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); |
| 14381 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 14382 | if (phba->nvmet_support) |
| 14383 | max_xri += LPFC_NVMET_BUF_POST; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14384 | return max_xri; |
| 14385 | } |
| 14386 | |
| 14387 | |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14388 | static int |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 14389 | lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset, |
| 14390 | uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize, |
| 14391 | const struct firmware *fw) |
| 14392 | { |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14393 | int rc; |
James Smart | f6c5e6c | 2021-07-22 15:17:18 -0700 | [diff] [blame] | 14394 | u8 sli_family; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 14395 | |
James Smart | f6c5e6c | 2021-07-22 15:17:18 -0700 | [diff] [blame] | 14396 | sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf); |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14397 | /* Three cases: (1) FW was not supported on the detected adapter. |
| 14398 | * (2) FW update has been locked out administratively. |
| 14399 | * (3) Some other error during FW update. |
| 14400 | * In each case, an unmaskable message is written to the console |
| 14401 | * for admin diagnosis. |
| 14402 | */ |
| 14403 | if (offset == ADD_STATUS_FW_NOT_SUPPORTED || |
James Smart | f6c5e6c | 2021-07-22 15:17:18 -0700 | [diff] [blame] | 14404 | (sli_family == LPFC_SLI_INTF_FAMILY_G6 && |
James Smart | 5792a0e | 2019-10-25 11:43:42 -0700 | [diff] [blame] | 14405 | magic_number != MAGIC_NUMBER_G6) || |
James Smart | f6c5e6c | 2021-07-22 15:17:18 -0700 | [diff] [blame] | 14406 | (sli_family == LPFC_SLI_INTF_FAMILY_G7 && |
| 14407 | magic_number != MAGIC_NUMBER_G7) || |
| 14408 | (sli_family == LPFC_SLI_INTF_FAMILY_G7P && |
| 14409 | magic_number != MAGIC_NUMBER_G7P)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14410 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14411 | "3030 This firmware version is not supported on" |
| 14412 | " this HBA model. Device:%x Magic:%x Type:%x " |
| 14413 | "ID:%x Size %d %zd\n", |
| 14414 | phba->pcidev->device, magic_number, ftype, fid, |
| 14415 | fsize, fw->size); |
| 14416 | rc = -EINVAL; |
| 14417 | } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14418 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14419 | "3021 Firmware downloads have been prohibited " |
| 14420 | "by a system configuration setting on " |
| 14421 | "Device:%x Magic:%x Type:%x ID:%x Size %d " |
| 14422 | "%zd\n", |
| 14423 | phba->pcidev->device, magic_number, ftype, fid, |
| 14424 | fsize, fw->size); |
| 14425 | rc = -EACCES; |
| 14426 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14427 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14428 | "3022 FW Download failed. Add Status x%x " |
| 14429 | "Device:%x Magic:%x Type:%x ID:%x Size %d " |
| 14430 | "%zd\n", |
| 14431 | offset, phba->pcidev->device, magic_number, |
| 14432 | ftype, fid, fsize, fw->size); |
| 14433 | rc = -EIO; |
| 14434 | } |
| 14435 | return rc; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 14436 | } |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 14437 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14438 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14439 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14440 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14441 | * @context: pointer to firmware image returned from request_firmware. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14442 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14443 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 14444 | static void |
| 14445 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14446 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 14447 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 14448 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 14449 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14450 | struct list_head dma_buffer_list; |
| 14451 | int i, rc = 0; |
| 14452 | struct lpfc_dmabuf *dmabuf, *next; |
| 14453 | uint32_t offset = 0, temp_offset = 0; |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 14454 | uint32_t magic_number, ftype, fid, fsize; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14455 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 14456 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 14457 | if (!fw) { |
| 14458 | rc = -ENXIO; |
| 14459 | goto out; |
| 14460 | } |
| 14461 | image = (struct lpfc_grp_hdr *)fw->data; |
| 14462 | |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 14463 | magic_number = be32_to_cpu(image->magic_number); |
| 14464 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 14465 | fid = bf_get_be32(lpfc_grp_hdr_id, image); |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 14466 | fsize = be32_to_cpu(image->size); |
| 14467 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14468 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14469 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14470 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14471 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 14472 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14473 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14474 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14475 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 14476 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 14477 | GFP_KERNEL); |
| 14478 | if (!dmabuf) { |
| 14479 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 14480 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14481 | } |
| 14482 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 14483 | SLI4_PAGE_SIZE, |
| 14484 | &dmabuf->phys, |
| 14485 | GFP_KERNEL); |
| 14486 | if (!dmabuf->virt) { |
| 14487 | kfree(dmabuf); |
| 14488 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 14489 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14490 | } |
| 14491 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 14492 | } |
| 14493 | while (offset < fw->size) { |
| 14494 | temp_offset = offset; |
| 14495 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 14496 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14497 | memcpy(dmabuf->virt, |
| 14498 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 14499 | fw->size - temp_offset); |
| 14500 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14501 | break; |
| 14502 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14503 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 14504 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 14505 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14506 | } |
| 14507 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 14508 | (fw->size - offset), &offset); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 14509 | if (rc) { |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14510 | rc = lpfc_log_write_firmware_error(phba, offset, |
| 14511 | magic_number, |
| 14512 | ftype, |
| 14513 | fid, |
| 14514 | fsize, |
| 14515 | fw); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 14516 | goto release_out; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 14517 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14518 | } |
| 14519 | rc = offset; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 14520 | } else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14521 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 14522 | "3029 Skipped Firmware update, Current " |
| 14523 | "Version:%s New Version:%s\n", |
| 14524 | fwrev, image->revision); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 14525 | |
| 14526 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14527 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 14528 | list_del(&dmabuf->list); |
| 14529 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 14530 | dmabuf->virt, dmabuf->phys); |
| 14531 | kfree(dmabuf); |
| 14532 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 14533 | release_firmware(fw); |
| 14534 | out: |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14535 | if (rc < 0) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14536 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14537 | "3062 Firmware update error, status %d.\n", rc); |
| 14538 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14539 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 14540 | "3024 Firmware update success: size %d.\n", rc); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14541 | } |
| 14542 | |
| 14543 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 14544 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 14545 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 14546 | * @fw_upgrade: which firmware to update. |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 14547 | * |
| 14548 | * This routine is called to perform Linux generic firmware upgrade on device |
| 14549 | * that supports such feature. |
| 14550 | **/ |
| 14551 | int |
| 14552 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 14553 | { |
| 14554 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 14555 | int ret; |
| 14556 | const struct firmware *fw; |
| 14557 | |
| 14558 | /* Only supported on SLI4 interface type 2 for now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 14559 | 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] | 14560 | LPFC_SLI_INTF_IF_TYPE_2) |
| 14561 | return -EPERM; |
| 14562 | |
| 14563 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 14564 | |
| 14565 | if (fw_upgrade == INT_FW_UPGRADE) { |
Shawn Guo | 0733d83 | 2021-04-25 10:00:24 +0800 | [diff] [blame] | 14566 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT, |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 14567 | file_name, &phba->pcidev->dev, |
| 14568 | GFP_KERNEL, (void *)phba, |
| 14569 | lpfc_write_firmware); |
| 14570 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 14571 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 14572 | if (!ret) |
| 14573 | lpfc_write_firmware(fw, (void *)phba); |
| 14574 | } else { |
| 14575 | ret = -EINVAL; |
| 14576 | } |
| 14577 | |
| 14578 | return ret; |
| 14579 | } |
| 14580 | |
| 14581 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14582 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 14583 | * @pdev: pointer to PCI device |
| 14584 | * @pid: pointer to PCI device identifier |
| 14585 | * |
| 14586 | * This routine is called from the kernel's PCI subsystem to device with |
| 14587 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 14588 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 14589 | * information of the device and driver to see if the driver state that it |
| 14590 | * can support this kind of device. If the match is successful, the driver |
| 14591 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 14592 | * it does all the initialization that it needs to do to handle the HBA |
| 14593 | * properly. |
| 14594 | * |
| 14595 | * Return code |
| 14596 | * 0 - driver can claim the device |
| 14597 | * negative value - driver can not claim the device |
| 14598 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 14599 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14600 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 14601 | { |
| 14602 | struct lpfc_hba *phba; |
| 14603 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14604 | struct Scsi_Host *shost = NULL; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 14605 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14606 | uint32_t cfg_mode, intr_mode; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14607 | |
| 14608 | /* Allocate memory for HBA structure */ |
| 14609 | phba = lpfc_hba_alloc(pdev); |
| 14610 | if (!phba) |
| 14611 | return -ENOMEM; |
| 14612 | |
Ewan D. Milne | 9977d88 | 2021-08-09 11:09:47 -0400 | [diff] [blame] | 14613 | INIT_LIST_HEAD(&phba->poll_list); |
| 14614 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14615 | /* Perform generic PCI device enabling operation */ |
| 14616 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 14617 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14618 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14619 | |
| 14620 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 14621 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 14622 | if (error) |
| 14623 | goto out_disable_pci_dev; |
| 14624 | |
| 14625 | /* Set up SLI-4 specific device PCI memory space */ |
| 14626 | error = lpfc_sli4_pci_mem_setup(phba); |
| 14627 | if (error) { |
| 14628 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14629 | "1410 Failed to set up pci memory space.\n"); |
| 14630 | goto out_disable_pci_dev; |
| 14631 | } |
| 14632 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14633 | /* Set up SLI-4 Specific device driver resources */ |
| 14634 | error = lpfc_sli4_driver_resource_setup(phba); |
| 14635 | if (error) { |
| 14636 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14637 | "1412 Failed to set up driver resource.\n"); |
| 14638 | goto out_unset_pci_mem_s4; |
| 14639 | } |
| 14640 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 14641 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 14642 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 14643 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14644 | /* Set up common device driver resources */ |
| 14645 | error = lpfc_setup_driver_resource_phase2(phba); |
| 14646 | if (error) { |
| 14647 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14648 | "1414 Failed to set up driver resource.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 14649 | goto out_unset_driver_resource_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14650 | } |
| 14651 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 14652 | /* Get the default values for Model Name and Description */ |
| 14653 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 14654 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14655 | /* Now, trying to enable interrupt and bring up the device */ |
| 14656 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14657 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 14658 | /* Put device to a known state before enabling interrupt */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14659 | phba->pport = NULL; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 14660 | lpfc_stop_port(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14661 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 14662 | /* Init cpu_map array */ |
| 14663 | lpfc_cpu_map_array_init(phba); |
| 14664 | |
| 14665 | /* Init hba_eq_hdl array */ |
| 14666 | lpfc_hba_eq_hdl_array_init(phba); |
| 14667 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 14668 | /* Configure and enable interrupt */ |
| 14669 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 14670 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14671 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 14672 | "0426 Failed to enable interrupt.\n"); |
| 14673 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14674 | goto out_unset_driver_resource; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14675 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 14676 | /* Default to single EQ for non-MSI-X */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14677 | if (phba->intr_type != MSIX) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14678 | phba->cfg_irq_chann = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14679 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 14680 | if (phba->nvmet_support) |
| 14681 | phba->cfg_nvmet_mrq = 1; |
| 14682 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14683 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 14684 | lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14685 | |
| 14686 | /* Create SCSI host to the physical port */ |
| 14687 | error = lpfc_create_shost(phba); |
| 14688 | if (error) { |
| 14689 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14690 | "1415 Failed to create scsi host.\n"); |
| 14691 | goto out_disable_intr; |
| 14692 | } |
| 14693 | vport = phba->pport; |
| 14694 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
| 14695 | |
| 14696 | /* Configure sysfs attributes */ |
| 14697 | error = lpfc_alloc_sysfs_attr(vport); |
| 14698 | if (error) { |
| 14699 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14700 | "1416 Failed to allocate sysfs attr\n"); |
| 14701 | goto out_destroy_shost; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14702 | } |
| 14703 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 14704 | /* Set up SLI-4 HBA */ |
| 14705 | if (lpfc_sli4_hba_setup(phba)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14706 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 14707 | "1421 Failed to set up hba\n"); |
| 14708 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14709 | goto out_free_sysfs_attr; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 14710 | } |
| 14711 | |
| 14712 | /* Log the current active interrupt mode */ |
| 14713 | phba->intr_mode = intr_mode; |
| 14714 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14715 | |
| 14716 | /* Perform post initialization setup */ |
| 14717 | lpfc_post_init_setup(phba); |
| 14718 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 14719 | /* NVME support in FW earlier in the driver load corrects the |
| 14720 | * FC4 type making a check for nvme_support unnecessary. |
| 14721 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 14722 | if (phba->nvmet_support == 0) { |
| 14723 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 14724 | /* Create NVME binding with nvme_fc_transport. This |
| 14725 | * ensures the vport is initialized. If the localport |
| 14726 | * create fails, it should not unload the driver to |
| 14727 | * support field issues. |
| 14728 | */ |
| 14729 | error = lpfc_nvme_create_localport(vport); |
| 14730 | if (error) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14731 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 14732 | "6004 NVME registration " |
| 14733 | "failed, error x%x\n", |
| 14734 | error); |
| 14735 | } |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 14736 | } |
| 14737 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 14738 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 14739 | /* check for firmware upgrade or downgrade */ |
| 14740 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 14741 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 14742 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 14743 | /* Check if there are static vports to be created. */ |
| 14744 | lpfc_create_static_vport(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 14745 | |
| 14746 | /* Enable RAS FW log support */ |
| 14747 | lpfc_sli4_ras_setup(phba); |
| 14748 | |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 14749 | timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14750 | cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp); |
| 14751 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14752 | return 0; |
| 14753 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14754 | out_free_sysfs_attr: |
| 14755 | lpfc_free_sysfs_attr(vport); |
| 14756 | out_destroy_shost: |
| 14757 | lpfc_destroy_shost(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 14758 | out_disable_intr: |
| 14759 | lpfc_sli4_disable_intr(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14760 | out_unset_driver_resource: |
| 14761 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14762 | out_unset_driver_resource_s4: |
| 14763 | lpfc_sli4_driver_resource_unset(phba); |
| 14764 | out_unset_pci_mem_s4: |
| 14765 | lpfc_sli4_pci_mem_unset(phba); |
| 14766 | out_disable_pci_dev: |
| 14767 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 14768 | if (shost) |
| 14769 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14770 | out_free_phba: |
| 14771 | lpfc_hba_free(phba); |
| 14772 | return error; |
| 14773 | } |
| 14774 | |
| 14775 | /** |
| 14776 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 14777 | * @pdev: pointer to PCI device |
| 14778 | * |
| 14779 | * This routine is called from the kernel's PCI subsystem to device with |
| 14780 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 14781 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 14782 | * device to be removed from the PCI subsystem properly. |
| 14783 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 14784 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14785 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 14786 | { |
| 14787 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 14788 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 14789 | struct lpfc_vport **vports; |
| 14790 | struct lpfc_hba *phba = vport->phba; |
| 14791 | int i; |
| 14792 | |
| 14793 | /* Mark the device unloading flag */ |
| 14794 | spin_lock_irq(&phba->hbalock); |
| 14795 | vport->load_flag |= FC_UNLOADING; |
| 14796 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0224383 | 2021-08-16 09:28:54 -0700 | [diff] [blame] | 14797 | if (phba->cgn_i) |
| 14798 | lpfc_unreg_congestion_buf(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14799 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14800 | lpfc_free_sysfs_attr(vport); |
| 14801 | |
| 14802 | /* Release all the vports against this physical port */ |
| 14803 | vports = lpfc_create_vport_work_array(phba); |
| 14804 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 14805 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 14806 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 14807 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14808 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 14809 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14810 | lpfc_destroy_vport_work_array(phba, vports); |
| 14811 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 14812 | /* Remove FC host with the physical port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14813 | fc_remove_host(shost); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 14814 | scsi_remove_host(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14815 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14816 | /* Perform ndlp cleanup on the physical port. The nvme and nvmet |
| 14817 | * localports are destroyed after to cleanup all transport memory. |
| 14818 | */ |
| 14819 | lpfc_cleanup(vport); |
| 14820 | lpfc_nvmet_destroy_targetport(phba); |
| 14821 | lpfc_nvme_destroy_localport(vport); |
| 14822 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 14823 | /* De-allocate multi-XRI pools */ |
| 14824 | if (phba->cfg_xri_rebalancing) |
| 14825 | lpfc_destroy_multixri_pools(phba); |
| 14826 | |
James Smart | 281d619 | 2018-01-30 15:58:47 -0800 | [diff] [blame] | 14827 | /* |
| 14828 | * Bring down the SLI Layer. This step disables all interrupts, |
| 14829 | * clears the rings, discards all mailbox commands, and resets |
| 14830 | * the HBA FCoE function. |
| 14831 | */ |
| 14832 | lpfc_debugfs_terminate(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14833 | |
Dick Kennedy | 1901762 | 2017-09-29 17:34:27 -0700 | [diff] [blame] | 14834 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 14835 | spin_lock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14836 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 14837 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14838 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 14839 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14840 | * buffers are released to their corresponding pools here. |
| 14841 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 14842 | lpfc_io_free(phba); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 14843 | lpfc_free_iocb_list(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 14844 | lpfc_sli4_hba_unset(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 14845 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 14846 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14847 | lpfc_sli4_driver_resource_unset(phba); |
| 14848 | |
| 14849 | /* Unmap adapter Control and Doorbell registers */ |
| 14850 | lpfc_sli4_pci_mem_unset(phba); |
| 14851 | |
| 14852 | /* Release PCI resources and disable device's PCI function */ |
| 14853 | scsi_host_put(shost); |
| 14854 | lpfc_disable_pci_dev(phba); |
| 14855 | |
| 14856 | /* Finally, free the driver's device data structure */ |
| 14857 | lpfc_hba_free(phba); |
| 14858 | |
| 14859 | return; |
| 14860 | } |
| 14861 | |
| 14862 | /** |
| 14863 | * 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] | 14864 | * @dev_d: pointer to device |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14865 | * |
| 14866 | * This routine is called from the kernel's PCI subsystem to support system |
| 14867 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 14868 | * this method, it quiesces the device by stopping the driver's worker |
| 14869 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 14870 | * the device offline. Note that as the driver implements the minimum PM |
| 14871 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 14872 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 14873 | * method call will be treated as SUSPEND and the driver will fully |
| 14874 | * reinitialize its device during resume() method call, the driver will set |
| 14875 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 14876 | * according to the @msg provided by the PM. |
| 14877 | * |
| 14878 | * Return code |
| 14879 | * 0 - driver suspended the device |
| 14880 | * Error otherwise |
| 14881 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14882 | static int __maybe_unused |
| 14883 | lpfc_pci_suspend_one_s4(struct device *dev_d) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14884 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14885 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14886 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 14887 | |
| 14888 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14889 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14890 | |
| 14891 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 14892 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14893 | lpfc_offline(phba); |
| 14894 | kthread_stop(phba->worker_thread); |
| 14895 | |
| 14896 | /* Disable interrupt from device */ |
| 14897 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 14898 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14899 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14900 | return 0; |
| 14901 | } |
| 14902 | |
| 14903 | /** |
| 14904 | * 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] | 14905 | * @dev_d: pointer to device |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14906 | * |
| 14907 | * This routine is called from the kernel's PCI subsystem to support system |
| 14908 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 14909 | * this method, it restores the device's PCI config space state and fully |
| 14910 | * reinitializes the device and brings it online. Note that as the driver |
| 14911 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 14912 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 14913 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 14914 | * will fully reinitialize its device during resume() method call, the device |
| 14915 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 14916 | * state. |
| 14917 | * |
| 14918 | * Return code |
| 14919 | * 0 - driver suspended the device |
| 14920 | * Error otherwise |
| 14921 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14922 | static int __maybe_unused |
| 14923 | lpfc_pci_resume_one_s4(struct device *dev_d) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14924 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14925 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14926 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 14927 | uint32_t intr_mode; |
| 14928 | int error; |
| 14929 | |
| 14930 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 14931 | "0292 PCI device Power Management resume.\n"); |
| 14932 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14933 | /* Startup the kernel thread for this host adapter. */ |
| 14934 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 14935 | "lpfc_worker_%d", phba->brd_no); |
| 14936 | if (IS_ERR(phba->worker_thread)) { |
| 14937 | error = PTR_ERR(phba->worker_thread); |
| 14938 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 14939 | "0293 PM resume failed to start worker " |
| 14940 | "thread: error=x%x.\n", error); |
| 14941 | return error; |
| 14942 | } |
| 14943 | |
| 14944 | /* Configure and enable interrupt */ |
| 14945 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 14946 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14947 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 14948 | "0294 PM resume Failed to enable interrupt\n"); |
| 14949 | return -EIO; |
| 14950 | } else |
| 14951 | phba->intr_mode = intr_mode; |
| 14952 | |
| 14953 | /* Restart HBA and bring it online */ |
| 14954 | lpfc_sli_brdrestart(phba); |
| 14955 | lpfc_online(phba); |
| 14956 | |
| 14957 | /* Log the current active interrupt mode */ |
| 14958 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 14959 | |
| 14960 | return 0; |
| 14961 | } |
| 14962 | |
| 14963 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14964 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 14965 | * @phba: pointer to lpfc hba data structure. |
| 14966 | * |
| 14967 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 14968 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 14969 | **/ |
| 14970 | static void |
| 14971 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 14972 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14973 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14974 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 14975 | /* |
| 14976 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 14977 | * and let the SCSI mid-layer to retry them to recover. |
| 14978 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 14979 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14980 | } |
| 14981 | |
| 14982 | /** |
| 14983 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 14984 | * @phba: pointer to lpfc hba data structure. |
| 14985 | * |
| 14986 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 14987 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 14988 | * pending I/Os. |
| 14989 | **/ |
| 14990 | static void |
| 14991 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 14992 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14993 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14994 | "2826 PCI channel disable preparing for reset\n"); |
| 14995 | |
| 14996 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 14997 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 14998 | |
| 14999 | /* Block all SCSI devices' I/Os on the host */ |
| 15000 | lpfc_scsi_dev_block(phba); |
| 15001 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 15002 | /* Flush all driver's outstanding I/Os as we are to reset */ |
| 15003 | lpfc_sli_flush_io_rings(phba); |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 15004 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15005 | /* stop all timers */ |
| 15006 | lpfc_stop_hba_timers(phba); |
| 15007 | |
| 15008 | /* Disable interrupt and pci device */ |
| 15009 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 15010 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15011 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15012 | } |
| 15013 | |
| 15014 | /** |
| 15015 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 15016 | * @phba: pointer to lpfc hba data structure. |
| 15017 | * |
| 15018 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 15019 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 15020 | * pending I/Os. |
| 15021 | **/ |
| 15022 | static void |
| 15023 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 15024 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15025 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15026 | "2827 PCI channel permanent disable for failure\n"); |
| 15027 | |
| 15028 | /* Block all SCSI devices' I/Os on the host */ |
| 15029 | lpfc_scsi_dev_block(phba); |
| 15030 | |
| 15031 | /* stop all timers */ |
| 15032 | lpfc_stop_hba_timers(phba); |
| 15033 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 15034 | /* Clean up all driver's outstanding I/Os */ |
| 15035 | lpfc_sli_flush_io_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15036 | } |
| 15037 | |
| 15038 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15039 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 15040 | * @pdev: pointer to PCI device. |
| 15041 | * @state: the current PCI connection state. |
| 15042 | * |
| 15043 | * This routine is called from the PCI subsystem for error handling to device |
| 15044 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 15045 | * after a PCI bus error affecting this device has been detected. When this |
| 15046 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 15047 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 15048 | * for the PCI subsystem to perform proper recovery as desired. |
| 15049 | * |
| 15050 | * Return codes |
| 15051 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 15052 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 15053 | **/ |
| 15054 | static pci_ers_result_t |
| 15055 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 15056 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15057 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 15058 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 15059 | |
| 15060 | switch (state) { |
| 15061 | case pci_channel_io_normal: |
| 15062 | /* Non-fatal error, prepare for recovery */ |
| 15063 | lpfc_sli4_prep_dev_for_recover(phba); |
| 15064 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 15065 | case pci_channel_io_frozen: |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 15066 | phba->hba_flag |= HBA_PCI_ERR; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15067 | /* Fatal error, prepare for slot reset */ |
| 15068 | lpfc_sli4_prep_dev_for_reset(phba); |
| 15069 | return PCI_ERS_RESULT_NEED_RESET; |
| 15070 | case pci_channel_io_perm_failure: |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 15071 | phba->hba_flag |= HBA_PCI_ERR; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15072 | /* Permanent failure, prepare for device down */ |
| 15073 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 15074 | return PCI_ERS_RESULT_DISCONNECT; |
| 15075 | default: |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 15076 | phba->hba_flag |= HBA_PCI_ERR; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15077 | /* Unknown state, prepare and request slot reset */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15078 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15079 | "2825 Unknown PCI error state: x%x\n", state); |
| 15080 | lpfc_sli4_prep_dev_for_reset(phba); |
| 15081 | return PCI_ERS_RESULT_NEED_RESET; |
| 15082 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15083 | } |
| 15084 | |
| 15085 | /** |
| 15086 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 15087 | * @pdev: pointer to PCI device. |
| 15088 | * |
| 15089 | * This routine is called from the PCI subsystem for error handling to device |
| 15090 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 15091 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 15092 | * PCI subsystem error recovery, after the driver returns |
| 15093 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 15094 | * recovery and then call this routine before calling the .resume method to |
| 15095 | * recover the device. This function will initialize the HBA device, enable |
| 15096 | * the interrupt, but it will just put the HBA to offline state without |
| 15097 | * passing any I/O traffic. |
| 15098 | * |
| 15099 | * Return codes |
| 15100 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 15101 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 15102 | */ |
| 15103 | static pci_ers_result_t |
| 15104 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 15105 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15106 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 15107 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 15108 | struct lpfc_sli *psli = &phba->sli; |
| 15109 | uint32_t intr_mode; |
| 15110 | |
| 15111 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 15112 | if (pci_enable_device_mem(pdev)) { |
| 15113 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 15114 | "PCI device after reset.\n"); |
| 15115 | return PCI_ERS_RESULT_DISCONNECT; |
| 15116 | } |
| 15117 | |
| 15118 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 15119 | |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 15120 | phba->hba_flag &= ~HBA_PCI_ERR; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 15121 | /* |
| 15122 | * As the new kernel behavior of pci_restore_state() API call clears |
| 15123 | * device saved_state flag, need to save the restored state again. |
| 15124 | */ |
| 15125 | pci_save_state(pdev); |
| 15126 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15127 | if (pdev->is_busmaster) |
| 15128 | pci_set_master(pdev); |
| 15129 | |
| 15130 | spin_lock_irq(&phba->hbalock); |
| 15131 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 15132 | spin_unlock_irq(&phba->hbalock); |
| 15133 | |
| 15134 | /* Configure and enable interrupt */ |
| 15135 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 15136 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15137 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15138 | "2824 Cannot re-enable interrupt after " |
| 15139 | "slot reset.\n"); |
| 15140 | return PCI_ERS_RESULT_DISCONNECT; |
| 15141 | } else |
| 15142 | phba->intr_mode = intr_mode; |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 15143 | lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15144 | |
| 15145 | /* Log the current active interrupt mode */ |
| 15146 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 15147 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15148 | return PCI_ERS_RESULT_RECOVERED; |
| 15149 | } |
| 15150 | |
| 15151 | /** |
| 15152 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 15153 | * @pdev: pointer to PCI device |
| 15154 | * |
| 15155 | * This routine is called from the PCI subsystem for error handling to device |
| 15156 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 15157 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 15158 | * error recovery. After this call, traffic can start to flow from this device |
| 15159 | * again. |
| 15160 | **/ |
| 15161 | static void |
| 15162 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 15163 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15164 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 15165 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 15166 | |
| 15167 | /* |
| 15168 | * In case of slot reset, as function reset is performed through |
| 15169 | * mailbox command which needs DMA to be enabled, this operation |
| 15170 | * has to be moved to the io resume phase. Taking device offline |
| 15171 | * will perform the necessary cleanup. |
| 15172 | */ |
| 15173 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 15174 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 15175 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 15176 | lpfc_offline(phba); |
| 15177 | lpfc_sli_brdrestart(phba); |
| 15178 | /* Bring the device back online */ |
| 15179 | lpfc_online(phba); |
| 15180 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15181 | } |
| 15182 | |
| 15183 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15184 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 15185 | * @pdev: pointer to PCI device |
| 15186 | * @pid: pointer to PCI device identifier |
| 15187 | * |
| 15188 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 15189 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 15190 | * at PCI device-specific information of the device and driver to see if the |
| 15191 | * driver state that it can support this kind of device. If the match is |
| 15192 | * successful, the driver core invokes this routine. This routine dispatches |
| 15193 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 15194 | * do all the initialization that it needs to do to handle the HBA device |
| 15195 | * properly. |
| 15196 | * |
| 15197 | * Return code |
| 15198 | * 0 - driver can claim the device |
| 15199 | * negative value - driver can not claim the device |
| 15200 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 15201 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15202 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 15203 | { |
| 15204 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15205 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15206 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 15207 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15208 | return -ENODEV; |
| 15209 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15210 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 15211 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15212 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15213 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15214 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 15215 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15216 | return rc; |
| 15217 | } |
| 15218 | |
| 15219 | /** |
| 15220 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 15221 | * @pdev: pointer to PCI device |
| 15222 | * |
| 15223 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 15224 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 15225 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 15226 | * remove routine, which will perform all the necessary cleanup for the |
| 15227 | * device to be removed from the PCI subsystem properly. |
| 15228 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 15229 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15230 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 15231 | { |
| 15232 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 15233 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 15234 | |
| 15235 | switch (phba->pci_dev_grp) { |
| 15236 | case LPFC_PCI_DEV_LP: |
| 15237 | lpfc_pci_remove_one_s3(pdev); |
| 15238 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15239 | case LPFC_PCI_DEV_OC: |
| 15240 | lpfc_pci_remove_one_s4(pdev); |
| 15241 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15242 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15243 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15244 | "1424 Invalid PCI device group: 0x%x\n", |
| 15245 | phba->pci_dev_grp); |
| 15246 | break; |
| 15247 | } |
| 15248 | return; |
| 15249 | } |
| 15250 | |
| 15251 | /** |
| 15252 | * 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] | 15253 | * @dev: pointer to device |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15254 | * |
| 15255 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 15256 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 15257 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 15258 | * suspend the device. |
| 15259 | * |
| 15260 | * Return code |
| 15261 | * 0 - driver suspended the device |
| 15262 | * Error otherwise |
| 15263 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 15264 | static int __maybe_unused |
| 15265 | lpfc_pci_suspend_one(struct device *dev) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15266 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 15267 | struct Scsi_Host *shost = dev_get_drvdata(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15268 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 15269 | int rc = -ENODEV; |
| 15270 | |
| 15271 | switch (phba->pci_dev_grp) { |
| 15272 | case LPFC_PCI_DEV_LP: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 15273 | rc = lpfc_pci_suspend_one_s3(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15274 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15275 | case LPFC_PCI_DEV_OC: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 15276 | rc = lpfc_pci_suspend_one_s4(dev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15277 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15278 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15279 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15280 | "1425 Invalid PCI device group: 0x%x\n", |
| 15281 | phba->pci_dev_grp); |
| 15282 | break; |
| 15283 | } |
| 15284 | return rc; |
| 15285 | } |
| 15286 | |
| 15287 | /** |
| 15288 | * 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] | 15289 | * @dev: pointer to device |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15290 | * |
| 15291 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 15292 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 15293 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 15294 | * resume the device. |
| 15295 | * |
| 15296 | * Return code |
| 15297 | * 0 - driver suspended the device |
| 15298 | * Error otherwise |
| 15299 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 15300 | static int __maybe_unused |
| 15301 | lpfc_pci_resume_one(struct device *dev) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15302 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 15303 | struct Scsi_Host *shost = dev_get_drvdata(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15304 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 15305 | int rc = -ENODEV; |
| 15306 | |
| 15307 | switch (phba->pci_dev_grp) { |
| 15308 | case LPFC_PCI_DEV_LP: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 15309 | rc = lpfc_pci_resume_one_s3(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15310 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15311 | case LPFC_PCI_DEV_OC: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 15312 | rc = lpfc_pci_resume_one_s4(dev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15313 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15314 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15315 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15316 | "1426 Invalid PCI device group: 0x%x\n", |
| 15317 | phba->pci_dev_grp); |
| 15318 | break; |
| 15319 | } |
| 15320 | return rc; |
| 15321 | } |
| 15322 | |
| 15323 | /** |
| 15324 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 15325 | * @pdev: pointer to PCI device. |
| 15326 | * @state: the current PCI connection state. |
| 15327 | * |
| 15328 | * This routine is registered to the PCI subsystem for error handling. This |
| 15329 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 15330 | * this device has been detected. When this routine is invoked, it dispatches |
| 15331 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 15332 | * routine, which will perform the proper error detected operation. |
| 15333 | * |
| 15334 | * Return codes |
| 15335 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 15336 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 15337 | **/ |
| 15338 | static pci_ers_result_t |
| 15339 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 15340 | { |
| 15341 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 15342 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 15343 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 15344 | |
James Smart | 25ac2c97 | 2021-09-10 16:31:54 -0700 | [diff] [blame] | 15345 | if (phba->link_state == LPFC_HBA_ERROR && |
| 15346 | phba->hba_flag & HBA_IOQ_FLUSH) |
| 15347 | return PCI_ERS_RESULT_NEED_RESET; |
| 15348 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15349 | switch (phba->pci_dev_grp) { |
| 15350 | case LPFC_PCI_DEV_LP: |
| 15351 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 15352 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15353 | case LPFC_PCI_DEV_OC: |
| 15354 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 15355 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15356 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15357 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15358 | "1427 Invalid PCI device group: 0x%x\n", |
| 15359 | phba->pci_dev_grp); |
| 15360 | break; |
| 15361 | } |
| 15362 | return rc; |
| 15363 | } |
| 15364 | |
| 15365 | /** |
| 15366 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 15367 | * @pdev: pointer to PCI device. |
| 15368 | * |
| 15369 | * This routine is registered to the PCI subsystem for error handling. This |
| 15370 | * function is called after PCI bus has been reset to restart the PCI card |
| 15371 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 15372 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 15373 | * routine, which will perform the proper device reset. |
| 15374 | * |
| 15375 | * Return codes |
| 15376 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 15377 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 15378 | **/ |
| 15379 | static pci_ers_result_t |
| 15380 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 15381 | { |
| 15382 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 15383 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 15384 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 15385 | |
| 15386 | switch (phba->pci_dev_grp) { |
| 15387 | case LPFC_PCI_DEV_LP: |
| 15388 | rc = lpfc_io_slot_reset_s3(pdev); |
| 15389 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15390 | case LPFC_PCI_DEV_OC: |
| 15391 | rc = lpfc_io_slot_reset_s4(pdev); |
| 15392 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15393 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15394 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15395 | "1428 Invalid PCI device group: 0x%x\n", |
| 15396 | phba->pci_dev_grp); |
| 15397 | break; |
| 15398 | } |
| 15399 | return rc; |
| 15400 | } |
| 15401 | |
| 15402 | /** |
| 15403 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 15404 | * @pdev: pointer to PCI device |
| 15405 | * |
| 15406 | * This routine is registered to the PCI subsystem for error handling. It |
| 15407 | * is called when kernel error recovery tells the lpfc driver that it is |
| 15408 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 15409 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 15410 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 15411 | **/ |
| 15412 | static void |
| 15413 | lpfc_io_resume(struct pci_dev *pdev) |
| 15414 | { |
| 15415 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 15416 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 15417 | |
| 15418 | switch (phba->pci_dev_grp) { |
| 15419 | case LPFC_PCI_DEV_LP: |
| 15420 | lpfc_io_resume_s3(pdev); |
| 15421 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 15422 | case LPFC_PCI_DEV_OC: |
| 15423 | lpfc_io_resume_s4(pdev); |
| 15424 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15425 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15426 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 15427 | "1429 Invalid PCI device group: 0x%x\n", |
| 15428 | phba->pci_dev_grp); |
| 15429 | break; |
| 15430 | } |
| 15431 | return; |
| 15432 | } |
| 15433 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15434 | /** |
| 15435 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 15436 | * @phba: pointer to lpfc hba data structure. |
| 15437 | * |
| 15438 | * This routine checks to see if OAS is supported for this adapter. If |
| 15439 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 15440 | * the enable oas flag is cleared and the pool created for OAS device data |
| 15441 | * is destroyed. |
| 15442 | * |
| 15443 | **/ |
YueHaibing | c709297 | 2019-04-17 23:05:54 +0800 | [diff] [blame] | 15444 | static void |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15445 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 15446 | { |
| 15447 | |
| 15448 | if (!phba->cfg_EnableXLane) |
| 15449 | return; |
| 15450 | |
| 15451 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 15452 | phba->cfg_fof = 1; |
| 15453 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 15454 | phba->cfg_fof = 0; |
Saurav Girepunje | c3e5aac | 2019-10-27 01:17:17 +0530 | [diff] [blame] | 15455 | mempool_destroy(phba->device_data_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15456 | phba->device_data_mem_pool = NULL; |
| 15457 | } |
| 15458 | |
| 15459 | return; |
| 15460 | } |
| 15461 | |
| 15462 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 15463 | * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter |
| 15464 | * @phba: pointer to lpfc hba data structure. |
| 15465 | * |
| 15466 | * This routine checks to see if RAS is supported by the adapter. Check the |
| 15467 | * function through which RAS support enablement is to be done. |
| 15468 | **/ |
| 15469 | void |
| 15470 | lpfc_sli4_ras_init(struct lpfc_hba *phba) |
| 15471 | { |
James Smart | f6c5e6c | 2021-07-22 15:17:18 -0700 | [diff] [blame] | 15472 | /* if ASIC_GEN_NUM >= 0xC) */ |
| 15473 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 15474 | LPFC_SLI_INTF_IF_TYPE_6) || |
| 15475 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
| 15476 | LPFC_SLI_INTF_FAMILY_G6)) { |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 15477 | phba->ras_fwlog.ras_hwsupport = true; |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 15478 | if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) && |
| 15479 | phba->cfg_ras_fwlog_buffsize) |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 15480 | phba->ras_fwlog.ras_enabled = true; |
| 15481 | else |
| 15482 | phba->ras_fwlog.ras_enabled = false; |
James Smart | f6c5e6c | 2021-07-22 15:17:18 -0700 | [diff] [blame] | 15483 | } else { |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 15484 | phba->ras_fwlog.ras_hwsupport = false; |
| 15485 | } |
| 15486 | } |
| 15487 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 15488 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15489 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 15490 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 15491 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 15492 | .error_detected = lpfc_io_error_detected, |
| 15493 | .slot_reset = lpfc_io_slot_reset, |
| 15494 | .resume = lpfc_io_resume, |
| 15495 | }; |
| 15496 | |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 15497 | static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one, |
| 15498 | lpfc_pci_suspend_one, |
| 15499 | lpfc_pci_resume_one); |
| 15500 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15501 | static struct pci_driver lpfc_driver = { |
| 15502 | .name = LPFC_DRIVER_NAME, |
| 15503 | .id_table = lpfc_id_table, |
| 15504 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 15505 | .remove = lpfc_pci_remove_one, |
Anton Blanchard | 85e8a23 | 2017-02-13 08:49:20 +1100 | [diff] [blame] | 15506 | .shutdown = lpfc_pci_remove_one, |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 15507 | .driver.pm = &lpfc_pci_pm_ops_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 15508 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15509 | }; |
| 15510 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 15511 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 15512 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 15513 | }; |
| 15514 | |
| 15515 | static struct miscdevice lpfc_mgmt_dev = { |
| 15516 | .minor = MISC_DYNAMIC_MINOR, |
| 15517 | .name = "lpfcmgmt", |
| 15518 | .fops = &lpfc_mgmt_fop, |
| 15519 | }; |
| 15520 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 15521 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 15522 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 15523 | * |
| 15524 | * This routine is to be invoked when the lpfc module is loaded into the |
| 15525 | * kernel. The special kernel macro module_init() is used to indicate the |
| 15526 | * role of this routine to the kernel as lpfc module entry point. |
| 15527 | * |
| 15528 | * Return codes |
| 15529 | * 0 - successful |
| 15530 | * -ENOMEM - FC attach transport failed |
| 15531 | * all others - failed |
| 15532 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15533 | static int __init |
| 15534 | lpfc_init(void) |
| 15535 | { |
| 15536 | int error = 0; |
| 15537 | |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 15538 | pr_info(LPFC_MODULE_DESC "\n"); |
| 15539 | pr_info(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15540 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 15541 | error = misc_register(&lpfc_mgmt_dev); |
| 15542 | if (error) |
| 15543 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 15544 | "misc_register returned with status %d", error); |
| 15545 | |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 15546 | error = -ENOMEM; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 15547 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 15548 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15549 | lpfc_transport_template = |
| 15550 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 15551 | if (lpfc_transport_template == NULL) |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 15552 | goto unregister; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 15553 | lpfc_vport_transport_template = |
| 15554 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 15555 | if (lpfc_vport_transport_template == NULL) { |
| 15556 | fc_release_transport(lpfc_transport_template); |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 15557 | goto unregister; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 15558 | } |
James Smart | 840a470 | 2020-11-15 11:26:40 -0800 | [diff] [blame] | 15559 | lpfc_wqe_cmd_template(); |
James Smart | bd3061b | 2018-03-05 12:04:05 -0800 | [diff] [blame] | 15560 | lpfc_nvmet_cmd_template(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 15561 | |
| 15562 | /* Initialize in case vector mapping is needed */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 15563 | lpfc_present_cpu = num_present_cpus(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 15564 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 15565 | error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, |
| 15566 | "lpfc/sli4:online", |
| 15567 | lpfc_cpu_online, lpfc_cpu_offline); |
| 15568 | if (error < 0) |
| 15569 | goto cpuhp_failure; |
| 15570 | lpfc_cpuhp_state = error; |
| 15571 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15572 | error = pci_register_driver(&lpfc_driver); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 15573 | if (error) |
| 15574 | goto unwind; |
| 15575 | |
| 15576 | return error; |
| 15577 | |
| 15578 | unwind: |
| 15579 | cpuhp_remove_multi_state(lpfc_cpuhp_state); |
| 15580 | cpuhp_failure: |
| 15581 | fc_release_transport(lpfc_transport_template); |
| 15582 | fc_release_transport(lpfc_vport_transport_template); |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 15583 | unregister: |
| 15584 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15585 | |
| 15586 | return error; |
| 15587 | } |
| 15588 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15589 | void lpfc_dmp_dbg(struct lpfc_hba *phba) |
| 15590 | { |
| 15591 | unsigned int start_idx; |
| 15592 | unsigned int dbg_cnt; |
| 15593 | unsigned int temp_idx; |
| 15594 | int i; |
| 15595 | int j = 0; |
James Smart | e861308 | 2021-07-07 11:43:33 -0700 | [diff] [blame] | 15596 | unsigned long rem_nsec, iflags; |
| 15597 | bool log_verbose = false; |
| 15598 | struct lpfc_vport *port_iterator; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15599 | |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 15600 | /* Don't dump messages if we explicitly set log_verbose for the |
| 15601 | * physical port or any vport. |
| 15602 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15603 | if (phba->cfg_log_verbose) |
| 15604 | return; |
| 15605 | |
James Smart | e861308 | 2021-07-07 11:43:33 -0700 | [diff] [blame] | 15606 | spin_lock_irqsave(&phba->port_list_lock, iflags); |
| 15607 | list_for_each_entry(port_iterator, &phba->port_list, listentry) { |
| 15608 | if (port_iterator->load_flag & FC_UNLOADING) |
| 15609 | continue; |
| 15610 | if (scsi_host_get(lpfc_shost_from_vport(port_iterator))) { |
| 15611 | if (port_iterator->cfg_log_verbose) |
| 15612 | log_verbose = true; |
| 15613 | |
| 15614 | scsi_host_put(lpfc_shost_from_vport(port_iterator)); |
| 15615 | |
| 15616 | if (log_verbose) { |
| 15617 | spin_unlock_irqrestore(&phba->port_list_lock, |
| 15618 | iflags); |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 15619 | return; |
| 15620 | } |
| 15621 | } |
| 15622 | } |
James Smart | e861308 | 2021-07-07 11:43:33 -0700 | [diff] [blame] | 15623 | spin_unlock_irqrestore(&phba->port_list_lock, iflags); |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 15624 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15625 | if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0) |
| 15626 | return; |
| 15627 | |
| 15628 | start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ; |
| 15629 | dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt); |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 15630 | if (!dbg_cnt) |
| 15631 | goto out; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15632 | temp_idx = start_idx; |
| 15633 | if (dbg_cnt >= DBG_LOG_SZ) { |
| 15634 | dbg_cnt = DBG_LOG_SZ; |
| 15635 | temp_idx -= 1; |
| 15636 | } else { |
| 15637 | if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) { |
| 15638 | temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ; |
| 15639 | } else { |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 15640 | if (start_idx < dbg_cnt) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15641 | start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx); |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 15642 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15643 | start_idx -= dbg_cnt; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15644 | } |
| 15645 | } |
| 15646 | dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n", |
| 15647 | start_idx, temp_idx, dbg_cnt); |
| 15648 | |
| 15649 | for (i = 0; i < dbg_cnt; i++) { |
| 15650 | if ((start_idx + i) < DBG_LOG_SZ) |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 15651 | temp_idx = (start_idx + i) % DBG_LOG_SZ; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15652 | else |
| 15653 | temp_idx = j++; |
| 15654 | rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC); |
| 15655 | dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s", |
| 15656 | temp_idx, |
| 15657 | (unsigned long)phba->dbg_log[temp_idx].t_ns, |
| 15658 | rem_nsec / 1000, |
| 15659 | phba->dbg_log[temp_idx].log); |
| 15660 | } |
James Smart | 0b3ad32 | 2021-01-04 10:02:39 -0800 | [diff] [blame] | 15661 | out: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15662 | atomic_set(&phba->dbg_log_cnt, 0); |
| 15663 | atomic_set(&phba->dbg_log_dmping, 0); |
| 15664 | } |
| 15665 | |
Lee Jones | 7fa03c7 | 2020-07-23 13:24:21 +0100 | [diff] [blame] | 15666 | __printf(2, 3) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 15667 | void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...) |
| 15668 | { |
| 15669 | unsigned int idx; |
| 15670 | va_list args; |
| 15671 | int dbg_dmping = atomic_read(&phba->dbg_log_dmping); |
| 15672 | struct va_format vaf; |
| 15673 | |
| 15674 | |
| 15675 | va_start(args, fmt); |
| 15676 | if (unlikely(dbg_dmping)) { |
| 15677 | vaf.fmt = fmt; |
| 15678 | vaf.va = &args; |
| 15679 | dev_info(&phba->pcidev->dev, "%pV", &vaf); |
| 15680 | va_end(args); |
| 15681 | return; |
| 15682 | } |
| 15683 | idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) % |
| 15684 | DBG_LOG_SZ; |
| 15685 | |
| 15686 | atomic_inc(&phba->dbg_log_cnt); |
| 15687 | |
| 15688 | vscnprintf(phba->dbg_log[idx].log, |
| 15689 | sizeof(phba->dbg_log[idx].log), fmt, args); |
| 15690 | va_end(args); |
| 15691 | |
| 15692 | phba->dbg_log[idx].t_ns = local_clock(); |
| 15693 | } |
| 15694 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 15695 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 15696 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 15697 | * |
| 15698 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 15699 | * The special kernel macro module_exit() is used to indicate the role of |
| 15700 | * this routine to the kernel as lpfc module exit point. |
| 15701 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15702 | static void __exit |
| 15703 | lpfc_exit(void) |
| 15704 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 15705 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15706 | pci_unregister_driver(&lpfc_driver); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 15707 | cpuhp_remove_multi_state(lpfc_cpuhp_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15708 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 15709 | fc_release_transport(lpfc_vport_transport_template); |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 15710 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15711 | } |
| 15712 | |
| 15713 | module_init(lpfc_init); |
| 15714 | module_exit(lpfc_exit); |
| 15715 | MODULE_LICENSE("GPL"); |
| 15716 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 15717 | MODULE_AUTHOR("Broadcom"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 15718 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |