| 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 | 145e5a8 | 2020-01-27 16:23:12 -0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term * |
James Smart | 3e21d1c | 2018-05-04 20:37:59 -0700 | [diff] [blame] | 5 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * |
James Smart | 5061157 | 2016-03-31 14:12:34 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * EMULEX and SLI are trademarks of Emulex. * |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 8 | * www.broadcom.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 12 | * modify it under the terms of version 2 of the GNU General * |
| 13 | * Public License as published by the Free Software Foundation. * |
| 14 | * This program is distributed in the hope that it will be useful. * |
| 15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 20 | * more details, a copy of which can be found in the file COPYING * |
| 21 | * included with this package. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | *******************************************************************/ |
| 23 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/dma-mapping.h> |
| 27 | #include <linux/idr.h> |
| 28 | #include <linux/interrupt.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 29 | #include <linux/module.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 30 | #include <linux/kthread.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/spinlock.h> |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 33 | #include <linux/ctype.h> |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 34 | #include <linux/aer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 36 | #include <linux/firmware.h> |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 37 | #include <linux/miscdevice.h> |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 38 | #include <linux/percpu.h> |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 39 | #include <linux/msi.h> |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 40 | #include <linux/irq.h> |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 41 | #include <linux/bitops.h> |
James Smart | 31f06d2 | 2019-08-14 16:56:31 -0700 | [diff] [blame] | 42 | #include <linux/crash_dump.h> |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 43 | #include <linux/cpu.h> |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 44 | #include <linux/cpuhotplug.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 45 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 46 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 47 | #include <scsi/scsi_device.h> |
| 48 | #include <scsi/scsi_host.h> |
| 49 | #include <scsi/scsi_transport_fc.h> |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 50 | #include <scsi/scsi_tcq.h> |
| 51 | #include <scsi/fc/fc_fs.h> |
| 52 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 53 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | #include "lpfc_hw.h" |
| 55 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 56 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 57 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 58 | #include "lpfc_disc.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 59 | #include "lpfc.h" |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 60 | #include "lpfc_scsi.h" |
| 61 | #include "lpfc_nvme.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 62 | #include "lpfc_logmsg.h" |
| 63 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 64 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 65 | #include "lpfc_version.h" |
James Smart | 12f4445 | 2016-07-06 12:36:03 -0700 | [diff] [blame] | 66 | #include "lpfc_ids.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 67 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 68 | static enum cpuhp_state lpfc_cpuhp_state; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 69 | /* Used when mapping IRQ vectors in a driver centric manner */ |
YueHaibing | d7b761b | 2019-05-31 23:28:41 +0800 | [diff] [blame] | 70 | static uint32_t lpfc_present_cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 71 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 72 | static void __lpfc_cpuhp_remove(struct lpfc_hba *phba); |
| 73 | static void lpfc_cpuhp_remove(struct lpfc_hba *phba); |
| 74 | static void lpfc_cpuhp_add(struct lpfc_hba *phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 75 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 76 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 77 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 78 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
| 79 | static int lpfc_setup_endian_order(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 80 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 81 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 82 | static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 83 | static void lpfc_init_sgl_list(struct lpfc_hba *); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 84 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); |
| 85 | static void lpfc_free_active_sgl(struct lpfc_hba *); |
| 86 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); |
| 87 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); |
| 88 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); |
| 89 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); |
| 90 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 91 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
| 92 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 93 | static void lpfc_sli4_oas_verify(struct lpfc_hba *phba); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 94 | static uint16_t lpfc_find_cpu_handle(struct lpfc_hba *, uint16_t, int); |
James Smart | aa6ff30 | 2019-05-21 17:49:09 -0700 | [diff] [blame] | 95 | static void lpfc_setup_bg(struct lpfc_hba *, struct Scsi_Host *); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 96 | |
| 97 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 98 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 99 | static DEFINE_IDR(lpfc_hba_index); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 100 | #define LPFC_NVMET_BUF_POST 254 |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 101 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 102 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 103 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 104 | * @phba: pointer to lpfc hba data structure. |
| 105 | * |
| 106 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 107 | * mailbox command. It retrieves the revision information from the HBA and |
| 108 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 109 | * configuration of the HBA. |
| 110 | * |
| 111 | * Return codes: |
| 112 | * 0 - success. |
| 113 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 114 | * Any other value - indicates an error. |
| 115 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 116 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 117 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 118 | { |
| 119 | lpfc_vpd_t *vp = &phba->vpd; |
| 120 | int i = 0, rc; |
| 121 | LPFC_MBOXQ_t *pmb; |
| 122 | MAILBOX_t *mb; |
| 123 | char *lpfc_vpd_data = NULL; |
| 124 | uint16_t offset = 0; |
| 125 | static char licensed[56] = |
| 126 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 127 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 128 | |
| 129 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 130 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 131 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 132 | return -ENOMEM; |
| 133 | } |
| 134 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 135 | mb = &pmb->u.mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 136 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 137 | |
| 138 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 139 | if (init_key) { |
| 140 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 141 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 142 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 143 | *ptext = cpu_to_be32(*ptext); |
| 144 | init_key = 0; |
| 145 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 146 | |
| 147 | lpfc_read_nv(phba, pmb); |
| 148 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 149 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 150 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 151 | sizeof (licensed)); |
| 152 | |
| 153 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 154 | |
| 155 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 156 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 157 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 158 | "error, mbxCmd x%x READ_NVPARM, " |
| 159 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 160 | mb->mbxCommand, mb->mbxStatus); |
| 161 | mempool_free(pmb, phba->mbox_mem_pool); |
| 162 | return -ERESTART; |
| 163 | } |
| 164 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 165 | sizeof(phba->wwnn)); |
| 166 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 167 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 168 | } |
| 169 | |
Martin Wilck | dfb7513 | 2018-11-12 09:58:37 +0100 | [diff] [blame] | 170 | /* |
| 171 | * Clear all option bits except LPFC_SLI3_BG_ENABLED, |
| 172 | * which was already set in lpfc_get_cfgparam() |
| 173 | */ |
| 174 | phba->sli3_options &= (uint32_t)LPFC_SLI3_BG_ENABLED; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 175 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 176 | /* Setup and issue mailbox READ REV command */ |
| 177 | lpfc_read_rev(phba, pmb); |
| 178 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 179 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 180 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 181 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 182 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 183 | mb->mbxCommand, mb->mbxStatus); |
| 184 | mempool_free( pmb, phba->mbox_mem_pool); |
| 185 | return -ERESTART; |
| 186 | } |
| 187 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 188 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 189 | /* |
| 190 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 191 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 192 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 193 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 194 | vp->rev.rBit = 0; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 195 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 196 | "0440 Adapter failed to init, READ_REV has " |
| 197 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 198 | mempool_free(pmb, phba->mbox_mem_pool); |
| 199 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 200 | } |
| 201 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 202 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 203 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 204 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 205 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 206 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 208 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 209 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 210 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 211 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 212 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 213 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 214 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 215 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 216 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 217 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 218 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 219 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 220 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 221 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 222 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 223 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 224 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 225 | /* If the sli feature level is less then 9, we must |
| 226 | * tear down all RPIs and VPIs on link down if NPIV |
| 227 | * is enabled. |
| 228 | */ |
| 229 | if (vp->rev.feaLevelHigh < 9) |
| 230 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 231 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 232 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 233 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 234 | sizeof (phba->RandomData)); |
| 235 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 236 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 237 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 238 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 239 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 240 | do { |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 241 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 242 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 243 | |
| 244 | if (rc != MBX_SUCCESS) { |
| 245 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 246 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 247 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 248 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 249 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 250 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 251 | /* dump mem may return a zero when finished or we got a |
| 252 | * mailbox error, either way we are done. |
| 253 | */ |
| 254 | if (mb->un.varDmp.word_cnt == 0) |
| 255 | break; |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 256 | |
| 257 | i = mb->un.varDmp.word_cnt * sizeof(uint32_t); |
| 258 | if (offset + i > DMP_VPD_SIZE) |
| 259 | i = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 260 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
Dick Kennedy | d91e3ab | 2020-06-30 14:49:52 -0700 | [diff] [blame] | 261 | lpfc_vpd_data + offset, i); |
| 262 | offset += i; |
| 263 | } while (offset < DMP_VPD_SIZE); |
| 264 | |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 265 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 266 | |
| 267 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 268 | out_free_mbox: |
| 269 | mempool_free(pmb, phba->mbox_mem_pool); |
| 270 | return 0; |
| 271 | } |
| 272 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 273 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 274 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 275 | * @phba: pointer to lpfc hba data structure. |
| 276 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 277 | * |
| 278 | * This is the completion handler for driver's configuring asynchronous event |
| 279 | * mailbox command to the device. If the mailbox command returns successfully, |
| 280 | * it will set internal async event support flag to 1; otherwise, it will |
| 281 | * set internal async event support flag to 0. |
| 282 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 283 | static void |
| 284 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 285 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 286 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 287 | phba->temp_sensor_support = 1; |
| 288 | else |
| 289 | phba->temp_sensor_support = 0; |
| 290 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 291 | return; |
| 292 | } |
| 293 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 294 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 295 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 296 | * @phba: pointer to lpfc hba data structure. |
| 297 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 298 | * |
| 299 | * This is the completion handler for dump mailbox command for getting |
| 300 | * wake up parameters. When this command complete, the response contain |
| 301 | * Option rom version of the HBA. This function translate the version number |
| 302 | * into a human readable string and store it in OptionROMVersion. |
| 303 | **/ |
| 304 | static void |
| 305 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 306 | { |
| 307 | struct prog_id *prg; |
| 308 | uint32_t prog_id_word; |
| 309 | char dist = ' '; |
| 310 | /* character array used for decoding dist type. */ |
| 311 | char dist_char[] = "nabx"; |
| 312 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 313 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 314 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 315 | return; |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 316 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 317 | |
| 318 | prg = (struct prog_id *) &prog_id_word; |
| 319 | |
| 320 | /* word 7 contain option rom version */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 321 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 322 | |
| 323 | /* Decode the Option rom version word to a readable string */ |
| 324 | if (prg->dist < 4) |
| 325 | dist = dist_char[prg->dist]; |
| 326 | |
| 327 | if ((prg->dist == 3) && (prg->num == 0)) |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 328 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 329 | prg->ver, prg->rev, prg->lev); |
| 330 | else |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 331 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d", |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 332 | prg->ver, prg->rev, prg->lev, |
| 333 | dist, prg->num); |
James Smart | 9f1e1b5 | 2008-12-04 22:39:40 -0500 | [diff] [blame] | 334 | mempool_free(pmboxq, phba->mbox_mem_pool); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 335 | return; |
| 336 | } |
| 337 | |
| 338 | /** |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 339 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, |
| 340 | * cfg_soft_wwnn, cfg_soft_wwpn |
| 341 | * @vport: pointer to lpfc vport data structure. |
| 342 | * |
| 343 | * |
| 344 | * Return codes |
| 345 | * None. |
| 346 | **/ |
| 347 | void |
| 348 | lpfc_update_vport_wwn(struct lpfc_vport *vport) |
| 349 | { |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 350 | uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level; |
| 351 | u32 *fawwpn_key = (u32 *)&vport->fc_sparam.un.vendorVersion[0]; |
| 352 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 353 | /* If the soft name exists then update it using the service params */ |
| 354 | if (vport->phba->cfg_soft_wwnn) |
| 355 | u64_to_wwn(vport->phba->cfg_soft_wwnn, |
| 356 | vport->fc_sparam.nodeName.u.wwn); |
| 357 | if (vport->phba->cfg_soft_wwpn) |
| 358 | u64_to_wwn(vport->phba->cfg_soft_wwpn, |
| 359 | vport->fc_sparam.portName.u.wwn); |
| 360 | |
| 361 | /* |
| 362 | * If the name is empty or there exists a soft name |
| 363 | * then copy the service params name, otherwise use the fc name |
| 364 | */ |
| 365 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) |
| 366 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| 367 | sizeof(struct lpfc_name)); |
| 368 | else |
| 369 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, |
| 370 | sizeof(struct lpfc_name)); |
| 371 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 372 | /* |
| 373 | * If the port name has changed, then set the Param changes flag |
| 374 | * to unreg the login |
| 375 | */ |
| 376 | if (vport->fc_portname.u.wwn[0] != 0 && |
| 377 | memcmp(&vport->fc_portname, &vport->fc_sparam.portName, |
| 378 | sizeof(struct lpfc_name))) |
| 379 | vport->vport_flag |= FAWWPN_PARAM_CHG; |
| 380 | |
| 381 | if (vport->fc_portname.u.wwn[0] == 0 || |
| 382 | vport->phba->cfg_soft_wwpn || |
| 383 | (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) || |
| 384 | vport->vport_flag & FAWWPN_SET) { |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 385 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| 386 | sizeof(struct lpfc_name)); |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 387 | vport->vport_flag &= ~FAWWPN_SET; |
| 388 | if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) |
| 389 | vport->vport_flag |= FAWWPN_SET; |
| 390 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 391 | else |
| 392 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, |
| 393 | sizeof(struct lpfc_name)); |
| 394 | } |
| 395 | |
| 396 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 397 | * lpfc_config_port_post - Perform lpfc initialization after config port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 398 | * @phba: pointer to lpfc hba data structure. |
| 399 | * |
| 400 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 401 | * command call. It performs all internal resource and state setups on the |
| 402 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 403 | * ELS ring timers, etc. |
| 404 | * |
| 405 | * Return codes |
| 406 | * 0 - success. |
| 407 | * Any other value - error. |
| 408 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 409 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 410 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 411 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 412 | struct lpfc_vport *vport = phba->pport; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 413 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 414 | LPFC_MBOXQ_t *pmb; |
| 415 | MAILBOX_t *mb; |
| 416 | struct lpfc_dmabuf *mp; |
| 417 | struct lpfc_sli *psli = &phba->sli; |
| 418 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 419 | int i, j; |
| 420 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 421 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 422 | spin_lock_irq(&phba->hbalock); |
| 423 | /* |
| 424 | * If the Config port completed correctly the HBA is not |
| 425 | * over heated any more. |
| 426 | */ |
| 427 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 428 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 429 | spin_unlock_irq(&phba->hbalock); |
| 430 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 431 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 432 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 433 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 434 | return -ENOMEM; |
| 435 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 436 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 437 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 438 | /* Get login parameters for NID. */ |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 439 | rc = lpfc_read_sparam(phba, pmb, 0); |
| 440 | if (rc) { |
| 441 | mempool_free(pmb, phba->mbox_mem_pool); |
| 442 | return -ENOMEM; |
| 443 | } |
| 444 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 445 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 446 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 447 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 448 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 449 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 450 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 451 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 452 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 453 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 454 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 455 | kfree(mp); |
| 456 | return -EIO; |
| 457 | } |
| 458 | |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 459 | mp = (struct lpfc_dmabuf *)pmb->ctx_buf; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 461 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 462 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 463 | kfree(mp); |
James Smart | 3e1f071 | 2018-11-29 16:09:29 -0800 | [diff] [blame] | 464 | pmb->ctx_buf = NULL; |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 465 | lpfc_update_vport_wwn(vport); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 466 | |
| 467 | /* Update the fc_host data structures with new wwn. */ |
| 468 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 469 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 470 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 471 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 472 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 473 | /* This should be consolidated into parse_vpd ? - mr */ |
| 474 | if (phba->SerialNumber[0] == 0) { |
| 475 | uint8_t *outptr; |
| 476 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 477 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 478 | for (i = 0; i < 12; i++) { |
| 479 | status = *outptr++; |
| 480 | j = ((status & 0xf0) >> 4); |
| 481 | if (j <= 9) |
| 482 | phba->SerialNumber[i] = |
| 483 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 484 | else |
| 485 | phba->SerialNumber[i] = |
| 486 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 487 | i++; |
| 488 | j = (status & 0xf); |
| 489 | if (j <= 9) |
| 490 | phba->SerialNumber[i] = |
| 491 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 492 | else |
| 493 | phba->SerialNumber[i] = |
| 494 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 495 | } |
| 496 | } |
| 497 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 498 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 499 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 500 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 501 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 502 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 503 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 504 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 505 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 506 | mempool_free( pmb, phba->mbox_mem_pool); |
| 507 | return -EIO; |
| 508 | } |
| 509 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 510 | /* Check if the port is disabled */ |
| 511 | lpfc_sli_read_link_ste(phba); |
| 512 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 513 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | f6770e7 | 2020-01-27 16:23:09 -0800 | [diff] [blame] | 514 | if (phba->cfg_hba_queue_depth > mb->un.varRdConfig.max_xri) { |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 515 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 516 | "3359 HBA queue depth changed from %d to %d\n", |
James Smart | f6770e7 | 2020-01-27 16:23:09 -0800 | [diff] [blame] | 517 | phba->cfg_hba_queue_depth, |
| 518 | mb->un.varRdConfig.max_xri); |
| 519 | phba->cfg_hba_queue_depth = mb->un.varRdConfig.max_xri; |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 520 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 521 | |
| 522 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 523 | |
| 524 | /* Get the default values for Model Name and Description */ |
| 525 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 526 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 527 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 528 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 529 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 530 | if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr) |
| 531 | psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| 532 | if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr) |
| 533 | psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 534 | |
| 535 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 536 | if (phba->sli_rev != 3) |
| 537 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 538 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 539 | /* |
| 540 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 541 | */ |
| 542 | if (phba->intr_type == MSIX) { |
| 543 | rc = lpfc_config_msi(phba, pmb); |
| 544 | if (rc) { |
| 545 | mempool_free(pmb, phba->mbox_mem_pool); |
| 546 | return -EIO; |
| 547 | } |
| 548 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 549 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 550 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 551 | "0352 Config MSI mailbox command " |
| 552 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 553 | pmb->u.mb.mbxCommand, |
| 554 | pmb->u.mb.mbxStatus); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 555 | mempool_free(pmb, phba->mbox_mem_pool); |
| 556 | return -EIO; |
| 557 | } |
| 558 | } |
| 559 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 560 | spin_lock_irq(&phba->hbalock); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 561 | /* Initialize ERATT handling flag */ |
| 562 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 563 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 564 | /* Enable appropriate host interrupts */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 565 | if (lpfc_readl(phba->HCregaddr, &status)) { |
| 566 | spin_unlock_irq(&phba->hbalock); |
| 567 | return -EIO; |
| 568 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 569 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 570 | if (psli->num_rings > 0) |
| 571 | status |= HC_R0INT_ENA; |
| 572 | if (psli->num_rings > 1) |
| 573 | status |= HC_R1INT_ENA; |
| 574 | if (psli->num_rings > 2) |
| 575 | status |= HC_R2INT_ENA; |
| 576 | if (psli->num_rings > 3) |
| 577 | status |= HC_R3INT_ENA; |
| 578 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 579 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 580 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 581 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 582 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 583 | writel(status, phba->HCregaddr); |
| 584 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 585 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 586 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 587 | /* Set up ring-0 (ELS) timer */ |
| 588 | timeout = phba->fc_ratov * 2; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 589 | mod_timer(&vport->els_tmofunc, |
| 590 | jiffies + msecs_to_jiffies(1000 * timeout)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 591 | /* Set up heart beat (HB) timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 592 | mod_timer(&phba->hb_tmofunc, |
| 593 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 594 | phba->hb_outstanding = 0; |
| 595 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 596 | /* Set up error attention (ERATT) polling timer */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 597 | mod_timer(&phba->eratt_poll, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 598 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 599 | |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 600 | if (phba->hba_flag & LINK_DISABLED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 601 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 602 | "2598 Adapter Link is disabled.\n"); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 603 | lpfc_down_link(phba, pmb); |
| 604 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 605 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 606 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 607 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 608 | "2599 Adapter failed to issue DOWN_LINK" |
| 609 | " mbox command rc 0x%x\n", rc); |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 610 | |
| 611 | mempool_free(pmb, phba->mbox_mem_pool); |
| 612 | return -EIO; |
| 613 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 614 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 615 | mempool_free(pmb, phba->mbox_mem_pool); |
| 616 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
| 617 | if (rc) |
| 618 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 619 | } |
| 620 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 621 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 622 | if (!pmb) { |
| 623 | phba->link_state = LPFC_HBA_ERROR; |
| 624 | return -ENOMEM; |
| 625 | } |
| 626 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 627 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 628 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 629 | pmb->vport = phba->pport; |
| 630 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 631 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 632 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 633 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 634 | "0456 Adapter failed to issue " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 635 | "ASYNCEVT_ENABLE mbox status x%x\n", |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 636 | rc); |
| 637 | mempool_free(pmb, phba->mbox_mem_pool); |
| 638 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 639 | |
| 640 | /* Get Option rom version */ |
| 641 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 9f1177a | 2010-02-26 14:12:57 -0500 | [diff] [blame] | 642 | if (!pmb) { |
| 643 | phba->link_state = LPFC_HBA_ERROR; |
| 644 | return -ENOMEM; |
| 645 | } |
| 646 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 647 | lpfc_dump_wakeup_param(phba, pmb); |
| 648 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 649 | pmb->vport = phba->pport; |
| 650 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 651 | |
| 652 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 653 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 654 | "0435 Adapter failed " |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 655 | "to get Option ROM version status x%x\n", rc); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 656 | mempool_free(pmb, phba->mbox_mem_pool); |
| 657 | } |
| 658 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 659 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 660 | } |
| 661 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 662 | /** |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 663 | * lpfc_hba_init_link - Initialize the FC link |
| 664 | * @phba: pointer to lpfc hba data structure. |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 665 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 666 | * |
| 667 | * This routine will issue the INIT_LINK mailbox command call. |
| 668 | * It is available to other drivers through the lpfc_hba data |
| 669 | * structure for use as a delayed link up mechanism with the |
| 670 | * module parameter lpfc_suppress_link_up. |
| 671 | * |
| 672 | * Return code |
| 673 | * 0 - success |
| 674 | * Any other value - error |
| 675 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 676 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 677 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 678 | { |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 679 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology |
| 684 | * @phba: pointer to lpfc hba data structure. |
| 685 | * @fc_topology: desired fc topology. |
| 686 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
| 687 | * |
| 688 | * This routine will issue the INIT_LINK mailbox command call. |
| 689 | * It is available to other drivers through the lpfc_hba data |
| 690 | * structure for use as a delayed link up mechanism with the |
| 691 | * module parameter lpfc_suppress_link_up. |
| 692 | * |
| 693 | * Return code |
| 694 | * 0 - success |
| 695 | * Any other value - error |
| 696 | **/ |
| 697 | int |
| 698 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, |
| 699 | uint32_t flag) |
| 700 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 701 | struct lpfc_vport *vport = phba->pport; |
| 702 | LPFC_MBOXQ_t *pmb; |
| 703 | MAILBOX_t *mb; |
| 704 | int rc; |
| 705 | |
| 706 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 707 | if (!pmb) { |
| 708 | phba->link_state = LPFC_HBA_ERROR; |
| 709 | return -ENOMEM; |
| 710 | } |
| 711 | mb = &pmb->u.mb; |
| 712 | pmb->vport = vport; |
| 713 | |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 714 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
| 715 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && |
| 716 | !(phba->lmt & LMT_1Gb)) || |
| 717 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && |
| 718 | !(phba->lmt & LMT_2Gb)) || |
| 719 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && |
| 720 | !(phba->lmt & LMT_4Gb)) || |
| 721 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && |
| 722 | !(phba->lmt & LMT_8Gb)) || |
| 723 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && |
| 724 | !(phba->lmt & LMT_10Gb)) || |
| 725 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 726 | !(phba->lmt & LMT_16Gb)) || |
| 727 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) && |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 728 | !(phba->lmt & LMT_32Gb)) || |
| 729 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_64G) && |
| 730 | !(phba->lmt & LMT_64Gb))) { |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 731 | /* Reset link speed to auto */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 732 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 733 | "1302 Invalid speed for this board:%d " |
| 734 | "Reset link speed to auto.\n", |
| 735 | phba->cfg_link_speed); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 736 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
| 737 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 738 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 739 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 740 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 741 | lpfc_set_loopback_flag(phba); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 742 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 743 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 744 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 745 | "0498 Adapter failed to init, mbxCmd x%x " |
| 746 | "INIT_LINK, mbxStatus x%x\n", |
| 747 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 748 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 749 | /* Clear all interrupt enable conditions */ |
| 750 | writel(0, phba->HCregaddr); |
| 751 | readl(phba->HCregaddr); /* flush */ |
| 752 | /* Clear all pending interrupts */ |
| 753 | writel(0xffffffff, phba->HAregaddr); |
| 754 | readl(phba->HAregaddr); /* flush */ |
| 755 | } |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 756 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 757 | if (rc != MBX_BUSY || flag == MBX_POLL) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 758 | mempool_free(pmb, phba->mbox_mem_pool); |
| 759 | return -EIO; |
| 760 | } |
James Smart | e40a02c | 2010-02-26 14:13:54 -0500 | [diff] [blame] | 761 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 762 | if (flag == MBX_POLL) |
| 763 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 764 | |
| 765 | return 0; |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * lpfc_hba_down_link - this routine downs the FC link |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 770 | * @phba: pointer to lpfc hba data structure. |
| 771 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 772 | * |
| 773 | * This routine will issue the DOWN_LINK mailbox command call. |
| 774 | * It is available to other drivers through the lpfc_hba data |
| 775 | * structure for use to stop the link. |
| 776 | * |
| 777 | * Return code |
| 778 | * 0 - success |
| 779 | * Any other value - error |
| 780 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 781 | static int |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 782 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 783 | { |
| 784 | LPFC_MBOXQ_t *pmb; |
| 785 | int rc; |
| 786 | |
| 787 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 788 | if (!pmb) { |
| 789 | phba->link_state = LPFC_HBA_ERROR; |
| 790 | return -ENOMEM; |
| 791 | } |
| 792 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 793 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 794 | "0491 Adapter Link is disabled.\n"); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 795 | lpfc_down_link(phba, pmb); |
| 796 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 797 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 798 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 799 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 800 | "2522 Adapter failed to issue DOWN_LINK" |
| 801 | " mbox command rc 0x%x\n", rc); |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 802 | |
| 803 | mempool_free(pmb, phba->mbox_mem_pool); |
| 804 | return -EIO; |
| 805 | } |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 806 | if (flag == MBX_POLL) |
| 807 | mempool_free(pmb, phba->mbox_mem_pool); |
| 808 | |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 813 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 814 | * @phba: pointer to lpfc HBA data structure. |
| 815 | * |
| 816 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 817 | * bringing down the SLI Layer. |
| 818 | * |
| 819 | * Return codes |
| 820 | * 0 - success. |
| 821 | * Any other value - error. |
| 822 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 823 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 824 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 825 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 826 | struct lpfc_vport **vports; |
| 827 | int i; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 828 | |
| 829 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 830 | /* Disable interrupts */ |
| 831 | writel(0, phba->HCregaddr); |
| 832 | readl(phba->HCregaddr); /* flush */ |
| 833 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 834 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 835 | if (phba->pport->load_flag & FC_UNLOADING) |
| 836 | lpfc_cleanup_discovery_resources(phba->pport); |
| 837 | else { |
| 838 | vports = lpfc_create_vport_work_array(phba); |
| 839 | if (vports != NULL) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 840 | for (i = 0; i <= phba->max_vports && |
| 841 | vports[i] != NULL; i++) |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 842 | lpfc_cleanup_discovery_resources(vports[i]); |
| 843 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 844 | } |
| 845 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 846 | } |
| 847 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 848 | /** |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 849 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free |
| 850 | * rspiocb which got deferred |
| 851 | * |
| 852 | * @phba: pointer to lpfc HBA data structure. |
| 853 | * |
| 854 | * This routine will cleanup completed slow path events after HBA is reset |
| 855 | * when bringing down the SLI Layer. |
| 856 | * |
| 857 | * |
| 858 | * Return codes |
| 859 | * void. |
| 860 | **/ |
| 861 | static void |
| 862 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) |
| 863 | { |
| 864 | struct lpfc_iocbq *rspiocbq; |
| 865 | struct hbq_dmabuf *dmabuf; |
| 866 | struct lpfc_cq_event *cq_event; |
| 867 | |
| 868 | spin_lock_irq(&phba->hbalock); |
| 869 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; |
| 870 | spin_unlock_irq(&phba->hbalock); |
| 871 | |
| 872 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { |
| 873 | /* Get the response iocb from the head of work queue */ |
| 874 | spin_lock_irq(&phba->hbalock); |
| 875 | list_remove_head(&phba->sli4_hba.sp_queue_event, |
| 876 | cq_event, struct lpfc_cq_event, list); |
| 877 | spin_unlock_irq(&phba->hbalock); |
| 878 | |
| 879 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { |
| 880 | case CQE_CODE_COMPL_WQE: |
| 881 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, |
| 882 | cq_event); |
| 883 | lpfc_sli_release_iocbq(phba, rspiocbq); |
| 884 | break; |
| 885 | case CQE_CODE_RECEIVE: |
| 886 | case CQE_CODE_RECEIVE_V1: |
| 887 | dmabuf = container_of(cq_event, struct hbq_dmabuf, |
| 888 | cq_event); |
| 889 | lpfc_in_buf_free(phba, &dmabuf->dbuf); |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | /** |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 895 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
| 896 | * @phba: pointer to lpfc HBA data structure. |
| 897 | * |
| 898 | * This routine will cleanup posted ELS buffers after the HBA is reset |
| 899 | * when bringing down the SLI Layer. |
| 900 | * |
| 901 | * |
| 902 | * Return codes |
| 903 | * void. |
| 904 | **/ |
| 905 | static void |
| 906 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) |
| 907 | { |
| 908 | struct lpfc_sli *psli = &phba->sli; |
| 909 | struct lpfc_sli_ring *pring; |
| 910 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 911 | LIST_HEAD(buflist); |
| 912 | int count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 913 | |
| 914 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 915 | lpfc_sli_hbqbuf_free_all(phba); |
| 916 | else { |
| 917 | /* Cleanup preposted buffers on the ELS ring */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 918 | pring = &psli->sli3_ring[LPFC_ELS_RING]; |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 919 | spin_lock_irq(&phba->hbalock); |
| 920 | list_splice_init(&pring->postbufq, &buflist); |
| 921 | spin_unlock_irq(&phba->hbalock); |
| 922 | |
| 923 | count = 0; |
| 924 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 925 | list_del(&mp->list); |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 926 | count++; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 927 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 928 | kfree(mp); |
| 929 | } |
James Smart | 07eab62 | 2014-04-04 13:51:44 -0400 | [diff] [blame] | 930 | |
| 931 | spin_lock_irq(&phba->hbalock); |
| 932 | pring->postbufq_cnt -= count; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 933 | spin_unlock_irq(&phba->hbalock); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | /** |
| 938 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset |
| 939 | * @phba: pointer to lpfc HBA data structure. |
| 940 | * |
| 941 | * This routine will cleanup the txcmplq after the HBA is reset when bringing |
| 942 | * down the SLI Layer. |
| 943 | * |
| 944 | * Return codes |
| 945 | * void |
| 946 | **/ |
| 947 | static void |
| 948 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) |
| 949 | { |
| 950 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 951 | struct lpfc_queue *qp = NULL; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 952 | struct lpfc_sli_ring *pring; |
| 953 | LIST_HEAD(completions); |
| 954 | int i; |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 955 | struct lpfc_iocbq *piocb, *next_iocb; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 956 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 957 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 958 | for (i = 0; i < psli->num_rings; i++) { |
| 959 | pring = &psli->sli3_ring[i]; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 960 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 961 | /* At this point in time the HBA is either reset or DOA |
| 962 | * Nothing should be on txcmplq as it will |
| 963 | * NEVER complete. |
| 964 | */ |
| 965 | list_splice_init(&pring->txcmplq, &completions); |
| 966 | pring->txcmplq_cnt = 0; |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 967 | spin_unlock_irq(&phba->hbalock); |
| 968 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 969 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 970 | } |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 971 | /* Cancel all the IOCBs from the completions list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 972 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 973 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
| 974 | return; |
| 975 | } |
| 976 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { |
| 977 | pring = qp->pring; |
| 978 | if (!pring) |
| 979 | continue; |
| 980 | spin_lock_irq(&pring->ring_lock); |
James Smart | c1dd911 | 2018-01-30 15:58:57 -0800 | [diff] [blame] | 981 | list_for_each_entry_safe(piocb, next_iocb, |
| 982 | &pring->txcmplq, list) |
| 983 | piocb->iocb_flag &= ~LPFC_IO_ON_TXCMPLQ; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 984 | list_splice_init(&pring->txcmplq, &completions); |
| 985 | pring->txcmplq_cnt = 0; |
| 986 | spin_unlock_irq(&pring->ring_lock); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 987 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 988 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 989 | /* Cancel all the IOCBs from the completions list */ |
| 990 | lpfc_sli_cancel_iocbs(phba, &completions, |
| 991 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 995 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 996 | * @phba: pointer to lpfc HBA data structure. |
| 997 | * |
| 998 | * This routine will do uninitialization after the HBA is reset when bring |
| 999 | * down the SLI Layer. |
| 1000 | * |
| 1001 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1002 | * 0 - success. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1003 | * Any other value - error. |
| 1004 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1005 | static int |
| 1006 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1007 | { |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1008 | lpfc_hba_free_post_buf(phba); |
| 1009 | lpfc_hba_clean_txcmplq(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1010 | return 0; |
| 1011 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 1012 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1013 | /** |
| 1014 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset |
| 1015 | * @phba: pointer to lpfc HBA data structure. |
| 1016 | * |
| 1017 | * This routine will do uninitialization after the HBA is reset when bring |
| 1018 | * down the SLI Layer. |
| 1019 | * |
| 1020 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1021 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1022 | * Any other value - error. |
| 1023 | **/ |
| 1024 | static int |
| 1025 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) |
| 1026 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1027 | struct lpfc_io_buf *psb, *psb_next; |
James Smart | 7cacae2 | 2020-03-31 09:50:03 -0700 | [diff] [blame] | 1028 | struct lpfc_async_xchg_ctx *ctxp, *ctxp_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1029 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1030 | LIST_HEAD(aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1031 | LIST_HEAD(nvme_aborts); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1032 | LIST_HEAD(nvmet_aborts); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1033 | struct lpfc_sglq *sglq_entry = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1034 | int cnt, idx; |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1035 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1036 | |
| 1037 | lpfc_sli_hbqbuf_free_all(phba); |
James Smart | bcece5f | 2014-04-04 13:51:34 -0400 | [diff] [blame] | 1038 | lpfc_hba_clean_txcmplq(phba); |
| 1039 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1040 | /* At this point in time the HBA is either reset or DOA. Either |
| 1041 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1042 | * on the lpfc_els_sgl_list so that it can either be freed if the |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1043 | * driver is unloading or reposted if the driver is restarting |
| 1044 | * the port. |
| 1045 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1046 | spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1047 | /* scsl_buf_list */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1048 | /* sgl_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1049 | * list. |
| 1050 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1051 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 0f65ff6 | 2010-02-26 14:14:23 -0500 | [diff] [blame] | 1052 | list_for_each_entry(sglq_entry, |
| 1053 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) |
| 1054 | sglq_entry->state = SGL_FREED; |
| 1055 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1056 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1057 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 1058 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 1059 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1060 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1061 | |
| 1062 | /* abts_xxxx_buf_list_lock required because worker thread uses this |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1063 | * list. |
| 1064 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1065 | cnt = 0; |
| 1066 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 1067 | qp = &phba->sli4_hba.hdwq[idx]; |
| 1068 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1069 | spin_lock(&qp->abts_io_buf_list_lock); |
| 1070 | list_splice_init(&qp->lpfc_abts_io_buf_list, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1071 | &aborts); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1072 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 1073 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1074 | psb->pCmd = NULL; |
| 1075 | psb->status = IOSTAT_SUCCESS; |
James Smart | cf1a1d3 | 2017-12-08 17:18:03 -0800 | [diff] [blame] | 1076 | cnt++; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1077 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1078 | spin_lock(&qp->io_buf_list_put_lock); |
| 1079 | list_splice_init(&aborts, &qp->lpfc_io_buf_list_put); |
| 1080 | qp->put_io_bufs += qp->abts_scsi_io_bufs; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1081 | qp->put_io_bufs += qp->abts_nvme_io_bufs; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1082 | qp->abts_scsi_io_bufs = 0; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1083 | qp->abts_nvme_io_bufs = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1084 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1085 | spin_unlock(&qp->abts_io_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1086 | } |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1087 | spin_unlock_irq(&phba->hbalock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1088 | |
| 1089 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1090 | spin_lock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1091 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list, |
| 1092 | &nvmet_aborts); |
James Smart | 731eedc | 2019-03-12 16:30:12 -0700 | [diff] [blame] | 1093 | spin_unlock_irq(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1094 | list_for_each_entry_safe(ctxp, ctxp_next, &nvmet_aborts, list) { |
James Smart | 7b7f551 | 2020-03-31 09:50:04 -0700 | [diff] [blame] | 1095 | ctxp->flag &= ~(LPFC_NVME_XBUSY | LPFC_NVME_ABORT_OP); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 1096 | lpfc_nvmet_ctxbuf_post(phba, ctxp->ctxbuf); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 1097 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1098 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 1099 | |
James Smart | 68e814f | 2014-05-21 08:04:59 -0400 | [diff] [blame] | 1100 | lpfc_sli4_free_sp_events(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 1101 | return cnt; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | /** |
| 1105 | * lpfc_hba_down_post - Wrapper func for hba down post routine |
| 1106 | * @phba: pointer to lpfc HBA data structure. |
| 1107 | * |
| 1108 | * This routine wraps the actual SLI3 or SLI4 routine for performing |
| 1109 | * uninitialization after the HBA is reset when bring down the SLI Layer. |
| 1110 | * |
| 1111 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 1112 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1113 | * Any other value - error. |
| 1114 | **/ |
| 1115 | int |
| 1116 | lpfc_hba_down_post(struct lpfc_hba *phba) |
| 1117 | { |
| 1118 | return (*phba->lpfc_hba_down_post)(phba); |
| 1119 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1120 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1121 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1122 | * lpfc_hb_timeout - The HBA-timer timeout handler |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1123 | * @t: timer context used to obtain the pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1124 | * |
| 1125 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 1126 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 1127 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1128 | * event will be used by the worker thread to invoke the actual timeout |
| 1129 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 1130 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 1131 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1132 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1133 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1134 | lpfc_hb_timeout(struct timer_list *t) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1135 | { |
| 1136 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1137 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1138 | unsigned long iflag; |
| 1139 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1140 | phba = from_timer(phba, t, hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1141 | |
| 1142 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1143 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1144 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 1145 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1146 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 1147 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 1148 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1149 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 1150 | if (!tmo_posted) |
| 1151 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1152 | return; |
| 1153 | } |
| 1154 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1155 | /** |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1156 | * lpfc_rrq_timeout - The RRQ-timer timeout handler |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1157 | * @t: timer context used to obtain the pointer to lpfc hba data structure. |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1158 | * |
| 1159 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When |
| 1160 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver |
| 1161 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 1162 | * event will be used by the worker thread to invoke the actual timeout |
| 1163 | * handler routine, lpfc_rrq_handler. Any periodical operations will |
| 1164 | * be performed in the timeout handler and the RRQ timeout event bit shall |
| 1165 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 1166 | **/ |
| 1167 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1168 | lpfc_rrq_timeout(struct timer_list *t) |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1169 | { |
| 1170 | struct lpfc_hba *phba; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1171 | unsigned long iflag; |
| 1172 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 1173 | phba = from_timer(phba, t, rrq_tmr); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1174 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1175 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1176 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
| 1177 | else |
| 1178 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1179 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
James Smart | 06918ac | 2014-02-20 09:57:57 -0500 | [diff] [blame] | 1180 | |
| 1181 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 1182 | lpfc_worker_wake_up(phba); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1186 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1187 | * @phba: pointer to lpfc hba data structure. |
| 1188 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 1189 | * |
| 1190 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 1191 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 1192 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 1193 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 1194 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 1195 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 1196 | * no error conditions detected, the heart-beat mailbox command timer is |
| 1197 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 1198 | * state is cleared for the next heart-beat. If the timer expired with the |
| 1199 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 1200 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1201 | static void |
| 1202 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 1203 | { |
| 1204 | unsigned long drvr_flag; |
| 1205 | |
| 1206 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 1207 | phba->hb_outstanding = 0; |
| 1208 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 1209 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1210 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1211 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 1212 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 1213 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1214 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1215 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1216 | jiffies + |
| 1217 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1218 | return; |
| 1219 | } |
| 1220 | |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1221 | /* |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 1222 | * lpfc_idle_stat_delay_work - idle_stat tracking |
| 1223 | * |
| 1224 | * This routine tracks per-cq idle_stat and determines polling decisions. |
| 1225 | * |
| 1226 | * Return codes: |
| 1227 | * None |
| 1228 | **/ |
| 1229 | static void |
| 1230 | lpfc_idle_stat_delay_work(struct work_struct *work) |
| 1231 | { |
| 1232 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1233 | struct lpfc_hba, |
| 1234 | idle_stat_delay_work); |
| 1235 | struct lpfc_queue *cq; |
| 1236 | struct lpfc_sli4_hdw_queue *hdwq; |
| 1237 | struct lpfc_idle_stat *idle_stat; |
| 1238 | u32 i, idle_percent; |
| 1239 | u64 wall, wall_idle, diff_wall, diff_idle, busy_time; |
| 1240 | |
| 1241 | if (phba->pport->load_flag & FC_UNLOADING) |
| 1242 | return; |
| 1243 | |
| 1244 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1245 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1246 | goto requeue; |
| 1247 | |
| 1248 | for_each_present_cpu(i) { |
| 1249 | hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq]; |
| 1250 | cq = hdwq->io_cq; |
| 1251 | |
| 1252 | /* Skip if we've already handled this cq's primary CPU */ |
| 1253 | if (cq->chann != i) |
| 1254 | continue; |
| 1255 | |
| 1256 | idle_stat = &phba->sli4_hba.idle_stat[i]; |
| 1257 | |
| 1258 | /* get_cpu_idle_time returns values as running counters. Thus, |
| 1259 | * to know the amount for this period, the prior counter values |
| 1260 | * need to be subtracted from the current counter values. |
| 1261 | * From there, the idle time stat can be calculated as a |
| 1262 | * percentage of 100 - the sum of the other consumption times. |
| 1263 | */ |
| 1264 | wall_idle = get_cpu_idle_time(i, &wall, 1); |
| 1265 | diff_idle = wall_idle - idle_stat->prev_idle; |
| 1266 | diff_wall = wall - idle_stat->prev_wall; |
| 1267 | |
| 1268 | if (diff_wall <= diff_idle) |
| 1269 | busy_time = 0; |
| 1270 | else |
| 1271 | busy_time = diff_wall - diff_idle; |
| 1272 | |
| 1273 | idle_percent = div64_u64(100 * busy_time, diff_wall); |
| 1274 | idle_percent = 100 - idle_percent; |
| 1275 | |
| 1276 | if (idle_percent < 15) |
| 1277 | cq->poll_mode = LPFC_QUEUE_WORK; |
| 1278 | else |
| 1279 | cq->poll_mode = LPFC_IRQ_POLL; |
| 1280 | |
| 1281 | idle_stat->prev_idle = wall_idle; |
| 1282 | idle_stat->prev_wall = wall; |
| 1283 | } |
| 1284 | |
| 1285 | requeue: |
| 1286 | schedule_delayed_work(&phba->idle_stat_delay_work, |
| 1287 | msecs_to_jiffies(LPFC_IDLE_STAT_DELAY)); |
| 1288 | } |
| 1289 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1290 | static void |
| 1291 | lpfc_hb_eq_delay_work(struct work_struct *work) |
| 1292 | { |
| 1293 | struct lpfc_hba *phba = container_of(to_delayed_work(work), |
| 1294 | struct lpfc_hba, eq_delay_work); |
| 1295 | struct lpfc_eq_intr_info *eqi, *eqi_new; |
| 1296 | struct lpfc_queue *eq, *eq_next; |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1297 | unsigned char *ena_delay = NULL; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1298 | uint32_t usdelay; |
| 1299 | int i; |
| 1300 | |
| 1301 | if (!phba->cfg_auto_imax || phba->pport->load_flag & FC_UNLOADING) |
| 1302 | return; |
| 1303 | |
| 1304 | if (phba->link_state == LPFC_HBA_ERROR || |
| 1305 | phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 1306 | goto requeue; |
| 1307 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1308 | ena_delay = kcalloc(phba->sli4_hba.num_possible_cpu, sizeof(*ena_delay), |
| 1309 | GFP_KERNEL); |
| 1310 | if (!ena_delay) |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1311 | goto requeue; |
| 1312 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1313 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 1314 | /* Get the EQ corresponding to the IRQ vector */ |
| 1315 | eq = phba->sli4_hba.hba_eq_hdl[i].eq; |
| 1316 | if (!eq) |
| 1317 | continue; |
| 1318 | if (eq->q_mode || eq->q_flag & HBA_EQ_DELAY_CHK) { |
| 1319 | eq->q_flag &= ~HBA_EQ_DELAY_CHK; |
| 1320 | ena_delay[eq->last_cpu] = 1; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame] | 1321 | } |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1322 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1323 | |
| 1324 | for_each_present_cpu(i) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1325 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, i); |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1326 | if (ena_delay[i]) { |
| 1327 | usdelay = (eqi->icnt >> 10) * LPFC_EQ_DELAY_STEP; |
| 1328 | if (usdelay > LPFC_MAX_AUTO_EQ_DELAY) |
| 1329 | usdelay = LPFC_MAX_AUTO_EQ_DELAY; |
| 1330 | } else { |
| 1331 | usdelay = 0; |
James Smart | 8d34a59 | 2019-08-14 16:56:35 -0700 | [diff] [blame] | 1332 | } |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1333 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1334 | eqi->icnt = 0; |
| 1335 | |
| 1336 | list_for_each_entry_safe(eq, eq_next, &eqi->list, cpu_list) { |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1337 | if (unlikely(eq->last_cpu != i)) { |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1338 | eqi_new = per_cpu_ptr(phba->sli4_hba.eq_info, |
| 1339 | eq->last_cpu); |
| 1340 | list_move_tail(&eq->cpu_list, &eqi_new->list); |
| 1341 | continue; |
| 1342 | } |
| 1343 | if (usdelay != eq->q_mode) |
| 1344 | lpfc_modify_hba_eq_delay(phba, eq->hdwq, 1, |
| 1345 | usdelay); |
| 1346 | } |
| 1347 | } |
| 1348 | |
James Smart | 8156d37 | 2019-10-18 14:18:26 -0700 | [diff] [blame] | 1349 | kfree(ena_delay); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 1350 | |
| 1351 | requeue: |
| 1352 | queue_delayed_work(phba->wq, &phba->eq_delay_work, |
| 1353 | msecs_to_jiffies(LPFC_EQ_DELAY_MSECS)); |
| 1354 | } |
| 1355 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1356 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1357 | * lpfc_hb_mxp_handler - Multi-XRI pools handler to adjust XRI distribution |
| 1358 | * @phba: pointer to lpfc hba data structure. |
| 1359 | * |
| 1360 | * For each heartbeat, this routine does some heuristic methods to adjust |
| 1361 | * XRI distribution. The goal is to fully utilize free XRIs. |
| 1362 | **/ |
| 1363 | static void lpfc_hb_mxp_handler(struct lpfc_hba *phba) |
| 1364 | { |
| 1365 | u32 i; |
| 1366 | u32 hwq_count; |
| 1367 | |
| 1368 | hwq_count = phba->cfg_hdw_queue; |
| 1369 | for (i = 0; i < hwq_count; i++) { |
| 1370 | /* Adjust XRIs in private pool */ |
| 1371 | lpfc_adjust_pvt_pool_count(phba, i); |
| 1372 | |
| 1373 | /* Adjust high watermark */ |
| 1374 | lpfc_adjust_high_watermark(phba, i); |
| 1375 | |
| 1376 | #ifdef LPFC_MXP_STAT |
| 1377 | /* Snapshot pbl, pvt and busy count */ |
| 1378 | lpfc_snapshot_mxp(phba, i); |
| 1379 | #endif |
| 1380 | } |
| 1381 | } |
| 1382 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1383 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1384 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1385 | * @phba: pointer to lpfc hba data structure. |
| 1386 | * |
| 1387 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 1388 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 1389 | * handler performs any periodic operations needed for the device. If such |
| 1390 | * periodic event has already been attended to either in the interrupt handler |
| 1391 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 1392 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 1393 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 1394 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 1395 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 1396 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 1397 | * to offline. |
| 1398 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1399 | void |
| 1400 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 1401 | { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1402 | struct lpfc_vport **vports; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1403 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1404 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1405 | int retval, i; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1406 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1407 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1408 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 1409 | if (phba->cfg_xri_rebalancing) { |
| 1410 | /* Multi-XRI pools handler */ |
| 1411 | lpfc_hb_mxp_handler(phba); |
| 1412 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1413 | |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1414 | vports = lpfc_create_vport_work_array(phba); |
| 1415 | if (vports != NULL) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1416 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1417 | lpfc_rcv_seq_check_edtov(vports[i]); |
James Smart | e3ba04c | 2019-12-18 15:58:02 -0800 | [diff] [blame] | 1418 | lpfc_fdmi_change_check(vports[i]); |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1419 | } |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 1420 | lpfc_destroy_vport_work_array(phba, vports); |
| 1421 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1422 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1423 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1424 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 1425 | return; |
| 1426 | |
| 1427 | spin_lock_irq(&phba->pport->work_port_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1428 | |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1429 | if (time_after(phba->last_completion_time + |
| 1430 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), |
| 1431 | jiffies)) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1432 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1433 | if (!phba->hb_outstanding) |
| 1434 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1435 | jiffies + |
| 1436 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1437 | else |
| 1438 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1439 | jiffies + |
| 1440 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1441 | return; |
| 1442 | } |
| 1443 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 1444 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 1445 | if (phba->elsbuf_cnt && |
| 1446 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 1447 | spin_lock_irq(&phba->hbalock); |
| 1448 | list_splice_init(&phba->elsbuf, &completions); |
| 1449 | phba->elsbuf_cnt = 0; |
| 1450 | phba->elsbuf_prev_cnt = 0; |
| 1451 | spin_unlock_irq(&phba->hbalock); |
| 1452 | |
| 1453 | while (!list_empty(&completions)) { |
| 1454 | list_remove_head(&completions, buf_ptr, |
| 1455 | struct lpfc_dmabuf, list); |
| 1456 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 1457 | kfree(buf_ptr); |
| 1458 | } |
| 1459 | } |
| 1460 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 1461 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1462 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1463 | if (phba->cfg_enable_hba_heartbeat) { |
| 1464 | if (!phba->hb_outstanding) { |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1465 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
| 1466 | (list_empty(&psli->mboxq))) { |
| 1467 | pmboxq = mempool_alloc(phba->mbox_mem_pool, |
| 1468 | GFP_KERNEL); |
| 1469 | if (!pmboxq) { |
| 1470 | mod_timer(&phba->hb_tmofunc, |
| 1471 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1472 | msecs_to_jiffies(1000 * |
| 1473 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1474 | return; |
| 1475 | } |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1476 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1477 | lpfc_heart_beat(phba, pmboxq); |
| 1478 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 1479 | pmboxq->vport = phba->pport; |
| 1480 | retval = lpfc_sli_issue_mbox(phba, pmboxq, |
| 1481 | MBX_NOWAIT); |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1482 | |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1483 | if (retval != MBX_BUSY && |
| 1484 | retval != MBX_SUCCESS) { |
| 1485 | mempool_free(pmboxq, |
| 1486 | phba->mbox_mem_pool); |
| 1487 | mod_timer(&phba->hb_tmofunc, |
| 1488 | jiffies + |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1489 | msecs_to_jiffies(1000 * |
| 1490 | LPFC_HB_MBOX_INTERVAL)); |
James Smart | bc73905 | 2010-08-04 16:11:18 -0400 | [diff] [blame] | 1491 | return; |
| 1492 | } |
| 1493 | phba->skipped_hb = 0; |
| 1494 | phba->hb_outstanding = 1; |
| 1495 | } else if (time_before_eq(phba->last_completion_time, |
| 1496 | phba->skipped_hb)) { |
| 1497 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 1498 | "2857 Last completion time not " |
| 1499 | " updated in %d ms\n", |
| 1500 | jiffies_to_msecs(jiffies |
| 1501 | - phba->last_completion_time)); |
| 1502 | } else |
| 1503 | phba->skipped_hb = jiffies; |
| 1504 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1505 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1506 | jiffies + |
| 1507 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1508 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1509 | } else { |
| 1510 | /* |
| 1511 | * If heart beat timeout called with hb_outstanding set |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1512 | * we need to give the hb mailbox cmd a chance to |
| 1513 | * complete or TMO. |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1514 | */ |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1515 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 1516 | "0459 Adapter heartbeat still out" |
| 1517 | "standing:last compl time was %d ms.\n", |
| 1518 | jiffies_to_msecs(jiffies |
| 1519 | - phba->last_completion_time)); |
| 1520 | mod_timer(&phba->hb_tmofunc, |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 1521 | jiffies + |
| 1522 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1523 | } |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 1524 | } else { |
| 1525 | mod_timer(&phba->hb_tmofunc, |
| 1526 | jiffies + |
| 1527 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1528 | } |
| 1529 | } |
| 1530 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1531 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1532 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1533 | * @phba: pointer to lpfc hba data structure. |
| 1534 | * |
| 1535 | * This routine is called to bring the HBA offline when HBA hardware error |
| 1536 | * other than Port Error 6 has been detected. |
| 1537 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1538 | static void |
| 1539 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 1540 | { |
| 1541 | struct lpfc_sli *psli = &phba->sli; |
| 1542 | |
| 1543 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1544 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1545 | spin_unlock_irq(&phba->hbalock); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1546 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1547 | |
| 1548 | lpfc_offline(phba); |
| 1549 | lpfc_reset_barrier(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1550 | spin_lock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1551 | lpfc_sli_brdreset(phba); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1552 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1553 | lpfc_hba_down_post(phba); |
| 1554 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 1555 | lpfc_unblock_mgmt_io(phba); |
| 1556 | phba->link_state = LPFC_HBA_ERROR; |
| 1557 | return; |
| 1558 | } |
| 1559 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1560 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1561 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention |
| 1562 | * @phba: pointer to lpfc hba data structure. |
| 1563 | * |
| 1564 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error |
| 1565 | * other than Port Error 6 has been detected. |
| 1566 | **/ |
James Smart | a88dbb6 | 2013-04-17 20:18:39 -0400 | [diff] [blame] | 1567 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1568 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
| 1569 | { |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1570 | spin_lock_irq(&phba->hbalock); |
| 1571 | phba->link_state = LPFC_HBA_ERROR; |
| 1572 | spin_unlock_irq(&phba->hbalock); |
| 1573 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1574 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1575 | lpfc_sli_flush_io_rings(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1576 | lpfc_offline(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1577 | lpfc_hba_down_post(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1578 | lpfc_unblock_mgmt_io(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | /** |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1582 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler |
| 1583 | * @phba: pointer to lpfc hba data structure. |
| 1584 | * |
| 1585 | * This routine is invoked to handle the deferred HBA hardware error |
| 1586 | * conditions. This type of error is indicated by HBA by setting ER1 |
| 1587 | * and another ER bit in the host status register. The driver will |
| 1588 | * wait until the ER1 bit clears before handling the error condition. |
| 1589 | **/ |
| 1590 | static void |
| 1591 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) |
| 1592 | { |
| 1593 | uint32_t old_host_status = phba->work_hs; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1594 | struct lpfc_sli *psli = &phba->sli; |
| 1595 | |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1596 | /* If the pci channel is offline, ignore possible errors, |
| 1597 | * since we cannot communicate with the pci card anyway. |
| 1598 | */ |
| 1599 | if (pci_channel_offline(phba->pcidev)) { |
| 1600 | spin_lock_irq(&phba->hbalock); |
| 1601 | phba->hba_flag &= ~DEFER_ERATT; |
| 1602 | spin_unlock_irq(&phba->hbalock); |
| 1603 | return; |
| 1604 | } |
| 1605 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1606 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 1607 | "0479 Deferred Adapter Hardware Error " |
| 1608 | "Data: x%x x%x x%x\n", |
| 1609 | phba->work_hs, phba->work_status[0], |
| 1610 | phba->work_status[1]); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1611 | |
| 1612 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1613 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1614 | spin_unlock_irq(&phba->hbalock); |
| 1615 | |
| 1616 | |
| 1617 | /* |
| 1618 | * Firmware stops when it triggred erratt. That could cause the I/Os |
| 1619 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the |
| 1620 | * SCSI layer retry it after re-establishing link. |
| 1621 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1622 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1623 | |
| 1624 | /* |
| 1625 | * There was a firmware error. Take the hba offline and then |
| 1626 | * attempt to restart it. |
| 1627 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1628 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1629 | lpfc_offline(phba); |
| 1630 | |
| 1631 | /* Wait for the ER1 bit to clear.*/ |
| 1632 | while (phba->work_hs & HS_FFER1) { |
| 1633 | msleep(100); |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 1634 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
| 1635 | phba->work_hs = UNPLUG_ERR ; |
| 1636 | break; |
| 1637 | } |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1638 | /* If driver is unloading let the worker thread continue */ |
| 1639 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 1640 | phba->work_hs = 0; |
| 1641 | break; |
| 1642 | } |
| 1643 | } |
| 1644 | |
| 1645 | /* |
| 1646 | * This is to ptrotect against a race condition in which |
| 1647 | * first write to the host attention register clear the |
| 1648 | * host status register. |
| 1649 | */ |
| 1650 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) |
| 1651 | phba->work_hs = old_host_status & ~HS_FFER1; |
| 1652 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1653 | spin_lock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1654 | phba->hba_flag &= ~DEFER_ERATT; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1655 | spin_unlock_irq(&phba->hbalock); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1656 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
| 1657 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); |
| 1658 | } |
| 1659 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1660 | static void |
| 1661 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) |
| 1662 | { |
| 1663 | struct lpfc_board_event_header board_event; |
| 1664 | struct Scsi_Host *shost; |
| 1665 | |
| 1666 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 1667 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 1668 | shost = lpfc_shost_from_vport(phba->pport); |
| 1669 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1670 | sizeof(board_event), |
| 1671 | (char *) &board_event, |
| 1672 | LPFC_NL_VENDOR_ID); |
| 1673 | } |
| 1674 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1675 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1676 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1677 | * @phba: pointer to lpfc hba data structure. |
| 1678 | * |
| 1679 | * This routine is invoked to handle the following HBA hardware error |
| 1680 | * conditions: |
| 1681 | * 1 - HBA error attention interrupt |
| 1682 | * 2 - DMA ring index out of range |
| 1683 | * 3 - Mailbox command came back as unknown |
| 1684 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1685 | static void |
| 1686 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1687 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1688 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1689 | struct lpfc_sli *psli = &phba->sli; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1690 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1691 | unsigned long temperature; |
| 1692 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1693 | struct Scsi_Host *shost; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1694 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1695 | /* If the pci channel is offline, ignore possible errors, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1696 | * since we cannot communicate with the pci card anyway. |
| 1697 | */ |
| 1698 | if (pci_channel_offline(phba->pcidev)) { |
| 1699 | spin_lock_irq(&phba->hbalock); |
| 1700 | phba->hba_flag &= ~DEFER_ERATT; |
| 1701 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 1702 | return; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1703 | } |
| 1704 | |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 1705 | /* If resets are disabled then leave the HBA alone and return */ |
| 1706 | if (!phba->cfg_enable_hba_reset) |
| 1707 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1708 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1709 | /* Send an internal error event to mgmt application */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 1710 | lpfc_board_errevt_to_mgmt(phba); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 1711 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 1712 | if (phba->hba_flag & DEFER_ERATT) |
| 1713 | lpfc_handle_deferred_eratt(phba); |
| 1714 | |
James Smart | dcf2a4e | 2010-09-29 11:18:53 -0400 | [diff] [blame] | 1715 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
| 1716 | if (phba->work_hs & HS_FFER6) |
| 1717 | /* Re-establishing Link */ |
| 1718 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1719 | "1301 Re-establishing Link " |
| 1720 | "Data: x%x x%x x%x\n", |
| 1721 | phba->work_hs, phba->work_status[0], |
| 1722 | phba->work_status[1]); |
| 1723 | if (phba->work_hs & HS_FFER8) |
| 1724 | /* Device Zeroization */ |
| 1725 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
| 1726 | "2861 Host Authentication device " |
| 1727 | "zeroization Data:x%x x%x x%x\n", |
| 1728 | phba->work_hs, phba->work_status[0], |
| 1729 | phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1730 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1731 | spin_lock_irq(&phba->hbalock); |
James Smart | f4b4c68 | 2009-05-22 14:53:12 -0400 | [diff] [blame] | 1732 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1733 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1734 | |
| 1735 | /* |
| 1736 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 1737 | * That could cause the I/Os dropped by the firmware. |
| 1738 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 1739 | * retry it after re-establishing link. |
| 1740 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 1741 | lpfc_sli_abort_fcp_rings(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1742 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1743 | /* |
| 1744 | * There was a firmware error. Take the hba offline and then |
| 1745 | * attempt to restart it. |
| 1746 | */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1747 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1749 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1751 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | return; |
| 1753 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1754 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1755 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 1756 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 1757 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1758 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1759 | temp_event_data.data = (uint32_t)temperature; |
| 1760 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1761 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1762 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1763 | "(%ld), taking this port offline " |
| 1764 | "Data: x%x x%x x%x\n", |
| 1765 | temperature, phba->work_hs, |
| 1766 | phba->work_status[0], phba->work_status[1]); |
| 1767 | |
| 1768 | shost = lpfc_shost_from_vport(phba->pport); |
| 1769 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1770 | sizeof(temp_event_data), |
| 1771 | (char *) &temp_event_data, |
| 1772 | SCSI_NL_VID_TYPE_PCI |
| 1773 | | PCI_VENDOR_ID_EMULEX); |
| 1774 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1775 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 1776 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1777 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1778 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 1779 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1780 | } else { |
| 1781 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1782 | * failure is a value other than FFER6. Do not call the offline |
| 1783 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1784 | */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1785 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1786 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1787 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1788 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1789 | phba->work_status[0], phba->work_status[1]); |
| 1790 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1791 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1792 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1793 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 1794 | sizeof(event_data), (char *) &event_data, |
| 1795 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 1796 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1797 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1798 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1799 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1800 | } |
| 1801 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1802 | /** |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1803 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg |
| 1804 | * @phba: pointer to lpfc hba data structure. |
| 1805 | * @mbx_action: flag for mailbox shutdown action. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 1806 | * @en_rn_msg: send reset/port recovery message. |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1807 | * This routine is invoked to perform an SLI4 port PCI function reset in |
| 1808 | * response to port status register polling attention. It waits for port |
| 1809 | * status register (ERR, RDY, RN) bits before proceeding with function reset. |
| 1810 | * During this process, interrupt vectors are freed and later requested |
| 1811 | * for handling possible port resource change. |
| 1812 | **/ |
| 1813 | static int |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1814 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
| 1815 | bool en_rn_msg) |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1816 | { |
| 1817 | int rc; |
| 1818 | uint32_t intr_mode; |
| 1819 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1820 | 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] | 1821 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 1822 | /* |
| 1823 | * On error status condition, driver need to wait for port |
| 1824 | * ready before performing reset. |
| 1825 | */ |
| 1826 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1827 | if (rc) |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1828 | return rc; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1829 | } |
James Smart | 0e916ee | 2016-07-06 12:36:06 -0700 | [diff] [blame] | 1830 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1831 | /* need reset: attempt for port recovery */ |
| 1832 | if (en_rn_msg) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1833 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1834 | "2887 Reset Needed: Attempting Port " |
| 1835 | "Recovery...\n"); |
| 1836 | lpfc_offline_prep(phba, mbx_action); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 1837 | lpfc_sli_flush_io_rings(phba); |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1838 | lpfc_offline(phba); |
| 1839 | /* release interrupt for possible resource change */ |
| 1840 | lpfc_sli4_disable_intr(phba); |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1841 | rc = lpfc_sli_brdrestart(phba); |
| 1842 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1843 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5a9eeff | 2018-11-29 16:09:32 -0800 | [diff] [blame] | 1844 | "6309 Failed to restart board\n"); |
| 1845 | return rc; |
| 1846 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1847 | /* request and enable interrupt */ |
| 1848 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 1849 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1850 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1851 | "3175 Failed to enable interrupt\n"); |
| 1852 | return -EIO; |
| 1853 | } |
| 1854 | phba->intr_mode = intr_mode; |
| 1855 | rc = lpfc_online(phba); |
| 1856 | if (rc == 0) |
| 1857 | lpfc_unblock_mgmt_io(phba); |
| 1858 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 1859 | return rc; |
| 1860 | } |
| 1861 | |
| 1862 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1863 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler |
| 1864 | * @phba: pointer to lpfc hba data structure. |
| 1865 | * |
| 1866 | * This routine is invoked to handle the SLI4 HBA hardware error attention |
| 1867 | * conditions. |
| 1868 | **/ |
| 1869 | static void |
| 1870 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) |
| 1871 | { |
| 1872 | struct lpfc_vport *vport = phba->pport; |
| 1873 | uint32_t event_data; |
| 1874 | struct Scsi_Host *shost; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1875 | uint32_t if_type; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1876 | struct lpfc_register portstat_reg = {0}; |
| 1877 | uint32_t reg_err1, reg_err2; |
| 1878 | uint32_t uerrlo_reg, uemasklo_reg; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1879 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 1880 | bool en_rn_msg = true; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1881 | struct temp_event temp_event_data; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1882 | struct lpfc_register portsmphr_reg; |
| 1883 | int rc, i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1884 | |
| 1885 | /* If the pci channel is offline, ignore possible errors, since |
| 1886 | * we cannot communicate with the pci card anyway. |
| 1887 | */ |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1888 | if (pci_channel_offline(phba->pcidev)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1889 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1890 | "3166 pci channel is offline\n"); |
| 1891 | lpfc_sli4_offline_eratt(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1892 | return; |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1893 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 1894 | |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1895 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1896 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1897 | switch (if_type) { |
| 1898 | case LPFC_SLI_INTF_IF_TYPE_0: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1899 | pci_rd_rc1 = lpfc_readl( |
| 1900 | phba->sli4_hba.u.if_type0.UERRLOregaddr, |
| 1901 | &uerrlo_reg); |
| 1902 | pci_rd_rc2 = lpfc_readl( |
| 1903 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, |
| 1904 | &uemasklo_reg); |
| 1905 | /* consider PCI bus read error as pci_channel_offline */ |
| 1906 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) |
| 1907 | return; |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1908 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
| 1909 | lpfc_sli4_offline_eratt(phba); |
| 1910 | return; |
| 1911 | } |
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 | "7623 Checking UE recoverable"); |
| 1914 | |
| 1915 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { |
| 1916 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1917 | &portsmphr_reg.word0)) |
| 1918 | continue; |
| 1919 | |
| 1920 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, |
| 1921 | &portsmphr_reg); |
| 1922 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1923 | LPFC_PORT_SEM_UE_RECOVERABLE) |
| 1924 | break; |
| 1925 | /*Sleep for 1Sec, before checking SEMAPHORE */ |
| 1926 | msleep(1000); |
| 1927 | } |
| 1928 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1929 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1930 | "4827 smphr_port_status x%x : Waited %dSec", |
| 1931 | smphr_port_status, i); |
| 1932 | |
| 1933 | /* Recoverable UE, reset the HBA device */ |
| 1934 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == |
| 1935 | LPFC_PORT_SEM_UE_RECOVERABLE) { |
| 1936 | for (i = 0; i < 20; i++) { |
| 1937 | msleep(1000); |
| 1938 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 1939 | &portsmphr_reg.word0) && |
| 1940 | (LPFC_POST_STAGE_PORT_READY == |
| 1941 | bf_get(lpfc_port_smphr_port_status, |
| 1942 | &portsmphr_reg))) { |
| 1943 | rc = lpfc_sli4_port_sta_fn_reset(phba, |
| 1944 | LPFC_MBX_NO_WAIT, en_rn_msg); |
| 1945 | if (rc == 0) |
| 1946 | return; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1947 | lpfc_printf_log(phba, KERN_ERR, |
| 1948 | LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1949 | "4215 Failed to recover UE"); |
| 1950 | break; |
| 1951 | } |
| 1952 | } |
| 1953 | } |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1954 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 1955 | "7624 Firmware not ready: Failing UE recovery," |
| 1956 | " waited %dSec", i); |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 1957 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1958 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1959 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1960 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 1961 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1962 | pci_rd_rc1 = lpfc_readl( |
| 1963 | phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 1964 | &portstat_reg.word0); |
| 1965 | /* consider PCI bus read error as pci_channel_offline */ |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1966 | if (pci_rd_rc1 == -EIO) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1967 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1968 | "3151 PCI bus read access failure: x%x\n", |
| 1969 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); |
James Smart | 32a9310 | 2019-03-12 16:30:13 -0700 | [diff] [blame] | 1970 | lpfc_sli4_offline_eratt(phba); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1971 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 1972 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1973 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 1974 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1975 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 1976 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 1977 | "2889 Port Overtemperature event, " |
| 1978 | "taking port offline Data: x%x x%x\n", |
| 1979 | reg_err1, reg_err2); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1980 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 1981 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1982 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 1983 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 1984 | temp_event_data.data = 0xFFFFFFFF; |
| 1985 | |
| 1986 | shost = lpfc_shost_from_vport(phba->pport); |
| 1987 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 1988 | sizeof(temp_event_data), |
| 1989 | (char *)&temp_event_data, |
| 1990 | SCSI_NL_VID_TYPE_PCI |
| 1991 | | PCI_VENDOR_ID_EMULEX); |
| 1992 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1993 | spin_lock_irq(&phba->hbalock); |
| 1994 | phba->over_temp_state = HBA_OVER_TEMP; |
| 1995 | spin_unlock_irq(&phba->hbalock); |
| 1996 | lpfc_sli4_offline_eratt(phba); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 1997 | return; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 1998 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 1999 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2000 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2001 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2002 | "3143 Port Down: Firmware Update " |
| 2003 | "Detected\n"); |
| 2004 | en_rn_msg = false; |
| 2005 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2006 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2007 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2008 | "3144 Port Down: Debug Dump\n"); |
| 2009 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 2010 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2011 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2012 | "3145 Port Down: Provisioning\n"); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2013 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 2014 | /* If resets are disabled then leave the HBA alone and return */ |
| 2015 | if (!phba->cfg_enable_hba_reset) |
| 2016 | return; |
| 2017 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2018 | /* Check port status register for function reset */ |
James Smart | e10b202 | 2014-02-20 09:57:43 -0500 | [diff] [blame] | 2019 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
| 2020 | en_rn_msg); |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2021 | if (rc == 0) { |
| 2022 | /* don't report event on forced debug dump */ |
| 2023 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
| 2024 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
| 2025 | return; |
| 2026 | else |
| 2027 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2028 | } |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 2029 | /* fall through for not able to recover */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2030 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8c24a4f | 2019-08-14 16:56:53 -0700 | [diff] [blame] | 2031 | "3152 Unrecoverable error\n"); |
| 2032 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 2033 | break; |
| 2034 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 2035 | default: |
| 2036 | break; |
| 2037 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2038 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 2039 | "3123 Report dump event to upper layer\n"); |
| 2040 | /* Send an internal error event to mgmt application */ |
| 2041 | lpfc_board_errevt_to_mgmt(phba); |
| 2042 | |
| 2043 | event_data = FC_REG_DUMP_EVENT; |
| 2044 | shost = lpfc_shost_from_vport(vport); |
| 2045 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2046 | sizeof(event_data), (char *) &event_data, |
| 2047 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | /** |
| 2051 | * lpfc_handle_eratt - Wrapper func for handling hba error attention |
| 2052 | * @phba: pointer to lpfc HBA data structure. |
| 2053 | * |
| 2054 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling |
| 2055 | * routine from the API jump table function pointer from the lpfc_hba struct. |
| 2056 | * |
| 2057 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 2058 | * 0 - success. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2059 | * Any other value - error. |
| 2060 | **/ |
| 2061 | void |
| 2062 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| 2063 | { |
| 2064 | (*phba->lpfc_handle_eratt)(phba); |
| 2065 | } |
| 2066 | |
| 2067 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2068 | * lpfc_handle_latt - The HBA link event handler |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2069 | * @phba: pointer to lpfc hba data structure. |
| 2070 | * |
| 2071 | * 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] | 2072 | * attention link event. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2073 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2074 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2075 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2076 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2077 | struct lpfc_vport *vport = phba->pport; |
| 2078 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2079 | LPFC_MBOXQ_t *pmb; |
| 2080 | volatile uint32_t control; |
| 2081 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2082 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2083 | |
| 2084 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2085 | if (!pmb) { |
| 2086 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2087 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2088 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2089 | |
| 2090 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2091 | if (!mp) { |
| 2092 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2093 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2094 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2095 | |
| 2096 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2097 | if (!mp->virt) { |
| 2098 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2099 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2100 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2101 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 2102 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2103 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2104 | |
| 2105 | psli->slistat.link_event++; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2106 | lpfc_read_topology(phba, pmb, mp); |
| 2107 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2108 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 2109 | /* Block ELS IOCBs until we have processed this mbox command */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2110 | phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 2111 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2112 | if (rc == MBX_NOT_FINISHED) { |
| 2113 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2114 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2115 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2116 | |
| 2117 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2118 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2119 | writel(HA_LATT, phba->HAregaddr); |
| 2120 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2121 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2122 | |
| 2123 | return; |
| 2124 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2125 | lpfc_handle_latt_free_mbuf: |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2126 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 2127 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2128 | lpfc_handle_latt_free_mp: |
| 2129 | kfree(mp); |
| 2130 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 2131 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2132 | lpfc_handle_latt_err_exit: |
| 2133 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2134 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2135 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 2136 | control = readl(phba->HCregaddr); |
| 2137 | control |= HC_LAINT_ENA; |
| 2138 | writel(control, phba->HCregaddr); |
| 2139 | readl(phba->HCregaddr); /* flush */ |
| 2140 | |
| 2141 | /* Clear Link Attention in HA REG */ |
| 2142 | writel(HA_LATT, phba->HAregaddr); |
| 2143 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2144 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2145 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2146 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2147 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2148 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 2149 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2150 | |
| 2151 | return; |
| 2152 | } |
| 2153 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2154 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2155 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2156 | * @phba: pointer to lpfc hba data structure. |
| 2157 | * @vpd: pointer to the vital product data. |
| 2158 | * @len: length of the vital product data in bytes. |
| 2159 | * |
| 2160 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 2161 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 2162 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 2163 | * |
| 2164 | * Return codes |
| 2165 | * 0 - pointer to the VPD passed in is NULL |
| 2166 | * 1 - success |
| 2167 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2168 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2169 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2170 | { |
| 2171 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 2172 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2173 | int i, j; |
| 2174 | int finished = 0; |
| 2175 | int index = 0; |
| 2176 | |
| 2177 | if (!vpd) |
| 2178 | return 0; |
| 2179 | |
| 2180 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2181 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2182 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2183 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 2184 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2185 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2186 | switch (vpd[index]) { |
| 2187 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2188 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2189 | index += 1; |
| 2190 | lenlo = vpd[index]; |
| 2191 | index += 1; |
| 2192 | lenhi = vpd[index]; |
| 2193 | index += 1; |
| 2194 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 2195 | index += i; |
| 2196 | break; |
| 2197 | case 0x90: |
| 2198 | index += 1; |
| 2199 | lenlo = vpd[index]; |
| 2200 | index += 1; |
| 2201 | lenhi = vpd[index]; |
| 2202 | index += 1; |
| 2203 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2204 | if (Length > len - index) |
| 2205 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2206 | while (Length > 0) { |
| 2207 | /* Look for Serial Number */ |
| 2208 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 2209 | index += 2; |
| 2210 | i = vpd[index]; |
| 2211 | index += 1; |
| 2212 | j = 0; |
| 2213 | Length -= (3+i); |
| 2214 | while(i--) { |
| 2215 | phba->SerialNumber[j++] = vpd[index++]; |
| 2216 | if (j == 31) |
| 2217 | break; |
| 2218 | } |
| 2219 | phba->SerialNumber[j] = 0; |
| 2220 | continue; |
| 2221 | } |
| 2222 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 2223 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 2224 | index += 2; |
| 2225 | i = vpd[index]; |
| 2226 | index += 1; |
| 2227 | j = 0; |
| 2228 | Length -= (3+i); |
| 2229 | while(i--) { |
| 2230 | phba->ModelDesc[j++] = vpd[index++]; |
| 2231 | if (j == 255) |
| 2232 | break; |
| 2233 | } |
| 2234 | phba->ModelDesc[j] = 0; |
| 2235 | continue; |
| 2236 | } |
| 2237 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 2238 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 2239 | index += 2; |
| 2240 | i = vpd[index]; |
| 2241 | index += 1; |
| 2242 | j = 0; |
| 2243 | Length -= (3+i); |
| 2244 | while(i--) { |
| 2245 | phba->ModelName[j++] = vpd[index++]; |
| 2246 | if (j == 79) |
| 2247 | break; |
| 2248 | } |
| 2249 | phba->ModelName[j] = 0; |
| 2250 | continue; |
| 2251 | } |
| 2252 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 2253 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 2254 | index += 2; |
| 2255 | i = vpd[index]; |
| 2256 | index += 1; |
| 2257 | j = 0; |
| 2258 | Length -= (3+i); |
| 2259 | while(i--) { |
| 2260 | phba->ProgramType[j++] = vpd[index++]; |
| 2261 | if (j == 255) |
| 2262 | break; |
| 2263 | } |
| 2264 | phba->ProgramType[j] = 0; |
| 2265 | continue; |
| 2266 | } |
| 2267 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 2268 | phba->vpd_flag |= VPD_PORT; |
| 2269 | index += 2; |
| 2270 | i = vpd[index]; |
| 2271 | index += 1; |
| 2272 | j = 0; |
| 2273 | Length -= (3+i); |
| 2274 | while(i--) { |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2275 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 2276 | (phba->sli4_hba.pport_name_sta == |
| 2277 | LPFC_SLI4_PPNAME_GET)) { |
| 2278 | j++; |
| 2279 | index++; |
| 2280 | } else |
| 2281 | phba->Port[j++] = vpd[index++]; |
| 2282 | if (j == 19) |
| 2283 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2284 | } |
James Smart | cd1c830 | 2011-10-10 21:33:25 -0400 | [diff] [blame] | 2285 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
| 2286 | (phba->sli4_hba.pport_name_sta == |
| 2287 | LPFC_SLI4_PPNAME_NON)) |
| 2288 | phba->Port[j] = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2289 | continue; |
| 2290 | } |
| 2291 | else { |
| 2292 | index += 2; |
| 2293 | i = vpd[index]; |
| 2294 | index += 1; |
| 2295 | index += i; |
| 2296 | Length -= (3 + i); |
| 2297 | } |
| 2298 | } |
| 2299 | finished = 0; |
| 2300 | break; |
| 2301 | case 0x78: |
| 2302 | finished = 1; |
| 2303 | break; |
| 2304 | default: |
| 2305 | index ++; |
| 2306 | break; |
| 2307 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2308 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2309 | |
| 2310 | return(1); |
| 2311 | } |
| 2312 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2313 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2314 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2315 | * @phba: pointer to lpfc hba data structure. |
| 2316 | * @mdp: pointer to the data structure to hold the derived model name. |
| 2317 | * @descp: pointer to the data structure to hold the derived description. |
| 2318 | * |
| 2319 | * This routine retrieves HBA's description based on its registered PCI device |
| 2320 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 2321 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 2322 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 2323 | * function returns, the @mdp will be filled with the model name. |
| 2324 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2325 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2326 | 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] | 2327 | { |
| 2328 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 2329 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2330 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2331 | int GE = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2332 | int oneConnect = 0; /* default is not a oneConnect */ |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2333 | struct { |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2334 | char *name; |
| 2335 | char *bus; |
| 2336 | char *function; |
| 2337 | } m = {"<Unknown>", "", ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2338 | |
| 2339 | if (mdp && mdp[0] != '\0' |
| 2340 | && descp && descp[0] != '\0') |
| 2341 | return; |
| 2342 | |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 2343 | if (phba->lmt & LMT_64Gb) |
| 2344 | max_speed = 64; |
| 2345 | else if (phba->lmt & LMT_32Gb) |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2346 | max_speed = 32; |
| 2347 | else if (phba->lmt & LMT_16Gb) |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2348 | max_speed = 16; |
| 2349 | else if (phba->lmt & LMT_10Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2350 | max_speed = 10; |
| 2351 | else if (phba->lmt & LMT_8Gb) |
| 2352 | max_speed = 8; |
| 2353 | else if (phba->lmt & LMT_4Gb) |
| 2354 | max_speed = 4; |
| 2355 | else if (phba->lmt & LMT_2Gb) |
| 2356 | max_speed = 2; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2357 | else if (phba->lmt & LMT_1Gb) |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2358 | max_speed = 1; |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2359 | else |
| 2360 | max_speed = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2361 | |
| 2362 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2363 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2364 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2365 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2366 | m = (typeof(m)){"LP6000", "PCI", |
| 2367 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2368 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2369 | case PCI_DEVICE_ID_SUPERFLY: |
| 2370 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2371 | m = (typeof(m)){"LP7000", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2372 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2373 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
| 2374 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2375 | break; |
| 2376 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2377 | m = (typeof(m)){"LP8000", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2378 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | break; |
| 2380 | case PCI_DEVICE_ID_CENTAUR: |
| 2381 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2382 | m = (typeof(m)){"LP9002", "PCI", ""}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2383 | else |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2384 | m = (typeof(m)){"LP9000", "PCI", ""}; |
| 2385 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2386 | break; |
| 2387 | case PCI_DEVICE_ID_RFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2388 | m = (typeof(m)){"LP952", "PCI", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2389 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2390 | break; |
| 2391 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2392 | m = (typeof(m)){"LP9802", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2393 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2394 | break; |
| 2395 | case PCI_DEVICE_ID_THOR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2396 | m = (typeof(m)){"LP10000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2397 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2398 | break; |
| 2399 | case PCI_DEVICE_ID_VIPER: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2400 | m = (typeof(m)){"LPX1000", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2401 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2402 | break; |
| 2403 | case PCI_DEVICE_ID_PFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2404 | m = (typeof(m)){"LP982", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2405 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2406 | break; |
| 2407 | case PCI_DEVICE_ID_TFLY: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2408 | m = (typeof(m)){"LP1050", "PCI-X", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2409 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2410 | break; |
| 2411 | case PCI_DEVICE_ID_HELIOS: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2412 | m = (typeof(m)){"LP11000", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2413 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2415 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2416 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2417 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2418 | break; |
| 2419 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2420 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2421 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2422 | break; |
| 2423 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2424 | m = (typeof(m)){"LPe1000", "PCIe", |
| 2425 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2426 | break; |
| 2427 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2428 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
| 2429 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2430 | break; |
| 2431 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2432 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
| 2433 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2434 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | case PCI_DEVICE_ID_BMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2436 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2437 | break; |
| 2438 | case PCI_DEVICE_ID_BSMB: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2439 | m = (typeof(m)){"LP111", "PCI-X2", |
| 2440 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2441 | break; |
| 2442 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2443 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2445 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2446 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2447 | break; |
| 2448 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2449 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 2450 | GE = 1; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2451 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2452 | case PCI_DEVICE_ID_ZMID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2453 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2454 | break; |
| 2455 | case PCI_DEVICE_ID_ZSMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2456 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2457 | break; |
| 2458 | case PCI_DEVICE_ID_LP101: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2459 | m = (typeof(m)){"LP101", "PCI-X", |
| 2460 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2461 | break; |
| 2462 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2463 | m = (typeof(m)){"LP10000-S", "PCI", |
| 2464 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 2465 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2466 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2467 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
| 2468 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 2469 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2470 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2471 | m = (typeof(m)){"LPe11000-S", "PCIe", |
| 2472 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2473 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2474 | case PCI_DEVICE_ID_SAT: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2475 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2476 | break; |
| 2477 | case PCI_DEVICE_ID_SAT_MID: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2478 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2479 | break; |
| 2480 | case PCI_DEVICE_ID_SAT_SMB: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2481 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2482 | break; |
| 2483 | case PCI_DEVICE_ID_SAT_DCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2484 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2485 | break; |
| 2486 | case PCI_DEVICE_ID_SAT_SCSP: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2487 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2488 | break; |
| 2489 | case PCI_DEVICE_ID_SAT_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2490 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 2491 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2492 | case PCI_DEVICE_ID_HORNET: |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2493 | m = (typeof(m)){"LP21000", "PCIe", |
| 2494 | "Obsolete, Unsupported FCoE Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2495 | GE = 1; |
| 2496 | break; |
| 2497 | case PCI_DEVICE_ID_PROTEUS_VF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2498 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2499 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2500 | break; |
| 2501 | case PCI_DEVICE_ID_PROTEUS_PF: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2502 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2503 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2504 | break; |
| 2505 | case PCI_DEVICE_ID_PROTEUS_S: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2506 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2507 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2508 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2509 | case PCI_DEVICE_ID_TIGERSHARK: |
| 2510 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2511 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2512 | break; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2513 | case PCI_DEVICE_ID_TOMCAT: |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2514 | oneConnect = 1; |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2515 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
| 2516 | break; |
| 2517 | case PCI_DEVICE_ID_FALCON: |
| 2518 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", |
| 2519 | "EmulexSecure Fibre"}; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2520 | break; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2521 | case PCI_DEVICE_ID_BALIUS: |
| 2522 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2523 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
James Smart | 98fc5dd | 2010-06-07 15:24:29 -0400 | [diff] [blame] | 2524 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2525 | case PCI_DEVICE_ID_LANCER_FC: |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2526 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2527 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2528 | case PCI_DEVICE_ID_LANCER_FC_VF: |
| 2529 | m = (typeof(m)){"LPe16000", "PCIe", |
| 2530 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
| 2531 | break; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2532 | case PCI_DEVICE_ID_LANCER_FCOE: |
| 2533 | oneConnect = 1; |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 2534 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 2535 | break; |
James Smart | 12222f4 | 2014-05-21 08:05:19 -0400 | [diff] [blame] | 2536 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
| 2537 | oneConnect = 1; |
| 2538 | m = (typeof(m)){"OCe15100", "PCIe", |
| 2539 | "Obsolete, Unsupported FCoE"}; |
| 2540 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 2541 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 2542 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; |
| 2543 | break; |
James Smart | c238b9b | 2018-02-22 08:18:44 -0800 | [diff] [blame] | 2544 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 2545 | m = (typeof(m)){"LPe36000", "PCIe", "Fibre Channel Adapter"}; |
| 2546 | break; |
James Smart | f8cafd3 | 2012-08-03 12:42:51 -0400 | [diff] [blame] | 2547 | case PCI_DEVICE_ID_SKYHAWK: |
| 2548 | case PCI_DEVICE_ID_SKYHAWK_VF: |
| 2549 | oneConnect = 1; |
| 2550 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; |
| 2551 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 2552 | default: |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2553 | m = (typeof(m)){"Unknown", "", ""}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 2554 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2555 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 2556 | |
| 2557 | if (mdp && mdp[0] == '\0') |
| 2558 | snprintf(mdp, 79,"%s", m.name); |
James Smart | c0c1151 | 2011-05-24 11:41:34 -0400 | [diff] [blame] | 2559 | /* |
| 2560 | * oneConnect hba requires special processing, they are all initiators |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2561 | * and we put the port number on the end |
| 2562 | */ |
| 2563 | if (descp && descp[0] == '\0') { |
| 2564 | if (oneConnect) |
| 2565 | snprintf(descp, 255, |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2566 | "Emulex OneConnect %s, %s Initiator %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2567 | m.name, m.function, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2568 | phba->Port); |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2569 | else if (max_speed == 0) |
| 2570 | snprintf(descp, 255, |
Sebastian Herbszt | 290237d | 2015-08-31 16:48:08 -0400 | [diff] [blame] | 2571 | "Emulex %s %s %s", |
James Smart | 4169d86 | 2012-09-29 11:32:09 -0400 | [diff] [blame] | 2572 | m.name, m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2573 | else |
| 2574 | snprintf(descp, 255, |
| 2575 | "Emulex %s %d%s %s %s", |
James Smart | a747c9c | 2009-11-18 15:41:10 -0500 | [diff] [blame] | 2576 | m.name, max_speed, (GE) ? "GE" : "Gb", |
| 2577 | m.bus, m.function); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 2578 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2579 | } |
| 2580 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2581 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2582 | * 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] | 2583 | * @phba: pointer to lpfc hba data structure. |
| 2584 | * @pring: pointer to a IOCB ring. |
| 2585 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 2586 | * |
| 2587 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 2588 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 2589 | * |
| 2590 | * Return codes |
| 2591 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 2592 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2593 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 2594 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2595 | { |
| 2596 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2597 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2598 | struct lpfc_dmabuf *mp1, *mp2; |
| 2599 | |
| 2600 | cnt += pring->missbufcnt; |
| 2601 | |
| 2602 | /* While there are buffers to post */ |
| 2603 | while (cnt > 0) { |
| 2604 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 2605 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2606 | if (iocb == NULL) { |
| 2607 | pring->missbufcnt = cnt; |
| 2608 | return cnt; |
| 2609 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2610 | icmd = &iocb->iocb; |
| 2611 | |
| 2612 | /* 2 buffers can be posted per command */ |
| 2613 | /* Allocate buffer to post */ |
| 2614 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2615 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2616 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 2617 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2618 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2619 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2620 | pring->missbufcnt = cnt; |
| 2621 | return cnt; |
| 2622 | } |
| 2623 | |
| 2624 | INIT_LIST_HEAD(&mp1->list); |
| 2625 | /* Allocate buffer to post */ |
| 2626 | if (cnt > 1) { |
| 2627 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 2628 | if (mp2) |
| 2629 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 2630 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2631 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2632 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2633 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2634 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2635 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2636 | pring->missbufcnt = cnt; |
| 2637 | return cnt; |
| 2638 | } |
| 2639 | |
| 2640 | INIT_LIST_HEAD(&mp2->list); |
| 2641 | } else { |
| 2642 | mp2 = NULL; |
| 2643 | } |
| 2644 | |
| 2645 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 2646 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 2647 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 2648 | icmd->ulpBdeCount = 1; |
| 2649 | cnt--; |
| 2650 | if (mp2) { |
| 2651 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 2652 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 2653 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 2654 | cnt--; |
| 2655 | icmd->ulpBdeCount = 2; |
| 2656 | } |
| 2657 | |
| 2658 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 2659 | icmd->ulpLe = 1; |
| 2660 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2661 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
| 2662 | IOCB_ERROR) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2663 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 2664 | kfree(mp1); |
| 2665 | cnt++; |
| 2666 | if (mp2) { |
| 2667 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 2668 | kfree(mp2); |
| 2669 | cnt++; |
| 2670 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2671 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2672 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | return cnt; |
| 2674 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2676 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2678 | } |
| 2679 | pring->missbufcnt = 0; |
| 2680 | return 0; |
| 2681 | } |
| 2682 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2683 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2684 | * 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] | 2685 | * @phba: pointer to lpfc hba data structure. |
| 2686 | * |
| 2687 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 2688 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2689 | * set to 64 IOCBs. SLI3 only. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2690 | * |
| 2691 | * Return codes |
| 2692 | * 0 - success (currently always success) |
| 2693 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2694 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2695 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2696 | { |
| 2697 | struct lpfc_sli *psli = &phba->sli; |
| 2698 | |
| 2699 | /* Ring 0, ELS / CT buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 2700 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2701 | /* Ring 2 - FCP no buffers needed */ |
| 2702 | |
| 2703 | return 0; |
| 2704 | } |
| 2705 | |
| 2706 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 2707 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2708 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2709 | * lpfc_sha_init - Set up initial array of hash table entries |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2710 | * @HashResultPointer: pointer to an array as hash table. |
| 2711 | * |
| 2712 | * This routine sets up the initial values to the array of hash table entries |
| 2713 | * for the LC HBAs. |
| 2714 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2715 | static void |
| 2716 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 2717 | { |
| 2718 | HashResultPointer[0] = 0x67452301; |
| 2719 | HashResultPointer[1] = 0xEFCDAB89; |
| 2720 | HashResultPointer[2] = 0x98BADCFE; |
| 2721 | HashResultPointer[3] = 0x10325476; |
| 2722 | HashResultPointer[4] = 0xC3D2E1F0; |
| 2723 | } |
| 2724 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2725 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2726 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2727 | * @HashResultPointer: pointer to an initial/result hash table. |
| 2728 | * @HashWorkingPointer: pointer to an working hash table. |
| 2729 | * |
| 2730 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 2731 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 2732 | * The results are putting back to the initial hash table, returned through |
| 2733 | * the @HashResultPointer as the result hash table. |
| 2734 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2735 | static void |
| 2736 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 2737 | { |
| 2738 | int t; |
| 2739 | uint32_t TEMP; |
| 2740 | uint32_t A, B, C, D, E; |
| 2741 | t = 16; |
| 2742 | do { |
| 2743 | HashWorkingPointer[t] = |
| 2744 | S(1, |
| 2745 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 2746 | 8] ^ |
| 2747 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 2748 | } while (++t <= 79); |
| 2749 | t = 0; |
| 2750 | A = HashResultPointer[0]; |
| 2751 | B = HashResultPointer[1]; |
| 2752 | C = HashResultPointer[2]; |
| 2753 | D = HashResultPointer[3]; |
| 2754 | E = HashResultPointer[4]; |
| 2755 | |
| 2756 | do { |
| 2757 | if (t < 20) { |
| 2758 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 2759 | } else if (t < 40) { |
| 2760 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 2761 | } else if (t < 60) { |
| 2762 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 2763 | } else { |
| 2764 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 2765 | } |
| 2766 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 2767 | E = D; |
| 2768 | D = C; |
| 2769 | C = S(30, B); |
| 2770 | B = A; |
| 2771 | A = TEMP; |
| 2772 | } while (++t <= 79); |
| 2773 | |
| 2774 | HashResultPointer[0] += A; |
| 2775 | HashResultPointer[1] += B; |
| 2776 | HashResultPointer[2] += C; |
| 2777 | HashResultPointer[3] += D; |
| 2778 | HashResultPointer[4] += E; |
| 2779 | |
| 2780 | } |
| 2781 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2782 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2783 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2784 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 2785 | * @HashWorking: pointer to the entry of the working hash array. |
| 2786 | * |
| 2787 | * This routine calculates the working hash array referred by @HashWorking |
| 2788 | * from the challenge random numbers associated with the host, referred by |
| 2789 | * @RandomChallenge. The result is put into the entry of the working hash |
| 2790 | * array and returned by reference through @HashWorking. |
| 2791 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2792 | static void |
| 2793 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 2794 | { |
| 2795 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 2796 | } |
| 2797 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2798 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2799 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2800 | * @phba: pointer to lpfc hba data structure. |
| 2801 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 2802 | * |
| 2803 | * This routine performs the special handling for LC HBA initialization. |
| 2804 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2805 | void |
| 2806 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 2807 | { |
| 2808 | int t; |
| 2809 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2810 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2811 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2812 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2813 | if (!HashWorking) |
| 2814 | return; |
| 2815 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2816 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 2817 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 2818 | |
| 2819 | for (t = 0; t < 7; t++) |
| 2820 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 2821 | |
| 2822 | lpfc_sha_init(hbainit); |
| 2823 | lpfc_sha_iterate(hbainit, HashWorking); |
| 2824 | kfree(HashWorking); |
| 2825 | } |
| 2826 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2827 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2828 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2829 | * @vport: pointer to a virtual N_Port data structure. |
| 2830 | * |
| 2831 | * This routine performs the necessary cleanups before deleting the @vport. |
| 2832 | * It invokes the discovery state machine to perform necessary state |
| 2833 | * transitions and to release the ndlps associated with the @vport. Note, |
| 2834 | * the physical port is treated as @vport 0. |
| 2835 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2836 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2837 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2838 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2839 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2840 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2841 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2842 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2843 | if (phba->link_state > LPFC_LINK_DOWN) |
| 2844 | lpfc_port_link_failure(vport); |
| 2845 | |
| 2846 | 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] | 2847 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 2848 | ndlp->nlp_DID == Fabric_DID) { |
| 2849 | /* Just free up ndlp with Fabric_DID for vports */ |
| 2850 | lpfc_nlp_put(ndlp); |
| 2851 | continue; |
| 2852 | } |
| 2853 | |
James Smart | a70e63e | 2020-11-15 11:26:38 -0800 | [diff] [blame] | 2854 | if (ndlp->nlp_DID == Fabric_Cntl_DID && |
| 2855 | ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
James Smart | eff4a01 | 2012-01-18 16:25:25 -0500 | [diff] [blame] | 2856 | lpfc_nlp_put(ndlp); |
| 2857 | continue; |
| 2858 | } |
| 2859 | |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2860 | /* Fabric Ports not in UNMAPPED state are cleaned up in the |
| 2861 | * DEVICE_RM event. |
| 2862 | */ |
| 2863 | if (ndlp->nlp_type & NLP_FABRIC && |
| 2864 | ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2865 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2866 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2867 | |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2868 | if (!(ndlp->fc4_xpt_flags & (NVME_XPT_REGD|SCSI_XPT_REGD))) |
| 2869 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 2870 | NLP_EVT_DEVICE_RM); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2871 | } |
| 2872 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2873 | /* At this point, ALL ndlp's should be gone |
| 2874 | * because of the previous NLP_EVT_DEVICE_RM. |
| 2875 | * Lets wait for this to happen, if needed. |
| 2876 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2877 | while (!list_empty(&vport->fc_nodes)) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2878 | if (i++ > 3000) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2879 | lpfc_printf_vlog(vport, KERN_ERR, |
| 2880 | LOG_TRACE_EVENT, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2881 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2882 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 2883 | &vport->fc_nodes, nlp_listp) { |
| 2884 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 2885 | LOG_TRACE_EVENT, |
| 2886 | "0282 did:x%x ndlp:x%px " |
| 2887 | "refcnt:%d xflags x%x nflag x%x\n", |
| 2888 | ndlp->nlp_DID, (void *)ndlp, |
| 2889 | kref_read(&ndlp->kref), |
| 2890 | ndlp->fc4_xpt_flags, |
| 2891 | ndlp->nlp_flag); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2892 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2893 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2894 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2895 | |
| 2896 | /* Wait for any activity on ndlps to settle */ |
| 2897 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2898 | } |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2899 | lpfc_cleanup_vports_rrqs(vport, NULL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2900 | } |
| 2901 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2902 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 2903 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2904 | * @vport: pointer to a virtual N_Port data structure. |
| 2905 | * |
| 2906 | * This routine stops all the timers associated with a @vport. This function |
| 2907 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 2908 | * port is treated as @vport 0. |
| 2909 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2910 | void |
| 2911 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2912 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2913 | del_timer_sync(&vport->els_tmofunc); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 2914 | del_timer_sync(&vport->delayed_disc_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2915 | lpfc_can_disctmo(vport); |
| 2916 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2917 | } |
| 2918 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2919 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2920 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2921 | * @phba: pointer to lpfc hba data structure. |
| 2922 | * |
| 2923 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The |
| 2924 | * caller of this routine should already hold the host lock. |
| 2925 | **/ |
| 2926 | void |
| 2927 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2928 | { |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2929 | /* Clear pending FCF rediscovery wait flag */ |
| 2930 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 2931 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2932 | /* Now, try to stop the timer */ |
| 2933 | del_timer(&phba->fcf.redisc_wait); |
| 2934 | } |
| 2935 | |
| 2936 | /** |
| 2937 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer |
| 2938 | * @phba: pointer to lpfc hba data structure. |
| 2939 | * |
| 2940 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It |
| 2941 | * checks whether the FCF rediscovery wait timer is pending with the host |
| 2942 | * lock held before proceeding with disabling the timer and clearing the |
| 2943 | * wait timer pendig flag. |
| 2944 | **/ |
| 2945 | void |
| 2946 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) |
| 2947 | { |
| 2948 | spin_lock_irq(&phba->hbalock); |
| 2949 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 2950 | /* FCF rediscovery timer already fired or stopped */ |
| 2951 | spin_unlock_irq(&phba->hbalock); |
| 2952 | return; |
| 2953 | } |
| 2954 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 5ac6b30 | 2010-10-22 11:05:36 -0400 | [diff] [blame] | 2955 | /* Clear failover in progress flags */ |
| 2956 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2957 | spin_unlock_irq(&phba->hbalock); |
| 2958 | } |
| 2959 | |
| 2960 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2961 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2962 | * @phba: pointer to lpfc hba data structure. |
| 2963 | * |
| 2964 | * This routine stops all the timers associated with a HBA. This function is |
| 2965 | * invoked before either putting a HBA offline or unloading the driver. |
| 2966 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2967 | void |
| 2968 | lpfc_stop_hba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2969 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 2970 | if (phba->pport) |
| 2971 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 2972 | cancel_delayed_work_sync(&phba->eq_delay_work); |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 2973 | cancel_delayed_work_sync(&phba->idle_stat_delay_work); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2974 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2975 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2976 | del_timer_sync(&phba->eratt_poll); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2977 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 1151e3e | 2011-02-16 12:39:35 -0500 | [diff] [blame] | 2978 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 2979 | del_timer_sync(&phba->rrq_tmr); |
| 2980 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; |
| 2981 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2982 | phba->hb_outstanding = 0; |
| 2983 | |
| 2984 | switch (phba->pci_dev_grp) { |
| 2985 | case LPFC_PCI_DEV_LP: |
| 2986 | /* Stop any LightPulse device specific driver timers */ |
| 2987 | del_timer_sync(&phba->fcp_poll_timer); |
| 2988 | break; |
| 2989 | case LPFC_PCI_DEV_OC: |
Paul Walmsley | cc0e5f1 | 2019-07-11 20:52:33 -0700 | [diff] [blame] | 2990 | /* Stop any OneConnect device specific driver timers */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2991 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2992 | break; |
| 2993 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 2994 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 2995 | "0297 Invalid device group (x%x)\n", |
| 2996 | phba->pci_dev_grp); |
| 2997 | break; |
| 2998 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2999 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3000 | } |
| 3001 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3002 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3003 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3004 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 3005 | * @mbx_action: flag for mailbox no wait action. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3006 | * |
| 3007 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 3008 | * management interface is marked as blocked, all the user space access to |
| 3009 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 3010 | * all be blocked. The HBA is set to block the management interface when the |
| 3011 | * driver prepares the HBA interface for online or offline. |
| 3012 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3013 | static void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3014 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3015 | { |
| 3016 | unsigned long iflag; |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3017 | uint8_t actcmd = MBX_HEARTBEAT; |
| 3018 | unsigned long timeout; |
| 3019 | |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3020 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3021 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3022 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 3023 | if (mbx_action == LPFC_MBX_NO_WAIT) |
| 3024 | return; |
| 3025 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
| 3026 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3027 | if (phba->sli.mbox_active) { |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3028 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3029 | /* Determine how long we might wait for the active mailbox |
| 3030 | * command to be gracefully completed by firmware. |
| 3031 | */ |
| 3032 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, |
| 3033 | phba->sli.mbox_active) * 1000) + jiffies; |
| 3034 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3035 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 3036 | |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3037 | /* Wait for the outstnading mailbox command to complete */ |
| 3038 | while (phba->sli.mbox_active) { |
| 3039 | /* Check active mailbox complete status every 2ms */ |
| 3040 | msleep(2); |
| 3041 | if (time_after(jiffies, timeout)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3042 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 3043 | "2813 Mgmt IO is Blocked %x " |
| 3044 | "- mbox cmd %x still active\n", |
| 3045 | phba->sli.sli_flag, actcmd); |
James Smart | 6e7288d | 2010-06-07 15:23:35 -0400 | [diff] [blame] | 3046 | break; |
| 3047 | } |
| 3048 | } |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 3049 | } |
| 3050 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3051 | /** |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3052 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. |
| 3053 | * @phba: pointer to lpfc hba data structure. |
| 3054 | * |
| 3055 | * Allocate RPIs for all active remote nodes. This is needed whenever |
| 3056 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose |
| 3057 | * is to fixup the temporary rpi assignments. |
| 3058 | **/ |
| 3059 | void |
| 3060 | lpfc_sli4_node_prep(struct lpfc_hba *phba) |
| 3061 | { |
| 3062 | struct lpfc_nodelist *ndlp, *next_ndlp; |
| 3063 | struct lpfc_vport **vports; |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3064 | int i, rpi; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3065 | |
| 3066 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 3067 | return; |
| 3068 | |
| 3069 | vports = lpfc_create_vport_work_array(phba); |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3070 | if (vports == NULL) |
| 3071 | return; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3072 | |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3073 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 3074 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3075 | continue; |
| 3076 | |
| 3077 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3078 | &vports[i]->fc_nodes, |
| 3079 | nlp_listp) { |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3080 | rpi = lpfc_sli4_alloc_rpi(phba); |
| 3081 | if (rpi == LPFC_RPI_ALLOC_ERROR) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3082 | /* TODO print log? */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3083 | continue; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3084 | } |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 3085 | ndlp->nlp_rpi = rpi; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3086 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, |
| 3087 | LOG_NODE | LOG_DISCOVERY, |
| 3088 | "0009 Assign RPI x%x to ndlp x%px " |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3089 | "DID:x%06x flg:x%x\n", |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3090 | ndlp->nlp_rpi, ndlp, ndlp->nlp_DID, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3091 | ndlp->nlp_flag); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3092 | } |
| 3093 | } |
| 3094 | lpfc_destroy_vport_work_array(phba, vports); |
| 3095 | } |
| 3096 | |
| 3097 | /** |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3098 | * lpfc_create_expedite_pool - create expedite pool |
| 3099 | * @phba: pointer to lpfc hba data structure. |
| 3100 | * |
| 3101 | * This routine moves a batch of XRIs from lpfc_io_buf_list_put of HWQ 0 |
| 3102 | * to expedite pool. Mark them as expedite. |
| 3103 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3104 | static void lpfc_create_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3105 | { |
| 3106 | struct lpfc_sli4_hdw_queue *qp; |
| 3107 | struct lpfc_io_buf *lpfc_ncmd; |
| 3108 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3109 | struct lpfc_epd_pool *epd_pool; |
| 3110 | unsigned long iflag; |
| 3111 | |
| 3112 | epd_pool = &phba->epd_pool; |
| 3113 | qp = &phba->sli4_hba.hdwq[0]; |
| 3114 | |
| 3115 | spin_lock_init(&epd_pool->lock); |
| 3116 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3117 | spin_lock(&epd_pool->lock); |
| 3118 | INIT_LIST_HEAD(&epd_pool->list); |
| 3119 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3120 | &qp->lpfc_io_buf_list_put, list) { |
| 3121 | list_move_tail(&lpfc_ncmd->list, &epd_pool->list); |
| 3122 | lpfc_ncmd->expedite = true; |
| 3123 | qp->put_io_bufs--; |
| 3124 | epd_pool->count++; |
| 3125 | if (epd_pool->count >= XRI_BATCH) |
| 3126 | break; |
| 3127 | } |
| 3128 | spin_unlock(&epd_pool->lock); |
| 3129 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3130 | } |
| 3131 | |
| 3132 | /** |
| 3133 | * lpfc_destroy_expedite_pool - destroy expedite pool |
| 3134 | * @phba: pointer to lpfc hba data structure. |
| 3135 | * |
| 3136 | * This routine returns XRIs from expedite pool to lpfc_io_buf_list_put |
| 3137 | * of HWQ 0. Clear the mark. |
| 3138 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3139 | static void lpfc_destroy_expedite_pool(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3140 | { |
| 3141 | struct lpfc_sli4_hdw_queue *qp; |
| 3142 | struct lpfc_io_buf *lpfc_ncmd; |
| 3143 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3144 | struct lpfc_epd_pool *epd_pool; |
| 3145 | unsigned long iflag; |
| 3146 | |
| 3147 | epd_pool = &phba->epd_pool; |
| 3148 | qp = &phba->sli4_hba.hdwq[0]; |
| 3149 | |
| 3150 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3151 | spin_lock(&epd_pool->lock); |
| 3152 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3153 | &epd_pool->list, list) { |
| 3154 | list_move_tail(&lpfc_ncmd->list, |
| 3155 | &qp->lpfc_io_buf_list_put); |
| 3156 | lpfc_ncmd->flags = false; |
| 3157 | qp->put_io_bufs++; |
| 3158 | epd_pool->count--; |
| 3159 | } |
| 3160 | spin_unlock(&epd_pool->lock); |
| 3161 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3162 | } |
| 3163 | |
| 3164 | /** |
| 3165 | * lpfc_create_multixri_pools - create multi-XRI pools |
| 3166 | * @phba: pointer to lpfc hba data structure. |
| 3167 | * |
| 3168 | * This routine initialize public, private per HWQ. Then, move XRIs from |
| 3169 | * lpfc_io_buf_list_put to public pool. High and low watermark are also |
| 3170 | * Initialized. |
| 3171 | **/ |
| 3172 | void lpfc_create_multixri_pools(struct lpfc_hba *phba) |
| 3173 | { |
| 3174 | u32 i, j; |
| 3175 | u32 hwq_count; |
| 3176 | u32 count_per_hwq; |
| 3177 | struct lpfc_io_buf *lpfc_ncmd; |
| 3178 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3179 | unsigned long iflag; |
| 3180 | struct lpfc_sli4_hdw_queue *qp; |
| 3181 | struct lpfc_multixri_pool *multixri_pool; |
| 3182 | struct lpfc_pbl_pool *pbl_pool; |
| 3183 | struct lpfc_pvt_pool *pvt_pool; |
| 3184 | |
| 3185 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3186 | "1234 num_hdw_queue=%d num_present_cpu=%d common_xri_cnt=%d\n", |
| 3187 | phba->cfg_hdw_queue, phba->sli4_hba.num_present_cpu, |
| 3188 | phba->sli4_hba.io_xri_cnt); |
| 3189 | |
| 3190 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3191 | lpfc_create_expedite_pool(phba); |
| 3192 | |
| 3193 | hwq_count = phba->cfg_hdw_queue; |
| 3194 | count_per_hwq = phba->sli4_hba.io_xri_cnt / hwq_count; |
| 3195 | |
| 3196 | for (i = 0; i < hwq_count; i++) { |
| 3197 | multixri_pool = kzalloc(sizeof(*multixri_pool), GFP_KERNEL); |
| 3198 | |
| 3199 | if (!multixri_pool) { |
| 3200 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3201 | "1238 Failed to allocate memory for " |
| 3202 | "multixri_pool\n"); |
| 3203 | |
| 3204 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3205 | lpfc_destroy_expedite_pool(phba); |
| 3206 | |
| 3207 | j = 0; |
| 3208 | while (j < i) { |
| 3209 | qp = &phba->sli4_hba.hdwq[j]; |
| 3210 | kfree(qp->p_multixri_pool); |
| 3211 | j++; |
| 3212 | } |
| 3213 | phba->cfg_xri_rebalancing = 0; |
| 3214 | return; |
| 3215 | } |
| 3216 | |
| 3217 | qp = &phba->sli4_hba.hdwq[i]; |
| 3218 | qp->p_multixri_pool = multixri_pool; |
| 3219 | |
| 3220 | multixri_pool->xri_limit = count_per_hwq; |
| 3221 | multixri_pool->rrb_next_hwqid = i; |
| 3222 | |
| 3223 | /* Deal with public free xri pool */ |
| 3224 | pbl_pool = &multixri_pool->pbl_pool; |
| 3225 | spin_lock_init(&pbl_pool->lock); |
| 3226 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3227 | spin_lock(&pbl_pool->lock); |
| 3228 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3229 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3230 | &qp->lpfc_io_buf_list_put, list) { |
| 3231 | list_move_tail(&lpfc_ncmd->list, &pbl_pool->list); |
| 3232 | qp->put_io_bufs--; |
| 3233 | pbl_pool->count++; |
| 3234 | } |
| 3235 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3236 | "1235 Moved %d buffers from PUT list over to pbl_pool[%d]\n", |
| 3237 | pbl_pool->count, i); |
| 3238 | spin_unlock(&pbl_pool->lock); |
| 3239 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3240 | |
| 3241 | /* Deal with private free xri pool */ |
| 3242 | pvt_pool = &multixri_pool->pvt_pool; |
| 3243 | pvt_pool->high_watermark = multixri_pool->xri_limit / 2; |
| 3244 | pvt_pool->low_watermark = XRI_BATCH; |
| 3245 | spin_lock_init(&pvt_pool->lock); |
| 3246 | spin_lock_irqsave(&pvt_pool->lock, iflag); |
| 3247 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3248 | pvt_pool->count = 0; |
| 3249 | spin_unlock_irqrestore(&pvt_pool->lock, iflag); |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | /** |
| 3254 | * lpfc_destroy_multixri_pools - destroy multi-XRI pools |
| 3255 | * @phba: pointer to lpfc hba data structure. |
| 3256 | * |
| 3257 | * This routine returns XRIs from public/private to lpfc_io_buf_list_put. |
| 3258 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 3259 | static void lpfc_destroy_multixri_pools(struct lpfc_hba *phba) |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3260 | { |
| 3261 | u32 i; |
| 3262 | u32 hwq_count; |
| 3263 | struct lpfc_io_buf *lpfc_ncmd; |
| 3264 | struct lpfc_io_buf *lpfc_ncmd_next; |
| 3265 | unsigned long iflag; |
| 3266 | struct lpfc_sli4_hdw_queue *qp; |
| 3267 | struct lpfc_multixri_pool *multixri_pool; |
| 3268 | struct lpfc_pbl_pool *pbl_pool; |
| 3269 | struct lpfc_pvt_pool *pvt_pool; |
| 3270 | |
| 3271 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 3272 | lpfc_destroy_expedite_pool(phba); |
| 3273 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 3274 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
| 3275 | lpfc_sli_flush_io_rings(phba); |
James Smart | c66a919 | 2019-03-12 16:30:19 -0700 | [diff] [blame] | 3276 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3277 | hwq_count = phba->cfg_hdw_queue; |
| 3278 | |
| 3279 | for (i = 0; i < hwq_count; i++) { |
| 3280 | qp = &phba->sli4_hba.hdwq[i]; |
| 3281 | multixri_pool = qp->p_multixri_pool; |
| 3282 | if (!multixri_pool) |
| 3283 | continue; |
| 3284 | |
| 3285 | qp->p_multixri_pool = NULL; |
| 3286 | |
| 3287 | spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag); |
| 3288 | |
| 3289 | /* Deal with public free xri pool */ |
| 3290 | pbl_pool = &multixri_pool->pbl_pool; |
| 3291 | spin_lock(&pbl_pool->lock); |
| 3292 | |
| 3293 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3294 | "1236 Moving %d buffers from pbl_pool[%d] TO PUT list\n", |
| 3295 | pbl_pool->count, i); |
| 3296 | |
| 3297 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3298 | &pbl_pool->list, list) { |
| 3299 | list_move_tail(&lpfc_ncmd->list, |
| 3300 | &qp->lpfc_io_buf_list_put); |
| 3301 | qp->put_io_bufs++; |
| 3302 | pbl_pool->count--; |
| 3303 | } |
| 3304 | |
| 3305 | INIT_LIST_HEAD(&pbl_pool->list); |
| 3306 | pbl_pool->count = 0; |
| 3307 | |
| 3308 | spin_unlock(&pbl_pool->lock); |
| 3309 | |
| 3310 | /* Deal with private free xri pool */ |
| 3311 | pvt_pool = &multixri_pool->pvt_pool; |
| 3312 | spin_lock(&pvt_pool->lock); |
| 3313 | |
| 3314 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3315 | "1237 Moving %d buffers from pvt_pool[%d] TO PUT list\n", |
| 3316 | pvt_pool->count, i); |
| 3317 | |
| 3318 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3319 | &pvt_pool->list, list) { |
| 3320 | list_move_tail(&lpfc_ncmd->list, |
| 3321 | &qp->lpfc_io_buf_list_put); |
| 3322 | qp->put_io_bufs++; |
| 3323 | pvt_pool->count--; |
| 3324 | } |
| 3325 | |
| 3326 | INIT_LIST_HEAD(&pvt_pool->list); |
| 3327 | pvt_pool->count = 0; |
| 3328 | |
| 3329 | spin_unlock(&pvt_pool->lock); |
| 3330 | spin_unlock_irqrestore(&qp->io_buf_list_put_lock, iflag); |
| 3331 | |
| 3332 | kfree(multixri_pool); |
| 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3337 | * lpfc_online - Initialize and bring a HBA online |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3338 | * @phba: pointer to lpfc hba data structure. |
| 3339 | * |
| 3340 | * This routine initializes the HBA and brings a HBA online. During this |
| 3341 | * process, the management interface is blocked to prevent user space access |
| 3342 | * to the HBA interfering with the driver initialization. |
| 3343 | * |
| 3344 | * Return codes |
| 3345 | * 0 - successful |
| 3346 | * 1 - failed |
| 3347 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3348 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3349 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3350 | { |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3351 | struct lpfc_vport *vport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3352 | struct lpfc_vport **vports; |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3353 | int i, error = 0; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3354 | bool vpis_cleared = false; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3355 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3356 | if (!phba) |
| 3357 | return 0; |
Julia Lawall | 372bd28 | 2008-12-16 16:15:08 +0100 | [diff] [blame] | 3358 | vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3359 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3360 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3361 | return 0; |
| 3362 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 3363 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3364 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3365 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3366 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3367 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3368 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 3369 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ |
| 3370 | lpfc_unblock_mgmt_io(phba); |
| 3371 | return 1; |
| 3372 | } |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3373 | spin_lock_irq(&phba->hbalock); |
| 3374 | if (!phba->sli4_hba.max_cfg_param.vpi_used) |
| 3375 | vpis_cleared = true; |
| 3376 | spin_unlock_irq(&phba->hbalock); |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3377 | |
| 3378 | /* Reestablish the local initiator port. |
| 3379 | * The offline process destroyed the previous lport. |
| 3380 | */ |
| 3381 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
| 3382 | !phba->nvmet_support) { |
| 3383 | error = lpfc_nvme_create_localport(phba->pport); |
| 3384 | if (error) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3385 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | a145fda | 2017-08-23 16:55:44 -0700 | [diff] [blame] | 3386 | "6132 NVME restore reg failed " |
| 3387 | "on nvmei error x%x\n", error); |
| 3388 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3389 | } else { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3390 | lpfc_sli_queue_init(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3391 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
| 3392 | lpfc_unblock_mgmt_io(phba); |
| 3393 | return 1; |
| 3394 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3395 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3396 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3397 | vports = lpfc_create_vport_work_array(phba); |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3398 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3399 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3400 | struct Scsi_Host *shost; |
| 3401 | shost = lpfc_shost_from_vport(vports[i]); |
| 3402 | spin_lock_irq(shost->host_lock); |
| 3403 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 3404 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 3405 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3406 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 3407 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
James Smart | 16a3a20 | 2013-04-17 20:14:38 -0400 | [diff] [blame] | 3408 | if ((vpis_cleared) && |
| 3409 | (vports[i]->port_type != |
| 3410 | LPFC_PHYSICAL_PORT)) |
| 3411 | vports[i]->vpi = 0; |
| 3412 | } |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3413 | spin_unlock_irq(shost->host_lock); |
| 3414 | } |
Arnd Bergmann | aeb6641 | 2016-03-14 15:29:44 +0100 | [diff] [blame] | 3415 | } |
| 3416 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3417 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3418 | if (phba->cfg_xri_rebalancing) |
| 3419 | lpfc_create_multixri_pools(phba); |
| 3420 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 3421 | lpfc_cpuhp_add(phba); |
| 3422 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3423 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3424 | return 0; |
| 3425 | } |
| 3426 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3427 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3428 | * 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] | 3429 | * @phba: pointer to lpfc hba data structure. |
| 3430 | * |
| 3431 | * This routine marks a HBA's management interface as not blocked. Once the |
| 3432 | * HBA's management interface is marked as not blocked, all the user space |
| 3433 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 3434 | * interface will be allowed. The HBA is set to block the management interface |
| 3435 | * when the driver prepares the HBA interface for online or offline and then |
| 3436 | * set to unblock the management interface afterwards. |
| 3437 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3438 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3439 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 3440 | { |
| 3441 | unsigned long iflag; |
| 3442 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3443 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 3444 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 3445 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3446 | } |
| 3447 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3448 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3449 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3450 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 3451 | * @mbx_action: flag for mailbox shutdown action. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3452 | * |
| 3453 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 3454 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 3455 | * queue to make it ready to be brought offline. |
| 3456 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3457 | void |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3458 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3459 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3460 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3461 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3462 | struct lpfc_vport **vports; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3463 | struct Scsi_Host *shost; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3464 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3465 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3466 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3467 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3468 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3469 | lpfc_block_mgmt_io(phba, mbx_action); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3470 | |
| 3471 | lpfc_linkdown(phba); |
| 3472 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3473 | /* Issue an unreg_login to all nodes on all vports */ |
| 3474 | vports = lpfc_create_vport_work_array(phba); |
| 3475 | if (vports != NULL) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3476 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 3477 | if (vports[i]->load_flag & FC_UNLOADING) |
| 3478 | continue; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3479 | shost = lpfc_shost_from_vport(vports[i]); |
| 3480 | spin_lock_irq(shost->host_lock); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 3481 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3482 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 3483 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 3484 | spin_unlock_irq(shost->host_lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 3485 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3486 | shost = lpfc_shost_from_vport(vports[i]); |
| 3487 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 3488 | &vports[i]->fc_nodes, |
| 3489 | nlp_listp) { |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3490 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3491 | /* Driver must assume RPI is invalid for |
| 3492 | * any unused or inactive node. |
| 3493 | */ |
| 3494 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 3495 | continue; |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3498 | spin_lock_irq(&ndlp->lock); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3499 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 3500 | spin_unlock_irq(&ndlp->lock); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3501 | /* |
| 3502 | * Whenever an SLI4 port goes offline, free the |
James Smart | 401ee0c | 2012-03-01 22:35:34 -0500 | [diff] [blame] | 3503 | * RPI. Get a new RPI when the adapter port |
| 3504 | * comes back online. |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3505 | */ |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3506 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 3507 | lpfc_printf_vlog(vports[i], KERN_INFO, |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3508 | LOG_NODE | LOG_DISCOVERY, |
| 3509 | "0011 Free RPI x%x on " |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 3510 | "ndlp: %p did x%x\n", |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3511 | ndlp->nlp_rpi, ndlp, |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3512 | ndlp->nlp_DID); |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 3513 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
James Smart | 0f15422 | 2019-09-21 20:58:52 -0700 | [diff] [blame] | 3514 | ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR; |
James Smart | be6bb94 | 2015-04-07 15:07:22 -0400 | [diff] [blame] | 3515 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3516 | lpfc_unreg_rpi(vports[i], ndlp); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3517 | |
| 3518 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 3519 | lpfc_disc_state_machine(vports[i], ndlp, |
| 3520 | NULL, NLP_EVT_DEVICE_RECOVERY); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 3521 | |
| 3522 | /* Don't remove the node unless the |
| 3523 | * has been unregistered with the |
| 3524 | * transport. If so, let dev_loss |
| 3525 | * take care of the node. |
| 3526 | */ |
| 3527 | if (!(ndlp->fc4_xpt_flags & |
| 3528 | (NVME_XPT_REGD | SCSI_XPT_REGD))) |
| 3529 | lpfc_disc_state_machine |
| 3530 | (vports[i], ndlp, |
| 3531 | NULL, |
| 3532 | NLP_EVT_DEVICE_RM); |
James Smart | 307e338 | 2020-11-15 11:26:30 -0800 | [diff] [blame] | 3533 | } |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 3534 | } |
| 3535 | } |
| 3536 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3537 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3538 | |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 3539 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 3540 | |
| 3541 | if (phba->wq) |
| 3542 | flush_workqueue(phba->wq); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3543 | } |
| 3544 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3545 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3546 | * lpfc_offline - Bring a HBA offline |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3547 | * @phba: pointer to lpfc hba data structure. |
| 3548 | * |
| 3549 | * This routine actually brings a HBA offline. It stops all the timers |
| 3550 | * associated with the HBA, brings down the SLI layer, and eventually |
| 3551 | * marks the HBA as in offline state for the upper layer protocol. |
| 3552 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3553 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3554 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3555 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3556 | struct Scsi_Host *shost; |
| 3557 | struct lpfc_vport **vports; |
| 3558 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3559 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3560 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 3561 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 3562 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3563 | /* stop port and all timers associated with this hba */ |
| 3564 | lpfc_stop_port(phba); |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 3565 | |
| 3566 | /* Tear down the local and target port registrations. The |
| 3567 | * nvme transports need to cleanup. |
| 3568 | */ |
| 3569 | lpfc_nvmet_destroy_targetport(phba); |
| 3570 | lpfc_nvme_destroy_localport(phba->pport); |
| 3571 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3572 | vports = lpfc_create_vport_work_array(phba); |
| 3573 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3574 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3575 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3576 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3577 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3578 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3579 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 3580 | now. */ |
| 3581 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3582 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 3583 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3584 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3585 | vports = lpfc_create_vport_work_array(phba); |
| 3586 | if (vports != NULL) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 3587 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3588 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 3589 | spin_lock_irq(shost->host_lock); |
| 3590 | vports[i]->work_port_events = 0; |
| 3591 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 3592 | spin_unlock_irq(shost->host_lock); |
| 3593 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 3594 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 3595 | __lpfc_cpuhp_remove(phba); |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3596 | |
| 3597 | if (phba->cfg_xri_rebalancing) |
| 3598 | lpfc_destroy_multixri_pools(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3599 | } |
| 3600 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3601 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3602 | * 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] | 3603 | * @phba: pointer to lpfc hba data structure. |
| 3604 | * |
| 3605 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 3606 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3607 | * the internal resources before the device is removed from the system. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3608 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3609 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3610 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3611 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3612 | struct lpfc_io_buf *sb, *sb_next; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3613 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3614 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 3615 | return; |
| 3616 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3617 | spin_lock_irq(&phba->hbalock); |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3618 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3619 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3620 | |
| 3621 | spin_lock(&phba->scsi_buf_list_put_lock); |
| 3622 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, |
| 3623 | list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3624 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3625 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3626 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3627 | kfree(sb); |
| 3628 | phba->total_scsi_bufs--; |
| 3629 | } |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3630 | spin_unlock(&phba->scsi_buf_list_put_lock); |
| 3631 | |
| 3632 | spin_lock(&phba->scsi_buf_list_get_lock); |
| 3633 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, |
| 3634 | list) { |
| 3635 | list_del(&sb->list); |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 3636 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
James Smart | a40fc5f | 2013-04-17 20:17:40 -0400 | [diff] [blame] | 3637 | sb->dma_handle); |
| 3638 | kfree(sb); |
| 3639 | phba->total_scsi_bufs--; |
| 3640 | } |
| 3641 | spin_unlock(&phba->scsi_buf_list_get_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3642 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3643 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3644 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3645 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3646 | * 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] | 3647 | * @phba: pointer to lpfc hba data structure. |
| 3648 | * |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3649 | * 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] | 3650 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 3651 | * the internal resources before the device is removed from the system. |
| 3652 | **/ |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3653 | void |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3654 | lpfc_io_free(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3655 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3656 | struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3657 | struct lpfc_sli4_hdw_queue *qp; |
| 3658 | int idx; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3659 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3660 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3661 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3662 | /* Release all the lpfc_nvme_bufs maintained by this host. */ |
| 3663 | spin_lock(&qp->io_buf_list_put_lock); |
| 3664 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3665 | &qp->lpfc_io_buf_list_put, |
| 3666 | list) { |
| 3667 | list_del(&lpfc_ncmd->list); |
| 3668 | qp->put_io_bufs--; |
| 3669 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3670 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3671 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 3672 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 3673 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3674 | kfree(lpfc_ncmd); |
| 3675 | qp->total_io_bufs--; |
| 3676 | } |
| 3677 | spin_unlock(&qp->io_buf_list_put_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3678 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3679 | spin_lock(&qp->io_buf_list_get_lock); |
| 3680 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
| 3681 | &qp->lpfc_io_buf_list_get, |
| 3682 | list) { |
| 3683 | list_del(&lpfc_ncmd->list); |
| 3684 | qp->get_io_bufs--; |
| 3685 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 3686 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 3687 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 3688 | lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd); |
| 3689 | lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3690 | kfree(lpfc_ncmd); |
| 3691 | qp->total_io_bufs--; |
| 3692 | } |
| 3693 | spin_unlock(&qp->io_buf_list_get_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3694 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3695 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 3696 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3697 | /** |
| 3698 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3699 | * @phba: pointer to lpfc hba data structure. |
| 3700 | * |
| 3701 | * This routine first calculates the sizes of the current els and allocated |
| 3702 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3703 | * XRIs assigned due to port function reset. During port initialization, the |
| 3704 | * current els and allocated scsi sgl lists are 0s. |
| 3705 | * |
| 3706 | * Return codes |
| 3707 | * 0 - successful (for now, it always returns 0) |
| 3708 | **/ |
| 3709 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3710 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3711 | { |
| 3712 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3713 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3714 | LIST_HEAD(els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3715 | int rc; |
| 3716 | |
| 3717 | /* |
| 3718 | * update on pci function's els xri-sgl list |
| 3719 | */ |
| 3720 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3721 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3722 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
| 3723 | /* els xri-sgl expanded */ |
| 3724 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; |
| 3725 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3726 | "3157 ELS xri-sgl count increased from " |
| 3727 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3728 | els_xri_cnt); |
| 3729 | /* allocate the additional els sgls */ |
| 3730 | for (i = 0; i < xri_cnt; i++) { |
| 3731 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3732 | GFP_KERNEL); |
| 3733 | if (sglq_entry == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3734 | lpfc_printf_log(phba, KERN_ERR, |
| 3735 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3736 | "2562 Failure to allocate an " |
| 3737 | "ELS sgl entry:%d\n", i); |
| 3738 | rc = -ENOMEM; |
| 3739 | goto out_free_mem; |
| 3740 | } |
| 3741 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
| 3742 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, |
| 3743 | &sglq_entry->phys); |
| 3744 | if (sglq_entry->virt == NULL) { |
| 3745 | kfree(sglq_entry); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3746 | lpfc_printf_log(phba, KERN_ERR, |
| 3747 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3748 | "2563 Failure to allocate an " |
| 3749 | "ELS mbuf:%d\n", i); |
| 3750 | rc = -ENOMEM; |
| 3751 | goto out_free_mem; |
| 3752 | } |
| 3753 | sglq_entry->sgl = sglq_entry->virt; |
| 3754 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); |
| 3755 | sglq_entry->state = SGL_FREED; |
| 3756 | list_add_tail(&sglq_entry->list, &els_sgl_list); |
| 3757 | } |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3758 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3759 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3760 | list_splice_init(&els_sgl_list, |
| 3761 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3762 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 38c2067 | 2013-03-01 16:37:44 -0500 | [diff] [blame] | 3763 | spin_unlock_irq(&phba->hbalock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3764 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
| 3765 | /* els xri-sgl shrinked */ |
| 3766 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; |
| 3767 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3768 | "3158 ELS xri-sgl count decreased from " |
| 3769 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, |
| 3770 | els_xri_cnt); |
| 3771 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3772 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3773 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, |
| 3774 | &els_sgl_list); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3775 | /* release extra els sgls from list */ |
| 3776 | for (i = 0; i < xri_cnt; i++) { |
| 3777 | list_remove_head(&els_sgl_list, |
| 3778 | sglq_entry, struct lpfc_sglq, list); |
| 3779 | if (sglq_entry) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3780 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
| 3781 | sglq_entry->phys); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3782 | kfree(sglq_entry); |
| 3783 | } |
| 3784 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3785 | list_splice_init(&els_sgl_list, |
| 3786 | &phba->sli4_hba.lpfc_els_sgl_list); |
| 3787 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3788 | spin_unlock_irq(&phba->hbalock); |
| 3789 | } else |
| 3790 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3791 | "3163 ELS xri-sgl count unchanged: %d\n", |
| 3792 | els_xri_cnt); |
| 3793 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; |
| 3794 | |
| 3795 | /* update xris to els sgls on the list */ |
| 3796 | sglq_entry = NULL; |
| 3797 | sglq_entry_next = NULL; |
| 3798 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3799 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3800 | lxri = lpfc_sli4_next_xritag(phba); |
| 3801 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3802 | lpfc_printf_log(phba, KERN_ERR, |
| 3803 | LOG_TRACE_EVENT, |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 3804 | "2400 Failed to allocate xri for " |
| 3805 | "ELS sgl\n"); |
| 3806 | rc = -ENOMEM; |
| 3807 | goto out_free_mem; |
| 3808 | } |
| 3809 | sglq_entry->sli4_lxritag = lxri; |
| 3810 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3811 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 3812 | return 0; |
| 3813 | |
| 3814 | out_free_mem: |
| 3815 | lpfc_free_els_sgl_list(phba); |
| 3816 | return rc; |
| 3817 | } |
| 3818 | |
| 3819 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3820 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping |
| 3821 | * @phba: pointer to lpfc hba data structure. |
| 3822 | * |
| 3823 | * This routine first calculates the sizes of the current els and allocated |
| 3824 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 3825 | * XRIs assigned due to port function reset. During port initialization, the |
| 3826 | * current els and allocated scsi sgl lists are 0s. |
| 3827 | * |
| 3828 | * Return codes |
| 3829 | * 0 - successful (for now, it always returns 0) |
| 3830 | **/ |
| 3831 | int |
| 3832 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) |
| 3833 | { |
| 3834 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; |
| 3835 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3836 | uint16_t nvmet_xri_cnt; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3837 | LIST_HEAD(nvmet_sgl_list); |
| 3838 | int rc; |
| 3839 | |
| 3840 | /* |
| 3841 | * update on pci function's nvmet xri-sgl list |
| 3842 | */ |
| 3843 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 61f3d4b | 2017-05-15 15:20:41 -0700 | [diff] [blame] | 3844 | |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 3845 | /* For NVMET, ALL remaining XRIs are dedicated for IO processing */ |
| 3846 | 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] | 3847 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { |
| 3848 | /* els xri-sgl expanded */ |
| 3849 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; |
| 3850 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3851 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", |
| 3852 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); |
| 3853 | /* allocate the additional nvmet sgls */ |
| 3854 | for (i = 0; i < xri_cnt; i++) { |
| 3855 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), |
| 3856 | GFP_KERNEL); |
| 3857 | if (sglq_entry == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3858 | lpfc_printf_log(phba, KERN_ERR, |
| 3859 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3860 | "6303 Failure to allocate an " |
| 3861 | "NVMET sgl entry:%d\n", i); |
| 3862 | rc = -ENOMEM; |
| 3863 | goto out_free_mem; |
| 3864 | } |
| 3865 | sglq_entry->buff_type = NVMET_BUFF_TYPE; |
| 3866 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, |
| 3867 | &sglq_entry->phys); |
| 3868 | if (sglq_entry->virt == NULL) { |
| 3869 | kfree(sglq_entry); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 3870 | lpfc_printf_log(phba, KERN_ERR, |
| 3871 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3872 | "6304 Failure to allocate an " |
| 3873 | "NVMET buf:%d\n", i); |
| 3874 | rc = -ENOMEM; |
| 3875 | goto out_free_mem; |
| 3876 | } |
| 3877 | sglq_entry->sgl = sglq_entry->virt; |
| 3878 | memset(sglq_entry->sgl, 0, |
| 3879 | phba->cfg_sg_dma_buf_size); |
| 3880 | sglq_entry->state = SGL_FREED; |
| 3881 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); |
| 3882 | } |
| 3883 | spin_lock_irq(&phba->hbalock); |
| 3884 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3885 | list_splice_init(&nvmet_sgl_list, |
| 3886 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3887 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3888 | spin_unlock_irq(&phba->hbalock); |
| 3889 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { |
| 3890 | /* nvmet xri-sgl shrunk */ |
| 3891 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; |
| 3892 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3893 | "6305 NVMET xri-sgl count decreased from " |
| 3894 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, |
| 3895 | nvmet_xri_cnt); |
| 3896 | spin_lock_irq(&phba->hbalock); |
| 3897 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 3898 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, |
| 3899 | &nvmet_sgl_list); |
| 3900 | /* release extra nvmet sgls from list */ |
| 3901 | for (i = 0; i < xri_cnt; i++) { |
| 3902 | list_remove_head(&nvmet_sgl_list, |
| 3903 | sglq_entry, struct lpfc_sglq, list); |
| 3904 | if (sglq_entry) { |
| 3905 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, |
| 3906 | sglq_entry->phys); |
| 3907 | kfree(sglq_entry); |
| 3908 | } |
| 3909 | } |
| 3910 | list_splice_init(&nvmet_sgl_list, |
| 3911 | &phba->sli4_hba.lpfc_nvmet_sgl_list); |
| 3912 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 3913 | spin_unlock_irq(&phba->hbalock); |
| 3914 | } else |
| 3915 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 3916 | "6306 NVMET xri-sgl count unchanged: %d\n", |
| 3917 | nvmet_xri_cnt); |
| 3918 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; |
| 3919 | |
| 3920 | /* update xris to nvmet sgls on the list */ |
| 3921 | sglq_entry = NULL; |
| 3922 | sglq_entry_next = NULL; |
| 3923 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, |
| 3924 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { |
| 3925 | lxri = lpfc_sli4_next_xritag(phba); |
| 3926 | if (lxri == NO_XRI) { |
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 | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 3929 | "6307 Failed to allocate xri for " |
| 3930 | "NVMET sgl\n"); |
| 3931 | rc = -ENOMEM; |
| 3932 | goto out_free_mem; |
| 3933 | } |
| 3934 | sglq_entry->sli4_lxritag = lxri; |
| 3935 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 3936 | } |
| 3937 | return 0; |
| 3938 | |
| 3939 | out_free_mem: |
| 3940 | lpfc_free_nvmet_sgl_list(phba); |
| 3941 | return rc; |
| 3942 | } |
| 3943 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3944 | int |
| 3945 | lpfc_io_buf_flush(struct lpfc_hba *phba, struct list_head *cbuf) |
| 3946 | { |
| 3947 | LIST_HEAD(blist); |
| 3948 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3949 | struct lpfc_io_buf *lpfc_cmd; |
| 3950 | struct lpfc_io_buf *iobufp, *prev_iobufp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3951 | int idx, cnt, xri, inserted; |
| 3952 | |
| 3953 | cnt = 0; |
| 3954 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 3955 | qp = &phba->sli4_hba.hdwq[idx]; |
| 3956 | spin_lock_irq(&qp->io_buf_list_get_lock); |
| 3957 | spin_lock(&qp->io_buf_list_put_lock); |
| 3958 | |
| 3959 | /* Take everything off the get and put lists */ |
| 3960 | list_splice_init(&qp->lpfc_io_buf_list_get, &blist); |
| 3961 | list_splice(&qp->lpfc_io_buf_list_put, &blist); |
| 3962 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 3963 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 3964 | cnt += qp->get_io_bufs + qp->put_io_bufs; |
| 3965 | qp->get_io_bufs = 0; |
| 3966 | qp->put_io_bufs = 0; |
| 3967 | qp->total_io_bufs = 0; |
| 3968 | spin_unlock(&qp->io_buf_list_put_lock); |
| 3969 | spin_unlock_irq(&qp->io_buf_list_get_lock); |
| 3970 | } |
| 3971 | |
| 3972 | /* |
| 3973 | * Take IO buffers off blist and put on cbuf sorted by XRI. |
| 3974 | * This is because POST_SGL takes a sequential range of XRIs |
| 3975 | * to post to the firmware. |
| 3976 | */ |
| 3977 | for (idx = 0; idx < cnt; idx++) { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 3978 | list_remove_head(&blist, lpfc_cmd, struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 3979 | if (!lpfc_cmd) |
| 3980 | return cnt; |
| 3981 | if (idx == 0) { |
| 3982 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 3983 | continue; |
| 3984 | } |
| 3985 | xri = lpfc_cmd->cur_iocbq.sli4_xritag; |
| 3986 | inserted = 0; |
| 3987 | prev_iobufp = NULL; |
| 3988 | list_for_each_entry(iobufp, cbuf, list) { |
| 3989 | if (xri < iobufp->cur_iocbq.sli4_xritag) { |
| 3990 | if (prev_iobufp) |
| 3991 | list_add(&lpfc_cmd->list, |
| 3992 | &prev_iobufp->list); |
| 3993 | else |
| 3994 | list_add(&lpfc_cmd->list, cbuf); |
| 3995 | inserted = 1; |
| 3996 | break; |
| 3997 | } |
| 3998 | prev_iobufp = iobufp; |
| 3999 | } |
| 4000 | if (!inserted) |
| 4001 | list_add_tail(&lpfc_cmd->list, cbuf); |
| 4002 | } |
| 4003 | return cnt; |
| 4004 | } |
| 4005 | |
| 4006 | int |
| 4007 | lpfc_io_buf_replenish(struct lpfc_hba *phba, struct list_head *cbuf) |
| 4008 | { |
| 4009 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4010 | struct lpfc_io_buf *lpfc_cmd; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4011 | int idx, cnt; |
| 4012 | |
| 4013 | qp = phba->sli4_hba.hdwq; |
| 4014 | cnt = 0; |
| 4015 | while (!list_empty(cbuf)) { |
| 4016 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 4017 | list_remove_head(cbuf, lpfc_cmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4018 | struct lpfc_io_buf, list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4019 | if (!lpfc_cmd) |
| 4020 | return cnt; |
| 4021 | cnt++; |
| 4022 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | 1fbf974 | 2019-01-28 11:14:26 -0800 | [diff] [blame] | 4023 | lpfc_cmd->hdwq_no = idx; |
| 4024 | lpfc_cmd->hdwq = qp; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4025 | lpfc_cmd->cur_iocbq.wqe_cmpl = NULL; |
| 4026 | lpfc_cmd->cur_iocbq.iocb_cmpl = NULL; |
| 4027 | spin_lock(&qp->io_buf_list_put_lock); |
| 4028 | list_add_tail(&lpfc_cmd->list, |
| 4029 | &qp->lpfc_io_buf_list_put); |
| 4030 | qp->put_io_bufs++; |
| 4031 | qp->total_io_bufs++; |
| 4032 | spin_unlock(&qp->io_buf_list_put_lock); |
| 4033 | } |
| 4034 | } |
| 4035 | return cnt; |
| 4036 | } |
| 4037 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 4038 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4039 | * lpfc_sli4_io_sgl_update - update xri-sgl sizing and mapping |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4040 | * @phba: pointer to lpfc hba data structure. |
| 4041 | * |
| 4042 | * This routine first calculates the sizes of the current els and allocated |
| 4043 | * scsi sgl lists, and then goes through all sgls to updates the physical |
| 4044 | * XRIs assigned due to port function reset. During port initialization, the |
| 4045 | * current els and allocated scsi sgl lists are 0s. |
| 4046 | * |
| 4047 | * Return codes |
| 4048 | * 0 - successful (for now, it always returns 0) |
| 4049 | **/ |
| 4050 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4051 | lpfc_sli4_io_sgl_update(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4052 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4053 | struct lpfc_io_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4054 | uint16_t i, lxri, els_xri_cnt; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4055 | uint16_t io_xri_cnt, io_xri_max; |
| 4056 | LIST_HEAD(io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4057 | int rc, cnt; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4058 | |
| 4059 | /* |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4060 | * update on pci function's allocated nvme xri-sgl list |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4061 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4062 | |
| 4063 | /* maximum number of xris available for nvme buffers */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4064 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4065 | io_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; |
| 4066 | phba->sli4_hba.io_xri_max = io_xri_max; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4067 | |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4068 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4069 | "6074 Current allocated XRI sgl count:%d, " |
| 4070 | "maximum XRI count:%d\n", |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4071 | phba->sli4_hba.io_xri_cnt, |
| 4072 | phba->sli4_hba.io_xri_max); |
James Smart | e8c0a77 | 2017-04-21 16:04:49 -0700 | [diff] [blame] | 4073 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4074 | cnt = lpfc_io_buf_flush(phba, &io_sgl_list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4075 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4076 | 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] | 4077 | /* max nvme xri shrunk below the allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4078 | io_xri_cnt = phba->sli4_hba.io_xri_cnt - |
| 4079 | phba->sli4_hba.io_xri_max; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4080 | /* release the extra allocated nvme buffers */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4081 | for (i = 0; i < io_xri_cnt; i++) { |
| 4082 | list_remove_head(&io_sgl_list, lpfc_ncmd, |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4083 | struct lpfc_io_buf, list); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4084 | if (lpfc_ncmd) { |
Romain Perier | 771db5c | 2017-07-06 10:13:05 +0200 | [diff] [blame] | 4085 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4086 | lpfc_ncmd->data, |
| 4087 | lpfc_ncmd->dma_handle); |
| 4088 | kfree(lpfc_ncmd); |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 4089 | } |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4090 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4091 | phba->sli4_hba.io_xri_cnt -= io_xri_cnt; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4092 | } |
| 4093 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4094 | /* update xris associated to remaining allocated nvme buffers */ |
| 4095 | lpfc_ncmd = NULL; |
| 4096 | lpfc_ncmd_next = NULL; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4097 | phba->sli4_hba.io_xri_cnt = cnt; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4098 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4099 | &io_sgl_list, list) { |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4100 | lxri = lpfc_sli4_next_xritag(phba); |
| 4101 | if (lxri == NO_XRI) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4102 | lpfc_printf_log(phba, KERN_ERR, |
| 4103 | LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4104 | "6075 Failed to allocate xri for " |
| 4105 | "nvme buffer\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4106 | rc = -ENOMEM; |
| 4107 | goto out_free_mem; |
| 4108 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4109 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; |
| 4110 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4111 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4112 | cnt = lpfc_io_buf_replenish(phba, &io_sgl_list); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4113 | return 0; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4114 | |
| 4115 | out_free_mem: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4116 | lpfc_io_free(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 4117 | return rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4118 | } |
| 4119 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4120 | /** |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4121 | * 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] | 4122 | * @phba: Pointer to lpfc hba data structure. |
| 4123 | * @num_to_alloc: The requested number of buffers to allocate. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4124 | * |
| 4125 | * This routine allocates nvme buffers for device with SLI-4 interface spec, |
| 4126 | * the nvme buffer contains all the necessary information needed to initiate |
| 4127 | * an I/O. After allocating up to @num_to_allocate IO buffers and put |
| 4128 | * them on a list, it post them to the port by using SGL block post. |
| 4129 | * |
| 4130 | * Return codes: |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4131 | * int - number of IO buffers that were allocated and posted. |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4132 | * 0 = failure, less than num_to_alloc is a partial failure. |
| 4133 | **/ |
| 4134 | int |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4135 | lpfc_new_io_buf(struct lpfc_hba *phba, int num_to_alloc) |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4136 | { |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 4137 | struct lpfc_io_buf *lpfc_ncmd; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4138 | struct lpfc_iocbq *pwqeq; |
| 4139 | uint16_t iotag, lxri = 0; |
| 4140 | int bcnt, num_posted; |
| 4141 | LIST_HEAD(prep_nblist); |
| 4142 | LIST_HEAD(post_nblist); |
| 4143 | LIST_HEAD(nvme_nblist); |
| 4144 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4145 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4146 | for (bcnt = 0; bcnt < num_to_alloc; bcnt++) { |
James Smart | 7f9989b | 2019-08-27 14:27:46 -0700 | [diff] [blame] | 4147 | lpfc_ncmd = kzalloc(sizeof(*lpfc_ncmd), GFP_KERNEL); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4148 | if (!lpfc_ncmd) |
| 4149 | break; |
| 4150 | /* |
| 4151 | * Get memory from the pci pool to map the virt space to |
| 4152 | * pci bus space for an I/O. The DMA buffer includes the |
| 4153 | * number of SGE's necessary to support the sg_tablesize. |
| 4154 | */ |
Thomas Meyer | a5c990e | 2019-05-29 22:21:36 +0200 | [diff] [blame] | 4155 | lpfc_ncmd->data = dma_pool_zalloc(phba->lpfc_sg_dma_buf_pool, |
| 4156 | GFP_KERNEL, |
| 4157 | &lpfc_ncmd->dma_handle); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4158 | if (!lpfc_ncmd->data) { |
| 4159 | kfree(lpfc_ncmd); |
| 4160 | break; |
| 4161 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4162 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4163 | if (phba->cfg_xpsgl && !phba->nvmet_support) { |
| 4164 | INIT_LIST_HEAD(&lpfc_ncmd->dma_sgl_xtra_list); |
| 4165 | } else { |
| 4166 | /* |
| 4167 | * 4K Page alignment is CRITICAL to BlockGuard, double |
| 4168 | * check to be sure. |
| 4169 | */ |
| 4170 | if ((phba->sli3_options & LPFC_SLI3_BG_ENABLED) && |
| 4171 | (((unsigned long)(lpfc_ncmd->data) & |
| 4172 | (unsigned long)(SLI4_PAGE_SIZE - 1)) != 0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4173 | lpfc_printf_log(phba, KERN_ERR, |
| 4174 | LOG_TRACE_EVENT, |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4175 | "3369 Memory alignment err: " |
| 4176 | "addr=%lx\n", |
| 4177 | (unsigned long)lpfc_ncmd->data); |
| 4178 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4179 | lpfc_ncmd->data, |
| 4180 | lpfc_ncmd->dma_handle); |
| 4181 | kfree(lpfc_ncmd); |
| 4182 | break; |
| 4183 | } |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4184 | } |
| 4185 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4186 | INIT_LIST_HEAD(&lpfc_ncmd->dma_cmd_rsp_list); |
| 4187 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4188 | lxri = lpfc_sli4_next_xritag(phba); |
| 4189 | if (lxri == NO_XRI) { |
| 4190 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4191 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4192 | kfree(lpfc_ncmd); |
| 4193 | break; |
| 4194 | } |
| 4195 | pwqeq = &lpfc_ncmd->cur_iocbq; |
| 4196 | |
| 4197 | /* Allocate iotag for lpfc_ncmd->cur_iocbq. */ |
| 4198 | iotag = lpfc_sli_next_iotag(phba, pwqeq); |
| 4199 | if (iotag == 0) { |
| 4200 | dma_pool_free(phba->lpfc_sg_dma_buf_pool, |
| 4201 | lpfc_ncmd->data, lpfc_ncmd->dma_handle); |
| 4202 | kfree(lpfc_ncmd); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4203 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4204 | "6121 Failed to allocate IOTAG for" |
| 4205 | " XRI:0x%x\n", lxri); |
| 4206 | lpfc_sli4_free_xri(phba, lxri); |
| 4207 | break; |
| 4208 | } |
| 4209 | pwqeq->sli4_lxritag = lxri; |
| 4210 | pwqeq->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; |
| 4211 | pwqeq->context1 = lpfc_ncmd; |
| 4212 | |
| 4213 | /* Initialize local short-hand pointers. */ |
| 4214 | lpfc_ncmd->dma_sgl = lpfc_ncmd->data; |
| 4215 | lpfc_ncmd->dma_phys_sgl = lpfc_ncmd->dma_handle; |
| 4216 | lpfc_ncmd->cur_iocbq.context1 = lpfc_ncmd; |
James Smart | c201726 | 2019-01-28 11:14:37 -0800 | [diff] [blame] | 4217 | spin_lock_init(&lpfc_ncmd->buf_lock); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4218 | |
| 4219 | /* add the nvme buffer to a post list */ |
| 4220 | list_add_tail(&lpfc_ncmd->list, &post_nblist); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4221 | phba->sli4_hba.io_xri_cnt++; |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4222 | } |
| 4223 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME, |
| 4224 | "6114 Allocate %d out of %d requested new NVME " |
| 4225 | "buffers\n", bcnt, num_to_alloc); |
| 4226 | |
| 4227 | /* post the list of nvme buffer sgls to port if available */ |
| 4228 | if (!list_empty(&post_nblist)) |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 4229 | num_posted = lpfc_sli4_post_io_sgl_list( |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 4230 | phba, &post_nblist, bcnt); |
| 4231 | else |
| 4232 | num_posted = 0; |
| 4233 | |
| 4234 | return num_posted; |
| 4235 | } |
| 4236 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4237 | static uint64_t |
| 4238 | lpfc_get_wwpn(struct lpfc_hba *phba) |
| 4239 | { |
| 4240 | uint64_t wwn; |
| 4241 | int rc; |
| 4242 | LPFC_MBOXQ_t *mboxq; |
| 4243 | MAILBOX_t *mb; |
| 4244 | |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4245 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 4246 | GFP_KERNEL); |
| 4247 | if (!mboxq) |
| 4248 | return (uint64_t)-1; |
| 4249 | |
| 4250 | /* First get WWN of HBA instance */ |
| 4251 | lpfc_read_nv(phba, mboxq); |
| 4252 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 4253 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4254 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4255 | "6019 Mailbox failed , mbxCmd x%x " |
| 4256 | "READ_NV, mbxStatus x%x\n", |
| 4257 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 4258 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
| 4259 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4260 | return (uint64_t) -1; |
| 4261 | } |
| 4262 | mb = &mboxq->u.mb; |
| 4263 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, sizeof(uint64_t)); |
| 4264 | /* wwn is WWPN of HBA instance */ |
| 4265 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 4266 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 4267 | return be64_to_cpu(wwn); |
| 4268 | else |
Maurizio Lombardi | 286871a | 2017-08-23 16:55:48 -0700 | [diff] [blame] | 4269 | return rol64(wwn, 32); |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4270 | } |
| 4271 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4272 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4273 | * lpfc_create_port - Create an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4274 | * @phba: pointer to lpfc hba data structure. |
| 4275 | * @instance: a unique integer ID to this FC port. |
| 4276 | * @dev: pointer to the device data structure. |
| 4277 | * |
| 4278 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 4279 | * can be created on top of either a physical port or a virtual port provided |
| 4280 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 4281 | * and associates the FC port created before adding the shost into the SCSI |
| 4282 | * layer. |
| 4283 | * |
| 4284 | * Return codes |
| 4285 | * @vport - pointer to the virtual N_Port data structure. |
| 4286 | * NULL - port create failed. |
| 4287 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4288 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4289 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4290 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4291 | struct lpfc_vport *vport; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4292 | struct Scsi_Host *shost = NULL; |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4293 | struct scsi_host_template *template; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4294 | int error = 0; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4295 | int i; |
| 4296 | uint64_t wwn; |
| 4297 | bool use_no_reset_hba = false; |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4298 | int rc; |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4299 | |
James Smart | 56bc802 | 2017-06-15 22:56:43 -0700 | [diff] [blame] | 4300 | if (lpfc_no_hba_reset_cnt) { |
| 4301 | if (phba->sli_rev < LPFC_SLI_REV4 && |
| 4302 | dev == &phba->pcidev->dev) { |
| 4303 | /* Reset the port first */ |
| 4304 | lpfc_sli_brdrestart(phba); |
| 4305 | rc = lpfc_sli_chipset_init(phba); |
| 4306 | if (rc) |
| 4307 | return NULL; |
| 4308 | } |
| 4309 | wwn = lpfc_get_wwpn(phba); |
| 4310 | } |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4311 | |
| 4312 | for (i = 0; i < lpfc_no_hba_reset_cnt; i++) { |
| 4313 | if (wwn == lpfc_no_hba_reset[i]) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4314 | lpfc_printf_log(phba, KERN_ERR, |
| 4315 | LOG_TRACE_EVENT, |
James Smart | 96418b5 | 2017-03-04 09:30:31 -0800 | [diff] [blame] | 4316 | "6020 Setting use_no_reset port=%llx\n", |
| 4317 | wwn); |
| 4318 | use_no_reset_hba = true; |
| 4319 | break; |
| 4320 | } |
| 4321 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4322 | |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4323 | /* Seed template for SCSI host registration */ |
| 4324 | if (dev == &phba->pcidev->dev) { |
| 4325 | template = &phba->port_template; |
| 4326 | |
| 4327 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 4328 | /* Seed physical port template */ |
| 4329 | memcpy(template, &lpfc_template, sizeof(*template)); |
| 4330 | |
James Smart | 7c30bb6 | 2020-10-20 13:27:16 -0700 | [diff] [blame] | 4331 | if (use_no_reset_hba) |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4332 | /* template is for a no reset SCSI Host */ |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4333 | template->eh_host_reset_handler = NULL; |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4334 | |
| 4335 | /* Template for all vports this physical port creates */ |
| 4336 | memcpy(&phba->vport_template, &lpfc_template, |
| 4337 | sizeof(*template)); |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4338 | phba->vport_template.shost_attrs = lpfc_vport_attrs; |
| 4339 | phba->vport_template.eh_bus_reset_handler = NULL; |
| 4340 | phba->vport_template.eh_host_reset_handler = NULL; |
| 4341 | phba->vport_template.vendor_id = 0; |
| 4342 | |
| 4343 | /* Initialize the host templates with updated value */ |
| 4344 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 4345 | template->sg_tablesize = phba->cfg_scsi_seg_cnt; |
| 4346 | phba->vport_template.sg_tablesize = |
| 4347 | phba->cfg_scsi_seg_cnt; |
| 4348 | } else { |
| 4349 | template->sg_tablesize = phba->cfg_sg_seg_cnt; |
| 4350 | phba->vport_template.sg_tablesize = |
| 4351 | phba->cfg_sg_seg_cnt; |
| 4352 | } |
| 4353 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4354 | } else { |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4355 | /* NVMET is for physical port only */ |
| 4356 | memcpy(template, &lpfc_template_nvme, |
| 4357 | sizeof(*template)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4358 | } |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4359 | } else { |
| 4360 | template = &phba->vport_template; |
James Smart | ea4142f | 2015-04-07 15:07:13 -0400 | [diff] [blame] | 4361 | } |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4362 | |
| 4363 | shost = scsi_host_alloc(template, sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4364 | if (!shost) |
| 4365 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4366 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4367 | vport = (struct lpfc_vport *) shost->hostdata; |
| 4368 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4369 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4370 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 4371 | vport->fc_rscn_flush = 0; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4372 | lpfc_get_vport_cfgparam(vport); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4373 | |
James Smart | f6e8479 | 2019-01-28 11:14:38 -0800 | [diff] [blame] | 4374 | /* Adjust value in vport */ |
| 4375 | vport->cfg_enable_fc4_type = phba->cfg_enable_fc4_type; |
| 4376 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4377 | shost->unique_id = instance; |
| 4378 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4379 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4380 | shost->this_id = -1; |
| 4381 | shost->max_cmd_len = 16; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4382 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4383 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | 77ffd34 | 2019-08-15 19:36:49 -0700 | [diff] [blame] | 4384 | if (!phba->cfg_fcp_mq_threshold || |
| 4385 | phba->cfg_fcp_mq_threshold > phba->cfg_hdw_queue) |
| 4386 | phba->cfg_fcp_mq_threshold = phba->cfg_hdw_queue; |
| 4387 | |
| 4388 | shost->nr_hw_queues = min_t(int, 2 * num_possible_nodes(), |
| 4389 | phba->cfg_fcp_mq_threshold); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 4390 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 4391 | shost->dma_boundary = |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 4392 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 4393 | |
| 4394 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 4395 | shost->sg_tablesize = LPFC_MAX_SG_TABLESIZE; |
| 4396 | else |
| 4397 | shost->sg_tablesize = phba->cfg_scsi_seg_cnt; |
James Smart | ace44e4 | 2019-01-28 11:14:27 -0800 | [diff] [blame] | 4398 | } else |
| 4399 | /* SLI-3 has a limited number of hardware queues (3), |
| 4400 | * thus there is only one for FCP processing. |
| 4401 | */ |
| 4402 | shost->nr_hw_queues = 1; |
James Smart | 81301a9 | 2008-12-04 22:39:46 -0500 | [diff] [blame] | 4403 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4404 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4405 | * Set initial can_queue value since 0 is no longer supported and |
| 4406 | * scsi_add_host will fail. This will be adjusted later based on the |
| 4407 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4408 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4409 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 4410 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4411 | shost->transportt = lpfc_vport_transport_template; |
| 4412 | vport->port_type = LPFC_NPIV_PORT; |
| 4413 | } else { |
| 4414 | shost->transportt = lpfc_transport_template; |
| 4415 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 4416 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4417 | |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 4418 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 4419 | "9081 CreatePort TMPLATE type %x TBLsize %d " |
| 4420 | "SEGcnt %d/%d\n", |
| 4421 | vport->port_type, shost->sg_tablesize, |
| 4422 | phba->cfg_scsi_seg_cnt, phba->cfg_sg_seg_cnt); |
| 4423 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4424 | /* Initialize all internally managed lists. */ |
| 4425 | INIT_LIST_HEAD(&vport->fc_nodes); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4426 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4427 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4428 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4429 | timer_setup(&vport->fc_disctmo, lpfc_disc_timeout, 0); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4430 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4431 | timer_setup(&vport->els_tmofunc, lpfc_els_timeout, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4432 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4433 | timer_setup(&vport->delayed_disc_tmo, lpfc_delayed_disc_tmo, 0); |
James Smart | 9249414 | 2011-02-16 12:39:44 -0500 | [diff] [blame] | 4434 | |
James Smart | aa6ff30 | 2019-05-21 17:49:09 -0700 | [diff] [blame] | 4435 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) |
| 4436 | lpfc_setup_bg(phba, shost); |
| 4437 | |
James Bottomley | d139b9b | 2009-11-05 13:33:12 -0600 | [diff] [blame] | 4438 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4439 | if (error) |
| 4440 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4441 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4442 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4443 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4444 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4445 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4446 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4447 | out_put_shost: |
| 4448 | scsi_host_put(shost); |
| 4449 | out: |
| 4450 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4451 | } |
| 4452 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4453 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4454 | * destroy_port - destroy an FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4455 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 4456 | * |
| 4457 | * This routine destroys a FC port from the upper layer protocol. All the |
| 4458 | * resources associated with the port are released. |
| 4459 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4460 | void |
| 4461 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4462 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4463 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 4464 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4465 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4466 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4467 | fc_remove_host(shost); |
| 4468 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4469 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4470 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4471 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 4472 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4473 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4474 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4475 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4476 | } |
| 4477 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4478 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4479 | * lpfc_get_instance - Get a unique integer ID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4480 | * |
| 4481 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 4482 | * uses the kernel idr facility to perform the task. |
| 4483 | * |
| 4484 | * Return codes: |
| 4485 | * instance - a unique integer ID allocated as the new instance. |
| 4486 | * -1 - lpfc get instance failed. |
| 4487 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4488 | int |
| 4489 | lpfc_get_instance(void) |
| 4490 | { |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4491 | int ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4492 | |
Tejun Heo | ab51603 | 2013-02-27 17:04:44 -0800 | [diff] [blame] | 4493 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); |
| 4494 | return ret < 0 ? -1 : ret; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4495 | } |
| 4496 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4497 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4498 | * 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] | 4499 | * @shost: pointer to SCSI host data structure. |
| 4500 | * @time: elapsed time of the scan in jiffies. |
| 4501 | * |
| 4502 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 4503 | * whether the scan host is finished. |
| 4504 | * |
| 4505 | * Note: there is no scan_start function as adapter initialization will have |
| 4506 | * asynchronously kicked off the link initialization. |
| 4507 | * |
| 4508 | * Return codes |
| 4509 | * 0 - SCSI host scan is not over yet. |
| 4510 | * 1 - SCSI host scan is over. |
| 4511 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4512 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 4513 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4514 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4515 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4516 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4517 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4518 | spin_lock_irq(shost->host_lock); |
| 4519 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4520 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4521 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4522 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4523 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4524 | if (time >= msecs_to_jiffies(30 * 1000)) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4525 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4526 | "0461 Scanning longer than 30 " |
| 4527 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4528 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4529 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4530 | } |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4531 | if (time >= msecs_to_jiffies(15 * 1000) && |
| 4532 | phba->link_state <= LPFC_LINK_DOWN) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4533 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4534 | "0465 Link down longer than 15 " |
| 4535 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4536 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4537 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4538 | } |
| 4539 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4540 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4541 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4542 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4543 | goto finished; |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 4544 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4545 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4546 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4547 | goto finished; |
| 4548 | |
| 4549 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4550 | |
| 4551 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4552 | spin_unlock_irq(shost->host_lock); |
| 4553 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4554 | } |
| 4555 | |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 4556 | static void lpfc_host_supported_speeds_set(struct Scsi_Host *shost) |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4557 | { |
| 4558 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; |
| 4559 | struct lpfc_hba *phba = vport->phba; |
| 4560 | |
| 4561 | fc_host_supported_speeds(shost) = 0; |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 4562 | /* |
| 4563 | * Avoid reporting supported link speed for FCoE as it can't be |
| 4564 | * controlled via FCoE. |
| 4565 | */ |
| 4566 | if (phba->hba_flag & HBA_FCOE_MODE) |
| 4567 | return; |
| 4568 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4569 | if (phba->lmt & LMT_128Gb) |
| 4570 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_128GBIT; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4571 | if (phba->lmt & LMT_64Gb) |
| 4572 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_64GBIT; |
| 4573 | if (phba->lmt & LMT_32Gb) |
| 4574 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; |
| 4575 | if (phba->lmt & LMT_16Gb) |
| 4576 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; |
| 4577 | if (phba->lmt & LMT_10Gb) |
| 4578 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
| 4579 | if (phba->lmt & LMT_8Gb) |
| 4580 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
| 4581 | if (phba->lmt & LMT_4Gb) |
| 4582 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 4583 | if (phba->lmt & LMT_2Gb) |
| 4584 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 4585 | if (phba->lmt & LMT_1Gb) |
| 4586 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 4587 | } |
| 4588 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4589 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4590 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4591 | * @shost: pointer to SCSI host data structure. |
| 4592 | * |
| 4593 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 4594 | * SCSI host can be either on top of a physical port or a virtual port. |
| 4595 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4596 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 4597 | { |
| 4598 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 4599 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4600 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4601 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4602 | */ |
| 4603 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4604 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 4605 | 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] | 4606 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 4607 | |
| 4608 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4609 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4610 | fc_host_supported_fc4s(shost)[2] = 1; |
| 4611 | fc_host_supported_fc4s(shost)[7] = 1; |
| 4612 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4613 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 4614 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4615 | |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 4616 | lpfc_host_supported_speeds_set(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4617 | |
| 4618 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4619 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 4620 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4621 | |
Mike Christie | 0af5d70 | 2010-09-15 16:52:31 -0500 | [diff] [blame] | 4622 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
| 4623 | |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4624 | /* This value is also unchanging */ |
| 4625 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 4626 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4627 | fc_host_active_fc4s(shost)[2] = 1; |
| 4628 | fc_host_active_fc4s(shost)[7] = 1; |
| 4629 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 4630 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4631 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 4632 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4633 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 4634 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 4635 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4636 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4637 | * lpfc_stop_port_s3 - Stop SLI3 device port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4638 | * @phba: pointer to lpfc hba data structure. |
| 4639 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4640 | * This routine is invoked to stop an SLI3 device port, it stops the device |
| 4641 | * from generating interrupts and stops the device driver's timers for the |
| 4642 | * device. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4643 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4644 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4645 | lpfc_stop_port_s3(struct lpfc_hba *phba) |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4646 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4647 | /* Clear all interrupt enable conditions */ |
| 4648 | writel(0, phba->HCregaddr); |
| 4649 | readl(phba->HCregaddr); /* flush */ |
| 4650 | /* Clear all pending interrupts */ |
| 4651 | writel(0xffffffff, phba->HAregaddr); |
| 4652 | readl(phba->HAregaddr); /* flush */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 4653 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4654 | /* Reset some HBA SLI setup states */ |
| 4655 | lpfc_stop_hba_timers(phba); |
| 4656 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 4657 | } |
| 4658 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4659 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4660 | * lpfc_stop_port_s4 - Stop SLI4 device port |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4661 | * @phba: pointer to lpfc hba data structure. |
| 4662 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4663 | * This routine is invoked to stop an SLI4 device port, it stops the device |
| 4664 | * from generating interrupts and stops the device driver's timers for the |
| 4665 | * device. |
| 4666 | **/ |
| 4667 | static void |
| 4668 | lpfc_stop_port_s4(struct lpfc_hba *phba) |
| 4669 | { |
| 4670 | /* Reset some HBA SLI4 setup states */ |
| 4671 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 4672 | if (phba->pport) |
| 4673 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4674 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4675 | } |
| 4676 | |
| 4677 | /** |
| 4678 | * lpfc_stop_port - Wrapper function for stopping hba port |
| 4679 | * @phba: Pointer to HBA context object. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 4680 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4681 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from |
| 4682 | * the API jump table function pointer from the lpfc_hba struct. |
| 4683 | **/ |
| 4684 | void |
| 4685 | lpfc_stop_port(struct lpfc_hba *phba) |
| 4686 | { |
| 4687 | phba->lpfc_stop_port(phba); |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 4688 | |
| 4689 | if (phba->wq) |
| 4690 | flush_workqueue(phba->wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4691 | } |
| 4692 | |
| 4693 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4694 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer |
| 4695 | * @phba: Pointer to hba for which this call is being executed. |
| 4696 | * |
| 4697 | * This routine starts the timer waiting for the FCF rediscovery to complete. |
| 4698 | **/ |
| 4699 | void |
| 4700 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) |
| 4701 | { |
| 4702 | unsigned long fcf_redisc_wait_tmo = |
| 4703 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); |
| 4704 | /* Start fcf rediscovery wait period timer */ |
| 4705 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); |
| 4706 | spin_lock_irq(&phba->hbalock); |
| 4707 | /* Allow action to new fcf asynchronous event */ |
| 4708 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); |
| 4709 | /* Mark the FCF rediscovery pending state */ |
| 4710 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; |
| 4711 | spin_unlock_irq(&phba->hbalock); |
| 4712 | } |
| 4713 | |
| 4714 | /** |
| 4715 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 4716 | * @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] | 4717 | * |
| 4718 | * This routine is invoked when waiting for FCF table rediscover has been |
| 4719 | * timed out. If new FCF record(s) has (have) been discovered during the |
| 4720 | * wait period, a new FCF event shall be added to the FCOE async event |
| 4721 | * list, and then worker thread shall be waked up for processing from the |
| 4722 | * worker thread context. |
| 4723 | **/ |
Rashika Kheria | e399b22 | 2014-09-03 12:55:28 -0400 | [diff] [blame] | 4724 | static void |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4725 | lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4726 | { |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 4727 | struct lpfc_hba *phba = from_timer(phba, t, fcf.redisc_wait); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4728 | |
| 4729 | /* Don't send FCF rediscovery event if timer cancelled */ |
| 4730 | spin_lock_irq(&phba->hbalock); |
| 4731 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { |
| 4732 | spin_unlock_irq(&phba->hbalock); |
| 4733 | return; |
| 4734 | } |
| 4735 | /* Clear FCF rediscovery timer pending flag */ |
| 4736 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; |
| 4737 | /* FCF rediscovery event to worker thread */ |
| 4738 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; |
| 4739 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 4740 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 4741 | "2776 FCF rediscover quiescent timer expired\n"); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 4742 | /* wake up worker thread */ |
| 4743 | lpfc_worker_wake_up(phba); |
| 4744 | } |
| 4745 | |
| 4746 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4747 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
| 4748 | * @phba: pointer to lpfc hba data structure. |
| 4749 | * @acqe_link: pointer to the async link completion queue entry. |
| 4750 | * |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4751 | * This routine is to parse the SLI4 link-attention link fault code. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4752 | **/ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4753 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4754 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, |
| 4755 | struct lpfc_acqe_link *acqe_link) |
| 4756 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4757 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
| 4758 | case LPFC_ASYNC_LINK_FAULT_NONE: |
| 4759 | case LPFC_ASYNC_LINK_FAULT_LOCAL: |
| 4760 | case LPFC_ASYNC_LINK_FAULT_REMOTE: |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4761 | case LPFC_ASYNC_LINK_FAULT_LR_LRR: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4762 | break; |
| 4763 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4764 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 4765 | "0398 Unknown link fault code: x%x\n", |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4766 | bf_get(lpfc_acqe_link_fault, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4767 | break; |
| 4768 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | /** |
| 4772 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
| 4773 | * @phba: pointer to lpfc hba data structure. |
| 4774 | * @acqe_link: pointer to the async link completion queue entry. |
| 4775 | * |
| 4776 | * This routine is to parse the SLI4 link attention type and translate it |
| 4777 | * into the base driver's link attention type coding. |
| 4778 | * |
| 4779 | * Return: Link attention type in terms of base driver's coding. |
| 4780 | **/ |
| 4781 | static uint8_t |
| 4782 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, |
| 4783 | struct lpfc_acqe_link *acqe_link) |
| 4784 | { |
| 4785 | uint8_t att_type; |
| 4786 | |
| 4787 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
| 4788 | case LPFC_ASYNC_LINK_STATUS_DOWN: |
| 4789 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4790 | att_type = LPFC_ATT_LINK_DOWN; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4791 | break; |
| 4792 | case LPFC_ASYNC_LINK_STATUS_UP: |
| 4793 | /* Ignore physical link up events - wait for logical link up */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4794 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4795 | break; |
| 4796 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4797 | att_type = LPFC_ATT_LINK_UP; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4798 | break; |
| 4799 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4800 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4801 | "0399 Invalid link attention type: x%x\n", |
| 4802 | bf_get(lpfc_acqe_link_status, acqe_link)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4803 | att_type = LPFC_ATT_RESERVED; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4804 | break; |
| 4805 | } |
| 4806 | return att_type; |
| 4807 | } |
| 4808 | |
| 4809 | /** |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4810 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed |
| 4811 | * @phba: pointer to lpfc hba data structure. |
| 4812 | * |
| 4813 | * This routine is to get an SLI3 FC port's link speed in Mbps. |
| 4814 | * |
| 4815 | * Return: link speed in terms of Mbps. |
| 4816 | **/ |
| 4817 | uint32_t |
| 4818 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) |
| 4819 | { |
| 4820 | uint32_t link_speed; |
| 4821 | |
| 4822 | if (!lpfc_is_link_up(phba)) |
| 4823 | return 0; |
| 4824 | |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 4825 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 4826 | switch (phba->fc_linkspeed) { |
| 4827 | case LPFC_LINK_SPEED_1GHZ: |
| 4828 | link_speed = 1000; |
| 4829 | break; |
| 4830 | case LPFC_LINK_SPEED_2GHZ: |
| 4831 | link_speed = 2000; |
| 4832 | break; |
| 4833 | case LPFC_LINK_SPEED_4GHZ: |
| 4834 | link_speed = 4000; |
| 4835 | break; |
| 4836 | case LPFC_LINK_SPEED_8GHZ: |
| 4837 | link_speed = 8000; |
| 4838 | break; |
| 4839 | case LPFC_LINK_SPEED_10GHZ: |
| 4840 | link_speed = 10000; |
| 4841 | break; |
| 4842 | case LPFC_LINK_SPEED_16GHZ: |
| 4843 | link_speed = 16000; |
| 4844 | break; |
| 4845 | default: |
| 4846 | link_speed = 0; |
| 4847 | } |
| 4848 | } else { |
| 4849 | if (phba->sli4_hba.link_state.logical_speed) |
| 4850 | link_speed = |
| 4851 | phba->sli4_hba.link_state.logical_speed; |
| 4852 | else |
| 4853 | link_speed = phba->sli4_hba.link_state.speed; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4854 | } |
| 4855 | return link_speed; |
| 4856 | } |
| 4857 | |
| 4858 | /** |
| 4859 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed |
| 4860 | * @phba: pointer to lpfc hba data structure. |
| 4861 | * @evt_code: asynchronous event code. |
| 4862 | * @speed_code: asynchronous event link speed code. |
| 4863 | * |
| 4864 | * This routine is to parse the giving SLI4 async event link speed code into |
| 4865 | * value of Mbps for the link speed. |
| 4866 | * |
| 4867 | * Return: link speed in terms of Mbps. |
| 4868 | **/ |
| 4869 | static uint32_t |
| 4870 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, |
| 4871 | uint8_t speed_code) |
| 4872 | { |
| 4873 | uint32_t port_speed; |
| 4874 | |
| 4875 | switch (evt_code) { |
| 4876 | case LPFC_TRAILER_CODE_LINK: |
| 4877 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4878 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4879 | port_speed = 0; |
| 4880 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4881 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4882 | port_speed = 10; |
| 4883 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4884 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4885 | port_speed = 100; |
| 4886 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4887 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4888 | port_speed = 1000; |
| 4889 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4890 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4891 | port_speed = 10000; |
| 4892 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4893 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
| 4894 | port_speed = 20000; |
| 4895 | break; |
| 4896 | case LPFC_ASYNC_LINK_SPEED_25GBPS: |
| 4897 | port_speed = 25000; |
| 4898 | break; |
| 4899 | case LPFC_ASYNC_LINK_SPEED_40GBPS: |
| 4900 | port_speed = 40000; |
| 4901 | break; |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 4902 | case LPFC_ASYNC_LINK_SPEED_100GBPS: |
| 4903 | port_speed = 100000; |
| 4904 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4905 | default: |
| 4906 | port_speed = 0; |
| 4907 | } |
| 4908 | break; |
| 4909 | case LPFC_TRAILER_CODE_FC: |
| 4910 | switch (speed_code) { |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4911 | case LPFC_FC_LA_SPEED_UNKNOWN: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4912 | port_speed = 0; |
| 4913 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4914 | case LPFC_FC_LA_SPEED_1G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4915 | port_speed = 1000; |
| 4916 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4917 | case LPFC_FC_LA_SPEED_2G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4918 | port_speed = 2000; |
| 4919 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4920 | case LPFC_FC_LA_SPEED_4G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4921 | port_speed = 4000; |
| 4922 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4923 | case LPFC_FC_LA_SPEED_8G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4924 | port_speed = 8000; |
| 4925 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4926 | case LPFC_FC_LA_SPEED_10G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4927 | port_speed = 10000; |
| 4928 | break; |
James Smart | 26d830e | 2015-04-07 15:07:17 -0400 | [diff] [blame] | 4929 | case LPFC_FC_LA_SPEED_16G: |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4930 | port_speed = 16000; |
| 4931 | break; |
James Smart | d38dd52 | 2015-08-31 16:48:17 -0400 | [diff] [blame] | 4932 | case LPFC_FC_LA_SPEED_32G: |
| 4933 | port_speed = 32000; |
| 4934 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 4935 | case LPFC_FC_LA_SPEED_64G: |
| 4936 | port_speed = 64000; |
| 4937 | break; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 4938 | case LPFC_FC_LA_SPEED_128G: |
| 4939 | port_speed = 128000; |
| 4940 | break; |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 4941 | default: |
| 4942 | port_speed = 0; |
| 4943 | } |
| 4944 | break; |
| 4945 | default: |
| 4946 | port_speed = 0; |
| 4947 | } |
| 4948 | return port_speed; |
| 4949 | } |
| 4950 | |
| 4951 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4952 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4953 | * @phba: pointer to lpfc hba data structure. |
| 4954 | * @acqe_link: pointer to the async link completion queue entry. |
| 4955 | * |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 4956 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4957 | **/ |
| 4958 | static void |
| 4959 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, |
| 4960 | struct lpfc_acqe_link *acqe_link) |
| 4961 | { |
| 4962 | struct lpfc_dmabuf *mp; |
| 4963 | LPFC_MBOXQ_t *pmb; |
| 4964 | MAILBOX_t *mb; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4965 | struct lpfc_mbx_read_top *la; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4966 | uint8_t att_type; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4967 | int rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4968 | |
| 4969 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 4970 | 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] | 4971 | return; |
James Smart | 32b9793 | 2009-07-19 10:01:21 -0400 | [diff] [blame] | 4972 | phba->fcoe_eventtag = acqe_link->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4973 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 4974 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4975 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4976 | "0395 The mboxq allocation failed\n"); |
| 4977 | return; |
| 4978 | } |
| 4979 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 4980 | if (!mp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4981 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4982 | "0396 The lpfc_dmabuf allocation failed\n"); |
| 4983 | goto out_free_pmb; |
| 4984 | } |
| 4985 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 4986 | if (!mp->virt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 4987 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4988 | "0397 The mbuf allocation failed\n"); |
| 4989 | goto out_free_dmabuf; |
| 4990 | } |
| 4991 | |
| 4992 | /* Cleanup any outstanding ELS commands */ |
| 4993 | lpfc_els_flush_all_cmd(phba); |
| 4994 | |
| 4995 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 4996 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 4997 | |
| 4998 | /* Update link event statistics */ |
| 4999 | phba->sli.slistat.link_event++; |
| 5000 | |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5001 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5002 | lpfc_read_topology(phba, pmb, mp); |
| 5003 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5004 | pmb->vport = phba->pport; |
| 5005 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5006 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5007 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5008 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
| 5009 | bf_get(lpfc_acqe_link_speed, acqe_link)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5010 | phba->sli4_hba.link_state.duplex = |
| 5011 | bf_get(lpfc_acqe_link_duplex, acqe_link); |
| 5012 | phba->sli4_hba.link_state.status = |
| 5013 | bf_get(lpfc_acqe_link_status, acqe_link); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5014 | phba->sli4_hba.link_state.type = |
| 5015 | bf_get(lpfc_acqe_link_type, acqe_link); |
| 5016 | phba->sli4_hba.link_state.number = |
| 5017 | bf_get(lpfc_acqe_link_number, acqe_link); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5018 | phba->sli4_hba.link_state.fault = |
| 5019 | bf_get(lpfc_acqe_link_fault, acqe_link); |
James Smart | 65467b6 | 2010-01-26 23:08:29 -0500 | [diff] [blame] | 5020 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5021 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
| 5022 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5023 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | c31098c | 2011-04-16 11:03:33 -0400 | [diff] [blame] | 5024 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
| 5025 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " |
| 5026 | "Logical speed:%dMbps Fault:%d\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5027 | phba->sli4_hba.link_state.speed, |
| 5028 | phba->sli4_hba.link_state.topology, |
| 5029 | phba->sli4_hba.link_state.status, |
| 5030 | phba->sli4_hba.link_state.type, |
| 5031 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5032 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5033 | phba->sli4_hba.link_state.fault); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5034 | /* |
| 5035 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch |
| 5036 | * topology info. Note: Optional for non FC-AL ports. |
| 5037 | */ |
| 5038 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { |
| 5039 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5040 | if (rc == MBX_NOT_FINISHED) |
| 5041 | goto out_free_dmabuf; |
| 5042 | return; |
| 5043 | } |
| 5044 | /* |
| 5045 | * For FCoE Mode: fill in all the topology information we need and call |
| 5046 | * the READ_TOPOLOGY completion routine to continue without actually |
| 5047 | * sending the READ_TOPOLOGY mailbox command to the port. |
| 5048 | */ |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5049 | /* Initialize completion status */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5050 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5051 | mb->mbxStatus = MBX_SUCCESS; |
| 5052 | |
| 5053 | /* Parse port fault information field */ |
| 5054 | lpfc_sli4_parse_latt_fault(phba, acqe_link); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5055 | |
| 5056 | /* Parse and translate link attention fields */ |
| 5057 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; |
| 5058 | la->eventTag = acqe_link->event_tag; |
| 5059 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); |
| 5060 | bf_set(lpfc_mbx_read_top_link_spd, la, |
James Smart | a085e87 | 2015-12-16 18:12:02 -0500 | [diff] [blame] | 5061 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5062 | |
| 5063 | /* Fake the the following irrelvant fields */ |
| 5064 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); |
| 5065 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); |
| 5066 | bf_set(lpfc_mbx_read_top_il, la, 0); |
| 5067 | bf_set(lpfc_mbx_read_top_pb, la, 0); |
| 5068 | bf_set(lpfc_mbx_read_top_fa, la, 0); |
| 5069 | bf_set(lpfc_mbx_read_top_mm, la, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5070 | |
| 5071 | /* Invoke the lpfc_handle_latt mailbox command callback function */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5072 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5073 | |
| 5074 | return; |
| 5075 | |
| 5076 | out_free_dmabuf: |
| 5077 | kfree(mp); |
| 5078 | out_free_pmb: |
| 5079 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5080 | } |
| 5081 | |
| 5082 | /** |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5083 | * lpfc_async_link_speed_to_read_top - Parse async evt link speed code to read |
| 5084 | * topology. |
| 5085 | * @phba: pointer to lpfc hba data structure. |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5086 | * @speed_code: asynchronous event link speed code. |
| 5087 | * |
| 5088 | * This routine is to parse the giving SLI4 async event link speed code into |
| 5089 | * value of Read topology link speed. |
| 5090 | * |
| 5091 | * Return: link speed in terms of Read topology. |
| 5092 | **/ |
| 5093 | static uint8_t |
| 5094 | lpfc_async_link_speed_to_read_top(struct lpfc_hba *phba, uint8_t speed_code) |
| 5095 | { |
| 5096 | uint8_t port_speed; |
| 5097 | |
| 5098 | switch (speed_code) { |
| 5099 | case LPFC_FC_LA_SPEED_1G: |
| 5100 | port_speed = LPFC_LINK_SPEED_1GHZ; |
| 5101 | break; |
| 5102 | case LPFC_FC_LA_SPEED_2G: |
| 5103 | port_speed = LPFC_LINK_SPEED_2GHZ; |
| 5104 | break; |
| 5105 | case LPFC_FC_LA_SPEED_4G: |
| 5106 | port_speed = LPFC_LINK_SPEED_4GHZ; |
| 5107 | break; |
| 5108 | case LPFC_FC_LA_SPEED_8G: |
| 5109 | port_speed = LPFC_LINK_SPEED_8GHZ; |
| 5110 | break; |
| 5111 | case LPFC_FC_LA_SPEED_16G: |
| 5112 | port_speed = LPFC_LINK_SPEED_16GHZ; |
| 5113 | break; |
| 5114 | case LPFC_FC_LA_SPEED_32G: |
| 5115 | port_speed = LPFC_LINK_SPEED_32GHZ; |
| 5116 | break; |
| 5117 | case LPFC_FC_LA_SPEED_64G: |
| 5118 | port_speed = LPFC_LINK_SPEED_64GHZ; |
| 5119 | break; |
| 5120 | case LPFC_FC_LA_SPEED_128G: |
| 5121 | port_speed = LPFC_LINK_SPEED_128GHZ; |
| 5122 | break; |
| 5123 | case LPFC_FC_LA_SPEED_256G: |
| 5124 | port_speed = LPFC_LINK_SPEED_256GHZ; |
| 5125 | break; |
| 5126 | default: |
| 5127 | port_speed = 0; |
| 5128 | break; |
| 5129 | } |
| 5130 | |
| 5131 | return port_speed; |
| 5132 | } |
| 5133 | |
| 5134 | #define trunk_link_status(__idx)\ |
| 5135 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5136 | ((phba->trunk_link.link##__idx.state == LPFC_LINK_UP) ?\ |
| 5137 | "Link up" : "Link down") : "NA" |
| 5138 | /* Did port __idx reported an error */ |
| 5139 | #define trunk_port_fault(__idx)\ |
| 5140 | bf_get(lpfc_acqe_fc_la_trunk_config_port##__idx, acqe_fc) ?\ |
| 5141 | (port_fault & (1 << __idx) ? "YES" : "NO") : "NA" |
| 5142 | |
| 5143 | static void |
| 5144 | lpfc_update_trunk_link_status(struct lpfc_hba *phba, |
| 5145 | struct lpfc_acqe_fc_la *acqe_fc) |
| 5146 | { |
| 5147 | uint8_t port_fault = bf_get(lpfc_acqe_fc_la_trunk_linkmask, acqe_fc); |
| 5148 | uint8_t err = bf_get(lpfc_acqe_fc_la_trunk_fault, acqe_fc); |
| 5149 | |
| 5150 | phba->sli4_hba.link_state.speed = |
| 5151 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5152 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5153 | |
| 5154 | phba->sli4_hba.link_state.logical_speed = |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5155 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5156 | /* We got FC link speed, convert to fc_linkspeed (READ_TOPOLOGY) */ |
| 5157 | phba->fc_linkspeed = |
| 5158 | lpfc_async_link_speed_to_read_top( |
| 5159 | phba, |
| 5160 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
| 5161 | |
| 5162 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port0, acqe_fc)) { |
| 5163 | phba->trunk_link.link0.state = |
| 5164 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port0, acqe_fc) |
| 5165 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5166 | phba->trunk_link.link0.fault = port_fault & 0x1 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5167 | } |
| 5168 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port1, acqe_fc)) { |
| 5169 | phba->trunk_link.link1.state = |
| 5170 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port1, acqe_fc) |
| 5171 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5172 | phba->trunk_link.link1.fault = port_fault & 0x2 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5173 | } |
| 5174 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port2, acqe_fc)) { |
| 5175 | phba->trunk_link.link2.state = |
| 5176 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port2, acqe_fc) |
| 5177 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5178 | phba->trunk_link.link2.fault = port_fault & 0x4 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5179 | } |
| 5180 | if (bf_get(lpfc_acqe_fc_la_trunk_config_port3, acqe_fc)) { |
| 5181 | phba->trunk_link.link3.state = |
| 5182 | bf_get(lpfc_acqe_fc_la_trunk_link_status_port3, acqe_fc) |
| 5183 | ? LPFC_LINK_UP : LPFC_LINK_DOWN; |
James Smart | 529b3dd | 2018-12-13 15:17:54 -0800 | [diff] [blame] | 5184 | phba->trunk_link.link3.fault = port_fault & 0x8 ? err : 0; |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5185 | } |
| 5186 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5187 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5188 | "2910 Async FC Trunking Event - Speed:%d\n" |
| 5189 | "\tLogical speed:%d " |
| 5190 | "port0: %s port1: %s port2: %s port3: %s\n", |
| 5191 | phba->sli4_hba.link_state.speed, |
| 5192 | phba->sli4_hba.link_state.logical_speed, |
| 5193 | trunk_link_status(0), trunk_link_status(1), |
| 5194 | trunk_link_status(2), trunk_link_status(3)); |
| 5195 | |
| 5196 | if (port_fault) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5197 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5198 | "3202 trunk error:0x%x (%s) seen on port0:%s " |
| 5199 | /* |
| 5200 | * SLI-4: We have only 0xA error codes |
| 5201 | * defined as of now. print an appropriate |
| 5202 | * message in case driver needs to be updated. |
| 5203 | */ |
| 5204 | "port1:%s port2:%s port3:%s\n", err, err > 0xA ? |
| 5205 | "UNDEFINED. update driver." : trunk_errmsg[err], |
| 5206 | trunk_port_fault(0), trunk_port_fault(1), |
| 5207 | trunk_port_fault(2), trunk_port_fault(3)); |
| 5208 | } |
| 5209 | |
| 5210 | |
| 5211 | /** |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5212 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event |
| 5213 | * @phba: pointer to lpfc hba data structure. |
| 5214 | * @acqe_fc: pointer to the async fc completion queue entry. |
| 5215 | * |
| 5216 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log |
| 5217 | * that the event was received and then issue a read_topology mailbox command so |
| 5218 | * that the rest of the driver will treat it the same as SLI3. |
| 5219 | **/ |
| 5220 | static void |
| 5221 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) |
| 5222 | { |
| 5223 | struct lpfc_dmabuf *mp; |
| 5224 | LPFC_MBOXQ_t *pmb; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5225 | MAILBOX_t *mb; |
| 5226 | struct lpfc_mbx_read_top *la; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5227 | int rc; |
| 5228 | |
| 5229 | if (bf_get(lpfc_trailer_type, acqe_fc) != |
| 5230 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5231 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5232 | "2895 Non FC link Event detected.(%d)\n", |
| 5233 | bf_get(lpfc_trailer_type, acqe_fc)); |
| 5234 | return; |
| 5235 | } |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 5236 | |
| 5237 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5238 | LPFC_FC_LA_TYPE_TRUNKING_EVENT) { |
| 5239 | lpfc_update_trunk_link_status(phba, acqe_fc); |
| 5240 | return; |
| 5241 | } |
| 5242 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5243 | /* Keep the link status for extra SLI4 state machine reference */ |
| 5244 | phba->sli4_hba.link_state.speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5245 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
| 5246 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5247 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
| 5248 | phba->sli4_hba.link_state.topology = |
| 5249 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); |
| 5250 | phba->sli4_hba.link_state.status = |
| 5251 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); |
| 5252 | phba->sli4_hba.link_state.type = |
| 5253 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); |
| 5254 | phba->sli4_hba.link_state.number = |
| 5255 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); |
| 5256 | phba->sli4_hba.link_state.fault = |
| 5257 | bf_get(lpfc_acqe_link_fault, acqe_fc); |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5258 | |
| 5259 | if (bf_get(lpfc_acqe_fc_la_att_type, acqe_fc) == |
| 5260 | LPFC_FC_LA_TYPE_LINK_DOWN) |
| 5261 | phba->sli4_hba.link_state.logical_speed = 0; |
| 5262 | else if (!phba->sli4_hba.conf_trunk) |
| 5263 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5264 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
James Smart | b8e6f13 | 2019-05-21 17:49:04 -0700 | [diff] [blame] | 5265 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5266 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5267 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " |
| 5268 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" |
| 5269 | "%dMbps Fault:%d\n", |
| 5270 | phba->sli4_hba.link_state.speed, |
| 5271 | phba->sli4_hba.link_state.topology, |
| 5272 | phba->sli4_hba.link_state.status, |
| 5273 | phba->sli4_hba.link_state.type, |
| 5274 | phba->sli4_hba.link_state.number, |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5275 | phba->sli4_hba.link_state.logical_speed, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5276 | phba->sli4_hba.link_state.fault); |
| 5277 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 5278 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5279 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5280 | "2897 The mboxq allocation failed\n"); |
| 5281 | return; |
| 5282 | } |
| 5283 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 5284 | if (!mp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5285 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5286 | "2898 The lpfc_dmabuf allocation failed\n"); |
| 5287 | goto out_free_pmb; |
| 5288 | } |
| 5289 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 5290 | if (!mp->virt) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5291 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5292 | "2899 The mbuf allocation failed\n"); |
| 5293 | goto out_free_dmabuf; |
| 5294 | } |
| 5295 | |
| 5296 | /* Cleanup any outstanding ELS commands */ |
| 5297 | lpfc_els_flush_all_cmd(phba); |
| 5298 | |
| 5299 | /* Block ELS IOCBs until we have done process link event */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 5300 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5301 | |
| 5302 | /* Update link event statistics */ |
| 5303 | phba->sli.slistat.link_event++; |
| 5304 | |
| 5305 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
| 5306 | lpfc_read_topology(phba, pmb, mp); |
| 5307 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; |
| 5308 | pmb->vport = phba->pport; |
| 5309 | |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5310 | 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] | 5311 | phba->link_flag &= ~(LS_MDS_LINK_DOWN | LS_MDS_LOOPBACK); |
| 5312 | |
| 5313 | switch (phba->sli4_hba.link_state.status) { |
| 5314 | case LPFC_FC_LA_TYPE_MDS_LINK_DOWN: |
| 5315 | phba->link_flag |= LS_MDS_LINK_DOWN; |
| 5316 | break; |
| 5317 | case LPFC_FC_LA_TYPE_MDS_LOOPBACK: |
| 5318 | phba->link_flag |= LS_MDS_LOOPBACK; |
| 5319 | break; |
| 5320 | default: |
| 5321 | break; |
| 5322 | } |
| 5323 | |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5324 | /* Initialize completion status */ |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5325 | mb = &pmb->u.mb; |
James Smart | 23288b7 | 2018-05-04 20:37:53 -0700 | [diff] [blame] | 5326 | mb->mbxStatus = MBX_SUCCESS; |
| 5327 | |
| 5328 | /* Parse port fault information field */ |
| 5329 | lpfc_sli4_parse_latt_fault(phba, (void *)acqe_fc); |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5330 | |
| 5331 | /* Parse and translate link attention fields */ |
| 5332 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; |
| 5333 | la->eventTag = acqe_fc->event_tag; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5334 | |
James Smart | aeb3c81 | 2017-04-21 16:05:02 -0700 | [diff] [blame] | 5335 | if (phba->sli4_hba.link_state.status == |
| 5336 | LPFC_FC_LA_TYPE_UNEXP_WWPN) { |
| 5337 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5338 | LPFC_FC_LA_TYPE_UNEXP_WWPN); |
| 5339 | } else { |
| 5340 | bf_set(lpfc_mbx_read_top_att_type, la, |
| 5341 | LPFC_FC_LA_TYPE_LINK_DOWN); |
| 5342 | } |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 5343 | /* Invoke the mailbox command callback function */ |
| 5344 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
| 5345 | |
| 5346 | return; |
| 5347 | } |
| 5348 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5349 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 5350 | if (rc == MBX_NOT_FINISHED) |
| 5351 | goto out_free_dmabuf; |
| 5352 | return; |
| 5353 | |
| 5354 | out_free_dmabuf: |
| 5355 | kfree(mp); |
| 5356 | out_free_pmb: |
| 5357 | mempool_free(pmb, phba->mbox_mem_pool); |
| 5358 | } |
| 5359 | |
| 5360 | /** |
| 5361 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event |
| 5362 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5363 | * @acqe_sli: pointer to the async SLI completion queue entry. |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5364 | * |
| 5365 | * This routine is to handle the SLI4 asynchronous SLI events. |
| 5366 | **/ |
| 5367 | static void |
| 5368 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) |
| 5369 | { |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5370 | char port_name; |
James Smart | 8c1312e | 2012-10-31 14:45:09 -0400 | [diff] [blame] | 5371 | char message[128]; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5372 | uint8_t status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5373 | uint8_t evt_type; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5374 | uint8_t operational = 0; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5375 | struct temp_event temp_event_data; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5376 | struct lpfc_acqe_misconfigured_event *misconfigured; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5377 | struct Scsi_Host *shost; |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5378 | struct lpfc_vport **vports; |
| 5379 | int rc, i; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5380 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5381 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); |
| 5382 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5383 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5384 | "2901 Async SLI event - Type:%d, Event Data: x%08x " |
| 5385 | "x%08x x%08x x%08x\n", evt_type, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5386 | acqe_sli->event_data1, acqe_sli->event_data2, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5387 | acqe_sli->reserved, acqe_sli->trailer); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5388 | |
| 5389 | port_name = phba->Port[0]; |
| 5390 | if (port_name == 0x00) |
| 5391 | port_name = '?'; /* get port name is empty */ |
| 5392 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5393 | switch (evt_type) { |
| 5394 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: |
| 5395 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5396 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; |
| 5397 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5398 | |
| 5399 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5400 | "3190 Over Temperature:%d Celsius- Port Name %c\n", |
| 5401 | acqe_sli->event_data1, port_name); |
| 5402 | |
James Smart | 310429e | 2016-07-06 12:35:54 -0700 | [diff] [blame] | 5403 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5404 | shost = lpfc_shost_from_vport(phba->pport); |
| 5405 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5406 | sizeof(temp_event_data), |
| 5407 | (char *)&temp_event_data, |
| 5408 | SCSI_NL_VID_TYPE_PCI |
| 5409 | | PCI_VENDOR_ID_EMULEX); |
| 5410 | break; |
| 5411 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: |
| 5412 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 5413 | temp_event_data.event_code = LPFC_NORMAL_TEMP; |
| 5414 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; |
| 5415 | |
| 5416 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5417 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", |
| 5418 | acqe_sli->event_data1, port_name); |
| 5419 | |
| 5420 | shost = lpfc_shost_from_vport(phba->pport); |
| 5421 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 5422 | sizeof(temp_event_data), |
| 5423 | (char *)&temp_event_data, |
| 5424 | SCSI_NL_VID_TYPE_PCI |
| 5425 | | PCI_VENDOR_ID_EMULEX); |
| 5426 | break; |
| 5427 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: |
| 5428 | misconfigured = (struct lpfc_acqe_misconfigured_event *) |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5429 | &acqe_sli->event_data1; |
| 5430 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5431 | /* fetch the status for this port */ |
| 5432 | switch (phba->sli4_hba.lnk_info.lnk_no) { |
| 5433 | case LPFC_LINK_NUMBER_0: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5434 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
| 5435 | &misconfigured->theEvent); |
| 5436 | operational = bf_get(lpfc_sli_misconfigured_port0_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5437 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5438 | break; |
| 5439 | case LPFC_LINK_NUMBER_1: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5440 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
| 5441 | &misconfigured->theEvent); |
| 5442 | operational = bf_get(lpfc_sli_misconfigured_port1_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5443 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5444 | break; |
| 5445 | case LPFC_LINK_NUMBER_2: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5446 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
| 5447 | &misconfigured->theEvent); |
| 5448 | operational = bf_get(lpfc_sli_misconfigured_port2_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5449 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5450 | break; |
| 5451 | case LPFC_LINK_NUMBER_3: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5452 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
| 5453 | &misconfigured->theEvent); |
| 5454 | operational = bf_get(lpfc_sli_misconfigured_port3_op, |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5455 | &misconfigured->theEvent); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5456 | break; |
| 5457 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5458 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5459 | "3296 " |
| 5460 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " |
| 5461 | "event: Invalid link %d", |
| 5462 | phba->sli4_hba.lnk_info.lnk_no); |
| 5463 | return; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5464 | } |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5465 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5466 | /* Skip if optic state unchanged */ |
| 5467 | if (phba->sli4_hba.lnk_info.optic_state == status) |
| 5468 | return; |
| 5469 | |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5470 | switch (status) { |
| 5471 | case LPFC_SLI_EVENT_STATUS_VALID: |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5472 | sprintf(message, "Physical Link is functional"); |
| 5473 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5474 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
| 5475 | sprintf(message, "Optics faulted/incorrectly " |
| 5476 | "installed/not installed - Reseat optics, " |
| 5477 | "if issue not resolved, replace."); |
| 5478 | break; |
| 5479 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: |
| 5480 | sprintf(message, |
| 5481 | "Optics of two types installed - Remove one " |
| 5482 | "optic or install matching pair of optics."); |
| 5483 | break; |
| 5484 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: |
| 5485 | sprintf(message, "Incompatible optics - Replace with " |
James Smart | 292098b | 2012-09-29 11:31:41 -0400 | [diff] [blame] | 5486 | "compatible optics for card to function."); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5487 | break; |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5488 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
| 5489 | sprintf(message, "Unqualified optics - Replace with " |
| 5490 | "Avago optics for Warranty and Technical " |
| 5491 | "Support - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5492 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5493 | break; |
| 5494 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: |
| 5495 | sprintf(message, "Uncertified optics - Replace with " |
| 5496 | "Avago-certified optics to enable link " |
| 5497 | "operation - Link is%s operational", |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 5498 | (operational) ? " not" : ""); |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5499 | break; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5500 | default: |
| 5501 | /* firmware is reporting a status we don't know about */ |
| 5502 | sprintf(message, "Unknown event status x%02x", status); |
| 5503 | break; |
| 5504 | } |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5505 | |
| 5506 | /* Issue READ_CONFIG mbox command to refresh supported speeds */ |
| 5507 | rc = lpfc_sli4_read_config(phba); |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5508 | if (rc) { |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5509 | phba->lmt = 0; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5510 | lpfc_printf_log(phba, KERN_ERR, |
| 5511 | LOG_TRACE_EVENT, |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5512 | "3194 Unable to retrieve supported " |
James Smart | 3952e91 | 2018-10-23 13:41:02 -0700 | [diff] [blame] | 5513 | "speeds, rc = 0x%x\n", rc); |
James Smart | cd71348 | 2018-10-23 13:41:01 -0700 | [diff] [blame] | 5514 | } |
| 5515 | vports = lpfc_create_vport_work_array(phba); |
| 5516 | if (vports != NULL) { |
| 5517 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5518 | i++) { |
| 5519 | shost = lpfc_shost_from_vport(vports[i]); |
| 5520 | lpfc_host_supported_speeds_set(shost); |
| 5521 | } |
| 5522 | } |
| 5523 | lpfc_destroy_vport_work_array(phba, vports); |
| 5524 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5525 | phba->sli4_hba.lnk_info.optic_state = status; |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5526 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 5527 | "3176 Port Name %c %s\n", port_name, message); |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5528 | break; |
| 5529 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: |
| 5530 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5531 | "3192 Remote DPort Test Initiated - " |
| 5532 | "Event Data1:x%08x Event Data2: x%08x\n", |
| 5533 | acqe_sli->event_data1, acqe_sli->event_data2); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5534 | break; |
James Smart | e7d8595 | 2019-10-18 14:18:29 -0700 | [diff] [blame] | 5535 | case LPFC_SLI_EVENT_TYPE_MISCONF_FAWWN: |
| 5536 | /* Misconfigured WWN. Reports that the SLI Port is configured |
| 5537 | * to use FA-WWN, but the attached device doesn’t support it. |
| 5538 | * No driver action is required. |
| 5539 | * Event Data1 - N.A, Event Data2 - N.A |
| 5540 | */ |
| 5541 | lpfc_log_msg(phba, KERN_WARNING, LOG_SLI, |
| 5542 | "2699 Misconfigured FA-WWN - Attached device does " |
| 5543 | "not support FA-WWN\n"); |
| 5544 | break; |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5545 | case LPFC_SLI_EVENT_TYPE_EEPROM_FAILURE: |
| 5546 | /* EEPROM failure. No driver action is required */ |
| 5547 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 5548 | "2518 EEPROM failure - " |
| 5549 | "Event Data1: x%08x Event Data2: x%08x\n", |
| 5550 | acqe_sli->event_data1, acqe_sli->event_data2); |
| 5551 | break; |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5552 | default: |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5553 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | d11ed16 | 2019-09-21 20:59:03 -0700 | [diff] [blame] | 5554 | "3193 Unrecognized SLI event, type: 0x%x", |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 5555 | evt_type); |
James Smart | 4b8bae0 | 2012-06-12 13:55:07 -0400 | [diff] [blame] | 5556 | break; |
| 5557 | } |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5558 | } |
| 5559 | |
| 5560 | /** |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5561 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport |
| 5562 | * @vport: pointer to vport data structure. |
| 5563 | * |
| 5564 | * This routine is to perform Clear Virtual Link (CVL) on a vport in |
| 5565 | * response to a CVL event. |
| 5566 | * |
| 5567 | * Return the pointer to the ndlp with the vport if successful, otherwise |
| 5568 | * return NULL. |
| 5569 | **/ |
| 5570 | static struct lpfc_nodelist * |
| 5571 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) |
| 5572 | { |
| 5573 | struct lpfc_nodelist *ndlp; |
| 5574 | struct Scsi_Host *shost; |
| 5575 | struct lpfc_hba *phba; |
| 5576 | |
| 5577 | if (!vport) |
| 5578 | return NULL; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5579 | phba = vport->phba; |
| 5580 | if (!phba) |
| 5581 | return NULL; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5582 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
| 5583 | if (!ndlp) { |
| 5584 | /* Cannot find existing Fabric ndlp, so allocate a new one */ |
James Smart | 9d3d340 | 2017-04-21 16:05:00 -0700 | [diff] [blame] | 5585 | ndlp = lpfc_nlp_init(vport, Fabric_DID); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5586 | if (!ndlp) |
| 5587 | return 0; |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5588 | /* Set the node type */ |
| 5589 | ndlp->nlp_type |= NLP_FABRIC; |
| 5590 | /* Put ndlp onto node list */ |
| 5591 | lpfc_enqueue_node(vport, ndlp); |
James Smart | 78730cf | 2010-04-06 15:06:30 -0400 | [diff] [blame] | 5592 | } |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5593 | if ((phba->pport->port_state < LPFC_FLOGI) && |
| 5594 | (phba->pport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5595 | return NULL; |
| 5596 | /* If virtual link is not yet instantiated ignore CVL */ |
James Smart | 63e801c | 2010-11-20 23:14:19 -0500 | [diff] [blame] | 5597 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
| 5598 | && (vport->port_state != LPFC_VPORT_FAILED)) |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5599 | return NULL; |
| 5600 | shost = lpfc_shost_from_vport(vport); |
| 5601 | if (!shost) |
| 5602 | return NULL; |
| 5603 | lpfc_linkdown_port(vport); |
| 5604 | lpfc_cleanup_pending_mbox(vport); |
| 5605 | spin_lock_irq(shost->host_lock); |
| 5606 | vport->fc_flag |= FC_VPORT_CVL_RCVD; |
| 5607 | spin_unlock_irq(shost->host_lock); |
| 5608 | |
| 5609 | return ndlp; |
| 5610 | } |
| 5611 | |
| 5612 | /** |
| 5613 | * 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] | 5614 | * @phba: pointer to lpfc hba data structure. |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5615 | * |
| 5616 | * This routine is to perform Clear Virtual Link (CVL) on all vports in |
| 5617 | * response to a FCF dead event. |
| 5618 | **/ |
| 5619 | static void |
| 5620 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) |
| 5621 | { |
| 5622 | struct lpfc_vport **vports; |
| 5623 | int i; |
| 5624 | |
| 5625 | vports = lpfc_create_vport_work_array(phba); |
| 5626 | if (vports) |
| 5627 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
| 5628 | lpfc_sli4_perform_vport_cvl(vports[i]); |
| 5629 | lpfc_destroy_vport_work_array(phba, vports); |
| 5630 | } |
| 5631 | |
| 5632 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5633 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5634 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5635 | * @acqe_fip: pointer to the async fcoe completion queue entry. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5636 | * |
| 5637 | * This routine is to handle the SLI4 asynchronous fcoe event. |
| 5638 | **/ |
| 5639 | static void |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 5640 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5641 | struct lpfc_acqe_fip *acqe_fip) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5642 | { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5643 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5644 | int rc; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5645 | struct lpfc_vport *vport; |
| 5646 | struct lpfc_nodelist *ndlp; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5647 | int active_vlink_present; |
| 5648 | struct lpfc_vport **vports; |
| 5649 | int i; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5650 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5651 | phba->fc_eventTag = acqe_fip->event_tag; |
| 5652 | phba->fcoe_eventtag = acqe_fip->event_tag; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5653 | switch (event_type) { |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5654 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
| 5655 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: |
| 5656 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5657 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5658 | "2546 New FCF event, evt_tag:x%x, " |
| 5659 | "index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5660 | acqe_fip->event_tag, |
| 5661 | acqe_fip->index); |
James Smart | 999d813 | 2010-03-15 11:24:56 -0400 | [diff] [blame] | 5662 | else |
| 5663 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | |
| 5664 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5665 | "2788 FCF param modified event, " |
| 5666 | "evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5667 | acqe_fip->event_tag, |
| 5668 | acqe_fip->index); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5669 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5670 | /* |
| 5671 | * During period of FCF discovery, read the FCF |
| 5672 | * table record indexed by the event to update |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5673 | * FCF roundrobin failover eligible FCF bmask. |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5674 | */ |
| 5675 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5676 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5677 | "2779 Read FCF (x%x) for updating " |
| 5678 | "roundrobin FCF failover bmask\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5679 | acqe_fip->index); |
| 5680 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5681 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5682 | |
| 5683 | /* If the FCF discovery is in progress, do nothing. */ |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5684 | spin_lock_irq(&phba->hbalock); |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5685 | if (phba->hba_flag & FCF_TS_INPROG) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5686 | spin_unlock_irq(&phba->hbalock); |
| 5687 | break; |
| 5688 | } |
| 5689 | /* If fast FCF failover rescan event is pending, do nothing */ |
James Smart | 036cad1 | 2018-10-23 13:41:06 -0700 | [diff] [blame] | 5690 | if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) { |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5691 | spin_unlock_irq(&phba->hbalock); |
| 5692 | break; |
| 5693 | } |
| 5694 | |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5695 | /* If the FCF has been in discovered state, do nothing. */ |
| 5696 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 5697 | spin_unlock_irq(&phba->hbalock); |
| 5698 | break; |
| 5699 | } |
| 5700 | spin_unlock_irq(&phba->hbalock); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5701 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5702 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
| 5703 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5704 | "2770 Start FCF table scan per async FCF " |
| 5705 | "event, evt_tag:x%x, index:x%x\n", |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5706 | acqe_fip->event_tag, acqe_fip->index); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5707 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
| 5708 | LPFC_FCOE_FCF_GET_FIRST); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5709 | if (rc) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5710 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5711 | "2547 Issue FCF scan read FCF mailbox " |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5712 | "command failed (x%x)\n", rc); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5713 | break; |
| 5714 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5715 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5716 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 5717 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
| 5718 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
| 5719 | acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5720 | break; |
| 5721 | |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5722 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5723 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5724 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 5725 | "2549 FCF (x%x) disconnected from network, " |
| 5726 | "tag:x%x\n", acqe_fip->index, |
| 5727 | acqe_fip->event_tag); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5728 | /* |
| 5729 | * If we are in the middle of FCF failover process, clear |
| 5730 | * the corresponding FCF bit in the roundrobin bitmap. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5731 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5732 | spin_lock_irq(&phba->hbalock); |
James Smart | a1cadfe | 2016-07-06 12:36:02 -0700 | [diff] [blame] | 5733 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
| 5734 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5735 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5736 | /* Update FLOGI FCF failover eligible FCF bmask */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5737 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5738 | break; |
| 5739 | } |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5740 | spin_unlock_irq(&phba->hbalock); |
| 5741 | |
| 5742 | /* If the event is not for currently used fcf do nothing */ |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5743 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5744 | break; |
| 5745 | |
| 5746 | /* |
| 5747 | * Otherwise, request the port to rediscover the entire FCF |
| 5748 | * table for a fast recovery from case that the current FCF |
| 5749 | * is no longer valid as we are not in the middle of FCF |
| 5750 | * failover process already. |
| 5751 | */ |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5752 | spin_lock_irq(&phba->hbalock); |
| 5753 | /* Mark the fast failover process in progress */ |
| 5754 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
| 5755 | spin_unlock_irq(&phba->hbalock); |
| 5756 | |
| 5757 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
| 5758 | "2771 Start FCF fast failover process due to " |
| 5759 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " |
| 5760 | "\n", acqe_fip->event_tag, acqe_fip->index); |
| 5761 | rc = lpfc_sli4_redisc_fcf_table(phba); |
| 5762 | if (rc) { |
| 5763 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5764 | LOG_TRACE_EVENT, |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5765 | "2772 Issue FCF rediscover mailbox " |
James Smart | c2b9712 | 2013-05-31 17:05:36 -0400 | [diff] [blame] | 5766 | "command failed, fail through to FCF " |
| 5767 | "dead event\n"); |
| 5768 | spin_lock_irq(&phba->hbalock); |
| 5769 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
| 5770 | spin_unlock_irq(&phba->hbalock); |
| 5771 | /* |
| 5772 | * Last resort will fail over by treating this |
| 5773 | * as a link down to FCF registration. |
| 5774 | */ |
| 5775 | lpfc_sli4_fcf_dead_failthrough(phba); |
| 5776 | } else { |
| 5777 | /* Reset FCF roundrobin bmask for new discovery */ |
| 5778 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
| 5779 | /* |
| 5780 | * Handling fast FCF failover to a DEAD FCF event is |
| 5781 | * considered equalivant to receiving CVL to all vports. |
| 5782 | */ |
| 5783 | lpfc_sli4_perform_all_vport_cvl(phba); |
| 5784 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5785 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5786 | case LPFC_FIP_EVENT_TYPE_CVL: |
James Smart | 80c1784 | 2012-03-01 22:35:45 -0500 | [diff] [blame] | 5787 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5788 | lpfc_printf_log(phba, KERN_ERR, |
| 5789 | LOG_TRACE_EVENT, |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5790 | "2718 Clear Virtual Link Received for VPI 0x%x" |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5791 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 5792 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5793 | vport = lpfc_find_vport_by_vpid(phba, |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 5794 | acqe_fip->index); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5795 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5796 | if (!ndlp) |
| 5797 | break; |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5798 | active_vlink_present = 0; |
| 5799 | |
| 5800 | vports = lpfc_create_vport_work_array(phba); |
| 5801 | if (vports) { |
| 5802 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; |
| 5803 | i++) { |
| 5804 | if ((!(vports[i]->fc_flag & |
| 5805 | FC_VPORT_CVL_RCVD)) && |
| 5806 | (vports[i]->port_state > LPFC_FDISC)) { |
| 5807 | active_vlink_present = 1; |
| 5808 | break; |
| 5809 | } |
| 5810 | } |
| 5811 | lpfc_destroy_vport_work_array(phba, vports); |
| 5812 | } |
| 5813 | |
James Smart | cc82355 | 2015-05-21 13:55:26 -0400 | [diff] [blame] | 5814 | /* |
| 5815 | * Don't re-instantiate if vport is marked for deletion. |
| 5816 | * If we are here first then vport_delete is going to wait |
| 5817 | * for discovery to complete. |
| 5818 | */ |
| 5819 | if (!(vport->load_flag & FC_UNLOADING) && |
| 5820 | active_vlink_present) { |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5821 | /* |
| 5822 | * If there are other active VLinks present, |
| 5823 | * re-instantiate the Vlink using FDISC. |
| 5824 | */ |
James Smart | 256ec0d | 2013-04-17 20:14:58 -0400 | [diff] [blame] | 5825 | mod_timer(&ndlp->nlp_delayfunc, |
| 5826 | jiffies + msecs_to_jiffies(1000)); |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5827 | spin_lock_irq(&ndlp->lock); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5828 | ndlp->nlp_flag |= NLP_DELAY_TMO; |
James Smart | c6adba1 | 2020-11-15 11:26:34 -0800 | [diff] [blame] | 5829 | spin_unlock_irq(&ndlp->lock); |
James Smart | 695a814 | 2010-01-26 23:08:03 -0500 | [diff] [blame] | 5830 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
| 5831 | vport->port_state = LPFC_FDISC; |
| 5832 | } else { |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5833 | /* |
| 5834 | * Otherwise, we request port to rediscover |
| 5835 | * the entire FCF table for a fast recovery |
| 5836 | * from possible case that the current FCF |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5837 | * is no longer valid if we are not already |
| 5838 | * in the FCF failover process. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5839 | */ |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5840 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5841 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5842 | spin_unlock_irq(&phba->hbalock); |
| 5843 | break; |
| 5844 | } |
| 5845 | /* Mark the fast failover process in progress */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5846 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5847 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5848 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
| 5849 | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 5850 | "2773 Start FCF failover per CVL, " |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5851 | "evt_tag:x%x\n", acqe_fip->event_tag); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5852 | rc = lpfc_sli4_redisc_fcf_table(phba); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5853 | if (rc) { |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5854 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5855 | LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5856 | "2774 Issue FCF rediscover " |
Colin Ian King | 7afc0ce | 2018-05-03 10:26:12 +0100 | [diff] [blame] | 5857 | "mailbox command failed, " |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5858 | "through to CVL event\n"); |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5859 | spin_lock_irq(&phba->hbalock); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 5860 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
James Smart | fc2b989 | 2010-02-26 14:15:29 -0500 | [diff] [blame] | 5861 | spin_unlock_irq(&phba->hbalock); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5862 | /* |
| 5863 | * Last resort will be re-try on the |
| 5864 | * the current registered FCF entry. |
| 5865 | */ |
| 5866 | lpfc_retry_pport_discovery(phba); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 5867 | } else |
| 5868 | /* |
| 5869 | * Reset FCF roundrobin bmask for new |
| 5870 | * discovery. |
| 5871 | */ |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 5872 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 5873 | } |
| 5874 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5875 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5876 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 5877 | "0288 Unknown FCoE event type 0x%x event tag " |
| 5878 | "0x%x\n", event_type, acqe_fip->event_tag); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5879 | break; |
| 5880 | } |
| 5881 | } |
| 5882 | |
| 5883 | /** |
| 5884 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event |
| 5885 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5886 | * @acqe_dcbx: pointer to the async dcbx completion queue entry. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5887 | * |
| 5888 | * This routine is to handle the SLI4 asynchronous dcbx event. |
| 5889 | **/ |
| 5890 | static void |
| 5891 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, |
| 5892 | struct lpfc_acqe_dcbx *acqe_dcbx) |
| 5893 | { |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 5894 | phba->fc_eventTag = acqe_dcbx->event_tag; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5895 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5896 | "0290 The SLI4 DCBX asynchronous event is not " |
| 5897 | "handled yet\n"); |
| 5898 | } |
| 5899 | |
| 5900 | /** |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5901 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event |
| 5902 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 5903 | * @acqe_grp5: pointer to the async grp5 completion queue entry. |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5904 | * |
| 5905 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event |
| 5906 | * is an asynchronous notified of a logical link speed change. The Port |
| 5907 | * reports the logical link speed in units of 10Mbps. |
| 5908 | **/ |
| 5909 | static void |
| 5910 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, |
| 5911 | struct lpfc_acqe_grp5 *acqe_grp5) |
| 5912 | { |
| 5913 | uint16_t prev_ll_spd; |
| 5914 | |
| 5915 | phba->fc_eventTag = acqe_grp5->event_tag; |
| 5916 | phba->fcoe_eventtag = acqe_grp5->event_tag; |
| 5917 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; |
| 5918 | phba->sli4_hba.link_state.logical_speed = |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5919 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5920 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 5921 | "2789 GRP5 Async Event: Updating logical link speed " |
James Smart | 8b68cd5 | 2012-09-29 11:32:37 -0400 | [diff] [blame] | 5922 | "from %dMbps to %dMbps\n", prev_ll_spd, |
| 5923 | phba->sli4_hba.link_state.logical_speed); |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5927 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event |
| 5928 | * @phba: pointer to lpfc hba data structure. |
| 5929 | * |
| 5930 | * This routine is invoked by the worker thread to process all the pending |
| 5931 | * SLI4 asynchronous events. |
| 5932 | **/ |
| 5933 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) |
| 5934 | { |
| 5935 | struct lpfc_cq_event *cq_event; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5936 | unsigned long iflags; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5937 | |
| 5938 | /* First, declare the async event has been handled */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5939 | spin_lock_irqsave(&phba->hbalock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5940 | phba->hba_flag &= ~ASYNC_EVENT; |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5941 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 5942 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5943 | /* Now, handle all the async events */ |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5944 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5945 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5946 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, |
| 5947 | cq_event, struct lpfc_cq_event, list); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5948 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, |
| 5949 | iflags); |
| 5950 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5951 | /* Process the asynchronous event */ |
| 5952 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { |
| 5953 | case LPFC_TRAILER_CODE_LINK: |
| 5954 | lpfc_sli4_async_link_evt(phba, |
| 5955 | &cq_event->cqe.acqe_link); |
| 5956 | break; |
| 5957 | case LPFC_TRAILER_CODE_FCOE: |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5958 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5959 | break; |
| 5960 | case LPFC_TRAILER_CODE_DCBX: |
| 5961 | lpfc_sli4_async_dcbx_evt(phba, |
| 5962 | &cq_event->cqe.acqe_dcbx); |
| 5963 | break; |
James Smart | b19a061 | 2010-04-06 14:48:51 -0400 | [diff] [blame] | 5964 | case LPFC_TRAILER_CODE_GRP5: |
| 5965 | lpfc_sli4_async_grp5_evt(phba, |
| 5966 | &cq_event->cqe.acqe_grp5); |
| 5967 | break; |
James Smart | 70f3c07 | 2010-12-15 17:57:33 -0500 | [diff] [blame] | 5968 | case LPFC_TRAILER_CODE_FC: |
| 5969 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); |
| 5970 | break; |
| 5971 | case LPFC_TRAILER_CODE_SLI: |
| 5972 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); |
| 5973 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5974 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 5975 | lpfc_printf_log(phba, KERN_ERR, |
| 5976 | LOG_TRACE_EVENT, |
Colin Ian King | 291c254 | 2019-12-18 08:43:01 +0000 | [diff] [blame] | 5977 | "1804 Invalid asynchronous event code: " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5978 | "x%x\n", bf_get(lpfc_trailer_code, |
| 5979 | &cq_event->cqe.mcqe_cmpl)); |
| 5980 | break; |
| 5981 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5982 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5983 | /* Free the completion event processed to the free pool */ |
| 5984 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5985 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5986 | } |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 5987 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 5988 | } |
| 5989 | |
| 5990 | /** |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 5991 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event |
| 5992 | * @phba: pointer to lpfc hba data structure. |
| 5993 | * |
| 5994 | * This routine is invoked by the worker thread to process FCF table |
| 5995 | * rediscovery pending completion event. |
| 5996 | **/ |
| 5997 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) |
| 5998 | { |
| 5999 | int rc; |
| 6000 | |
| 6001 | spin_lock_irq(&phba->hbalock); |
| 6002 | /* Clear FCF rediscovery timeout event */ |
| 6003 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; |
| 6004 | /* Clear driver fast failover FCF record flag */ |
| 6005 | phba->fcf.failover_rec.flag = 0; |
| 6006 | /* Set state for FCF fast failover */ |
| 6007 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; |
| 6008 | spin_unlock_irq(&phba->hbalock); |
| 6009 | |
| 6010 | /* Scan FCF table from the first entry to re-discover SAN */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6011 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6012 | "2777 Start post-quiescent FCF table scan\n"); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6013 | 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] | 6014 | if (rc) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6015 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6016 | "2747 Issue FCF scan read FCF mailbox " |
| 6017 | "command failed 0x%x\n", rc); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6018 | } |
| 6019 | |
| 6020 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6021 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table |
| 6022 | * @phba: pointer to lpfc hba data structure. |
| 6023 | * @dev_grp: The HBA PCI-Device group number. |
| 6024 | * |
| 6025 | * This routine is invoked to set up the per HBA PCI-Device group function |
| 6026 | * API jump table entries. |
| 6027 | * |
| 6028 | * Return: 0 if success, otherwise -ENODEV |
| 6029 | **/ |
| 6030 | int |
| 6031 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6032 | { |
| 6033 | int rc; |
| 6034 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6035 | /* Set up lpfc PCI-device group */ |
| 6036 | phba->pci_dev_grp = dev_grp; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6037 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6038 | /* The LPFC_PCI_DEV_OC uses SLI4 */ |
| 6039 | if (dev_grp == LPFC_PCI_DEV_OC) |
| 6040 | phba->sli_rev = LPFC_SLI_REV4; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6041 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6042 | /* Set up device INIT API function jump table */ |
| 6043 | rc = lpfc_init_api_table_setup(phba, dev_grp); |
| 6044 | if (rc) |
| 6045 | return -ENODEV; |
| 6046 | /* Set up SCSI API function jump table */ |
| 6047 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); |
| 6048 | if (rc) |
| 6049 | return -ENODEV; |
| 6050 | /* Set up SLI API function jump table */ |
| 6051 | rc = lpfc_sli_api_table_setup(phba, dev_grp); |
| 6052 | if (rc) |
| 6053 | return -ENODEV; |
| 6054 | /* Set up MBOX API function jump table */ |
| 6055 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); |
| 6056 | if (rc) |
| 6057 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6058 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6059 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6060 | } |
| 6061 | |
| 6062 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 6063 | * lpfc_log_intr_mode - Log the active interrupt mode |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6064 | * @phba: pointer to lpfc hba data structure. |
| 6065 | * @intr_mode: active interrupt mode adopted. |
| 6066 | * |
| 6067 | * This routine it invoked to log the currently used active interrupt mode |
| 6068 | * to the device. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6069 | **/ |
| 6070 | 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] | 6071 | { |
| 6072 | switch (intr_mode) { |
| 6073 | case 0: |
| 6074 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6075 | "0470 Enable INTx interrupt mode.\n"); |
| 6076 | break; |
| 6077 | case 1: |
| 6078 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6079 | "0481 Enabled MSI interrupt mode.\n"); |
| 6080 | break; |
| 6081 | case 2: |
| 6082 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 6083 | "0480 Enabled MSI-X interrupt mode.\n"); |
| 6084 | break; |
| 6085 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6086 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6087 | "0482 Illegal interrupt mode.\n"); |
| 6088 | break; |
| 6089 | } |
| 6090 | return; |
| 6091 | } |
| 6092 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6093 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6094 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6095 | * @phba: pointer to lpfc hba data structure. |
| 6096 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6097 | * This routine is invoked to enable the PCI device that is common to all |
| 6098 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6099 | * |
| 6100 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6101 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6102 | * other values - error |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6103 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6104 | static int |
| 6105 | lpfc_enable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6106 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6107 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6108 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6109 | /* Obtain PCI device reference */ |
| 6110 | if (!phba->pcidev) |
| 6111 | goto out_error; |
| 6112 | else |
| 6113 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6114 | /* Enable PCI device */ |
| 6115 | if (pci_enable_device_mem(pdev)) |
| 6116 | goto out_error; |
| 6117 | /* Request PCI resource for the device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6118 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6119 | goto out_disable_device; |
| 6120 | /* Set up device as PCI master and save state for EEH */ |
| 6121 | pci_set_master(pdev); |
| 6122 | pci_try_set_mwi(pdev); |
| 6123 | pci_save_state(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6124 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6125 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
Jon Mason | 453193e | 2013-09-11 15:38:13 -0700 | [diff] [blame] | 6126 | if (pci_is_pcie(pdev)) |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6127 | pdev->needs_freset = 1; |
| 6128 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6129 | return 0; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6130 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6131 | out_disable_device: |
| 6132 | pci_disable_device(pdev); |
| 6133 | out_error: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6134 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6135 | "1401 Failed to enable pci device\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6136 | return -ENODEV; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6140 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6141 | * @phba: pointer to lpfc hba data structure. |
| 6142 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6143 | * This routine is invoked to disable the PCI device that is common to all |
| 6144 | * PCI devices. |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6145 | **/ |
| 6146 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6147 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6148 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6149 | struct pci_dev *pdev; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6150 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6151 | /* Obtain PCI device reference */ |
| 6152 | if (!phba->pcidev) |
| 6153 | return; |
| 6154 | else |
| 6155 | pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6156 | /* Release PCI resource and disable PCI device */ |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 6157 | pci_release_mem_regions(pdev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6158 | pci_disable_device(pdev); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 6159 | |
| 6160 | return; |
| 6161 | } |
| 6162 | |
| 6163 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6164 | * lpfc_reset_hba - Reset a hba |
| 6165 | * @phba: pointer to lpfc hba data structure. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6166 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6167 | * This routine is invoked to reset a hba device. It brings the HBA |
| 6168 | * offline, performs a board restart, and then brings the board back |
| 6169 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up |
| 6170 | * on outstanding mailbox commands. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 6171 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6172 | void |
| 6173 | lpfc_reset_hba(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6174 | { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6175 | /* If resets are disabled then set error state and return. */ |
| 6176 | if (!phba->cfg_enable_hba_reset) { |
| 6177 | phba->link_state = LPFC_HBA_ERROR; |
| 6178 | return; |
| 6179 | } |
James Smart | ee62021 | 2014-04-04 13:51:53 -0400 | [diff] [blame] | 6180 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
| 6181 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
| 6182 | else |
| 6183 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6184 | lpfc_offline(phba); |
| 6185 | lpfc_sli_brdrestart(phba); |
| 6186 | lpfc_online(phba); |
| 6187 | lpfc_unblock_mgmt_io(phba); |
| 6188 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6189 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6190 | /** |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6191 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions |
| 6192 | * @phba: pointer to lpfc hba data structure. |
| 6193 | * |
| 6194 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6195 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6196 | * enable the number of virtual functions to the physical function. As |
| 6197 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6198 | * API call does not considered as an error condition for most of the device. |
| 6199 | **/ |
| 6200 | uint16_t |
| 6201 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) |
| 6202 | { |
| 6203 | struct pci_dev *pdev = phba->pcidev; |
| 6204 | uint16_t nr_virtfn; |
| 6205 | int pos; |
| 6206 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6207 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 6208 | if (pos == 0) |
| 6209 | return 0; |
| 6210 | |
| 6211 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); |
| 6212 | return nr_virtfn; |
| 6213 | } |
| 6214 | |
| 6215 | /** |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6216 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions |
| 6217 | * @phba: pointer to lpfc hba data structure. |
| 6218 | * @nr_vfn: number of virtual functions to be enabled. |
| 6219 | * |
| 6220 | * This function enables the PCI SR-IOV virtual functions to a physical |
| 6221 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to |
| 6222 | * enable the number of virtual functions to the physical function. As |
| 6223 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() |
| 6224 | * API call does not considered as an error condition for most of the device. |
| 6225 | **/ |
| 6226 | int |
| 6227 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) |
| 6228 | { |
| 6229 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6230 | uint16_t max_nr_vfn; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6231 | int rc; |
| 6232 | |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6233 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
| 6234 | if (nr_vfn > max_nr_vfn) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6235 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 6236 | "3057 Requested vfs (%d) greater than " |
| 6237 | "supported vfs (%d)", nr_vfn, max_nr_vfn); |
| 6238 | return -EINVAL; |
| 6239 | } |
| 6240 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6241 | rc = pci_enable_sriov(pdev, nr_vfn); |
| 6242 | if (rc) { |
| 6243 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6244 | "2806 Failed to enable sriov on this device " |
| 6245 | "with vfn number nr_vf:%d, rc:%d\n", |
| 6246 | nr_vfn, rc); |
| 6247 | } else |
| 6248 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6249 | "2807 Successful enable sriov on this device " |
| 6250 | "with vfn number nr_vf:%d\n", nr_vfn); |
| 6251 | return rc; |
| 6252 | } |
| 6253 | |
| 6254 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6255 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6256 | * @phba: pointer to lpfc hba data structure. |
| 6257 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6258 | * This routine is invoked to set up the driver internal resources before the |
| 6259 | * device specific resource setup to support the HBA device it attached to. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6260 | * |
| 6261 | * Return codes |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6262 | * 0 - successful |
| 6263 | * other values - error |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6264 | **/ |
| 6265 | static int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6266 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6267 | { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6268 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6269 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6270 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6271 | * Driver resources common to all SLI revisions |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6272 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6273 | atomic_set(&phba->fast_event_count, 0); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6274 | atomic_set(&phba->dbg_log_idx, 0); |
| 6275 | atomic_set(&phba->dbg_log_cnt, 0); |
| 6276 | atomic_set(&phba->dbg_log_dmping, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6277 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6278 | |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6279 | /* Initialize port_list spinlock */ |
| 6280 | spin_lock_init(&phba->port_list_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6281 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 6282 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6283 | INIT_LIST_HEAD(&phba->work_list); |
| 6284 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
| 6285 | |
| 6286 | /* Initialize the wait queue head for the kernel thread */ |
| 6287 | init_waitqueue_head(&phba->work_waitq); |
| 6288 | |
| 6289 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6290 | "1403 Protocols supported %s %s %s\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6291 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
| 6292 | "SCSI" : " "), |
| 6293 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6294 | "NVME" : " "), |
| 6295 | (phba->nvmet_support ? "NVMET" : " ")); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6296 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6297 | /* Initialize the IO buffer list used by driver for SLI3 SCSI */ |
| 6298 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
| 6299 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); |
| 6300 | spin_lock_init(&phba->scsi_buf_list_put_lock); |
| 6301 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6302 | |
| 6303 | /* Initialize the fabric iocb list */ |
| 6304 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 6305 | |
| 6306 | /* Initialize list to save ELS buffers */ |
| 6307 | INIT_LIST_HEAD(&phba->elsbuf); |
| 6308 | |
| 6309 | /* Initialize FCF connection rec list */ |
| 6310 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); |
| 6311 | |
| 6312 | /* Initialize OAS configuration list */ |
| 6313 | spin_lock_init(&phba->devicelock); |
| 6314 | INIT_LIST_HEAD(&phba->luns); |
| 6315 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6316 | /* MBOX heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6317 | timer_setup(&psli->mbox_tmo, lpfc_mbox_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6318 | /* Fabric block timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6319 | timer_setup(&phba->fabric_block_timer, lpfc_fabric_block_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6320 | /* EA polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6321 | timer_setup(&phba->eratt_poll, lpfc_poll_eratt, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6322 | /* Heartbeat timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6323 | timer_setup(&phba->hb_tmofunc, lpfc_hb_timeout, 0); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6324 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 6325 | INIT_DELAYED_WORK(&phba->eq_delay_work, lpfc_hb_eq_delay_work); |
| 6326 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 6327 | INIT_DELAYED_WORK(&phba->idle_stat_delay_work, |
| 6328 | lpfc_idle_stat_delay_work); |
| 6329 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6330 | return 0; |
| 6331 | } |
| 6332 | |
| 6333 | /** |
| 6334 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev |
| 6335 | * @phba: pointer to lpfc hba data structure. |
| 6336 | * |
| 6337 | * This routine is invoked to set up the driver internal resources specific to |
| 6338 | * support the SLI-3 HBA device it attached to. |
| 6339 | * |
| 6340 | * Return codes |
| 6341 | * 0 - successful |
| 6342 | * other values - error |
| 6343 | **/ |
| 6344 | static int |
| 6345 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) |
| 6346 | { |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6347 | int rc, entry_sz; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6348 | |
| 6349 | /* |
| 6350 | * Initialize timers used by driver |
| 6351 | */ |
| 6352 | |
| 6353 | /* FCP polling mode timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6354 | timer_setup(&phba->fcp_poll_timer, lpfc_poll_timeout, 0); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6355 | |
| 6356 | /* Host attention work mask setup */ |
| 6357 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| 6358 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 6359 | |
| 6360 | /* Get all the module params for configuring this host */ |
| 6361 | lpfc_get_cfgparam(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6362 | /* Set up phase-1 common device driver resources */ |
| 6363 | |
| 6364 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6365 | if (rc) |
| 6366 | return -ENODEV; |
| 6367 | |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 6368 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
| 6369 | phba->menlo_flag |= HBA_MENLO_SUPPORT; |
| 6370 | /* check for menlo minimum sg count */ |
| 6371 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) |
| 6372 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; |
| 6373 | } |
| 6374 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6375 | if (!phba->sli.sli3_ring) |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6376 | phba->sli.sli3_ring = kcalloc(LPFC_SLI3_MAX_RING, |
| 6377 | sizeof(struct lpfc_sli_ring), |
| 6378 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6379 | if (!phba->sli.sli3_ring) |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6380 | return -ENOMEM; |
| 6381 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6382 | /* |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6383 | * 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] | 6384 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6385 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6386 | |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6387 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 6388 | entry_sz = sizeof(struct sli4_sge); |
| 6389 | else |
| 6390 | entry_sz = sizeof(struct ulp_bde64); |
| 6391 | |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6392 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ |
| 6393 | if (phba->cfg_enable_bg) { |
| 6394 | /* |
| 6395 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, |
| 6396 | * the FCP rsp, and a BDE for each. Sice we have no control |
| 6397 | * over how many protection data segments the SCSI Layer |
| 6398 | * will hand us (ie: there could be one for every block |
| 6399 | * in the IO), we just allocate enough BDEs to accomidate |
| 6400 | * our max amount and we need to limit lpfc_sg_seg_cnt to |
| 6401 | * minimize the risk of running out. |
| 6402 | */ |
| 6403 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6404 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6405 | (LPFC_MAX_SG_SEG_CNT * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6406 | |
| 6407 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) |
| 6408 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; |
| 6409 | |
| 6410 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ |
| 6411 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; |
| 6412 | } else { |
| 6413 | /* |
| 6414 | * The scsi_buf for a regular I/O will hold the FCP cmnd, |
| 6415 | * the FCP rsp, a BDE for each, and a BDE for up to |
| 6416 | * cfg_sg_seg_cnt data segments. |
| 6417 | */ |
| 6418 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6419 | sizeof(struct fcp_rsp) + |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 6420 | ((phba->cfg_sg_seg_cnt + 2) * entry_sz); |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6421 | |
| 6422 | /* Total BDEs in BPL for scsi_sg_list */ |
| 6423 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; |
| 6424 | } |
| 6425 | |
| 6426 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
James Smart | c90b448 | 2020-03-22 11:12:56 -0700 | [diff] [blame] | 6427 | "9088 INIT sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", |
James Smart | 96f7077 | 2013-04-17 20:16:15 -0400 | [diff] [blame] | 6428 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 6429 | phba->cfg_total_seg_cnt); |
| 6430 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6431 | phba->max_vpi = LPFC_MAX_VPI; |
| 6432 | /* This will be set to correct value after config_port mbox */ |
| 6433 | phba->max_vports = 0; |
| 6434 | |
| 6435 | /* |
| 6436 | * Initialize the SLI Layer to run with lpfc HBAs. |
| 6437 | */ |
| 6438 | lpfc_sli_setup(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6439 | lpfc_sli_queue_init(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6440 | |
| 6441 | /* Allocate device driver memory */ |
| 6442 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) |
| 6443 | return -ENOMEM; |
| 6444 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6445 | phba->lpfc_sg_dma_buf_pool = |
| 6446 | dma_pool_create("lpfc_sg_dma_buf_pool", |
| 6447 | &phba->pcidev->dev, phba->cfg_sg_dma_buf_size, |
| 6448 | BPL_ALIGN_SZ, 0); |
| 6449 | |
| 6450 | if (!phba->lpfc_sg_dma_buf_pool) |
| 6451 | goto fail_free_mem; |
| 6452 | |
| 6453 | phba->lpfc_cmd_rsp_buf_pool = |
| 6454 | dma_pool_create("lpfc_cmd_rsp_buf_pool", |
| 6455 | &phba->pcidev->dev, |
| 6456 | sizeof(struct fcp_cmnd) + |
| 6457 | sizeof(struct fcp_rsp), |
| 6458 | BPL_ALIGN_SZ, 0); |
| 6459 | |
| 6460 | if (!phba->lpfc_cmd_rsp_buf_pool) |
| 6461 | goto fail_free_dma_buf_pool; |
| 6462 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 6463 | /* |
| 6464 | * Enable sr-iov virtual functions if supported and configured |
| 6465 | * through the module parameter. |
| 6466 | */ |
| 6467 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 6468 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 6469 | phba->cfg_sriov_nr_virtfn); |
| 6470 | if (rc) { |
| 6471 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 6472 | "2808 Requested number of SR-IOV " |
| 6473 | "virtual functions (%d) is not " |
| 6474 | "supported\n", |
| 6475 | phba->cfg_sriov_nr_virtfn); |
| 6476 | phba->cfg_sriov_nr_virtfn = 0; |
| 6477 | } |
| 6478 | } |
| 6479 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6480 | return 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6481 | |
| 6482 | fail_free_dma_buf_pool: |
| 6483 | dma_pool_destroy(phba->lpfc_sg_dma_buf_pool); |
| 6484 | phba->lpfc_sg_dma_buf_pool = NULL; |
| 6485 | fail_free_mem: |
| 6486 | lpfc_mem_free(phba); |
| 6487 | return -ENOMEM; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 6488 | } |
| 6489 | |
| 6490 | /** |
| 6491 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev |
| 6492 | * @phba: pointer to lpfc hba data structure. |
| 6493 | * |
| 6494 | * This routine is invoked to unset the driver internal resources set up |
| 6495 | * specific for supporting the SLI-3 HBA device it attached to. |
| 6496 | **/ |
| 6497 | static void |
| 6498 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) |
| 6499 | { |
| 6500 | /* Free device driver memory allocated */ |
| 6501 | lpfc_mem_free_all(phba); |
| 6502 | |
| 6503 | return; |
| 6504 | } |
| 6505 | |
| 6506 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6507 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
| 6508 | * @phba: pointer to lpfc hba data structure. |
| 6509 | * |
| 6510 | * This routine is invoked to set up the driver internal resources specific to |
| 6511 | * support the SLI-4 HBA device it attached to. |
| 6512 | * |
| 6513 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 6514 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6515 | * other values - error |
| 6516 | **/ |
| 6517 | static int |
| 6518 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
| 6519 | { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6520 | LPFC_MBOXQ_t *mboxq; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6521 | MAILBOX_t *mb; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6522 | int rc, i, max_buf_size; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 6523 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
| 6524 | struct lpfc_mqe *mqe; |
James Smart | 09294d4 | 2013-04-17 20:16:05 -0400 | [diff] [blame] | 6525 | int longs; |
James Smart | 81e6a63 | 2017-11-20 16:00:43 -0800 | [diff] [blame] | 6526 | int extra; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6527 | uint64_t wwn; |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6528 | u32 if_type; |
| 6529 | u32 if_fam; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6530 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6531 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
James Smart | eede497 | 2019-11-21 09:55:56 -0800 | [diff] [blame] | 6532 | phba->sli4_hba.num_possible_cpu = cpumask_last(cpu_possible_mask) + 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6533 | phba->sli4_hba.curr_disp_cpu = 0; |
| 6534 | |
James Smart | 716d3bc | 2013-09-06 12:18:28 -0400 | [diff] [blame] | 6535 | /* Get all the module params for configuring this host */ |
| 6536 | lpfc_get_cfgparam(phba); |
| 6537 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6538 | /* Set up phase-1 common device driver resources */ |
| 6539 | rc = lpfc_setup_driver_resource_phase1(phba); |
| 6540 | if (rc) |
| 6541 | return -ENODEV; |
| 6542 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6543 | /* Before proceed, wait for POST done and device ready */ |
| 6544 | rc = lpfc_sli4_post_status_check(phba); |
| 6545 | if (rc) |
| 6546 | return -ENODEV; |
| 6547 | |
James Smart | 3cee98d | 2019-08-14 16:56:34 -0700 | [diff] [blame] | 6548 | /* Allocate all driver workqueues here */ |
| 6549 | |
| 6550 | /* The lpfc_wq workqueue for deferred irq use */ |
| 6551 | phba->wq = alloc_workqueue("lpfc_wq", WQ_MEM_RECLAIM, 0); |
| 6552 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6553 | /* |
| 6554 | * Initialize timers used by driver |
| 6555 | */ |
| 6556 | |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6557 | timer_setup(&phba->rrq_tmr, lpfc_rrq_timeout, 0); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6558 | |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 6559 | /* FCF rediscover timer */ |
Kees Cook | f22eb4d | 2017-09-06 20:24:26 -0700 | [diff] [blame] | 6560 | 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] | 6561 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6562 | /* |
James Smart | 7ad20aa | 2011-05-24 11:44:28 -0400 | [diff] [blame] | 6563 | * Control structure for handling external multi-buffer mailbox |
| 6564 | * command pass-through. |
| 6565 | */ |
| 6566 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, |
| 6567 | sizeof(struct lpfc_mbox_ext_buf_ctx)); |
| 6568 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); |
| 6569 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6570 | phba->max_vpi = LPFC_MAX_VPI; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6571 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6572 | /* This will be set to correct value after the read_config mbox */ |
| 6573 | phba->max_vports = 0; |
| 6574 | |
| 6575 | /* Program the default value of vlan_id and fc_map */ |
| 6576 | phba->valid_vlan = 0; |
| 6577 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; |
| 6578 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; |
| 6579 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; |
| 6580 | |
| 6581 | /* |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6582 | * 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] | 6583 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
| 6584 | * The WQ create will allocate the ring. |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 6585 | */ |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 6586 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6587 | /* Initialize buffer queue management fields */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6588 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6589 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
| 6590 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; |
| 6591 | |
| 6592 | /* |
| 6593 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. |
| 6594 | */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 6595 | /* Initialize the Abort buffer list used by driver */ |
| 6596 | spin_lock_init(&phba->sli4_hba.abts_io_buf_list_lock); |
| 6597 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_io_buf_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6598 | |
| 6599 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6600 | /* Initialize the Abort nvme buffer list used by driver */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 6601 | spin_lock_init(&phba->sli4_hba.abts_nvmet_buf_list_lock); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 6602 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6603 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_io_wait_list); |
James Smart | 79d8c4c | 2019-05-21 17:48:56 -0700 | [diff] [blame] | 6604 | spin_lock_init(&phba->sli4_hba.t_active_list_lock); |
| 6605 | INIT_LIST_HEAD(&phba->sli4_hba.t_active_ctx_list); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6606 | } |
| 6607 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6608 | /* This abort list used by worker thread */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6609 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
James Smart | a8cf5df | 2017-05-15 15:20:46 -0700 | [diff] [blame] | 6610 | spin_lock_init(&phba->sli4_hba.nvmet_io_wait_lock); |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 6611 | spin_lock_init(&phba->sli4_hba.asynce_list_lock); |
| 6612 | spin_lock_init(&phba->sli4_hba.els_xri_abrt_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6613 | |
| 6614 | /* |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6615 | * Initialize driver internal slow-path work queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6616 | */ |
| 6617 | |
| 6618 | /* Driver internel slow-path CQ Event pool */ |
| 6619 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); |
| 6620 | /* Response IOCB work queue list */ |
James Smart | 45ed119 | 2009-10-02 15:17:02 -0400 | [diff] [blame] | 6621 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6622 | /* Asynchronous event CQ Event work queue list */ |
| 6623 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6624 | /* Slow-path XRI aborted CQ Event work queue list */ |
| 6625 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); |
| 6626 | /* Receive queue CQ Event work queue list */ |
| 6627 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); |
| 6628 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6629 | /* Initialize extent block lists. */ |
| 6630 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); |
| 6631 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); |
| 6632 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); |
| 6633 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); |
| 6634 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6635 | /* Initialize mboxq lists. If the early init routines fail |
| 6636 | * these lists need to be correctly initialized. |
| 6637 | */ |
| 6638 | INIT_LIST_HEAD(&phba->sli.mboxq); |
| 6639 | INIT_LIST_HEAD(&phba->sli.mboxq_cmpl); |
| 6640 | |
James Smart | 448193b | 2015-12-16 18:12:05 -0500 | [diff] [blame] | 6641 | /* initialize optic_state to 0xFF */ |
| 6642 | phba->sli4_hba.lnk_info.optic_state = 0xff; |
| 6643 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6644 | /* Allocate device driver memory */ |
| 6645 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); |
| 6646 | if (rc) |
| 6647 | return -ENOMEM; |
| 6648 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6649 | /* IF Type 2 ports get initialized now. */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 6650 | 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] | 6651 | LPFC_SLI_INTF_IF_TYPE_2) { |
| 6652 | rc = lpfc_pci_function_reset(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6653 | if (unlikely(rc)) { |
| 6654 | rc = -ENODEV; |
| 6655 | goto out_free_mem; |
| 6656 | } |
James Smart | 946727d | 2015-04-07 15:07:09 -0400 | [diff] [blame] | 6657 | phba->temp_sensor_support = 1; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6658 | } |
| 6659 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6660 | /* Create the bootstrap mailbox command */ |
| 6661 | rc = lpfc_create_bootstrap_mbox(phba); |
| 6662 | if (unlikely(rc)) |
| 6663 | goto out_free_mem; |
| 6664 | |
| 6665 | /* Set up the host's endian order with the device. */ |
| 6666 | rc = lpfc_setup_endian_order(phba); |
| 6667 | if (unlikely(rc)) |
| 6668 | goto out_free_bsmbx; |
| 6669 | |
| 6670 | /* Set up the hba's configuration parameters. */ |
| 6671 | rc = lpfc_sli4_read_config(phba); |
| 6672 | if (unlikely(rc)) |
| 6673 | goto out_free_bsmbx; |
James Smart | cff261f | 2013-12-17 20:29:47 -0500 | [diff] [blame] | 6674 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); |
| 6675 | if (unlikely(rc)) |
| 6676 | goto out_free_bsmbx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6677 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 6678 | /* IF Type 0 ports get initialized now. */ |
| 6679 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 6680 | LPFC_SLI_INTF_IF_TYPE_0) { |
| 6681 | rc = lpfc_pci_function_reset(phba); |
| 6682 | if (unlikely(rc)) |
| 6683 | goto out_free_bsmbx; |
| 6684 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6685 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6686 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 6687 | GFP_KERNEL); |
| 6688 | if (!mboxq) { |
| 6689 | rc = -ENOMEM; |
| 6690 | goto out_free_bsmbx; |
| 6691 | } |
| 6692 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6693 | /* Check for NVMET being configured */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6694 | phba->nvmet_support = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6695 | if (lpfc_enable_nvmet_cnt) { |
| 6696 | |
| 6697 | /* First get WWN of HBA instance */ |
| 6698 | lpfc_read_nv(phba, mboxq); |
| 6699 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 6700 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6701 | lpfc_printf_log(phba, KERN_ERR, |
| 6702 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6703 | "6016 Mailbox failed , mbxCmd x%x " |
| 6704 | "READ_NV, mbxStatus x%x\n", |
| 6705 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), |
| 6706 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 6707 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6708 | rc = -EIO; |
| 6709 | goto out_free_bsmbx; |
| 6710 | } |
| 6711 | mb = &mboxq->u.mb; |
| 6712 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, |
| 6713 | sizeof(uint64_t)); |
| 6714 | wwn = cpu_to_be64(wwn); |
| 6715 | phba->sli4_hba.wwnn.u.name = wwn; |
| 6716 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, |
| 6717 | sizeof(uint64_t)); |
| 6718 | /* wwn is WWPN of HBA instance */ |
| 6719 | wwn = cpu_to_be64(wwn); |
| 6720 | phba->sli4_hba.wwpn.u.name = wwn; |
| 6721 | |
| 6722 | /* Check to see if it matches any module parameter */ |
| 6723 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { |
| 6724 | if (wwn == lpfc_enable_nvmet[i]) { |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6725 | #if (IS_ENABLED(CONFIG_NVME_TARGET_FC)) |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6726 | if (lpfc_nvmet_mem_alloc(phba)) |
| 6727 | break; |
| 6728 | |
| 6729 | phba->nvmet_support = 1; /* a match */ |
| 6730 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6731 | lpfc_printf_log(phba, KERN_ERR, |
| 6732 | LOG_TRACE_EVENT, |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6733 | "6017 NVME Target %016llx\n", |
| 6734 | wwn); |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6735 | #else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6736 | lpfc_printf_log(phba, KERN_ERR, |
| 6737 | LOG_TRACE_EVENT, |
James Smart | 7d70803 | 2017-03-08 14:36:01 -0800 | [diff] [blame] | 6738 | "6021 Can't enable NVME Target." |
| 6739 | " NVME_TARGET_FC infrastructure" |
| 6740 | " is not in kernel\n"); |
| 6741 | #endif |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 6742 | /* Not supported for NVMET */ |
| 6743 | phba->cfg_xri_rebalancing = 0; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 6744 | if (phba->irq_chann_mode == NHT_MODE) { |
| 6745 | phba->cfg_irq_chann = |
| 6746 | phba->sli4_hba.num_present_cpu; |
| 6747 | phba->cfg_hdw_queue = |
| 6748 | phba->sli4_hba.num_present_cpu; |
| 6749 | phba->irq_chann_mode = NORMAL_MODE; |
| 6750 | } |
James Smart | 3c603be | 2017-05-15 15:20:44 -0700 | [diff] [blame] | 6751 | break; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 6752 | } |
| 6753 | } |
| 6754 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6755 | |
| 6756 | lpfc_nvme_mod_param_dep(phba); |
| 6757 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6758 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6759 | lpfc_supported_pages(mboxq); |
| 6760 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6761 | if (!rc) { |
| 6762 | mqe = &mboxq->u.mqe; |
| 6763 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), |
| 6764 | LPFC_MAX_SUPPORTED_PAGES); |
| 6765 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { |
| 6766 | switch (pn_page[i]) { |
| 6767 | case LPFC_SLI4_PARAMETERS: |
| 6768 | phba->sli4_hba.pc_sli4_params.supported = 1; |
| 6769 | break; |
| 6770 | default: |
| 6771 | break; |
| 6772 | } |
| 6773 | } |
| 6774 | /* Read the port's SLI4 Parameters capabilities if supported. */ |
| 6775 | if (phba->sli4_hba.pc_sli4_params.supported) |
| 6776 | rc = lpfc_pc_sli4_params_get(phba, mboxq); |
| 6777 | if (rc) { |
| 6778 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6779 | rc = -EIO; |
| 6780 | goto out_free_bsmbx; |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6781 | } |
| 6782 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 6783 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6784 | /* |
| 6785 | * Get sli4 parameters that override parameters from Port capabilities. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6786 | * If this call fails, it isn't critical unless the SLI4 parameters come |
| 6787 | * back in conflict. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 6788 | */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6789 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
| 6790 | if (rc) { |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6791 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 6792 | &phba->sli4_hba.sli_intf); |
| 6793 | if_fam = bf_get(lpfc_sli_intf_sli_family, |
| 6794 | &phba->sli4_hba.sli_intf); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6795 | if (phba->sli4_hba.extents_in_use && |
| 6796 | phba->sli4_hba.rpi_hdrs_in_use) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6797 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 6798 | "2999 Unsupported SLI4 Parameters " |
| 6799 | "Extents and RPI headers enabled.\n"); |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6800 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6801 | if_fam == LPFC_SLI_INTF_FAMILY_BE2) { |
| 6802 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6803 | rc = -EIO; |
| 6804 | goto out_free_bsmbx; |
| 6805 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6806 | } |
James Smart | b92dc72 | 2018-05-24 21:09:01 -0700 | [diff] [blame] | 6807 | if (!(if_type == LPFC_SLI_INTF_IF_TYPE_0 && |
| 6808 | if_fam == LPFC_SLI_INTF_FAMILY_BE2)) { |
| 6809 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 6810 | rc = -EIO; |
| 6811 | goto out_free_bsmbx; |
| 6812 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 6813 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6814 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6815 | /* |
| 6816 | * 1 for cmd, 1 for rsp, NVME adds an extra one |
| 6817 | * for boundary conditions in its max_sgl_segment template. |
| 6818 | */ |
| 6819 | extra = 2; |
| 6820 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 6821 | extra++; |
| 6822 | |
| 6823 | /* |
| 6824 | * It doesn't matter what family our adapter is in, we are |
| 6825 | * limited to 2 Pages, 512 SGEs, for our SGL. |
| 6826 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp |
| 6827 | */ |
| 6828 | max_buf_size = (2 * SLI4_PAGE_SIZE); |
| 6829 | |
| 6830 | /* |
| 6831 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
| 6832 | * used to create the sg_dma_buf_pool must be calculated. |
| 6833 | */ |
| 6834 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) { |
| 6835 | /* Both cfg_enable_bg and cfg_external_dif code paths */ |
| 6836 | |
| 6837 | /* |
| 6838 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
| 6839 | * the FCP rsp, and a SGE. Sice we have no control |
| 6840 | * over how many protection segments the SCSI Layer |
| 6841 | * will hand us (ie: there could be one for every block |
| 6842 | * in the IO), just allocate enough SGEs to accomidate |
| 6843 | * our max amount and we need to limit lpfc_sg_seg_cnt |
| 6844 | * to minimize the risk of running out. |
| 6845 | */ |
| 6846 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6847 | sizeof(struct fcp_rsp) + max_buf_size; |
| 6848 | |
| 6849 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ |
| 6850 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; |
| 6851 | |
| 6852 | /* |
| 6853 | * If supporting DIF, reduce the seg count for scsi to |
| 6854 | * allow room for the DIF sges. |
| 6855 | */ |
| 6856 | if (phba->cfg_enable_bg && |
| 6857 | phba->cfg_sg_seg_cnt > LPFC_MAX_BG_SLI4_SEG_CNT_DIF) |
| 6858 | phba->cfg_scsi_seg_cnt = LPFC_MAX_BG_SLI4_SEG_CNT_DIF; |
| 6859 | else |
| 6860 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6861 | |
| 6862 | } else { |
| 6863 | /* |
| 6864 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
| 6865 | * the FCP rsp, a SGE for each, and a SGE for up to |
| 6866 | * cfg_sg_seg_cnt data segments. |
| 6867 | */ |
| 6868 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
| 6869 | sizeof(struct fcp_rsp) + |
| 6870 | ((phba->cfg_sg_seg_cnt + extra) * |
| 6871 | sizeof(struct sli4_sge)); |
| 6872 | |
| 6873 | /* Total SGEs for scsi_sg_list */ |
| 6874 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + extra; |
| 6875 | phba->cfg_scsi_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6876 | |
| 6877 | /* |
| 6878 | * NOTE: if (phba->cfg_sg_seg_cnt + extra) <= 256 we only |
| 6879 | * need to post 1 page for the SGL. |
| 6880 | */ |
| 6881 | } |
| 6882 | |
| 6883 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 6884 | phba->cfg_sg_dma_buf_size = LPFC_DEFAULT_XPSGL_SIZE; |
| 6885 | else if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) |
| 6886 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; |
| 6887 | else |
| 6888 | phba->cfg_sg_dma_buf_size = |
| 6889 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); |
| 6890 | |
| 6891 | phba->border_sge_num = phba->cfg_sg_dma_buf_size / |
| 6892 | sizeof(struct sli4_sge); |
| 6893 | |
| 6894 | /* Limit to LPFC_MAX_NVME_SEG_CNT for NVME. */ |
| 6895 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 6896 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_NVME_SEG_CNT) { |
| 6897 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME | LOG_INIT, |
| 6898 | "6300 Reducing NVME sg segment " |
| 6899 | "cnt to %d\n", |
| 6900 | LPFC_MAX_NVME_SEG_CNT); |
| 6901 | phba->cfg_nvme_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
| 6902 | } else |
| 6903 | phba->cfg_nvme_seg_cnt = phba->cfg_sg_seg_cnt; |
| 6904 | } |
| 6905 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6906 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
| 6907 | "9087 sg_seg_cnt:%d dmabuf_size:%d " |
| 6908 | "total:%d scsi:%d nvme:%d\n", |
| 6909 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, |
| 6910 | phba->cfg_total_seg_cnt, phba->cfg_scsi_seg_cnt, |
| 6911 | phba->cfg_nvme_seg_cnt); |
| 6912 | |
| 6913 | if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE) |
| 6914 | i = phba->cfg_sg_dma_buf_size; |
| 6915 | else |
| 6916 | i = SLI4_PAGE_SIZE; |
| 6917 | |
| 6918 | phba->lpfc_sg_dma_buf_pool = |
| 6919 | dma_pool_create("lpfc_sg_dma_buf_pool", |
| 6920 | &phba->pcidev->dev, |
| 6921 | phba->cfg_sg_dma_buf_size, |
| 6922 | i, 0); |
| 6923 | if (!phba->lpfc_sg_dma_buf_pool) |
| 6924 | goto out_free_bsmbx; |
| 6925 | |
| 6926 | phba->lpfc_cmd_rsp_buf_pool = |
| 6927 | dma_pool_create("lpfc_cmd_rsp_buf_pool", |
| 6928 | &phba->pcidev->dev, |
| 6929 | sizeof(struct fcp_cmnd) + |
| 6930 | sizeof(struct fcp_rsp), |
| 6931 | i, 0); |
| 6932 | if (!phba->lpfc_cmd_rsp_buf_pool) |
| 6933 | goto out_free_sg_dma_buf; |
| 6934 | |
James Smart | cb5172e | 2010-03-15 11:25:07 -0400 | [diff] [blame] | 6935 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6936 | |
| 6937 | /* Verify OAS is supported */ |
| 6938 | lpfc_sli4_oas_verify(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 6939 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 6940 | /* Verify RAS support on adapter */ |
| 6941 | lpfc_sli4_ras_init(phba); |
| 6942 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 6943 | /* Verify all the SLI4 queues */ |
| 6944 | rc = lpfc_sli4_queue_verify(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6945 | if (rc) |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6946 | goto out_free_cmd_rsp_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6947 | |
| 6948 | /* Create driver internal CQE event pool */ |
| 6949 | rc = lpfc_sli4_cq_event_pool_create(phba); |
| 6950 | if (rc) |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 6951 | goto out_free_cmd_rsp_buf; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6952 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6953 | /* Initialize sgl lists per host */ |
| 6954 | lpfc_init_sgl_list(phba); |
| 6955 | |
| 6956 | /* Allocate and initialize active sgl array */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6957 | rc = lpfc_init_active_sgl_array(phba); |
| 6958 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6959 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6960 | "1430 Failed to initialize sgl list.\n"); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 6961 | goto out_destroy_cq_event_pool; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6962 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6963 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
| 6964 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6965 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6966 | "1432 Failed to initialize rpi headers.\n"); |
| 6967 | goto out_free_active_sgl; |
| 6968 | } |
| 6969 | |
James Smart | a93ff37 | 2010-10-22 11:06:08 -0400 | [diff] [blame] | 6970 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6971 | 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] | 6972 | phba->fcf.fcf_rr_bmask = kcalloc(longs, sizeof(unsigned long), |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6973 | GFP_KERNEL); |
| 6974 | if (!phba->fcf.fcf_rr_bmask) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6975 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6976 | "2759 Failed allocate memory for FCF round " |
| 6977 | "robin failover bmask\n"); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 6978 | rc = -ENOMEM; |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 6979 | goto out_remove_rpi_hdrs; |
| 6980 | } |
| 6981 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 6982 | phba->sli4_hba.hba_eq_hdl = kcalloc(phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 6983 | sizeof(struct lpfc_hba_eq_hdl), |
| 6984 | GFP_KERNEL); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6985 | if (!phba->sli4_hba.hba_eq_hdl) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6986 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 6987 | "2572 Failed allocate memory for " |
| 6988 | "fast-path per-EQ handle array\n"); |
| 6989 | rc = -ENOMEM; |
| 6990 | goto out_free_fcf_rr_bmask; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 6991 | } |
| 6992 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 6993 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_possible_cpu, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 6994 | sizeof(struct lpfc_vector_map_info), |
| 6995 | GFP_KERNEL); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6996 | if (!phba->sli4_hba.cpu_map) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 6997 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 6998 | "3327 Failed allocate memory for msi-x " |
| 6999 | "interrupt vector mapping\n"); |
| 7000 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7001 | goto out_free_hba_eq_hdl; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7002 | } |
James Smart | b246de1 | 2013-05-31 17:03:07 -0400 | [diff] [blame] | 7003 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7004 | phba->sli4_hba.eq_info = alloc_percpu(struct lpfc_eq_intr_info); |
| 7005 | if (!phba->sli4_hba.eq_info) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7006 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7007 | "3321 Failed allocation for per_cpu stats\n"); |
| 7008 | rc = -ENOMEM; |
| 7009 | goto out_free_hba_cpu_map; |
| 7010 | } |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7011 | |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7012 | phba->sli4_hba.idle_stat = kcalloc(phba->sli4_hba.num_possible_cpu, |
| 7013 | sizeof(*phba->sli4_hba.idle_stat), |
| 7014 | GFP_KERNEL); |
| 7015 | if (!phba->sli4_hba.idle_stat) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7016 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7017 | "3390 Failed allocation for idle_stat\n"); |
| 7018 | rc = -ENOMEM; |
| 7019 | goto out_free_hba_eq_info; |
| 7020 | } |
| 7021 | |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7022 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 7023 | phba->sli4_hba.c_stat = alloc_percpu(struct lpfc_hdwq_stat); |
| 7024 | if (!phba->sli4_hba.c_stat) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7025 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7026 | "3332 Failed allocating per cpu hdwq stats\n"); |
| 7027 | rc = -ENOMEM; |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7028 | goto out_free_hba_idle_stat; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7029 | } |
| 7030 | #endif |
| 7031 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 7032 | /* |
| 7033 | * Enable sr-iov virtual functions if supported and configured |
| 7034 | * through the module parameter. |
| 7035 | */ |
| 7036 | if (phba->cfg_sriov_nr_virtfn > 0) { |
| 7037 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, |
| 7038 | phba->cfg_sriov_nr_virtfn); |
| 7039 | if (rc) { |
| 7040 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 7041 | "3020 Requested number of SR-IOV " |
| 7042 | "virtual functions (%d) is not " |
| 7043 | "supported\n", |
| 7044 | phba->cfg_sriov_nr_virtfn); |
| 7045 | phba->cfg_sriov_nr_virtfn = 0; |
| 7046 | } |
| 7047 | } |
| 7048 | |
James Smart | 5248a74 | 2011-07-22 18:37:06 -0400 | [diff] [blame] | 7049 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7050 | |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7051 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7052 | out_free_hba_idle_stat: |
| 7053 | kfree(phba->sli4_hba.idle_stat); |
| 7054 | #endif |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7055 | out_free_hba_eq_info: |
| 7056 | free_percpu(phba->sli4_hba.eq_info); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7057 | out_free_hba_cpu_map: |
| 7058 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7059 | out_free_hba_eq_hdl: |
| 7060 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7061 | out_free_fcf_rr_bmask: |
| 7062 | kfree(phba->fcf.fcf_rr_bmask); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7063 | out_remove_rpi_hdrs: |
| 7064 | lpfc_sli4_remove_rpi_hdrs(phba); |
| 7065 | out_free_active_sgl: |
| 7066 | lpfc_free_active_sgl(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7067 | out_destroy_cq_event_pool: |
| 7068 | lpfc_sli4_cq_event_pool_destroy(phba); |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 7069 | out_free_cmd_rsp_buf: |
| 7070 | dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool); |
| 7071 | phba->lpfc_cmd_rsp_buf_pool = NULL; |
| 7072 | out_free_sg_dma_buf: |
| 7073 | dma_pool_destroy(phba->lpfc_sg_dma_buf_pool); |
| 7074 | phba->lpfc_sg_dma_buf_pool = NULL; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7075 | out_free_bsmbx: |
| 7076 | lpfc_destroy_bootstrap_mbox(phba); |
| 7077 | out_free_mem: |
| 7078 | lpfc_mem_free(phba); |
| 7079 | return rc; |
| 7080 | } |
| 7081 | |
| 7082 | /** |
| 7083 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev |
| 7084 | * @phba: pointer to lpfc hba data structure. |
| 7085 | * |
| 7086 | * This routine is invoked to unset the driver internal resources set up |
| 7087 | * specific for supporting the SLI-4 HBA device it attached to. |
| 7088 | **/ |
| 7089 | static void |
| 7090 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) |
| 7091 | { |
| 7092 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; |
| 7093 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7094 | free_percpu(phba->sli4_hba.eq_info); |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 7095 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 7096 | free_percpu(phba->sli4_hba.c_stat); |
| 7097 | #endif |
Dick Kennedy | 317aeb8 | 2020-06-30 14:49:59 -0700 | [diff] [blame] | 7098 | kfree(phba->sli4_hba.idle_stat); |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 7099 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7100 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
| 7101 | kfree(phba->sli4_hba.cpu_map); |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 7102 | phba->sli4_hba.num_possible_cpu = 0; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7103 | phba->sli4_hba.num_present_cpu = 0; |
James Smart | 76fd07a | 2014-02-20 09:57:18 -0500 | [diff] [blame] | 7104 | phba->sli4_hba.curr_disp_cpu = 0; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 7105 | cpumask_clear(&phba->sli4_hba.irq_aff_mask); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 7106 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7107 | /* Free memory allocated for fast-path work queue handles */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7108 | kfree(phba->sli4_hba.hba_eq_hdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7109 | |
| 7110 | /* Free the allocated rpi headers. */ |
| 7111 | lpfc_sli4_remove_rpi_hdrs(phba); |
James Smart | d11e31d | 2009-06-10 17:23:06 -0400 | [diff] [blame] | 7112 | lpfc_sli4_remove_rpis(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7113 | |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 7114 | /* Free eligible FCF index bmask */ |
| 7115 | kfree(phba->fcf.fcf_rr_bmask); |
| 7116 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7117 | /* Free the ELS sgl list */ |
| 7118 | lpfc_free_active_sgl(phba); |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7119 | lpfc_free_els_sgl_list(phba); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7120 | lpfc_free_nvmet_sgl_list(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7121 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7122 | /* Free the completion queue EQ event pool */ |
| 7123 | lpfc_sli4_cq_event_release_all(phba); |
| 7124 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 7125 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7126 | /* Release resource identifiers. */ |
| 7127 | lpfc_sli4_dealloc_resource_identifiers(phba); |
| 7128 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7129 | /* Free the bsmbx region. */ |
| 7130 | lpfc_destroy_bootstrap_mbox(phba); |
| 7131 | |
| 7132 | /* Free the SLI Layer memory with SLI4 HBAs */ |
| 7133 | lpfc_mem_free_all(phba); |
| 7134 | |
| 7135 | /* Free the current connect table */ |
| 7136 | list_for_each_entry_safe(conn_entry, next_conn_entry, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7137 | &phba->fcf_conn_rec_list, list) { |
| 7138 | list_del_init(&conn_entry->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7139 | kfree(conn_entry); |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 7140 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7141 | |
| 7142 | return; |
| 7143 | } |
| 7144 | |
| 7145 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 7146 | * lpfc_init_api_table_setup - Set up init api function jump table |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7147 | * @phba: The hba struct for which this call is being executed. |
| 7148 | * @dev_grp: The HBA PCI-Device group number. |
| 7149 | * |
| 7150 | * This routine sets up the device INIT interface API function jump table |
| 7151 | * in @phba struct. |
| 7152 | * |
| 7153 | * Returns: 0 - success, -ENODEV - failure. |
| 7154 | **/ |
| 7155 | int |
| 7156 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) |
| 7157 | { |
James Smart | 84d1b00 | 2010-02-12 14:42:33 -0500 | [diff] [blame] | 7158 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
| 7159 | phba->lpfc_hba_down_link = lpfc_hba_down_link; |
James Smart | 7f86059 | 2011-03-11 16:05:52 -0500 | [diff] [blame] | 7160 | phba->lpfc_selective_reset = lpfc_selective_reset; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7161 | switch (dev_grp) { |
| 7162 | case LPFC_PCI_DEV_LP: |
| 7163 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; |
| 7164 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; |
| 7165 | phba->lpfc_stop_port = lpfc_stop_port_s3; |
| 7166 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7167 | case LPFC_PCI_DEV_OC: |
| 7168 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; |
| 7169 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; |
| 7170 | phba->lpfc_stop_port = lpfc_stop_port_s4; |
| 7171 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7172 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7173 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7174 | "1431 Invalid HBA PCI-device group: 0x%x\n", |
| 7175 | dev_grp); |
| 7176 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7177 | } |
| 7178 | return 0; |
| 7179 | } |
| 7180 | |
| 7181 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7182 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. |
| 7183 | * @phba: pointer to lpfc hba data structure. |
| 7184 | * |
| 7185 | * This routine is invoked to set up the driver internal resources after the |
| 7186 | * device specific resource setup to support the HBA device it attached to. |
| 7187 | * |
| 7188 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7189 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7190 | * other values - error |
| 7191 | **/ |
| 7192 | static int |
| 7193 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) |
| 7194 | { |
| 7195 | int error; |
| 7196 | |
| 7197 | /* Startup the kernel thread for this host adapter. */ |
| 7198 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 7199 | "lpfc_worker_%d", phba->brd_no); |
| 7200 | if (IS_ERR(phba->worker_thread)) { |
| 7201 | error = PTR_ERR(phba->worker_thread); |
| 7202 | return error; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7203 | } |
| 7204 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7205 | return 0; |
| 7206 | } |
| 7207 | |
| 7208 | /** |
| 7209 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. |
| 7210 | * @phba: pointer to lpfc hba data structure. |
| 7211 | * |
| 7212 | * This routine is invoked to unset the driver internal resources set up after |
| 7213 | * the device specific resource setup for supporting the HBA device it |
| 7214 | * attached to. |
| 7215 | **/ |
| 7216 | static void |
| 7217 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) |
| 7218 | { |
Dick Kennedy | f485c18 | 2017-09-29 17:34:34 -0700 | [diff] [blame] | 7219 | if (phba->wq) { |
| 7220 | flush_workqueue(phba->wq); |
| 7221 | destroy_workqueue(phba->wq); |
| 7222 | phba->wq = NULL; |
| 7223 | } |
| 7224 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7225 | /* Stop kernel worker thread */ |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 7226 | if (phba->worker_thread) |
| 7227 | kthread_stop(phba->worker_thread); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7228 | } |
| 7229 | |
| 7230 | /** |
| 7231 | * lpfc_free_iocb_list - Free iocb list. |
| 7232 | * @phba: pointer to lpfc hba data structure. |
| 7233 | * |
| 7234 | * This routine is invoked to free the driver's IOCB list and memory. |
| 7235 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7236 | void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7237 | lpfc_free_iocb_list(struct lpfc_hba *phba) |
| 7238 | { |
| 7239 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
| 7240 | |
| 7241 | spin_lock_irq(&phba->hbalock); |
| 7242 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 7243 | &phba->lpfc_iocb_list, list) { |
| 7244 | list_del(&iocbq_entry->list); |
| 7245 | kfree(iocbq_entry); |
| 7246 | phba->total_iocbq_bufs--; |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7247 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7248 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7249 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7250 | return; |
| 7251 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7252 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7253 | /** |
| 7254 | * lpfc_init_iocb_list - Allocate and initialize iocb list. |
| 7255 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 7256 | * @iocb_count: number of requested iocbs |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7257 | * |
| 7258 | * This routine is invoked to allocate and initizlize the driver's IOCB |
| 7259 | * list and set up the IOCB tag array accordingly. |
| 7260 | * |
| 7261 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7262 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7263 | * other values - error |
| 7264 | **/ |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 7265 | int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7266 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) |
| 7267 | { |
| 7268 | struct lpfc_iocbq *iocbq_entry = NULL; |
| 7269 | uint16_t iotag; |
| 7270 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7271 | |
| 7272 | /* Initialize and populate the iocb list per host. */ |
| 7273 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7274 | for (i = 0; i < iocb_count; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 7275 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7276 | if (iocbq_entry == NULL) { |
| 7277 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 7278 | "expected %d count. Unloading driver.\n", |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 7279 | __func__, i, iocb_count); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7280 | goto out_free_iocbq; |
| 7281 | } |
| 7282 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7283 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 7284 | if (iotag == 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7285 | kfree(iocbq_entry); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7286 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7287 | "Unloading driver.\n", __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 7288 | goto out_free_iocbq; |
| 7289 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7290 | iocbq_entry->sli4_lxritag = NO_XRI; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7291 | iocbq_entry->sli4_xritag = NO_XRI; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7292 | |
| 7293 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7294 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 7295 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7296 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7297 | } |
| 7298 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7299 | return 0; |
| 7300 | |
| 7301 | out_free_iocbq: |
| 7302 | lpfc_free_iocb_list(phba); |
| 7303 | |
| 7304 | return -ENOMEM; |
| 7305 | } |
| 7306 | |
| 7307 | /** |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7308 | * lpfc_free_sgl_list - Free a given sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7309 | * @phba: pointer to lpfc hba data structure. |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7310 | * @sglq_list: pointer to the head of sgl list. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7311 | * |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7312 | * This routine is invoked to free a give sgl list and memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7313 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7314 | void |
| 7315 | 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] | 7316 | { |
| 7317 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7318 | |
| 7319 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { |
| 7320 | list_del(&sglq_entry->list); |
| 7321 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7322 | kfree(sglq_entry); |
| 7323 | } |
| 7324 | } |
| 7325 | |
| 7326 | /** |
| 7327 | * lpfc_free_els_sgl_list - Free els sgl list. |
| 7328 | * @phba: pointer to lpfc hba data structure. |
| 7329 | * |
| 7330 | * This routine is invoked to free the driver's els sgl list and memory. |
| 7331 | **/ |
| 7332 | static void |
| 7333 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) |
| 7334 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7335 | LIST_HEAD(sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7336 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7337 | /* Retrieve all els sgls from driver list */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7338 | spin_lock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7339 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7340 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); |
| 7341 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7342 | spin_unlock_irq(&phba->hbalock); |
| 7343 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7344 | /* Now free the sgl list */ |
| 7345 | lpfc_free_sgl_list(phba, &sglq_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7346 | } |
| 7347 | |
| 7348 | /** |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7349 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. |
| 7350 | * @phba: pointer to lpfc hba data structure. |
| 7351 | * |
| 7352 | * This routine is invoked to free the driver's nvmet sgl list and memory. |
| 7353 | **/ |
| 7354 | static void |
| 7355 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) |
| 7356 | { |
| 7357 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
| 7358 | LIST_HEAD(sglq_list); |
| 7359 | |
| 7360 | /* Retrieve all nvmet sgls from driver list */ |
| 7361 | spin_lock_irq(&phba->hbalock); |
| 7362 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
| 7363 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); |
| 7364 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
| 7365 | spin_unlock_irq(&phba->hbalock); |
| 7366 | |
| 7367 | /* Now free the sgl list */ |
| 7368 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { |
| 7369 | list_del(&sglq_entry->list); |
| 7370 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); |
| 7371 | kfree(sglq_entry); |
| 7372 | } |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 7373 | |
| 7374 | /* Update the nvmet_xri_cnt to reflect no current sgls. |
| 7375 | * The next initialization cycle sets the count and allocates |
| 7376 | * the sgls over again. |
| 7377 | */ |
| 7378 | phba->sli4_hba.nvmet_xri_cnt = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7379 | } |
| 7380 | |
| 7381 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7382 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. |
| 7383 | * @phba: pointer to lpfc hba data structure. |
| 7384 | * |
| 7385 | * This routine is invoked to allocate the driver's active sgl memory. |
| 7386 | * This array will hold the sglq_entry's for active IOs. |
| 7387 | **/ |
| 7388 | static int |
| 7389 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) |
| 7390 | { |
| 7391 | int size; |
| 7392 | size = sizeof(struct lpfc_sglq *); |
| 7393 | size *= phba->sli4_hba.max_cfg_param.max_xri; |
| 7394 | |
| 7395 | phba->sli4_hba.lpfc_sglq_active_list = |
| 7396 | kzalloc(size, GFP_KERNEL); |
| 7397 | if (!phba->sli4_hba.lpfc_sglq_active_list) |
| 7398 | return -ENOMEM; |
| 7399 | return 0; |
| 7400 | } |
| 7401 | |
| 7402 | /** |
| 7403 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
| 7404 | * @phba: pointer to lpfc hba data structure. |
| 7405 | * |
| 7406 | * This routine is invoked to walk through the array of active sglq entries |
| 7407 | * and free all of the resources. |
| 7408 | * This is just a place holder for now. |
| 7409 | **/ |
| 7410 | static void |
| 7411 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
| 7412 | { |
| 7413 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
| 7414 | } |
| 7415 | |
| 7416 | /** |
| 7417 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
| 7418 | * @phba: pointer to lpfc hba data structure. |
| 7419 | * |
| 7420 | * This routine is invoked to allocate and initizlize the driver's sgl |
| 7421 | * list and set up the sgl xritag tag array accordingly. |
| 7422 | * |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7423 | **/ |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7424 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7425 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
| 7426 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7427 | /* Initialize and populate the sglq list per host/VF. */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7428 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7429 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7430 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 7431 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7432 | |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 7433 | /* els xri-sgl book keeping */ |
| 7434 | phba->sli4_hba.els_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7435 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7436 | /* nvme xri-buffer book keeping */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7437 | phba->sli4_hba.io_xri_cnt = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7438 | } |
| 7439 | |
| 7440 | /** |
| 7441 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port |
| 7442 | * @phba: pointer to lpfc hba data structure. |
| 7443 | * |
| 7444 | * This routine is invoked to post rpi header templates to the |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7445 | * port for those SLI4 ports that do not support extents. This routine |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7446 | * 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] | 7447 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
| 7448 | * and should be called only when interrupts are disabled. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7449 | * |
| 7450 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7451 | * 0 - successful |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 7452 | * -ERROR - otherwise. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7453 | **/ |
| 7454 | int |
| 7455 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) |
| 7456 | { |
| 7457 | int rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7458 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7459 | |
| 7460 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 7461 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7462 | return rc; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7463 | if (phba->sli4_hba.extents_in_use) |
| 7464 | return -EIO; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7465 | |
| 7466 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); |
| 7467 | if (!rpi_hdr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7468 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7469 | "0391 Error during rpi post operation\n"); |
| 7470 | lpfc_sli4_remove_rpis(phba); |
| 7471 | rc = -ENODEV; |
| 7472 | } |
| 7473 | |
| 7474 | return rc; |
| 7475 | } |
| 7476 | |
| 7477 | /** |
| 7478 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region |
| 7479 | * @phba: pointer to lpfc hba data structure. |
| 7480 | * |
| 7481 | * This routine is invoked to allocate a single 4KB memory region to |
| 7482 | * support rpis and stores them in the phba. This single region |
| 7483 | * provides support for up to 64 rpis. The region is used globally |
| 7484 | * by the device. |
| 7485 | * |
| 7486 | * Returns: |
| 7487 | * A valid rpi hdr on success. |
| 7488 | * A NULL pointer on any failure. |
| 7489 | **/ |
| 7490 | struct lpfc_rpi_hdr * |
| 7491 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) |
| 7492 | { |
| 7493 | uint16_t rpi_limit, curr_rpi_range; |
| 7494 | struct lpfc_dmabuf *dmabuf; |
| 7495 | struct lpfc_rpi_hdr *rpi_hdr; |
| 7496 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7497 | /* |
| 7498 | * If the SLI4 port supports extents, posting the rpi header isn't |
| 7499 | * required. Set the expected maximum count and let the actual value |
| 7500 | * get set when extents are fully allocated. |
| 7501 | */ |
| 7502 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7503 | return NULL; |
| 7504 | if (phba->sli4_hba.extents_in_use) |
| 7505 | return NULL; |
| 7506 | |
| 7507 | /* The limit on the logical index is just the max_rpi count. */ |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7508 | rpi_limit = phba->sli4_hba.max_cfg_param.max_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7509 | |
| 7510 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7511 | /* |
| 7512 | * Establish the starting RPI in this header block. The starting |
| 7513 | * rpi is normalized to a zero base because the physical rpi is |
| 7514 | * port based. |
| 7515 | */ |
James Smart | 97f2ecf | 2012-03-01 22:35:23 -0500 | [diff] [blame] | 7516 | curr_rpi_range = phba->sli4_hba.next_rpi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7517 | spin_unlock_irq(&phba->hbalock); |
| 7518 | |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7519 | /* Reached full RPI range */ |
| 7520 | if (curr_rpi_range == rpi_limit) |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7521 | return NULL; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7522 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7523 | /* |
| 7524 | * First allocate the protocol header region for the port. The |
| 7525 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. |
| 7526 | */ |
| 7527 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 7528 | if (!dmabuf) |
| 7529 | return NULL; |
| 7530 | |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7531 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 7532 | LPFC_HDR_TEMPLATE_SIZE, |
| 7533 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7534 | if (!dmabuf->virt) { |
| 7535 | rpi_hdr = NULL; |
| 7536 | goto err_free_dmabuf; |
| 7537 | } |
| 7538 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7539 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
| 7540 | rpi_hdr = NULL; |
| 7541 | goto err_free_coherent; |
| 7542 | } |
| 7543 | |
| 7544 | /* Save the rpi header data for cleanup later. */ |
| 7545 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); |
| 7546 | if (!rpi_hdr) |
| 7547 | goto err_free_coherent; |
| 7548 | |
| 7549 | rpi_hdr->dmabuf = dmabuf; |
| 7550 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; |
| 7551 | rpi_hdr->page_count = 1; |
| 7552 | spin_lock_irq(&phba->hbalock); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7553 | |
| 7554 | /* The rpi_hdr stores the logical index only. */ |
| 7555 | rpi_hdr->start_rpi = curr_rpi_range; |
James Smart | 845d9e8 | 2017-05-15 15:20:38 -0700 | [diff] [blame] | 7556 | 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] | 7557 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
| 7558 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7559 | spin_unlock_irq(&phba->hbalock); |
| 7560 | return rpi_hdr; |
| 7561 | |
| 7562 | err_free_coherent: |
| 7563 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, |
| 7564 | dmabuf->virt, dmabuf->phys); |
| 7565 | err_free_dmabuf: |
| 7566 | kfree(dmabuf); |
| 7567 | return NULL; |
| 7568 | } |
| 7569 | |
| 7570 | /** |
| 7571 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions |
| 7572 | * @phba: pointer to lpfc hba data structure. |
| 7573 | * |
| 7574 | * This routine is invoked to remove all memory resources allocated |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7575 | * to support rpis for SLI4 ports not supporting extents. This routine |
| 7576 | * presumes the caller has released all rpis consumed by fabric or port |
| 7577 | * logins and is prepared to have the header pages removed. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7578 | **/ |
| 7579 | void |
| 7580 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) |
| 7581 | { |
| 7582 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; |
| 7583 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7584 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
| 7585 | goto exit; |
| 7586 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7587 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
| 7588 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { |
| 7589 | list_del(&rpi_hdr->list); |
| 7590 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, |
| 7591 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); |
| 7592 | kfree(rpi_hdr->dmabuf); |
| 7593 | kfree(rpi_hdr); |
| 7594 | } |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 7595 | exit: |
| 7596 | /* There are no rpis available to the port now. */ |
| 7597 | phba->sli4_hba.next_rpi = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7598 | } |
| 7599 | |
| 7600 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7601 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. |
| 7602 | * @pdev: pointer to pci device data structure. |
| 7603 | * |
| 7604 | * This routine is invoked to allocate the driver hba data structure for an |
| 7605 | * HBA device. If the allocation is successful, the phba reference to the |
| 7606 | * PCI device data structure is set. |
| 7607 | * |
| 7608 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7609 | * pointer to @phba - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7610 | * NULL - error |
| 7611 | **/ |
| 7612 | static struct lpfc_hba * |
| 7613 | lpfc_hba_alloc(struct pci_dev *pdev) |
| 7614 | { |
| 7615 | struct lpfc_hba *phba; |
| 7616 | |
| 7617 | /* Allocate memory for HBA structure */ |
| 7618 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); |
| 7619 | if (!phba) { |
Jiri Slaby | e34ccdf | 2009-07-13 23:25:54 +0200 | [diff] [blame] | 7620 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7621 | return NULL; |
| 7622 | } |
| 7623 | |
| 7624 | /* Set reference to PCI device in HBA structure */ |
| 7625 | phba->pcidev = pdev; |
| 7626 | |
| 7627 | /* Assign an unused board number */ |
| 7628 | phba->brd_no = lpfc_get_instance(); |
| 7629 | if (phba->brd_no < 0) { |
| 7630 | kfree(phba); |
| 7631 | return NULL; |
| 7632 | } |
James Smart | 65791f1 | 2016-07-06 12:35:56 -0700 | [diff] [blame] | 7633 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7634 | |
James Smart | 4fede78 | 2010-01-26 23:08:55 -0500 | [diff] [blame] | 7635 | spin_lock_init(&phba->ct_ev_lock); |
James Smart | f1c3b0f | 2009-07-19 10:01:32 -0400 | [diff] [blame] | 7636 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
| 7637 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7638 | return phba; |
| 7639 | } |
| 7640 | |
| 7641 | /** |
| 7642 | * lpfc_hba_free - Free driver hba data structure with a device. |
| 7643 | * @phba: pointer to lpfc hba data structure. |
| 7644 | * |
| 7645 | * This routine is invoked to free the driver hba data structure with an |
| 7646 | * HBA device. |
| 7647 | **/ |
| 7648 | static void |
| 7649 | lpfc_hba_free(struct lpfc_hba *phba) |
| 7650 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 7651 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 7652 | kfree(phba->sli4_hba.hdwq); |
| 7653 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7654 | /* Release the driver assigned board number */ |
| 7655 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 7656 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 7657 | /* Free memory allocated with sli3 rings */ |
| 7658 | kfree(phba->sli.sli3_ring); |
| 7659 | phba->sli.sli3_ring = NULL; |
James Smart | 2a76a28 | 2012-08-03 12:35:54 -0400 | [diff] [blame] | 7660 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7661 | kfree(phba); |
| 7662 | return; |
| 7663 | } |
| 7664 | |
| 7665 | /** |
| 7666 | * lpfc_create_shost - Create hba physical port with associated scsi host. |
| 7667 | * @phba: pointer to lpfc hba data structure. |
| 7668 | * |
| 7669 | * This routine is invoked to create HBA physical port and associate a SCSI |
| 7670 | * host with it. |
| 7671 | * |
| 7672 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7673 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7674 | * other values - error |
| 7675 | **/ |
| 7676 | static int |
| 7677 | lpfc_create_shost(struct lpfc_hba *phba) |
| 7678 | { |
| 7679 | struct lpfc_vport *vport; |
| 7680 | struct Scsi_Host *shost; |
| 7681 | |
| 7682 | /* Initialize HBA FC structure */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7683 | phba->fc_edtov = FF_DEF_EDTOV; |
| 7684 | phba->fc_ratov = FF_DEF_RATOV; |
| 7685 | phba->fc_altov = FF_DEF_ALTOV; |
| 7686 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 7687 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 7688 | atomic_set(&phba->sdev_cnt, 0); |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 7689 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7690 | if (!vport) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7691 | return -ENODEV; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7692 | |
| 7693 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7694 | phba->pport = vport; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 7695 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7696 | if (phba->nvmet_support) { |
| 7697 | /* Only 1 vport (pport) will support NVME target */ |
James Smart | ea85a20 | 2019-10-18 14:18:25 -0700 | [diff] [blame] | 7698 | phba->targetport = NULL; |
| 7699 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; |
| 7700 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME_DISC, |
| 7701 | "6076 NVME Target Found\n"); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 7702 | } |
| 7703 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7704 | lpfc_debugfs_initialize(vport); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7705 | /* Put reference to SCSI host to driver's device private data */ |
| 7706 | pci_set_drvdata(phba->pcidev, shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7707 | |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7708 | /* |
| 7709 | * At this point we are fully registered with PSA. In addition, |
| 7710 | * any initial discovery should be completed. |
| 7711 | */ |
| 7712 | vport->load_flag |= FC_ALLOW_FDMI; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7713 | if (phba->cfg_enable_SmartSAN || |
| 7714 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7715 | |
| 7716 | /* Setup appropriate attribute masks */ |
| 7717 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; |
James Smart | 8663cbb | 2016-03-31 14:12:33 -0700 | [diff] [blame] | 7718 | if (phba->cfg_enable_SmartSAN) |
James Smart | 4258e98 | 2015-12-16 18:11:58 -0500 | [diff] [blame] | 7719 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
| 7720 | else |
| 7721 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; |
| 7722 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7723 | return 0; |
| 7724 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7725 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7726 | /** |
| 7727 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. |
| 7728 | * @phba: pointer to lpfc hba data structure. |
| 7729 | * |
| 7730 | * This routine is invoked to destroy HBA physical port and the associated |
| 7731 | * SCSI host. |
| 7732 | **/ |
| 7733 | static void |
| 7734 | lpfc_destroy_shost(struct lpfc_hba *phba) |
| 7735 | { |
| 7736 | struct lpfc_vport *vport = phba->pport; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7737 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7738 | /* Destroy physical port that associated with the SCSI host */ |
| 7739 | destroy_port(vport); |
| 7740 | |
| 7741 | return; |
| 7742 | } |
| 7743 | |
| 7744 | /** |
| 7745 | * lpfc_setup_bg - Setup Block guard structures and debug areas. |
| 7746 | * @phba: pointer to lpfc hba data structure. |
| 7747 | * @shost: the shost to be used to detect Block guard settings. |
| 7748 | * |
| 7749 | * This routine sets up the local Block guard protocol settings for @shost. |
| 7750 | * This routine also allocates memory for debugging bg buffers. |
| 7751 | **/ |
| 7752 | static void |
| 7753 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) |
| 7754 | { |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7755 | uint32_t old_mask; |
| 7756 | uint32_t old_guard; |
| 7757 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7758 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7759 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7760 | "1478 Registering BlockGuard with the " |
| 7761 | "SCSI layer\n"); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7762 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7763 | old_mask = phba->cfg_prot_mask; |
| 7764 | old_guard = phba->cfg_prot_guard; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7765 | |
| 7766 | /* Only allow supported values */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7767 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7768 | SHOST_DIX_TYPE0_PROTECTION | |
| 7769 | SHOST_DIX_TYPE1_PROTECTION); |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7770 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
| 7771 | SHOST_DIX_GUARD_CRC); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7772 | |
| 7773 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7774 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
| 7775 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7776 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7777 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
| 7778 | if ((old_mask != phba->cfg_prot_mask) || |
| 7779 | (old_guard != phba->cfg_prot_guard)) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7780 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7781 | "1475 Registering BlockGuard with the " |
| 7782 | "SCSI layer: mask %d guard %d\n", |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7783 | phba->cfg_prot_mask, |
| 7784 | phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7785 | |
James Smart | b3b98b7 | 2016-10-13 15:06:06 -0700 | [diff] [blame] | 7786 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
| 7787 | scsi_host_set_guard(shost, phba->cfg_prot_guard); |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7788 | } else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 7789 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | bbeb79b | 2012-06-12 13:54:27 -0400 | [diff] [blame] | 7790 | "1479 Not Registering BlockGuard with the SCSI " |
| 7791 | "layer, Bad protection parameters: %d %d\n", |
| 7792 | old_mask, old_guard); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 7793 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7794 | } |
| 7795 | |
| 7796 | /** |
| 7797 | * lpfc_post_init_setup - Perform necessary device post initialization setup. |
| 7798 | * @phba: pointer to lpfc hba data structure. |
| 7799 | * |
| 7800 | * This routine is invoked to perform all the necessary post initialization |
| 7801 | * setup for the device. |
| 7802 | **/ |
| 7803 | static void |
| 7804 | lpfc_post_init_setup(struct lpfc_hba *phba) |
| 7805 | { |
| 7806 | struct Scsi_Host *shost; |
| 7807 | struct lpfc_adapter_event_header adapter_event; |
| 7808 | |
| 7809 | /* Get the default values for Model Name and Description */ |
| 7810 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 7811 | |
| 7812 | /* |
| 7813 | * hba setup may have changed the hba_queue_depth so we need to |
| 7814 | * adjust the value of can_queue. |
| 7815 | */ |
| 7816 | shost = pci_get_drvdata(phba->pcidev); |
| 7817 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 7818 | |
| 7819 | lpfc_host_attrib_init(shost); |
| 7820 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 7821 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 7822 | spin_lock_irq(shost->host_lock); |
| 7823 | lpfc_poll_start_timer(phba); |
| 7824 | spin_unlock_irq(shost->host_lock); |
| 7825 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 7826 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 7827 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 7828 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7829 | /* Send board arrival event to upper layer */ |
| 7830 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 7831 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 7832 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7833 | sizeof(adapter_event), |
| 7834 | (char *) &adapter_event, |
| 7835 | LPFC_NL_VENDOR_ID); |
| 7836 | return; |
| 7837 | } |
| 7838 | |
| 7839 | /** |
| 7840 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. |
| 7841 | * @phba: pointer to lpfc hba data structure. |
| 7842 | * |
| 7843 | * This routine is invoked to set up the PCI device memory space for device |
| 7844 | * with SLI-3 interface spec. |
| 7845 | * |
| 7846 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 7847 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7848 | * other values - error |
| 7849 | **/ |
| 7850 | static int |
| 7851 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) |
| 7852 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7853 | struct pci_dev *pdev = phba->pcidev; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7854 | unsigned long bar0map_len, bar2map_len; |
| 7855 | int i, hbq_count; |
| 7856 | void *ptr; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7857 | int error; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7858 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7859 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7860 | return -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7861 | |
| 7862 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7863 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 7864 | if (error) |
| 7865 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 7866 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 7867 | return error; |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 7868 | error = -ENODEV; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7869 | |
| 7870 | /* Get the bus address of Bar0 and Bar2 and the number of bytes |
| 7871 | * required by each mapping. |
| 7872 | */ |
| 7873 | phba->pci_bar0_map = pci_resource_start(pdev, 0); |
| 7874 | bar0map_len = pci_resource_len(pdev, 0); |
| 7875 | |
| 7876 | phba->pci_bar2_map = pci_resource_start(pdev, 2); |
| 7877 | bar2map_len = pci_resource_len(pdev, 2); |
| 7878 | |
| 7879 | /* Map HBA SLIM to a kernel virtual address. */ |
| 7880 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
| 7881 | if (!phba->slim_memmap_p) { |
| 7882 | dev_printk(KERN_ERR, &pdev->dev, |
| 7883 | "ioremap failed for SLIM memory.\n"); |
| 7884 | goto out; |
| 7885 | } |
| 7886 | |
| 7887 | /* Map HBA Control Registers to a kernel virtual address. */ |
| 7888 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
| 7889 | if (!phba->ctrl_regs_memmap_p) { |
| 7890 | dev_printk(KERN_ERR, &pdev->dev, |
| 7891 | "ioremap failed for HBA control registers.\n"); |
| 7892 | goto out_iounmap_slim; |
| 7893 | } |
| 7894 | |
| 7895 | /* Allocate memory for SLI-2 structures */ |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 7896 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7897 | &phba->slim2p.phys, GFP_KERNEL); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7898 | if (!phba->slim2p.virt) |
| 7899 | goto out_iounmap; |
| 7900 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7901 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 7902 | phba->mbox_ext = (phba->slim2p.virt + |
| 7903 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7904 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 7905 | phba->IOCBs = (phba->slim2p.virt + |
| 7906 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| 7907 | |
| 7908 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, |
| 7909 | lpfc_sli_hbq_size(), |
| 7910 | &phba->hbqslimp.phys, |
| 7911 | GFP_KERNEL); |
| 7912 | if (!phba->hbqslimp.virt) |
| 7913 | goto out_free_slim; |
| 7914 | |
| 7915 | hbq_count = lpfc_sli_hbq_count(); |
| 7916 | ptr = phba->hbqslimp.virt; |
| 7917 | for (i = 0; i < hbq_count; ++i) { |
| 7918 | phba->hbqs[i].hbq_virt = ptr; |
| 7919 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 7920 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 7921 | sizeof(struct lpfc_hbq_entry)); |
| 7922 | } |
| 7923 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 7924 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 7925 | |
| 7926 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 7927 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7928 | phba->MBslimaddr = phba->slim_memmap_p; |
| 7929 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 7930 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 7931 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 7932 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 7933 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7934 | return 0; |
| 7935 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7936 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 7937 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7938 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7939 | out_iounmap: |
| 7940 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 7941 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7942 | iounmap(phba->slim_memmap_p); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 7943 | out: |
| 7944 | return error; |
| 7945 | } |
| 7946 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 7947 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 7948 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. |
| 7949 | * @phba: pointer to lpfc hba data structure. |
| 7950 | * |
| 7951 | * This routine is invoked to unset the PCI device memory space for device |
| 7952 | * with SLI-3 interface spec. |
| 7953 | **/ |
| 7954 | static void |
| 7955 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) |
| 7956 | { |
| 7957 | struct pci_dev *pdev; |
| 7958 | |
| 7959 | /* Obtain PCI device reference */ |
| 7960 | if (!phba->pcidev) |
| 7961 | return; |
| 7962 | else |
| 7963 | pdev = phba->pcidev; |
| 7964 | |
| 7965 | /* Free coherent DMA memory allocated */ |
| 7966 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 7967 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| 7968 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 7969 | phba->slim2p.virt, phba->slim2p.phys); |
| 7970 | |
| 7971 | /* I/O memory unmap */ |
| 7972 | iounmap(phba->ctrl_regs_memmap_p); |
| 7973 | iounmap(phba->slim_memmap_p); |
| 7974 | |
| 7975 | return; |
| 7976 | } |
| 7977 | |
| 7978 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7979 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
| 7980 | * @phba: pointer to lpfc hba data structure. |
| 7981 | * |
| 7982 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
| 7983 | * done and check status. |
| 7984 | * |
| 7985 | * Return 0 if successful, otherwise -ENODEV. |
| 7986 | **/ |
| 7987 | int |
| 7988 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) |
| 7989 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7990 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
| 7991 | struct lpfc_register reg_data; |
| 7992 | int i, port_error = 0; |
| 7993 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7994 | |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 7995 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
| 7996 | memset(®_data, 0, sizeof(reg_data)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 7997 | if (!phba->sli4_hba.PSMPHRregaddr) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 7998 | return -ENODEV; |
| 7999 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8000 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
| 8001 | for (i = 0; i < 3000; i++) { |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8002 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
| 8003 | &portsmphr_reg.word0) || |
| 8004 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8005 | /* Port has a fatal POST error, break out */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8006 | port_error = -ENODEV; |
| 8007 | break; |
| 8008 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8009 | if (LPFC_POST_STAGE_PORT_READY == |
| 8010 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8011 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8012 | msleep(10); |
| 8013 | } |
| 8014 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8015 | /* |
| 8016 | * If there was a port error during POST, then don't proceed with |
| 8017 | * other register reads as the data may not be valid. Just exit. |
| 8018 | */ |
| 8019 | if (port_error) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8020 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8021 | "1408 Port Failed POST - portsmphr=0x%x, " |
| 8022 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " |
| 8023 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", |
| 8024 | portsmphr_reg.word0, |
| 8025 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), |
| 8026 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), |
| 8027 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), |
| 8028 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), |
| 8029 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), |
| 8030 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), |
| 8031 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), |
| 8032 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); |
| 8033 | } else { |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8034 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8035 | "2534 Device Info: SLIFamily=0x%x, " |
| 8036 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " |
| 8037 | "SLIHint_2=0x%x, FT=0x%x\n", |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8038 | bf_get(lpfc_sli_intf_sli_family, |
| 8039 | &phba->sli4_hba.sli_intf), |
| 8040 | bf_get(lpfc_sli_intf_slirev, |
| 8041 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 8042 | bf_get(lpfc_sli_intf_if_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8043 | &phba->sli4_hba.sli_intf), |
James Smart | 085c647 | 2010-11-20 23:11:37 -0500 | [diff] [blame] | 8044 | bf_get(lpfc_sli_intf_sli_hint1, |
| 8045 | &phba->sli4_hba.sli_intf), |
| 8046 | bf_get(lpfc_sli_intf_sli_hint2, |
| 8047 | &phba->sli4_hba.sli_intf), |
| 8048 | bf_get(lpfc_sli_intf_func_type, |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8049 | &phba->sli4_hba.sli_intf)); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8050 | /* |
| 8051 | * Check for other Port errors during the initialization |
| 8052 | * process. Fail the load if the port did not come up |
| 8053 | * correctly. |
| 8054 | */ |
| 8055 | if_type = bf_get(lpfc_sli_intf_if_type, |
| 8056 | &phba->sli4_hba.sli_intf); |
| 8057 | switch (if_type) { |
| 8058 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8059 | phba->sli4_hba.ue_mask_lo = |
| 8060 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); |
| 8061 | phba->sli4_hba.ue_mask_hi = |
| 8062 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); |
| 8063 | uerrlo_reg.word0 = |
| 8064 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); |
| 8065 | uerrhi_reg.word0 = |
| 8066 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); |
| 8067 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || |
| 8068 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8069 | lpfc_printf_log(phba, KERN_ERR, |
| 8070 | LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8071 | "1422 Unrecoverable Error " |
| 8072 | "Detected during POST " |
| 8073 | "uerr_lo_reg=0x%x, " |
| 8074 | "uerr_hi_reg=0x%x, " |
| 8075 | "ue_mask_lo_reg=0x%x, " |
| 8076 | "ue_mask_hi_reg=0x%x\n", |
| 8077 | uerrlo_reg.word0, |
| 8078 | uerrhi_reg.word0, |
| 8079 | phba->sli4_hba.ue_mask_lo, |
| 8080 | phba->sli4_hba.ue_mask_hi); |
| 8081 | port_error = -ENODEV; |
| 8082 | } |
| 8083 | break; |
| 8084 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8085 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8086 | /* Final checks. The port status should be clean. */ |
James Smart | 9940b97 | 2011-03-11 16:06:12 -0500 | [diff] [blame] | 8087 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
| 8088 | ®_data.word0) || |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 8089 | (bf_get(lpfc_sliport_status_err, ®_data) && |
| 8090 | !bf_get(lpfc_sliport_status_rn, ®_data))) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8091 | phba->work_status[0] = |
| 8092 | readl(phba->sli4_hba.u.if_type2. |
| 8093 | ERR1regaddr); |
| 8094 | phba->work_status[1] = |
| 8095 | readl(phba->sli4_hba.u.if_type2. |
| 8096 | ERR2regaddr); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8097 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 8098 | "2888 Unrecoverable port error " |
| 8099 | "following POST: port status reg " |
| 8100 | "0x%x, port_smphr reg 0x%x, " |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8101 | "error 1=0x%x, error 2=0x%x\n", |
| 8102 | reg_data.word0, |
| 8103 | portsmphr_reg.word0, |
| 8104 | phba->work_status[0], |
| 8105 | phba->work_status[1]); |
| 8106 | port_error = -ENODEV; |
| 8107 | } |
| 8108 | break; |
| 8109 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8110 | default: |
| 8111 | break; |
| 8112 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 8113 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8114 | return port_error; |
| 8115 | } |
| 8116 | |
| 8117 | /** |
| 8118 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. |
| 8119 | * @phba: pointer to lpfc hba data structure. |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8120 | * @if_type: The SLI4 interface type getting configured. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8121 | * |
| 8122 | * This routine is invoked to set up SLI4 BAR0 PCI config space register |
| 8123 | * memory map. |
| 8124 | **/ |
| 8125 | static void |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8126 | 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] | 8127 | { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8128 | switch (if_type) { |
| 8129 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8130 | phba->sli4_hba.u.if_type0.UERRLOregaddr = |
| 8131 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; |
| 8132 | phba->sli4_hba.u.if_type0.UERRHIregaddr = |
| 8133 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; |
| 8134 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = |
| 8135 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; |
| 8136 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = |
| 8137 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; |
| 8138 | phba->sli4_hba.SLIINTFregaddr = |
| 8139 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8140 | break; |
| 8141 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 8142 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8143 | phba->sli4_hba.conf_regs_memmap_p + |
| 8144 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8145 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8146 | phba->sli4_hba.conf_regs_memmap_p + |
| 8147 | LPFC_CTL_PORT_ER1_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8148 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8149 | phba->sli4_hba.conf_regs_memmap_p + |
| 8150 | LPFC_CTL_PORT_ER2_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8151 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8152 | phba->sli4_hba.conf_regs_memmap_p + |
| 8153 | LPFC_CTL_PORT_CTL_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8154 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8155 | phba->sli4_hba.conf_regs_memmap_p + |
| 8156 | LPFC_CTL_PORT_STA_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8157 | phba->sli4_hba.SLIINTFregaddr = |
| 8158 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; |
| 8159 | phba->sli4_hba.PSMPHRregaddr = |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 8160 | phba->sli4_hba.conf_regs_memmap_p + |
| 8161 | LPFC_CTL_PORT_SEM_OFFSET; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8162 | phba->sli4_hba.RQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8163 | phba->sli4_hba.conf_regs_memmap_p + |
| 8164 | LPFC_ULP0_RQ_DOORBELL; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8165 | phba->sli4_hba.WQDBregaddr = |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8166 | phba->sli4_hba.conf_regs_memmap_p + |
| 8167 | LPFC_ULP0_WQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8168 | phba->sli4_hba.CQDBregaddr = |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8169 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8170 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8171 | phba->sli4_hba.MQDBregaddr = |
| 8172 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; |
| 8173 | phba->sli4_hba.BMBXregaddr = |
| 8174 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8175 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8176 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8177 | phba->sli4_hba.u.if_type2.EQDregaddr = |
| 8178 | phba->sli4_hba.conf_regs_memmap_p + |
| 8179 | LPFC_CTL_PORT_EQ_DELAY_OFFSET; |
| 8180 | phba->sli4_hba.u.if_type2.ERR1regaddr = |
| 8181 | phba->sli4_hba.conf_regs_memmap_p + |
| 8182 | LPFC_CTL_PORT_ER1_OFFSET; |
| 8183 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
| 8184 | phba->sli4_hba.conf_regs_memmap_p + |
| 8185 | LPFC_CTL_PORT_ER2_OFFSET; |
| 8186 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
| 8187 | phba->sli4_hba.conf_regs_memmap_p + |
| 8188 | LPFC_CTL_PORT_CTL_OFFSET; |
| 8189 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
| 8190 | phba->sli4_hba.conf_regs_memmap_p + |
| 8191 | LPFC_CTL_PORT_STA_OFFSET; |
| 8192 | phba->sli4_hba.PSMPHRregaddr = |
| 8193 | phba->sli4_hba.conf_regs_memmap_p + |
| 8194 | LPFC_CTL_PORT_SEM_OFFSET; |
| 8195 | phba->sli4_hba.BMBXregaddr = |
| 8196 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; |
| 8197 | break; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8198 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8199 | default: |
| 8200 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 8201 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8202 | if_type); |
| 8203 | break; |
| 8204 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8205 | } |
| 8206 | |
| 8207 | /** |
| 8208 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. |
| 8209 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 8210 | * @if_type: sli if type to operate on. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8211 | * |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8212 | * This routine is invoked to set up SLI4 BAR1 register memory map. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8213 | **/ |
| 8214 | static void |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8215 | 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] | 8216 | { |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8217 | switch (if_type) { |
| 8218 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8219 | phba->sli4_hba.PSMPHRregaddr = |
| 8220 | phba->sli4_hba.ctrl_regs_memmap_p + |
| 8221 | LPFC_SLIPORT_IF0_SMPHR; |
| 8222 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8223 | LPFC_HST_ISR0; |
| 8224 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8225 | LPFC_HST_IMR0; |
| 8226 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
| 8227 | LPFC_HST_ISCR0; |
| 8228 | break; |
| 8229 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 8230 | phba->sli4_hba.RQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8231 | LPFC_IF6_RQ_DOORBELL; |
| 8232 | phba->sli4_hba.WQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8233 | LPFC_IF6_WQ_DOORBELL; |
| 8234 | phba->sli4_hba.CQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8235 | LPFC_IF6_CQ_DOORBELL; |
| 8236 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8237 | LPFC_IF6_EQ_DOORBELL; |
| 8238 | phba->sli4_hba.MQDBregaddr = phba->sli4_hba.drbl_regs_memmap_p + |
| 8239 | LPFC_IF6_MQ_DOORBELL; |
| 8240 | break; |
| 8241 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8242 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8243 | default: |
| 8244 | dev_err(&phba->pcidev->dev, |
| 8245 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 8246 | if_type); |
| 8247 | break; |
| 8248 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8249 | } |
| 8250 | |
| 8251 | /** |
| 8252 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
| 8253 | * @phba: pointer to lpfc hba data structure. |
| 8254 | * @vf: virtual function number |
| 8255 | * |
| 8256 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
| 8257 | * based on the given viftual function number, @vf. |
| 8258 | * |
| 8259 | * Return 0 if successful, otherwise -ENODEV. |
| 8260 | **/ |
| 8261 | static int |
| 8262 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) |
| 8263 | { |
| 8264 | if (vf > LPFC_VIR_FUNC_MAX) |
| 8265 | return -ENODEV; |
| 8266 | |
| 8267 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8268 | vf * LPFC_VFR_PAGE_SIZE + |
| 8269 | LPFC_ULP0_RQ_DOORBELL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8270 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 8271 | vf * LPFC_VFR_PAGE_SIZE + |
| 8272 | LPFC_ULP0_WQ_DOORBELL); |
James Smart | 9dd3542 | 2018-02-22 08:18:41 -0800 | [diff] [blame] | 8273 | phba->sli4_hba.CQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8274 | vf * LPFC_VFR_PAGE_SIZE + |
| 8275 | LPFC_EQCQ_DOORBELL); |
| 8276 | phba->sli4_hba.EQDBregaddr = phba->sli4_hba.CQDBregaddr; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8277 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8278 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); |
| 8279 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
| 8280 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); |
| 8281 | return 0; |
| 8282 | } |
| 8283 | |
| 8284 | /** |
| 8285 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
| 8286 | * @phba: pointer to lpfc hba data structure. |
| 8287 | * |
| 8288 | * This routine is invoked to create the bootstrap mailbox |
| 8289 | * region consistent with the SLI-4 interface spec. This |
| 8290 | * routine allocates all memory necessary to communicate |
| 8291 | * mailbox commands to the port and sets up all alignment |
| 8292 | * needs. No locks are expected to be held when calling |
| 8293 | * this routine. |
| 8294 | * |
| 8295 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8296 | * 0 - successful |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8297 | * -ENOMEM - could not allocated memory. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8298 | **/ |
| 8299 | static int |
| 8300 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
| 8301 | { |
| 8302 | uint32_t bmbx_size; |
| 8303 | struct lpfc_dmabuf *dmabuf; |
| 8304 | struct dma_address *dma_address; |
| 8305 | uint32_t pa_addr; |
| 8306 | uint64_t phys_addr; |
| 8307 | |
| 8308 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 8309 | if (!dmabuf) |
| 8310 | return -ENOMEM; |
| 8311 | |
| 8312 | /* |
| 8313 | * The bootstrap mailbox region is comprised of 2 parts |
| 8314 | * plus an alignment restriction of 16 bytes. |
| 8315 | */ |
| 8316 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 8317 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, bmbx_size, |
| 8318 | &dmabuf->phys, GFP_KERNEL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8319 | if (!dmabuf->virt) { |
| 8320 | kfree(dmabuf); |
| 8321 | return -ENOMEM; |
| 8322 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8323 | |
| 8324 | /* |
| 8325 | * Initialize the bootstrap mailbox pointers now so that the register |
| 8326 | * operations are simple later. The mailbox dma address is required |
| 8327 | * to be 16-byte aligned. Also align the virtual memory as each |
| 8328 | * maibox is copied into the bmbx mailbox region before issuing the |
| 8329 | * command to the port. |
| 8330 | */ |
| 8331 | phba->sli4_hba.bmbx.dmabuf = dmabuf; |
| 8332 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; |
| 8333 | |
| 8334 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, |
| 8335 | LPFC_ALIGN_16_BYTE); |
| 8336 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, |
| 8337 | LPFC_ALIGN_16_BYTE); |
| 8338 | |
| 8339 | /* |
| 8340 | * Set the high and low physical addresses now. The SLI4 alignment |
| 8341 | * requirement is 16 bytes and the mailbox is posted to the port |
| 8342 | * as two 30-bit addresses. The other data is a bit marking whether |
| 8343 | * the 30-bit address is the high or low address. |
| 8344 | * Upcast bmbx aphys to 64bits so shift instruction compiles |
| 8345 | * clean on 32 bit machines. |
| 8346 | */ |
| 8347 | dma_address = &phba->sli4_hba.bmbx.dma_address; |
| 8348 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; |
| 8349 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); |
| 8350 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | |
| 8351 | LPFC_BMBX_BIT1_ADDR_HI); |
| 8352 | |
| 8353 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); |
| 8354 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | |
| 8355 | LPFC_BMBX_BIT1_ADDR_LO); |
| 8356 | return 0; |
| 8357 | } |
| 8358 | |
| 8359 | /** |
| 8360 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
| 8361 | * @phba: pointer to lpfc hba data structure. |
| 8362 | * |
| 8363 | * This routine is invoked to teardown the bootstrap mailbox |
| 8364 | * region and release all host resources. This routine requires |
| 8365 | * the caller to ensure all mailbox commands recovered, no |
| 8366 | * additional mailbox comands are sent, and interrupts are disabled |
| 8367 | * before calling this routine. |
| 8368 | * |
| 8369 | **/ |
| 8370 | static void |
| 8371 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
| 8372 | { |
| 8373 | dma_free_coherent(&phba->pcidev->dev, |
| 8374 | phba->sli4_hba.bmbx.bmbx_size, |
| 8375 | phba->sli4_hba.bmbx.dmabuf->virt, |
| 8376 | phba->sli4_hba.bmbx.dmabuf->phys); |
| 8377 | |
| 8378 | kfree(phba->sli4_hba.bmbx.dmabuf); |
| 8379 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); |
| 8380 | } |
| 8381 | |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8382 | static const char * const lpfc_topo_to_str[] = { |
| 8383 | "Loop then P2P", |
| 8384 | "Loopback", |
| 8385 | "P2P Only", |
| 8386 | "Unsupported", |
| 8387 | "Loop Only", |
| 8388 | "Unsupported", |
| 8389 | "P2P then Loop", |
| 8390 | }; |
| 8391 | |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 8392 | #define LINK_FLAGS_DEF 0x0 |
| 8393 | #define LINK_FLAGS_P2P 0x1 |
| 8394 | #define LINK_FLAGS_LOOP 0x2 |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8395 | /** |
| 8396 | * lpfc_map_topology - Map the topology read from READ_CONFIG |
| 8397 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 8398 | * @rd_config: pointer to read config data |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8399 | * |
| 8400 | * This routine is invoked to map the topology values as read |
| 8401 | * from the read config mailbox command. If the persistent |
| 8402 | * topology feature is supported, the firmware will provide the |
| 8403 | * saved topology information to be used in INIT_LINK |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8404 | **/ |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8405 | static void |
| 8406 | lpfc_map_topology(struct lpfc_hba *phba, struct lpfc_mbx_read_config *rd_config) |
| 8407 | { |
| 8408 | u8 ptv, tf, pt; |
| 8409 | |
| 8410 | ptv = bf_get(lpfc_mbx_rd_conf_ptv, rd_config); |
| 8411 | tf = bf_get(lpfc_mbx_rd_conf_tf, rd_config); |
| 8412 | pt = bf_get(lpfc_mbx_rd_conf_pt, rd_config); |
| 8413 | |
| 8414 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8415 | "2027 Read Config Data : ptv:0x%x, tf:0x%x pt:0x%x", |
| 8416 | ptv, tf, pt); |
| 8417 | if (!ptv) { |
| 8418 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8419 | "2019 FW does not support persistent topology " |
| 8420 | "Using driver parameter defined value [%s]", |
| 8421 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8422 | return; |
| 8423 | } |
| 8424 | /* FW supports persistent topology - override module parameter value */ |
| 8425 | phba->hba_flag |= HBA_PERSISTENT_TOPO; |
| 8426 | switch (phba->pcidev->device) { |
| 8427 | case PCI_DEVICE_ID_LANCER_G7_FC: |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8428 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 8429 | if (!tf) { |
| 8430 | phba->cfg_topology = ((pt == LINK_FLAGS_LOOP) |
| 8431 | ? FLAGS_TOPOLOGY_MODE_LOOP |
| 8432 | : FLAGS_TOPOLOGY_MODE_PT_PT); |
| 8433 | } else { |
| 8434 | phba->hba_flag &= ~HBA_PERSISTENT_TOPO; |
| 8435 | } |
| 8436 | break; |
| 8437 | default: /* G5 */ |
| 8438 | if (tf) { |
| 8439 | /* If topology failover set - pt is '0' or '1' */ |
| 8440 | phba->cfg_topology = (pt ? FLAGS_TOPOLOGY_MODE_PT_LOOP : |
| 8441 | FLAGS_TOPOLOGY_MODE_LOOP_PT); |
| 8442 | } else { |
| 8443 | phba->cfg_topology = ((pt == LINK_FLAGS_P2P) |
| 8444 | ? FLAGS_TOPOLOGY_MODE_PT_PT |
| 8445 | : FLAGS_TOPOLOGY_MODE_LOOP); |
| 8446 | } |
| 8447 | break; |
| 8448 | } |
| 8449 | if (phba->hba_flag & HBA_PERSISTENT_TOPO) { |
| 8450 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8451 | "2020 Using persistent topology value [%s]", |
| 8452 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8453 | } else { |
| 8454 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8455 | "2021 Invalid topology values from FW " |
| 8456 | "Using driver parameter defined value [%s]", |
| 8457 | lpfc_topo_to_str[phba->cfg_topology]); |
| 8458 | } |
| 8459 | } |
| 8460 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8461 | /** |
| 8462 | * lpfc_sli4_read_config - Get the config parameters. |
| 8463 | * @phba: pointer to lpfc hba data structure. |
| 8464 | * |
| 8465 | * This routine is invoked to read the configuration parameters from the HBA. |
| 8466 | * The configuration parameters are used to set the base and maximum values |
| 8467 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource |
| 8468 | * allocation for the port. |
| 8469 | * |
| 8470 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8471 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8472 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8473 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8474 | **/ |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8475 | int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8476 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
| 8477 | { |
| 8478 | LPFC_MBOXQ_t *pmb; |
| 8479 | struct lpfc_mbx_read_config *rd_config; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8480 | union lpfc_sli4_cfg_shdr *shdr; |
| 8481 | uint32_t shdr_status, shdr_add_status; |
| 8482 | struct lpfc_mbx_get_func_cfg *get_func_cfg; |
| 8483 | struct lpfc_rsrc_desc_fcfcoe *desc; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8484 | char *pdesc_0; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8485 | uint16_t forced_link_speed; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8486 | uint32_t if_type, qmin; |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8487 | int length, i, rc = 0, rc2; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8488 | |
| 8489 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 8490 | if (!pmb) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8491 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8492 | "2011 Unable to allocate memory for issuing " |
| 8493 | "SLI_CONFIG_SPECIAL mailbox command\n"); |
| 8494 | return -ENOMEM; |
| 8495 | } |
| 8496 | |
| 8497 | lpfc_read_config(phba, pmb); |
| 8498 | |
| 8499 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 8500 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8501 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 8502 | "2012 Mailbox failed , mbxCmd x%x " |
| 8503 | "READ_CONFIG, mbxStatus x%x\n", |
| 8504 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8505 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8506 | rc = -EIO; |
| 8507 | } else { |
| 8508 | rd_config = &pmb->u.mqe.un.rd_config; |
James Smart | ff78d8f | 2011-12-13 13:21:35 -0500 | [diff] [blame] | 8509 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
| 8510 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; |
| 8511 | phba->sli4_hba.lnk_info.lnk_tp = |
| 8512 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); |
| 8513 | phba->sli4_hba.lnk_info.lnk_no = |
| 8514 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); |
| 8515 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8516 | "3081 lnk_type:%d, lnk_numb:%d\n", |
| 8517 | phba->sli4_hba.lnk_info.lnk_tp, |
| 8518 | phba->sli4_hba.lnk_info.lnk_no); |
| 8519 | } else |
| 8520 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, |
| 8521 | "3082 Mailbox (x%x) returned ldv:x0\n", |
| 8522 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); |
James Smart | 44fd7fe | 2017-08-23 16:55:47 -0700 | [diff] [blame] | 8523 | if (bf_get(lpfc_mbx_rd_conf_bbscn_def, rd_config)) { |
| 8524 | phba->bbcredit_support = 1; |
| 8525 | phba->sli4_hba.bbscn_params.word0 = rd_config->word8; |
| 8526 | } |
| 8527 | |
James Smart | 1dc5ec2 | 2018-10-23 13:41:11 -0700 | [diff] [blame] | 8528 | phba->sli4_hba.conf_trunk = |
| 8529 | bf_get(lpfc_mbx_rd_conf_trunk, rd_config); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8530 | phba->sli4_hba.extents_in_use = |
| 8531 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8532 | phba->sli4_hba.max_cfg_param.max_xri = |
| 8533 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); |
James Smart | 31f06d2 | 2019-08-14 16:56:31 -0700 | [diff] [blame] | 8534 | /* Reduce resource usage in kdump environment */ |
| 8535 | if (is_kdump_kernel() && |
| 8536 | phba->sli4_hba.max_cfg_param.max_xri > 512) |
| 8537 | phba->sli4_hba.max_cfg_param.max_xri = 512; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8538 | phba->sli4_hba.max_cfg_param.xri_base = |
| 8539 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); |
| 8540 | phba->sli4_hba.max_cfg_param.max_vpi = |
| 8541 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); |
James Smart | 8b47ae6 | 2018-11-29 16:09:33 -0800 | [diff] [blame] | 8542 | /* Limit the max we support */ |
| 8543 | if (phba->sli4_hba.max_cfg_param.max_vpi > LPFC_MAX_VPORTS) |
| 8544 | phba->sli4_hba.max_cfg_param.max_vpi = LPFC_MAX_VPORTS; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8545 | phba->sli4_hba.max_cfg_param.vpi_base = |
| 8546 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); |
| 8547 | phba->sli4_hba.max_cfg_param.max_rpi = |
| 8548 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); |
| 8549 | phba->sli4_hba.max_cfg_param.rpi_base = |
| 8550 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); |
| 8551 | phba->sli4_hba.max_cfg_param.max_vfi = |
| 8552 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); |
| 8553 | phba->sli4_hba.max_cfg_param.vfi_base = |
| 8554 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); |
| 8555 | phba->sli4_hba.max_cfg_param.max_fcfi = |
| 8556 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8557 | phba->sli4_hba.max_cfg_param.max_eq = |
| 8558 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); |
| 8559 | phba->sli4_hba.max_cfg_param.max_rq = |
| 8560 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); |
| 8561 | phba->sli4_hba.max_cfg_param.max_wq = |
| 8562 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); |
| 8563 | phba->sli4_hba.max_cfg_param.max_cq = |
| 8564 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); |
| 8565 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); |
| 8566 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; |
| 8567 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; |
| 8568 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; |
James Smart | 5ffc266 | 2009-11-18 15:39:44 -0500 | [diff] [blame] | 8569 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
| 8570 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8571 | phba->max_vports = phba->max_vpi; |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 8572 | lpfc_map_topology(phba, rd_config); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8573 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 8574 | "2003 cfg params Extents? %d " |
| 8575 | "XRI(B:%d M:%d), " |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8576 | "VPI(B:%d M:%d) " |
| 8577 | "VFI(B:%d M:%d) " |
| 8578 | "RPI(B:%d M:%d) " |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 8579 | "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] | 8580 | phba->sli4_hba.extents_in_use, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8581 | phba->sli4_hba.max_cfg_param.xri_base, |
| 8582 | phba->sli4_hba.max_cfg_param.max_xri, |
| 8583 | phba->sli4_hba.max_cfg_param.vpi_base, |
| 8584 | phba->sli4_hba.max_cfg_param.max_vpi, |
| 8585 | phba->sli4_hba.max_cfg_param.vfi_base, |
| 8586 | phba->sli4_hba.max_cfg_param.max_vfi, |
| 8587 | phba->sli4_hba.max_cfg_param.rpi_base, |
| 8588 | phba->sli4_hba.max_cfg_param.max_rpi, |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8589 | phba->sli4_hba.max_cfg_param.max_fcfi, |
| 8590 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8591 | phba->sli4_hba.max_cfg_param.max_cq, |
| 8592 | phba->sli4_hba.max_cfg_param.max_wq, |
Dick Kennedy | a1e4d3d | 2020-08-03 14:02:22 -0700 | [diff] [blame] | 8593 | phba->sli4_hba.max_cfg_param.max_rq, |
| 8594 | phba->lmt); |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 8595 | |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8596 | /* |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8597 | * Calculate queue resources based on how |
| 8598 | * many WQ/CQ/EQs are available. |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8599 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8600 | qmin = phba->sli4_hba.max_cfg_param.max_wq; |
| 8601 | if (phba->sli4_hba.max_cfg_param.max_cq < qmin) |
| 8602 | qmin = phba->sli4_hba.max_cfg_param.max_cq; |
| 8603 | if (phba->sli4_hba.max_cfg_param.max_eq < qmin) |
| 8604 | qmin = phba->sli4_hba.max_cfg_param.max_eq; |
| 8605 | /* |
| 8606 | * Whats left after this can go toward NVME / FCP. |
| 8607 | * The minus 4 accounts for ELS, NVME LS, MBOX |
| 8608 | * plus one extra. When configured for |
| 8609 | * NVMET, FCP io channel WQs are not created. |
| 8610 | */ |
| 8611 | qmin -= 4; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8612 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8613 | /* Check to see if there is enough for NVME */ |
| 8614 | if ((phba->cfg_irq_chann > qmin) || |
| 8615 | (phba->cfg_hdw_queue > qmin)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8616 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
Dick Kennedy | 9e3e365 | 2020-08-03 14:02:23 -0700 | [diff] [blame] | 8617 | "2005 Reducing Queues - " |
| 8618 | "FW resource limitation: " |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8619 | "WQ %d CQ %d EQ %d: min %d: " |
| 8620 | "IRQ %d HDWQ %d\n", |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8621 | phba->sli4_hba.max_cfg_param.max_wq, |
| 8622 | phba->sli4_hba.max_cfg_param.max_cq, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8623 | phba->sli4_hba.max_cfg_param.max_eq, |
| 8624 | qmin, phba->cfg_irq_chann, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8625 | phba->cfg_hdw_queue); |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8626 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8627 | if (phba->cfg_irq_chann > qmin) |
| 8628 | phba->cfg_irq_chann = qmin; |
| 8629 | if (phba->cfg_hdw_queue > qmin) |
| 8630 | phba->cfg_hdw_queue = qmin; |
James Smart | d38f33b | 2018-05-04 20:37:54 -0700 | [diff] [blame] | 8631 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8632 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8633 | |
| 8634 | if (rc) |
| 8635 | goto read_cfg_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8636 | |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8637 | /* Update link speed if forced link speed is supported */ |
| 8638 | 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] | 8639 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8640 | forced_link_speed = |
| 8641 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); |
| 8642 | if (forced_link_speed) { |
| 8643 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; |
| 8644 | |
| 8645 | switch (forced_link_speed) { |
| 8646 | case LINK_SPEED_1G: |
| 8647 | phba->cfg_link_speed = |
| 8648 | LPFC_USER_LINK_SPEED_1G; |
| 8649 | break; |
| 8650 | case LINK_SPEED_2G: |
| 8651 | phba->cfg_link_speed = |
| 8652 | LPFC_USER_LINK_SPEED_2G; |
| 8653 | break; |
| 8654 | case LINK_SPEED_4G: |
| 8655 | phba->cfg_link_speed = |
| 8656 | LPFC_USER_LINK_SPEED_4G; |
| 8657 | break; |
| 8658 | case LINK_SPEED_8G: |
| 8659 | phba->cfg_link_speed = |
| 8660 | LPFC_USER_LINK_SPEED_8G; |
| 8661 | break; |
| 8662 | case LINK_SPEED_10G: |
| 8663 | phba->cfg_link_speed = |
| 8664 | LPFC_USER_LINK_SPEED_10G; |
| 8665 | break; |
| 8666 | case LINK_SPEED_16G: |
| 8667 | phba->cfg_link_speed = |
| 8668 | LPFC_USER_LINK_SPEED_16G; |
| 8669 | break; |
| 8670 | case LINK_SPEED_32G: |
| 8671 | phba->cfg_link_speed = |
| 8672 | LPFC_USER_LINK_SPEED_32G; |
| 8673 | break; |
James Smart | fbd8a6b | 2018-02-22 08:18:45 -0800 | [diff] [blame] | 8674 | case LINK_SPEED_64G: |
| 8675 | phba->cfg_link_speed = |
| 8676 | LPFC_USER_LINK_SPEED_64G; |
| 8677 | break; |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8678 | case 0xffff: |
| 8679 | phba->cfg_link_speed = |
| 8680 | LPFC_USER_LINK_SPEED_AUTO; |
| 8681 | break; |
| 8682 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8683 | lpfc_printf_log(phba, KERN_ERR, |
| 8684 | LOG_TRACE_EVENT, |
James Smart | c691816 | 2016-10-13 15:06:16 -0700 | [diff] [blame] | 8685 | "0047 Unrecognized link " |
| 8686 | "speed : %d\n", |
| 8687 | forced_link_speed); |
| 8688 | phba->cfg_link_speed = |
| 8689 | LPFC_USER_LINK_SPEED_AUTO; |
| 8690 | } |
| 8691 | } |
| 8692 | } |
| 8693 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8694 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
James Smart | 572709e | 2013-07-15 18:32:43 -0400 | [diff] [blame] | 8695 | length = phba->sli4_hba.max_cfg_param.max_xri - |
| 8696 | lpfc_sli4_get_els_iocb_cnt(phba); |
| 8697 | if (phba->cfg_hba_queue_depth > length) { |
| 8698 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 8699 | "3361 HBA queue depth changed from %d to %d\n", |
| 8700 | phba->cfg_hba_queue_depth, length); |
| 8701 | phba->cfg_hba_queue_depth = length; |
| 8702 | } |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8703 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8704 | 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] | 8705 | LPFC_SLI_INTF_IF_TYPE_2) |
| 8706 | goto read_cfg_out; |
| 8707 | |
| 8708 | /* get the pf# and vf# for SLI4 if_type 2 port */ |
| 8709 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - |
| 8710 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 8711 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 8712 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, |
| 8713 | length, LPFC_SLI4_MBX_EMBED); |
| 8714 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8715 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8716 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 8717 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; |
| 8718 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 8719 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8720 | if (rc2 || shdr_status || shdr_add_status) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8721 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8722 | "3026 Mailbox failed , mbxCmd x%x " |
| 8723 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", |
| 8724 | bf_get(lpfc_mqe_command, &pmb->u.mqe), |
| 8725 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8726 | goto read_cfg_out; |
| 8727 | } |
| 8728 | |
| 8729 | /* search for fc_fcoe resrouce descriptor */ |
| 8730 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8731 | |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8732 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
| 8733 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; |
| 8734 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); |
| 8735 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) |
| 8736 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; |
| 8737 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) |
| 8738 | goto read_cfg_out; |
| 8739 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8740 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8741 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8742 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8743 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8744 | phba->sli4_hba.iov.pf_number = |
| 8745 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); |
| 8746 | phba->sli4_hba.iov.vf_number = |
| 8747 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); |
| 8748 | break; |
| 8749 | } |
| 8750 | } |
| 8751 | |
| 8752 | if (i < LPFC_RSRC_DESC_MAX_NUM) |
| 8753 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
| 8754 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " |
| 8755 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, |
| 8756 | phba->sli4_hba.iov.vf_number); |
James Smart | 8aa134a | 2012-08-14 14:25:29 -0400 | [diff] [blame] | 8757 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8758 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8759 | "3028 GET_FUNCTION_CONFIG: failed to find " |
Colin Ian King | c4dba18 | 2018-10-16 18:28:53 +0100 | [diff] [blame] | 8760 | "Resource Descriptor:x%x\n", |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8761 | LPFC_RSRC_DESC_TYPE_FCFCOE); |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 8762 | |
| 8763 | read_cfg_out: |
| 8764 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8765 | return rc; |
| 8766 | } |
| 8767 | |
| 8768 | /** |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8769 | * 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] | 8770 | * @phba: pointer to lpfc hba data structure. |
| 8771 | * |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8772 | * This routine is invoked to setup the port-side endian order when |
| 8773 | * the port if_type is 0. This routine has no function for other |
| 8774 | * if_types. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8775 | * |
| 8776 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8777 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8778 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 8779 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8780 | **/ |
| 8781 | static int |
| 8782 | lpfc_setup_endian_order(struct lpfc_hba *phba) |
| 8783 | { |
| 8784 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8785 | uint32_t if_type, rc = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8786 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
| 8787 | HOST_ENDIAN_HIGH_WORD1}; |
| 8788 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8789 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 8790 | switch (if_type) { |
| 8791 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 8792 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 8793 | GFP_KERNEL); |
| 8794 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8795 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8796 | "0492 Unable to allocate memory for " |
| 8797 | "issuing SLI_CONFIG_SPECIAL mailbox " |
| 8798 | "command\n"); |
| 8799 | return -ENOMEM; |
| 8800 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8801 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8802 | /* |
| 8803 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first |
| 8804 | * two words to contain special data values and no other data. |
| 8805 | */ |
| 8806 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 8807 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); |
| 8808 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 8809 | if (rc != MBX_SUCCESS) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8810 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8811 | "0493 SLI_CONFIG_SPECIAL mailbox " |
| 8812 | "failed with status x%x\n", |
| 8813 | rc); |
| 8814 | rc = -EIO; |
| 8815 | } |
| 8816 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 8817 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 8818 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 8819 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 8820 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 8821 | default: |
| 8822 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8823 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8824 | return rc; |
| 8825 | } |
| 8826 | |
| 8827 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8828 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8829 | * @phba: pointer to lpfc hba data structure. |
| 8830 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8831 | * This routine is invoked to check the user settable queue counts for EQs. |
| 8832 | * 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] | 8833 | * adhere to the constraints of the system's interrupt vectors and the port's |
| 8834 | * queue resources. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8835 | * |
| 8836 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 8837 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 8838 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8839 | **/ |
| 8840 | static int |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8841 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8842 | { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8843 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8844 | * Sanity check for configured queue parameters against the run-time |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8845 | * device parameters |
| 8846 | */ |
| 8847 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8848 | if (phba->nvmet_support) { |
James Smart | 97a9ed3 | 2019-10-18 14:18:17 -0700 | [diff] [blame] | 8849 | if (phba->cfg_hdw_queue < phba->cfg_nvmet_mrq) |
| 8850 | phba->cfg_nvmet_mrq = phba->cfg_hdw_queue; |
James Smart | 982ab12 | 2019-03-12 16:30:10 -0700 | [diff] [blame] | 8851 | if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX) |
| 8852 | phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX; |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 8853 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8854 | |
| 8855 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 8856 | "2574 IO channels: hdwQ %d IRQ %d MRQ: %d\n", |
| 8857 | phba->cfg_hdw_queue, phba->cfg_irq_chann, |
| 8858 | phba->cfg_nvmet_mrq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8859 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 8860 | /* Get EQ depth from module parameter, fake the default for now */ |
| 8861 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8862 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8863 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8864 | /* Get CQ depth from module parameter, fake the default for now */ |
| 8865 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8866 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8867 | return 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8868 | } |
| 8869 | |
| 8870 | static int |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8871 | lpfc_alloc_io_wq_cq(struct lpfc_hba *phba, int idx) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8872 | { |
| 8873 | struct lpfc_queue *qdesc; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8874 | u32 wqesize; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8875 | int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8876 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8877 | cpu = lpfc_find_cpu_handle(phba, idx, LPFC_FIND_BY_HDWQ); |
| 8878 | /* Create Fast Path IO CQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8879 | if (phba->enab_exp_wqcq_pages) |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8880 | /* Increase the CQ size when WQEs contain an embedded cdb */ |
| 8881 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
| 8882 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8883 | LPFC_CQE_EXP_COUNT, cpu); |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8884 | |
| 8885 | else |
| 8886 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8887 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8888 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8889 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8890 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 8891 | "0499 Failed allocate fast-path IO CQ (%d)\n", |
| 8892 | idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8893 | return 1; |
| 8894 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 8895 | qdesc->qe_valid = 1; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8896 | qdesc->hdwq = idx; |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8897 | qdesc->chann = cpu; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8898 | phba->sli4_hba.hdwq[idx].io_cq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8899 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8900 | /* Create Fast Path IO WQs */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8901 | if (phba->enab_exp_wqcq_pages) { |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8902 | /* Increase the WQ size when WQEs contain an embedded cdb */ |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8903 | wqesize = (phba->fcp_embed_io) ? |
| 8904 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8905 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_EXPANDED_PAGE_SIZE, |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8906 | wqesize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8907 | LPFC_WQE_EXP_COUNT, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8908 | } else |
James Smart | a51e41b | 2017-12-08 17:18:06 -0800 | [diff] [blame] | 8909 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 8910 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 8911 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 8912 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8913 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8914 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8915 | "0503 Failed allocate fast-path IO WQ (%d)\n", |
| 8916 | idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8917 | return 1; |
| 8918 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8919 | qdesc->hdwq = idx; |
| 8920 | qdesc->chann = cpu; |
| 8921 | phba->sli4_hba.hdwq[idx].io_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8922 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 8923 | return 0; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8924 | } |
| 8925 | |
| 8926 | /** |
| 8927 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
| 8928 | * @phba: pointer to lpfc hba data structure. |
| 8929 | * |
| 8930 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
| 8931 | * operation. For each SLI4 queue type, the parameters such as queue entry |
| 8932 | * count (queue depth) shall be taken from the module parameter. For now, |
| 8933 | * we just use some constant number as place holder. |
| 8934 | * |
| 8935 | * Return codes |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 8936 | * 0 - successful |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8937 | * -ENOMEM - No availble memory |
| 8938 | * -EIO - The mailbox failed to complete successfully. |
| 8939 | **/ |
| 8940 | int |
| 8941 | lpfc_sli4_queue_create(struct lpfc_hba *phba) |
| 8942 | { |
| 8943 | struct lpfc_queue *qdesc; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8944 | int idx, cpu, eqcpu; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8945 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 8946 | struct lpfc_vector_map_info *cpup; |
| 8947 | struct lpfc_vector_map_info *eqcpup; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 8948 | struct lpfc_eq_intr_info *eqi; |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8949 | |
| 8950 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8951 | * Create HBA Record arrays. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8952 | * Both NVME and FCP will share that same vectors / EQs |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 8953 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8954 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
| 8955 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; |
| 8956 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; |
| 8957 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; |
| 8958 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; |
| 8959 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8960 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
| 8961 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; |
| 8962 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; |
| 8963 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8964 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8965 | if (!phba->sli4_hba.hdwq) { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8966 | phba->sli4_hba.hdwq = kcalloc( |
| 8967 | phba->cfg_hdw_queue, sizeof(struct lpfc_sli4_hdw_queue), |
| 8968 | GFP_KERNEL); |
| 8969 | if (!phba->sli4_hba.hdwq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 8970 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8971 | "6427 Failed allocate memory for " |
| 8972 | "fast-path Hardware Queue array\n"); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8973 | goto out_error; |
| 8974 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8975 | /* Prepare hardware queues to take IO buffers */ |
| 8976 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 8977 | qp = &phba->sli4_hba.hdwq[idx]; |
| 8978 | spin_lock_init(&qp->io_buf_list_get_lock); |
| 8979 | spin_lock_init(&qp->io_buf_list_put_lock); |
| 8980 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_get); |
| 8981 | INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put); |
| 8982 | qp->get_io_bufs = 0; |
| 8983 | qp->put_io_bufs = 0; |
| 8984 | qp->total_io_bufs = 0; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 8985 | spin_lock_init(&qp->abts_io_buf_list_lock); |
| 8986 | INIT_LIST_HEAD(&qp->lpfc_abts_io_buf_list); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8987 | qp->abts_scsi_io_bufs = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 8988 | qp->abts_nvme_io_bufs = 0; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 8989 | INIT_LIST_HEAD(&qp->sgl_list); |
| 8990 | INIT_LIST_HEAD(&qp->cmd_rsp_buf_list); |
| 8991 | spin_lock_init(&qp->hdwq_lock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 8992 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 8993 | } |
| 8994 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 8995 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 8996 | if (phba->nvmet_support) { |
| 8997 | phba->sli4_hba.nvmet_cqset = kcalloc( |
| 8998 | phba->cfg_nvmet_mrq, |
| 8999 | sizeof(struct lpfc_queue *), |
| 9000 | GFP_KERNEL); |
| 9001 | if (!phba->sli4_hba.nvmet_cqset) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9002 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9003 | "3121 Fail allocate memory for " |
| 9004 | "fast-path CQ set array\n"); |
| 9005 | goto out_error; |
| 9006 | } |
| 9007 | phba->sli4_hba.nvmet_mrq_hdr = kcalloc( |
| 9008 | phba->cfg_nvmet_mrq, |
| 9009 | sizeof(struct lpfc_queue *), |
| 9010 | GFP_KERNEL); |
| 9011 | if (!phba->sli4_hba.nvmet_mrq_hdr) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9012 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9013 | "3122 Fail allocate memory for " |
| 9014 | "fast-path RQ set hdr array\n"); |
| 9015 | goto out_error; |
| 9016 | } |
| 9017 | phba->sli4_hba.nvmet_mrq_data = kcalloc( |
| 9018 | phba->cfg_nvmet_mrq, |
| 9019 | sizeof(struct lpfc_queue *), |
| 9020 | GFP_KERNEL); |
| 9021 | if (!phba->sli4_hba.nvmet_mrq_data) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9022 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9023 | "3124 Fail allocate memory for " |
| 9024 | "fast-path RQ set data array\n"); |
| 9025 | goto out_error; |
| 9026 | } |
| 9027 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9028 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9029 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9030 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9031 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9032 | /* Create HBA Event Queues (EQs) */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9033 | for_each_present_cpu(cpu) { |
| 9034 | /* We only want to create 1 EQ per vector, even though |
| 9035 | * multiple CPUs might be using that vector. so only |
| 9036 | * selects the CPUs that are LPFC_CPU_FIRST_IRQ. |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9037 | */ |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9038 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9039 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9040 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9041 | |
| 9042 | /* Get a ptr to the Hardware Queue associated with this CPU */ |
| 9043 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 9044 | |
| 9045 | /* Allocate an EQ */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9046 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9047 | phba->sli4_hba.eq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9048 | phba->sli4_hba.eq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9049 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9050 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9051 | "0497 Failed allocate EQ (%d)\n", |
| 9052 | cpup->hdwq); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9053 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9054 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9055 | qdesc->qe_valid = 1; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9056 | qdesc->hdwq = cpup->hdwq; |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 9057 | qdesc->chann = cpu; /* First CPU this EQ is affinitized to */ |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 9058 | qdesc->last_cpu = qdesc->chann; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9059 | |
| 9060 | /* Save the allocated EQ in the Hardware Queue */ |
| 9061 | qp->hba_eq = qdesc; |
| 9062 | |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 9063 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, qdesc->last_cpu); |
| 9064 | list_add(&qdesc->cpu_list, &eqi->list); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9065 | } |
| 9066 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9067 | /* Now we need to populate the other Hardware Queues, that share |
| 9068 | * an IRQ vector, with the associated EQ ptr. |
| 9069 | */ |
| 9070 | for_each_present_cpu(cpu) { |
| 9071 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9072 | |
| 9073 | /* Check for EQ already allocated in previous loop */ |
| 9074 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 9075 | continue; |
| 9076 | |
| 9077 | /* Check for multiple CPUs per hdwq */ |
| 9078 | qp = &phba->sli4_hba.hdwq[cpup->hdwq]; |
| 9079 | if (qp->hba_eq) |
| 9080 | continue; |
| 9081 | |
| 9082 | /* We need to share an EQ for this hdwq */ |
| 9083 | eqcpu = lpfc_find_cpu_handle(phba, cpup->eq, LPFC_FIND_BY_EQ); |
| 9084 | eqcpup = &phba->sli4_hba.cpu_map[eqcpu]; |
| 9085 | qp->hba_eq = phba->sli4_hba.hdwq[eqcpup->hdwq].hba_eq; |
| 9086 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9087 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9088 | /* Allocate IO Path SLI4 CQ/WQs */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9089 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9090 | if (lpfc_alloc_io_wq_cq(phba, idx)) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9091 | goto out_error; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9092 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9093 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9094 | if (phba->nvmet_support) { |
| 9095 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
| 9096 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 9097 | LPFC_FIND_BY_HDWQ); |
| 9098 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9099 | LPFC_DEFAULT_PAGE_SIZE, |
| 9100 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9101 | phba->sli4_hba.cq_ecount, |
| 9102 | cpu); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9103 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9104 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9105 | "3142 Failed allocate NVME " |
| 9106 | "CQ Set (%d)\n", idx); |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9107 | goto out_error; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9108 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9109 | qdesc->qe_valid = 1; |
| 9110 | qdesc->hdwq = idx; |
| 9111 | qdesc->chann = cpu; |
| 9112 | phba->sli4_hba.nvmet_cqset[idx] = qdesc; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9113 | } |
| 9114 | } |
| 9115 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9116 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9117 | * Create Slow Path Completion Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9118 | */ |
| 9119 | |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9120 | cpu = lpfc_find_cpu_handle(phba, 0, LPFC_FIND_BY_EQ); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9121 | /* Create slow-path Mailbox Command Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9122 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9123 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9124 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9125 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9126 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9127 | "0500 Failed allocate slow-path mailbox CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9128 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9129 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9130 | qdesc->qe_valid = 1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9131 | phba->sli4_hba.mbx_cq = qdesc; |
| 9132 | |
| 9133 | /* Create slow-path ELS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9134 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9135 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9136 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9137 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9138 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9139 | "0501 Failed allocate slow-path ELS CQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9140 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9141 | } |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9142 | qdesc->qe_valid = 1; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9143 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9144 | phba->sli4_hba.els_cq = qdesc; |
| 9145 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9146 | |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9147 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9148 | * Create Slow Path Work Queues (WQs) |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9149 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9150 | |
| 9151 | /* Create Mailbox Command Queue */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9152 | |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9153 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9154 | phba->sli4_hba.mq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9155 | phba->sli4_hba.mq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9156 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9157 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9158 | "0505 Failed allocate slow-path MQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9159 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9160 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9161 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9162 | phba->sli4_hba.mbx_wq = qdesc; |
| 9163 | |
| 9164 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9165 | * Create ELS Work Queues |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9166 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9167 | |
| 9168 | /* Create slow-path ELS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9169 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9170 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9171 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9172 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9173 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9174 | "0504 Failed allocate slow-path ELS WQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9175 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9176 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9177 | qdesc->chann = cpu; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9178 | phba->sli4_hba.els_wq = qdesc; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9179 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9180 | |
| 9181 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9182 | /* Create NVME LS Complete Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9183 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9184 | phba->sli4_hba.cq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9185 | phba->sli4_hba.cq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9186 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9187 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9188 | "6079 Failed allocate NVME LS CQ\n"); |
| 9189 | goto out_error; |
| 9190 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9191 | qdesc->chann = cpu; |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 9192 | qdesc->qe_valid = 1; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9193 | phba->sli4_hba.nvmels_cq = qdesc; |
| 9194 | |
| 9195 | /* Create NVME LS Work Queue */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9196 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9197 | phba->sli4_hba.wq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9198 | phba->sli4_hba.wq_ecount, cpu); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9199 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9200 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9201 | "6080 Failed allocate NVME LS WQ\n"); |
| 9202 | goto out_error; |
| 9203 | } |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9204 | qdesc->chann = cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9205 | phba->sli4_hba.nvmels_wq = qdesc; |
| 9206 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
| 9207 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9208 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9209 | /* |
| 9210 | * Create Receive Queue (RQ) |
| 9211 | */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9212 | |
| 9213 | /* Create Receive Queue for header */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9214 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9215 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9216 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9217 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9218 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9219 | "0506 Failed allocate receive HRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9220 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9221 | } |
| 9222 | phba->sli4_hba.hdr_rq = qdesc; |
| 9223 | |
| 9224 | /* Create Receive Queue for data */ |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9225 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_DEFAULT_PAGE_SIZE, |
| 9226 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9227 | phba->sli4_hba.rq_ecount, cpu); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9228 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9229 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9230 | "0507 Failed allocate receive DRQ\n"); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9231 | goto out_error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9232 | } |
| 9233 | phba->sli4_hba.dat_rq = qdesc; |
| 9234 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9235 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && |
| 9236 | phba->nvmet_support) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9237 | for (idx = 0; idx < phba->cfg_nvmet_mrq; idx++) { |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9238 | cpu = lpfc_find_cpu_handle(phba, idx, |
| 9239 | LPFC_FIND_BY_HDWQ); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9240 | /* Create NVMET Receive Queue for header */ |
| 9241 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9242 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9243 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9244 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9245 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9246 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9247 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9248 | "3146 Failed allocate " |
| 9249 | "receive HRQ\n"); |
| 9250 | goto out_error; |
| 9251 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9252 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9253 | phba->sli4_hba.nvmet_mrq_hdr[idx] = qdesc; |
| 9254 | |
| 9255 | /* Only needed for header of RQ pair */ |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9256 | qdesc->rqbp = kzalloc_node(sizeof(*qdesc->rqbp), |
| 9257 | GFP_KERNEL, |
| 9258 | cpu_to_node(cpu)); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9259 | if (qdesc->rqbp == NULL) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9260 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9261 | "6131 Failed allocate " |
| 9262 | "Header RQBP\n"); |
| 9263 | goto out_error; |
| 9264 | } |
| 9265 | |
Dick Kennedy | 4b40d02 | 2017-08-23 16:55:38 -0700 | [diff] [blame] | 9266 | /* Put list in known state in case driver load fails. */ |
| 9267 | INIT_LIST_HEAD(&qdesc->rqbp->rqb_buffer_list); |
| 9268 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9269 | /* Create NVMET Receive Queue for data */ |
| 9270 | qdesc = lpfc_sli4_queue_alloc(phba, |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9271 | LPFC_DEFAULT_PAGE_SIZE, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9272 | phba->sli4_hba.rq_esize, |
James Smart | c1a21eb | 2019-03-12 16:30:29 -0700 | [diff] [blame] | 9273 | LPFC_NVMET_RQE_DEF_COUNT, |
| 9274 | cpu); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9275 | if (!qdesc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9276 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9277 | "3156 Failed allocate " |
| 9278 | "receive DRQ\n"); |
| 9279 | goto out_error; |
| 9280 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 9281 | qdesc->hdwq = idx; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9282 | phba->sli4_hba.nvmet_mrq_data[idx] = qdesc; |
| 9283 | } |
| 9284 | } |
| 9285 | |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9286 | /* Clear NVME stats */ |
| 9287 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 9288 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9289 | memset(&phba->sli4_hba.hdwq[idx].nvme_cstat, 0, |
| 9290 | sizeof(phba->sli4_hba.hdwq[idx].nvme_cstat)); |
| 9291 | } |
| 9292 | } |
James Smart | 4c47efc | 2019-01-28 11:14:25 -0800 | [diff] [blame] | 9293 | |
| 9294 | /* Clear SCSI stats */ |
| 9295 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
| 9296 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9297 | memset(&phba->sli4_hba.hdwq[idx].scsi_cstat, 0, |
| 9298 | sizeof(phba->sli4_hba.hdwq[idx].scsi_cstat)); |
| 9299 | } |
| 9300 | } |
| 9301 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9302 | return 0; |
| 9303 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9304 | out_error: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9305 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9306 | return -ENOMEM; |
| 9307 | } |
| 9308 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9309 | static inline void |
| 9310 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) |
| 9311 | { |
| 9312 | if (*qp != NULL) { |
| 9313 | lpfc_sli4_queue_free(*qp); |
| 9314 | *qp = NULL; |
| 9315 | } |
| 9316 | } |
| 9317 | |
| 9318 | static inline void |
| 9319 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) |
| 9320 | { |
| 9321 | int idx; |
| 9322 | |
| 9323 | if (*qs == NULL) |
| 9324 | return; |
| 9325 | |
| 9326 | for (idx = 0; idx < max; idx++) |
| 9327 | __lpfc_sli4_release_queue(&(*qs)[idx]); |
| 9328 | |
| 9329 | kfree(*qs); |
| 9330 | *qs = NULL; |
| 9331 | } |
| 9332 | |
| 9333 | static inline void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9334 | lpfc_sli4_release_hdwq(struct lpfc_hba *phba) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9335 | { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9336 | struct lpfc_sli4_hdw_queue *hdwq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9337 | struct lpfc_queue *eq; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9338 | uint32_t idx; |
| 9339 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9340 | hdwq = phba->sli4_hba.hdwq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9341 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9342 | /* Loop thru all Hardware Queues */ |
| 9343 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 9344 | /* Free the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9345 | lpfc_sli4_queue_free(hdwq[idx].io_cq); |
| 9346 | lpfc_sli4_queue_free(hdwq[idx].io_wq); |
James Smart | 821bc88 | 2020-01-27 16:23:05 -0800 | [diff] [blame] | 9347 | hdwq[idx].hba_eq = NULL; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9348 | hdwq[idx].io_cq = NULL; |
| 9349 | hdwq[idx].io_wq = NULL; |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 9350 | if (phba->cfg_xpsgl && !phba->nvmet_support) |
| 9351 | lpfc_free_sgl_per_hdwq(phba, &hdwq[idx]); |
| 9352 | lpfc_free_cmd_rsp_buf_per_hdwq(phba, &hdwq[idx]); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9353 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9354 | /* Loop thru all IRQ vectors */ |
| 9355 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 9356 | /* Free the EQ corresponding to the IRQ vector */ |
| 9357 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 9358 | lpfc_sli4_queue_free(eq); |
| 9359 | phba->sli4_hba.hba_eq_hdl[idx].eq = NULL; |
| 9360 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9361 | } |
| 9362 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9363 | /** |
| 9364 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues |
| 9365 | * @phba: pointer to lpfc hba data structure. |
| 9366 | * |
| 9367 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA |
| 9368 | * operation. |
| 9369 | * |
| 9370 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9371 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9372 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9373 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9374 | **/ |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 9375 | void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9376 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
| 9377 | { |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9378 | /* |
| 9379 | * Set FREE_INIT before beginning to free the queues. |
| 9380 | * Wait until the users of queues to acknowledge to |
| 9381 | * release queues by clearing FREE_WAIT. |
| 9382 | */ |
| 9383 | spin_lock_irq(&phba->hbalock); |
| 9384 | phba->sli.sli_flag |= LPFC_QUEUE_FREE_INIT; |
| 9385 | while (phba->sli.sli_flag & LPFC_QUEUE_FREE_WAIT) { |
| 9386 | spin_unlock_irq(&phba->hbalock); |
| 9387 | msleep(20); |
| 9388 | spin_lock_irq(&phba->hbalock); |
| 9389 | } |
| 9390 | spin_unlock_irq(&phba->hbalock); |
| 9391 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 9392 | lpfc_sli4_cleanup_poll_list(phba); |
| 9393 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9394 | /* Release HBA eqs */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9395 | if (phba->sli4_hba.hdwq) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9396 | lpfc_sli4_release_hdwq(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9397 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9398 | if (phba->nvmet_support) { |
| 9399 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_cqset, |
| 9400 | phba->cfg_nvmet_mrq); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9401 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9402 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_hdr, |
| 9403 | phba->cfg_nvmet_mrq); |
| 9404 | lpfc_sli4_release_queues(&phba->sli4_hba.nvmet_mrq_data, |
| 9405 | phba->cfg_nvmet_mrq); |
| 9406 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9407 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9408 | /* Release mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9409 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9410 | |
| 9411 | /* Release ELS work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9412 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); |
| 9413 | |
| 9414 | /* Release ELS work queue */ |
| 9415 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9416 | |
| 9417 | /* Release unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9418 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); |
| 9419 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9420 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9421 | /* Release ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9422 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); |
| 9423 | |
| 9424 | /* Release NVME LS complete queue */ |
| 9425 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9426 | |
| 9427 | /* Release mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9428 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); |
| 9429 | |
| 9430 | /* Everything on this list has been freed */ |
| 9431 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
James Smart | 4645f7b | 2019-03-12 16:30:14 -0700 | [diff] [blame] | 9432 | |
| 9433 | /* Done with freeing the queues */ |
| 9434 | spin_lock_irq(&phba->hbalock); |
| 9435 | phba->sli.sli_flag &= ~LPFC_QUEUE_FREE_INIT; |
| 9436 | spin_unlock_irq(&phba->hbalock); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9437 | } |
| 9438 | |
| 9439 | int |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9440 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) |
| 9441 | { |
| 9442 | struct lpfc_rqb *rqbp; |
| 9443 | struct lpfc_dmabuf *h_buf; |
| 9444 | struct rqb_dmabuf *rqb_buffer; |
| 9445 | |
| 9446 | rqbp = rq->rqbp; |
| 9447 | while (!list_empty(&rqbp->rqb_buffer_list)) { |
| 9448 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, |
| 9449 | struct lpfc_dmabuf, list); |
| 9450 | |
| 9451 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); |
| 9452 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); |
| 9453 | rqbp->buffer_count--; |
| 9454 | } |
| 9455 | return 1; |
| 9456 | } |
| 9457 | |
| 9458 | static int |
| 9459 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, |
| 9460 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, |
| 9461 | int qidx, uint32_t qtype) |
| 9462 | { |
| 9463 | struct lpfc_sli_ring *pring; |
| 9464 | int rc; |
| 9465 | |
| 9466 | if (!eq || !cq || !wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9467 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9468 | "6085 Fast-path %s (%d) not allocated\n", |
| 9469 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); |
| 9470 | return -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9471 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9472 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9473 | /* create the Cq first */ |
| 9474 | rc = lpfc_cq_create(phba, cq, eq, |
| 9475 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); |
| 9476 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9477 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 9478 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", |
| 9479 | qidx, (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9480 | return rc; |
| 9481 | } |
| 9482 | |
| 9483 | if (qtype != LPFC_MBOX) { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9484 | /* Setup cq_map for fast lookup */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9485 | if (cq_map) |
| 9486 | *cq_map = cq->queue_id; |
| 9487 | |
| 9488 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9489 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", |
| 9490 | qidx, cq->queue_id, qidx, eq->queue_id); |
| 9491 | |
| 9492 | /* create the wq */ |
| 9493 | rc = lpfc_wq_create(phba, wq, cq, qtype); |
| 9494 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9495 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c835c08 | 2019-03-12 16:30:30 -0700 | [diff] [blame] | 9496 | "4618 Fail setup fastpath WQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9497 | qidx, (uint32_t)rc); |
| 9498 | /* no need to tear down cq - caller will do so */ |
| 9499 | return rc; |
| 9500 | } |
| 9501 | |
| 9502 | /* Bind this CQ/WQ to the NVME ring */ |
| 9503 | pring = wq->pring; |
| 9504 | pring->sli.sli4.wqp = (void *)wq; |
| 9505 | cq->pring = pring; |
| 9506 | |
| 9507 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9508 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", |
| 9509 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); |
| 9510 | } else { |
| 9511 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); |
| 9512 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9513 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
| 9514 | "0539 Failed setup of slow-path MQ: " |
| 9515 | "rc = 0x%x\n", rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9516 | /* no need to tear down cq - caller will do so */ |
| 9517 | return rc; |
| 9518 | } |
| 9519 | |
| 9520 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9521 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9522 | phba->sli4_hba.mbx_wq->queue_id, |
| 9523 | phba->sli4_hba.mbx_cq->queue_id); |
| 9524 | } |
| 9525 | |
| 9526 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9527 | } |
| 9528 | |
| 9529 | /** |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9530 | * lpfc_setup_cq_lookup - Setup the CQ lookup table |
| 9531 | * @phba: pointer to lpfc hba data structure. |
| 9532 | * |
| 9533 | * This routine will populate the cq_lookup table by all |
| 9534 | * available CQ queue_id's. |
| 9535 | **/ |
Bart Van Assche | 3999df7 | 2019-03-28 11:06:16 -0700 | [diff] [blame] | 9536 | static void |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9537 | lpfc_setup_cq_lookup(struct lpfc_hba *phba) |
| 9538 | { |
| 9539 | struct lpfc_queue *eq, *childq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9540 | int qidx; |
| 9541 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9542 | memset(phba->sli4_hba.cq_lookup, 0, |
| 9543 | (sizeof(struct lpfc_queue *) * (phba->sli4_hba.cq_max + 1))); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9544 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9545 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9546 | /* Get the EQ corresponding to the IRQ vector */ |
| 9547 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9548 | if (!eq) |
| 9549 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9550 | /* Loop through all CQs associated with that EQ */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9551 | list_for_each_entry(childq, &eq->child_list, list) { |
| 9552 | if (childq->queue_id > phba->sli4_hba.cq_max) |
| 9553 | continue; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9554 | if (childq->subtype == LPFC_IO) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9555 | phba->sli4_hba.cq_lookup[childq->queue_id] = |
| 9556 | childq; |
| 9557 | } |
| 9558 | } |
| 9559 | } |
| 9560 | |
| 9561 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9562 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues |
| 9563 | * @phba: pointer to lpfc hba data structure. |
| 9564 | * |
| 9565 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA |
| 9566 | * operation. |
| 9567 | * |
| 9568 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9569 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9570 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9571 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9572 | **/ |
| 9573 | int |
| 9574 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) |
| 9575 | { |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9576 | uint32_t shdr_status, shdr_add_status; |
| 9577 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9578 | struct lpfc_vector_map_info *cpup; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9579 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9580 | LPFC_MBOXQ_t *mboxq; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9581 | int qidx, cpu; |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9582 | uint32_t length, usdelay; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9583 | int rc = -ENOMEM; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9584 | |
| 9585 | /* Check for dual-ULP support */ |
| 9586 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 9587 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9588 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9589 | "3249 Unable to allocate memory for " |
| 9590 | "QUERY_FW_CFG mailbox command\n"); |
| 9591 | return -ENOMEM; |
| 9592 | } |
| 9593 | length = (sizeof(struct lpfc_mbx_query_fw_config) - |
| 9594 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 9595 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 9596 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, |
| 9597 | length, LPFC_SLI4_MBX_EMBED); |
| 9598 | |
| 9599 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 9600 | |
| 9601 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 9602 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 9603 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 9604 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); |
| 9605 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9606 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9607 | "3250 QUERY_FW_CFG mailbox failed with status " |
| 9608 | "x%x add_status x%x, mbx status x%x\n", |
| 9609 | shdr_status, shdr_add_status, rc); |
| 9610 | if (rc != MBX_TIMEOUT) |
| 9611 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 9612 | rc = -ENXIO; |
| 9613 | goto out_error; |
| 9614 | } |
| 9615 | |
| 9616 | phba->sli4_hba.fw_func_mode = |
| 9617 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; |
| 9618 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; |
| 9619 | 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] | 9620 | phba->sli4_hba.physical_port = |
| 9621 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; |
James Smart | 962bc51 | 2013-01-03 15:44:00 -0500 | [diff] [blame] | 9622 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9623 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " |
| 9624 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, |
| 9625 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); |
| 9626 | |
| 9627 | if (rc != MBX_TIMEOUT) |
| 9628 | mempool_free(mboxq, phba->mbox_mem_pool); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9629 | |
| 9630 | /* |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9631 | * Set up HBA Event Queues (EQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9632 | */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9633 | qp = phba->sli4_hba.hdwq; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9634 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9635 | /* Set up HBA event queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9636 | if (!qp) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9637 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9638 | "3147 Fast-path EQs not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9639 | rc = -ENOMEM; |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9640 | goto out_error; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 9641 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9642 | |
| 9643 | /* Loop thru all IRQ vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9644 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9645 | /* Create HBA Event Queues (EQs) in order */ |
| 9646 | for_each_present_cpu(cpu) { |
| 9647 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9648 | |
| 9649 | /* Look for the CPU thats using that vector with |
| 9650 | * LPFC_CPU_FIRST_IRQ set. |
| 9651 | */ |
| 9652 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 9653 | continue; |
| 9654 | if (qidx != cpup->eq) |
| 9655 | continue; |
| 9656 | |
| 9657 | /* Create an EQ for that vector */ |
| 9658 | rc = lpfc_eq_create(phba, qp[cpup->hdwq].hba_eq, |
| 9659 | phba->cfg_fcp_imax); |
| 9660 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9661 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9662 | "0523 Failed setup of fast-path" |
| 9663 | " EQ (%d), rc = 0x%x\n", |
| 9664 | cpup->eq, (uint32_t)rc); |
| 9665 | goto out_destroy; |
| 9666 | } |
| 9667 | |
| 9668 | /* Save the EQ for that vector in the hba_eq_hdl */ |
| 9669 | phba->sli4_hba.hba_eq_hdl[cpup->eq].eq = |
| 9670 | qp[cpup->hdwq].hba_eq; |
| 9671 | |
| 9672 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9673 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
| 9674 | cpup->eq, |
| 9675 | qp[cpup->hdwq].hba_eq->queue_id); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9676 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9677 | } |
| 9678 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9679 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9680 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9681 | cpu = lpfc_find_cpu_handle(phba, qidx, LPFC_FIND_BY_HDWQ); |
| 9682 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 9683 | |
| 9684 | /* Create the CQ/WQ corresponding to the Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9685 | rc = lpfc_create_wq_cq(phba, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9686 | phba->sli4_hba.hdwq[cpup->hdwq].hba_eq, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9687 | qp[qidx].io_cq, |
| 9688 | qp[qidx].io_wq, |
| 9689 | &phba->sli4_hba.hdwq[qidx].io_cq_map, |
| 9690 | qidx, |
| 9691 | LPFC_IO); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9692 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9693 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9694 | "0535 Failed to setup fastpath " |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9695 | "IO WQ/CQ (%d), rc = 0x%x\n", |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9696 | qidx, (uint32_t)rc); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9697 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9698 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 9699 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9700 | |
| 9701 | /* |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9702 | * Set up Slow Path Complete Queues (CQs) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9703 | */ |
| 9704 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9705 | /* Set up slow-path MBOX CQ/MQ */ |
| 9706 | |
| 9707 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9708 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9709 | "0528 %s not allocated\n", |
| 9710 | phba->sli4_hba.mbx_cq ? |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9711 | "Mailbox WQ" : "Mailbox CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9712 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9713 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9714 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9715 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9716 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 9717 | phba->sli4_hba.mbx_cq, |
| 9718 | phba->sli4_hba.mbx_wq, |
| 9719 | NULL, 0, LPFC_MBOX); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9720 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9721 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9722 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
| 9723 | (uint32_t)rc); |
| 9724 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9725 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9726 | if (phba->nvmet_support) { |
| 9727 | if (!phba->sli4_hba.nvmet_cqset) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9728 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9729 | "3165 Fast-path NVME CQ Set " |
| 9730 | "array not allocated\n"); |
| 9731 | rc = -ENOMEM; |
| 9732 | goto out_destroy; |
| 9733 | } |
| 9734 | if (phba->cfg_nvmet_mrq > 1) { |
| 9735 | rc = lpfc_cq_create_set(phba, |
| 9736 | phba->sli4_hba.nvmet_cqset, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9737 | qp, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9738 | LPFC_WCQ, LPFC_NVMET); |
| 9739 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9740 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9741 | "3164 Failed setup of NVME CQ " |
| 9742 | "Set, rc = 0x%x\n", |
| 9743 | (uint32_t)rc); |
| 9744 | goto out_destroy; |
| 9745 | } |
| 9746 | } else { |
| 9747 | /* Set up NVMET Receive Complete Queue */ |
| 9748 | rc = lpfc_cq_create(phba, phba->sli4_hba.nvmet_cqset[0], |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9749 | qp[0].hba_eq, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9750 | LPFC_WCQ, LPFC_NVMET); |
| 9751 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9752 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9753 | "6089 Failed setup NVMET CQ: " |
| 9754 | "rc = 0x%x\n", (uint32_t)rc); |
| 9755 | goto out_destroy; |
| 9756 | } |
James Smart | 81b96ed | 2017-11-20 16:00:29 -0800 | [diff] [blame] | 9757 | phba->sli4_hba.nvmet_cqset[0]->chann = 0; |
| 9758 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9759 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9760 | "6090 NVMET CQ setup: cq-id=%d, " |
| 9761 | "parent eq-id=%d\n", |
| 9762 | phba->sli4_hba.nvmet_cqset[0]->queue_id, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9763 | qp[0].hba_eq->queue_id); |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9764 | } |
| 9765 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9766 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9767 | /* Set up slow-path ELS WQ/CQ */ |
| 9768 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9769 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9770 | "0530 ELS %s not allocated\n", |
| 9771 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9772 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9773 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9774 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9775 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9776 | phba->sli4_hba.els_cq, |
| 9777 | phba->sli4_hba.els_wq, |
| 9778 | NULL, 0, LPFC_ELS); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9779 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9780 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9781 | "0525 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
| 9782 | (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9783 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9784 | } |
| 9785 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9786 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", |
| 9787 | phba->sli4_hba.els_wq->queue_id, |
| 9788 | phba->sli4_hba.els_cq->queue_id); |
| 9789 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9790 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9791 | /* Set up NVME LS Complete Queue */ |
| 9792 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9793 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9794 | "6091 LS %s not allocated\n", |
| 9795 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); |
| 9796 | rc = -ENOMEM; |
| 9797 | goto out_destroy; |
| 9798 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9799 | rc = lpfc_create_wq_cq(phba, qp[0].hba_eq, |
| 9800 | phba->sli4_hba.nvmels_cq, |
| 9801 | phba->sli4_hba.nvmels_wq, |
| 9802 | NULL, 0, LPFC_NVME_LS); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9803 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9804 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9805 | "0526 Failed setup of NVVME LS WQ/CQ: " |
| 9806 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9807 | goto out_destroy; |
| 9808 | } |
| 9809 | |
| 9810 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9811 | "6096 ELS WQ setup: wq-id=%d, " |
| 9812 | "parent cq-id=%d\n", |
| 9813 | phba->sli4_hba.nvmels_wq->queue_id, |
| 9814 | phba->sli4_hba.nvmels_cq->queue_id); |
| 9815 | } |
| 9816 | |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9817 | /* |
| 9818 | * Create NVMET Receive Queue (RQ) |
| 9819 | */ |
| 9820 | if (phba->nvmet_support) { |
| 9821 | if ((!phba->sli4_hba.nvmet_cqset) || |
| 9822 | (!phba->sli4_hba.nvmet_mrq_hdr) || |
| 9823 | (!phba->sli4_hba.nvmet_mrq_data)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9824 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9825 | "6130 MRQ CQ Queues not " |
| 9826 | "allocated\n"); |
| 9827 | rc = -ENOMEM; |
| 9828 | goto out_destroy; |
| 9829 | } |
| 9830 | if (phba->cfg_nvmet_mrq > 1) { |
| 9831 | rc = lpfc_mrq_create(phba, |
| 9832 | phba->sli4_hba.nvmet_mrq_hdr, |
| 9833 | phba->sli4_hba.nvmet_mrq_data, |
| 9834 | phba->sli4_hba.nvmet_cqset, |
| 9835 | LPFC_NVMET); |
| 9836 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9837 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9838 | "6098 Failed setup of NVMET " |
| 9839 | "MRQ: rc = 0x%x\n", |
| 9840 | (uint32_t)rc); |
| 9841 | goto out_destroy; |
| 9842 | } |
| 9843 | |
| 9844 | } else { |
| 9845 | rc = lpfc_rq_create(phba, |
| 9846 | phba->sli4_hba.nvmet_mrq_hdr[0], |
| 9847 | phba->sli4_hba.nvmet_mrq_data[0], |
| 9848 | phba->sli4_hba.nvmet_cqset[0], |
| 9849 | LPFC_NVMET); |
| 9850 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9851 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9852 | "6057 Failed setup of NVMET " |
| 9853 | "Receive Queue: rc = 0x%x\n", |
| 9854 | (uint32_t)rc); |
| 9855 | goto out_destroy; |
| 9856 | } |
| 9857 | |
| 9858 | lpfc_printf_log( |
| 9859 | phba, KERN_INFO, LOG_INIT, |
| 9860 | "6099 NVMET RQ setup: hdr-rq-id=%d, " |
| 9861 | "dat-rq-id=%d parent cq-id=%d\n", |
| 9862 | phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id, |
| 9863 | phba->sli4_hba.nvmet_mrq_data[0]->queue_id, |
| 9864 | phba->sli4_hba.nvmet_cqset[0]->queue_id); |
| 9865 | |
| 9866 | } |
| 9867 | } |
| 9868 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9869 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9870 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9871 | "0540 Receive Queue not allocated\n"); |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 9872 | rc = -ENOMEM; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9873 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9874 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9875 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9876 | 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] | 9877 | phba->sli4_hba.els_cq, LPFC_USOL); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9878 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9879 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9880 | "0541 Failed setup of Receive Queue: " |
James Smart | a2fc4aef | 2014-09-03 12:57:55 -0400 | [diff] [blame] | 9881 | "rc = 0x%x\n", (uint32_t)rc); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9882 | goto out_destroy; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9883 | } |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 9884 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9885 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 9886 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " |
| 9887 | "parent cq-id=%d\n", |
| 9888 | phba->sli4_hba.hdr_rq->queue_id, |
| 9889 | phba->sli4_hba.dat_rq->queue_id, |
James Smart | 4d9ab99 | 2009-10-02 15:16:39 -0400 | [diff] [blame] | 9890 | phba->sli4_hba.els_cq->queue_id); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9891 | |
James Smart | cb733e3 | 2019-01-28 11:14:32 -0800 | [diff] [blame] | 9892 | if (phba->cfg_fcp_imax) |
| 9893 | usdelay = LPFC_SEC_TO_USEC / phba->cfg_fcp_imax; |
| 9894 | else |
| 9895 | usdelay = 0; |
| 9896 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9897 | for (qidx = 0; qidx < phba->cfg_irq_chann; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9898 | qidx += LPFC_MAX_EQ_DELAY_EQID_CNT) |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 9899 | 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] | 9900 | usdelay); |
James Smart | 43140ca | 2017-03-04 09:30:34 -0800 | [diff] [blame] | 9901 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9902 | if (phba->sli4_hba.cq_max) { |
| 9903 | kfree(phba->sli4_hba.cq_lookup); |
| 9904 | phba->sli4_hba.cq_lookup = kcalloc((phba->sli4_hba.cq_max + 1), |
| 9905 | sizeof(struct lpfc_queue *), GFP_KERNEL); |
| 9906 | if (!phba->sli4_hba.cq_lookup) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 9907 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9908 | "0549 Failed setup of CQ Lookup table: " |
| 9909 | "size 0x%x\n", phba->sli4_hba.cq_max); |
Dan Carpenter | fad28e3 | 2019-02-11 21:43:00 +0300 | [diff] [blame] | 9910 | rc = -ENOMEM; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9911 | goto out_destroy; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9912 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 9913 | lpfc_setup_cq_lookup(phba); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 9914 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9915 | return 0; |
| 9916 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9917 | out_destroy: |
| 9918 | lpfc_sli4_queue_unset(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9919 | out_error: |
| 9920 | return rc; |
| 9921 | } |
| 9922 | |
| 9923 | /** |
| 9924 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues |
| 9925 | * @phba: pointer to lpfc hba data structure. |
| 9926 | * |
| 9927 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA |
| 9928 | * operation. |
| 9929 | * |
| 9930 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 9931 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 9932 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 9933 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9934 | **/ |
| 9935 | void |
| 9936 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) |
| 9937 | { |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9938 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9939 | struct lpfc_queue *eq; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9940 | int qidx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9941 | |
| 9942 | /* Unset mailbox command work queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9943 | if (phba->sli4_hba.mbx_wq) |
| 9944 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); |
| 9945 | |
| 9946 | /* Unset NVME LS work queue */ |
| 9947 | if (phba->sli4_hba.nvmels_wq) |
| 9948 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); |
| 9949 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9950 | /* Unset ELS work queue */ |
Colin Ian King | 019c0d6 | 2017-05-06 23:13:55 +0100 | [diff] [blame] | 9951 | if (phba->sli4_hba.els_wq) |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9952 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
| 9953 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9954 | /* Unset unsolicited receive queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9955 | if (phba->sli4_hba.hdr_rq) |
| 9956 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, |
| 9957 | phba->sli4_hba.dat_rq); |
| 9958 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9959 | /* Unset mailbox command complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9960 | if (phba->sli4_hba.mbx_cq) |
| 9961 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); |
| 9962 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 9963 | /* Unset ELS complete queue */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 9964 | if (phba->sli4_hba.els_cq) |
| 9965 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
| 9966 | |
| 9967 | /* Unset NVME LS complete queue */ |
| 9968 | if (phba->sli4_hba.nvmels_cq) |
| 9969 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); |
| 9970 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9971 | if (phba->nvmet_support) { |
| 9972 | /* Unset NVMET MRQ queue */ |
| 9973 | if (phba->sli4_hba.nvmet_mrq_hdr) { |
| 9974 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9975 | lpfc_rq_destroy( |
| 9976 | phba, |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9977 | phba->sli4_hba.nvmet_mrq_hdr[qidx], |
| 9978 | phba->sli4_hba.nvmet_mrq_data[qidx]); |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9979 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9980 | |
James Smart | bcb24f6 | 2017-11-20 16:00:36 -0800 | [diff] [blame] | 9981 | /* Unset NVMET CQ Set complete queue */ |
| 9982 | if (phba->sli4_hba.nvmet_cqset) { |
| 9983 | for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) |
| 9984 | lpfc_cq_destroy( |
| 9985 | phba, phba->sli4_hba.nvmet_cqset[qidx]); |
| 9986 | } |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 9987 | } |
| 9988 | |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9989 | /* Unset fast-path SLI4 queues */ |
| 9990 | if (phba->sli4_hba.hdwq) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9991 | /* Loop thru all Hardware Queues */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9992 | for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) { |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9993 | /* Destroy the CQ/WQ corresponding to Hardware Queue */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 9994 | qp = &phba->sli4_hba.hdwq[qidx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 9995 | lpfc_wq_destroy(phba, qp->io_wq); |
| 9996 | lpfc_cq_destroy(phba, qp->io_cq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 9997 | } |
| 9998 | /* Loop thru all IRQ vectors */ |
| 9999 | for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) { |
| 10000 | /* Destroy the EQ corresponding to the IRQ vector */ |
| 10001 | eq = phba->sli4_hba.hba_eq_hdl[qidx].eq; |
| 10002 | lpfc_eq_destroy(phba, eq); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 10003 | } |
| 10004 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10005 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10006 | kfree(phba->sli4_hba.cq_lookup); |
| 10007 | phba->sli4_hba.cq_lookup = NULL; |
| 10008 | phba->sli4_hba.cq_max = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10009 | } |
| 10010 | |
| 10011 | /** |
| 10012 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool |
| 10013 | * @phba: pointer to lpfc hba data structure. |
| 10014 | * |
| 10015 | * This routine is invoked to allocate and set up a pool of completion queue |
| 10016 | * events. The body of the completion queue event is a completion queue entry |
| 10017 | * CQE. For now, this pool is used for the interrupt service routine to queue |
| 10018 | * the following HBA completion queue events for the worker thread to process: |
| 10019 | * - Mailbox asynchronous events |
| 10020 | * - Receive queue completion unsolicited events |
| 10021 | * Later, this can be used for all the slow-path events. |
| 10022 | * |
| 10023 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10024 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10025 | * -ENOMEM - No available memory |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10026 | **/ |
| 10027 | static int |
| 10028 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) |
| 10029 | { |
| 10030 | struct lpfc_cq_event *cq_event; |
| 10031 | int i; |
| 10032 | |
| 10033 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { |
| 10034 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); |
| 10035 | if (!cq_event) |
| 10036 | goto out_pool_create_fail; |
| 10037 | list_add_tail(&cq_event->list, |
| 10038 | &phba->sli4_hba.sp_cqe_event_pool); |
| 10039 | } |
| 10040 | return 0; |
| 10041 | |
| 10042 | out_pool_create_fail: |
| 10043 | lpfc_sli4_cq_event_pool_destroy(phba); |
| 10044 | return -ENOMEM; |
| 10045 | } |
| 10046 | |
| 10047 | /** |
| 10048 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool |
| 10049 | * @phba: pointer to lpfc hba data structure. |
| 10050 | * |
| 10051 | * This routine is invoked to free the pool of completion queue events at |
| 10052 | * driver unload time. Note that, it is the responsibility of the driver |
| 10053 | * cleanup routine to free all the outstanding completion-queue events |
| 10054 | * allocated from this pool back into the pool before invoking this routine |
| 10055 | * to destroy the pool. |
| 10056 | **/ |
| 10057 | static void |
| 10058 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) |
| 10059 | { |
| 10060 | struct lpfc_cq_event *cq_event, *next_cq_event; |
| 10061 | |
| 10062 | list_for_each_entry_safe(cq_event, next_cq_event, |
| 10063 | &phba->sli4_hba.sp_cqe_event_pool, list) { |
| 10064 | list_del(&cq_event->list); |
| 10065 | kfree(cq_event); |
| 10066 | } |
| 10067 | } |
| 10068 | |
| 10069 | /** |
| 10070 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 10071 | * @phba: pointer to lpfc hba data structure. |
| 10072 | * |
| 10073 | * This routine is the lock free version of the API invoked to allocate a |
| 10074 | * completion-queue event from the free pool. |
| 10075 | * |
| 10076 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 10077 | * NULL otherwise. |
| 10078 | **/ |
| 10079 | struct lpfc_cq_event * |
| 10080 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 10081 | { |
| 10082 | struct lpfc_cq_event *cq_event = NULL; |
| 10083 | |
| 10084 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, |
| 10085 | struct lpfc_cq_event, list); |
| 10086 | return cq_event; |
| 10087 | } |
| 10088 | |
| 10089 | /** |
| 10090 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool |
| 10091 | * @phba: pointer to lpfc hba data structure. |
| 10092 | * |
| 10093 | * This routine is the lock version of the API invoked to allocate a |
| 10094 | * completion-queue event from the free pool. |
| 10095 | * |
| 10096 | * Return: Pointer to the newly allocated completion-queue event if successful |
| 10097 | * NULL otherwise. |
| 10098 | **/ |
| 10099 | struct lpfc_cq_event * |
| 10100 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) |
| 10101 | { |
| 10102 | struct lpfc_cq_event *cq_event; |
| 10103 | unsigned long iflags; |
| 10104 | |
| 10105 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10106 | cq_event = __lpfc_sli4_cq_event_alloc(phba); |
| 10107 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10108 | return cq_event; |
| 10109 | } |
| 10110 | |
| 10111 | /** |
| 10112 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 10113 | * @phba: pointer to lpfc hba data structure. |
| 10114 | * @cq_event: pointer to the completion queue event to be freed. |
| 10115 | * |
| 10116 | * This routine is the lock free version of the API invoked to release a |
| 10117 | * completion-queue event back into the free pool. |
| 10118 | **/ |
| 10119 | void |
| 10120 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 10121 | struct lpfc_cq_event *cq_event) |
| 10122 | { |
| 10123 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); |
| 10124 | } |
| 10125 | |
| 10126 | /** |
| 10127 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool |
| 10128 | * @phba: pointer to lpfc hba data structure. |
| 10129 | * @cq_event: pointer to the completion queue event to be freed. |
| 10130 | * |
| 10131 | * This routine is the lock version of the API invoked to release a |
| 10132 | * completion-queue event back into the free pool. |
| 10133 | **/ |
| 10134 | void |
| 10135 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, |
| 10136 | struct lpfc_cq_event *cq_event) |
| 10137 | { |
| 10138 | unsigned long iflags; |
| 10139 | spin_lock_irqsave(&phba->hbalock, iflags); |
| 10140 | __lpfc_sli4_cq_event_release(phba, cq_event); |
| 10141 | spin_unlock_irqrestore(&phba->hbalock, iflags); |
| 10142 | } |
| 10143 | |
| 10144 | /** |
| 10145 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool |
| 10146 | * @phba: pointer to lpfc hba data structure. |
| 10147 | * |
| 10148 | * This routine is to free all the pending completion-queue events to the |
| 10149 | * back into the free pool for device reset. |
| 10150 | **/ |
| 10151 | static void |
| 10152 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) |
| 10153 | { |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 10154 | LIST_HEAD(cq_event_list); |
| 10155 | struct lpfc_cq_event *cq_event; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10156 | unsigned long iflags; |
| 10157 | |
| 10158 | /* Retrieve all the pending WCQEs from pending WCQE lists */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10159 | |
James Smart | e7dab16 | 2020-10-20 13:27:12 -0700 | [diff] [blame] | 10160 | /* Pending ELS XRI abort events */ |
| 10161 | spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
| 10162 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, |
| 10163 | &cq_event_list); |
| 10164 | spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags); |
| 10165 | |
| 10166 | /* Pending asynnc events */ |
| 10167 | spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags); |
| 10168 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, |
| 10169 | &cq_event_list); |
| 10170 | spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags); |
| 10171 | |
| 10172 | while (!list_empty(&cq_event_list)) { |
| 10173 | list_remove_head(&cq_event_list, cq_event, |
| 10174 | struct lpfc_cq_event, list); |
| 10175 | lpfc_sli4_cq_event_release(phba, cq_event); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10176 | } |
| 10177 | } |
| 10178 | |
| 10179 | /** |
| 10180 | * lpfc_pci_function_reset - Reset pci function. |
| 10181 | * @phba: pointer to lpfc hba data structure. |
| 10182 | * |
| 10183 | * This routine is invoked to request a PCI function reset. It will destroys |
| 10184 | * all resources assigned to the PCI function which originates this request. |
| 10185 | * |
| 10186 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10187 | * 0 - successful |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 10188 | * -ENOMEM - No available memory |
James Smart | d439d28 | 2010-09-29 11:18:45 -0400 | [diff] [blame] | 10189 | * -EIO - The mailbox failed to complete successfully. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10190 | **/ |
| 10191 | int |
| 10192 | lpfc_pci_function_reset(struct lpfc_hba *phba) |
| 10193 | { |
| 10194 | LPFC_MBOXQ_t *mboxq; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10195 | uint32_t rc = 0, if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10196 | uint32_t shdr_status, shdr_add_status; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10197 | uint32_t rdy_chk; |
| 10198 | uint32_t port_reset = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10199 | union lpfc_sli4_cfg_shdr *shdr; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10200 | struct lpfc_register reg_data; |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10201 | uint16_t devid; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10202 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10203 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10204 | switch (if_type) { |
| 10205 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10206 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
| 10207 | GFP_KERNEL); |
| 10208 | if (!mboxq) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10209 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10210 | "0494 Unable to allocate memory for " |
| 10211 | "issuing SLI_FUNCTION_RESET mailbox " |
| 10212 | "command\n"); |
| 10213 | return -ENOMEM; |
| 10214 | } |
| 10215 | |
| 10216 | /* Setup PCI function reset mailbox-ioctl command */ |
| 10217 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 10218 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, |
| 10219 | LPFC_SLI4_MBX_EMBED); |
| 10220 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 10221 | shdr = (union lpfc_sli4_cfg_shdr *) |
| 10222 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; |
| 10223 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); |
| 10224 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, |
| 10225 | &shdr->response); |
| 10226 | if (rc != MBX_TIMEOUT) |
| 10227 | mempool_free(mboxq, phba->mbox_mem_pool); |
| 10228 | if (shdr_status || shdr_add_status || rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10229 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10230 | "0495 SLI_FUNCTION_RESET mailbox " |
| 10231 | "failed with status x%x add_status x%x," |
| 10232 | " mbx status x%x\n", |
| 10233 | shdr_status, shdr_add_status, rc); |
| 10234 | rc = -ENXIO; |
| 10235 | } |
| 10236 | break; |
| 10237 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10238 | case LPFC_SLI_INTF_IF_TYPE_6: |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10239 | wait: |
| 10240 | /* |
| 10241 | * Poll the Port Status Register and wait for RDY for |
| 10242 | * up to 30 seconds. If the port doesn't respond, treat |
| 10243 | * it as an error. |
| 10244 | */ |
James Smart | 77d093f | 2015-04-07 15:07:08 -0400 | [diff] [blame] | 10245 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10246 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
| 10247 | STATUSregaddr, ®_data.word0)) { |
| 10248 | rc = -ENODEV; |
| 10249 | goto out; |
| 10250 | } |
| 10251 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
| 10252 | break; |
| 10253 | msleep(20); |
| 10254 | } |
| 10255 | |
| 10256 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { |
| 10257 | phba->work_status[0] = readl( |
| 10258 | phba->sli4_hba.u.if_type2.ERR1regaddr); |
| 10259 | phba->work_status[1] = readl( |
| 10260 | phba->sli4_hba.u.if_type2.ERR2regaddr); |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10261 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10262 | "2890 Port not ready, port status reg " |
| 10263 | "0x%x error 1=0x%x, error 2=0x%x\n", |
| 10264 | reg_data.word0, |
| 10265 | phba->work_status[0], |
| 10266 | phba->work_status[1]); |
| 10267 | rc = -ENODEV; |
| 10268 | goto out; |
| 10269 | } |
| 10270 | |
| 10271 | if (!port_reset) { |
| 10272 | /* |
| 10273 | * Reset the port now |
| 10274 | */ |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10275 | reg_data.word0 = 0; |
| 10276 | bf_set(lpfc_sliport_ctrl_end, ®_data, |
| 10277 | LPFC_SLIPORT_LITTLE_ENDIAN); |
| 10278 | bf_set(lpfc_sliport_ctrl_ip, ®_data, |
| 10279 | LPFC_SLIPORT_INIT_PORT); |
| 10280 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. |
| 10281 | CTRLregaddr); |
James Smart | 8fcb8ac | 2012-03-01 22:35:58 -0500 | [diff] [blame] | 10282 | /* flush */ |
James Smart | 2b81f94 | 2012-03-01 22:37:18 -0500 | [diff] [blame] | 10283 | pci_read_config_word(phba->pcidev, |
| 10284 | PCI_DEVICE_ID, &devid); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10285 | |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10286 | port_reset = 1; |
| 10287 | msleep(20); |
| 10288 | goto wait; |
| 10289 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { |
| 10290 | rc = -ENODEV; |
| 10291 | goto out; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10292 | } |
| 10293 | break; |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10294 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10295 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10296 | default: |
| 10297 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10298 | } |
| 10299 | |
James Smart | 73d91e5 | 2011-10-10 21:32:10 -0400 | [diff] [blame] | 10300 | out: |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10301 | /* Catch the not-ready port failure after a port reset. */ |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10302 | if (rc) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10303 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10304 | "3317 HBA not functional: IP Reset Failed " |
James Smart | 2f6fa2c | 2014-09-03 12:57:08 -0400 | [diff] [blame] | 10305 | "try: echo fw_reset > board_mode\n"); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10306 | rc = -ENODEV; |
James Smart | 229adb0 | 2013-04-17 20:16:51 -0400 | [diff] [blame] | 10307 | } |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10308 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10309 | return rc; |
| 10310 | } |
| 10311 | |
| 10312 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10313 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. |
| 10314 | * @phba: pointer to lpfc hba data structure. |
| 10315 | * |
| 10316 | * This routine is invoked to set up the PCI device memory space for device |
| 10317 | * with SLI-4 interface spec. |
| 10318 | * |
| 10319 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10320 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10321 | * other values - error |
| 10322 | **/ |
| 10323 | static int |
| 10324 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) |
| 10325 | { |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10326 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10327 | unsigned long bar0map_len, bar1map_len, bar2map_len; |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10328 | int error; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10329 | uint32_t if_type; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10330 | |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10331 | if (!pdev) |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10332 | return -ENODEV; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10333 | |
| 10334 | /* Set the device DMA mask size */ |
Hannes Reinecke | 56de835 | 2019-02-18 08:34:19 +0100 | [diff] [blame] | 10335 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 10336 | if (error) |
| 10337 | error = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 10338 | if (error) |
Christoph Hellwig | f30e1bf | 2018-10-18 15:10:21 +0200 | [diff] [blame] | 10339 | return error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10340 | |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10341 | /* |
| 10342 | * The BARs and register set definitions and offset locations are |
| 10343 | * dependent on the if_type. |
| 10344 | */ |
| 10345 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, |
| 10346 | &phba->sli4_hba.sli_intf.word0)) { |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10347 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10348 | } |
| 10349 | |
| 10350 | /* There is no SLI3 failback for SLI4 devices. */ |
| 10351 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != |
| 10352 | LPFC_SLI_INTF_VALID) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10353 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10354 | "2894 SLI_INTF reg contents invalid " |
| 10355 | "sli_intf reg 0x%x\n", |
| 10356 | phba->sli4_hba.sli_intf.word0); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10357 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10358 | } |
| 10359 | |
| 10360 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 10361 | /* |
| 10362 | * Get the bus address of SLI4 device Bar regions and the |
| 10363 | * number of bytes required by each mapping. The mapping of the |
| 10364 | * particular PCI BARs regions is dependent on the type of |
| 10365 | * SLI4 device. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10366 | */ |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10367 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
| 10368 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); |
| 10369 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10370 | |
| 10371 | /* |
| 10372 | * Map SLI4 PCI Config Space Register base to a kernel virtual |
| 10373 | * addr |
| 10374 | */ |
| 10375 | phba->sli4_hba.conf_regs_memmap_p = |
| 10376 | ioremap(phba->pci_bar0_map, bar0map_len); |
| 10377 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10378 | dev_printk(KERN_ERR, &pdev->dev, |
| 10379 | "ioremap failed for SLI4 PCI config " |
| 10380 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10381 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10382 | } |
James Smart | f5ca6f2 | 2013-09-06 12:21:09 -0400 | [diff] [blame] | 10383 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10384 | /* Set up BAR0 PCI config space register memory map */ |
| 10385 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 10386 | } else { |
| 10387 | phba->pci_bar0_map = pci_resource_start(pdev, 1); |
| 10388 | bar0map_len = pci_resource_len(pdev, 1); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10389 | if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) { |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10390 | dev_printk(KERN_ERR, &pdev->dev, |
| 10391 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10392 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10393 | } |
| 10394 | phba->sli4_hba.conf_regs_memmap_p = |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10395 | ioremap(phba->pci_bar0_map, bar0map_len); |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10396 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
| 10397 | dev_printk(KERN_ERR, &pdev->dev, |
| 10398 | "ioremap failed for SLI4 PCI config " |
| 10399 | "registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10400 | return -ENODEV; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10401 | } |
| 10402 | lpfc_sli4_bar0_register_memmap(phba, if_type); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10403 | } |
| 10404 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10405 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10406 | if (pci_resource_start(pdev, PCI_64BIT_BAR2)) { |
| 10407 | /* |
| 10408 | * Map SLI4 if type 0 HBA Control Register base to a |
| 10409 | * kernel virtual address and setup the registers. |
| 10410 | */ |
| 10411 | phba->pci_bar1_map = pci_resource_start(pdev, |
| 10412 | PCI_64BIT_BAR2); |
| 10413 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10414 | phba->sli4_hba.ctrl_regs_memmap_p = |
| 10415 | ioremap(phba->pci_bar1_map, |
| 10416 | bar1map_len); |
| 10417 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
| 10418 | dev_err(&pdev->dev, |
| 10419 | "ioremap failed for SLI4 HBA " |
| 10420 | "control registers.\n"); |
| 10421 | error = -ENOMEM; |
| 10422 | goto out_iounmap_conf; |
| 10423 | } |
| 10424 | phba->pci_bar2_memmap_p = |
| 10425 | phba->sli4_hba.ctrl_regs_memmap_p; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10426 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10427 | } else { |
| 10428 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10429 | goto out_iounmap_conf; |
| 10430 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10431 | } |
| 10432 | |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10433 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_6) && |
| 10434 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
| 10435 | /* |
| 10436 | * Map SLI4 if type 6 HBA Doorbell Register base to a kernel |
| 10437 | * virtual address and setup the registers. |
| 10438 | */ |
| 10439 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
| 10440 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); |
| 10441 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10442 | ioremap(phba->pci_bar1_map, bar1map_len); |
| 10443 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10444 | dev_err(&pdev->dev, |
| 10445 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10446 | error = -ENOMEM; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10447 | goto out_iounmap_conf; |
| 10448 | } |
| 10449 | phba->pci_bar2_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
| 10450 | lpfc_sli4_bar1_register_memmap(phba, if_type); |
| 10451 | } |
| 10452 | |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10453 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 10454 | if (pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10455 | /* |
| 10456 | * Map SLI4 if type 0 HBA Doorbell Register base to |
| 10457 | * a kernel virtual address and setup the registers. |
| 10458 | */ |
| 10459 | phba->pci_bar2_map = pci_resource_start(pdev, |
| 10460 | PCI_64BIT_BAR4); |
| 10461 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10462 | phba->sli4_hba.drbl_regs_memmap_p = |
| 10463 | ioremap(phba->pci_bar2_map, |
| 10464 | bar2map_len); |
| 10465 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
| 10466 | dev_err(&pdev->dev, |
| 10467 | "ioremap failed for SLI4 HBA" |
| 10468 | " doorbell registers.\n"); |
| 10469 | error = -ENOMEM; |
| 10470 | goto out_iounmap_ctrl; |
| 10471 | } |
| 10472 | phba->pci_bar4_memmap_p = |
| 10473 | phba->sli4_hba.drbl_regs_memmap_p; |
| 10474 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
| 10475 | if (error) |
| 10476 | goto out_iounmap_all; |
| 10477 | } else { |
| 10478 | error = -ENOMEM; |
James Smart | 2fcee4b | 2010-12-15 17:57:46 -0500 | [diff] [blame] | 10479 | goto out_iounmap_all; |
James Smart | e4b9794 | 2017-11-20 16:00:31 -0800 | [diff] [blame] | 10480 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10481 | } |
| 10482 | |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10483 | if (if_type == LPFC_SLI_INTF_IF_TYPE_6 && |
| 10484 | pci_resource_start(pdev, PCI_64BIT_BAR4)) { |
| 10485 | /* |
| 10486 | * Map SLI4 if type 6 HBA DPP Register base to a kernel |
| 10487 | * virtual address and setup the registers. |
| 10488 | */ |
| 10489 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
| 10490 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); |
| 10491 | phba->sli4_hba.dpp_regs_memmap_p = |
| 10492 | ioremap(phba->pci_bar2_map, bar2map_len); |
| 10493 | if (!phba->sli4_hba.dpp_regs_memmap_p) { |
| 10494 | dev_err(&pdev->dev, |
| 10495 | "ioremap failed for SLI4 HBA dpp registers.\n"); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10496 | error = -ENOMEM; |
James Smart | 1351e69 | 2018-02-22 08:18:43 -0800 | [diff] [blame] | 10497 | goto out_iounmap_ctrl; |
| 10498 | } |
| 10499 | phba->pci_bar4_memmap_p = phba->sli4_hba.dpp_regs_memmap_p; |
| 10500 | } |
| 10501 | |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10502 | /* Set up the EQ/CQ register handeling functions now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10503 | switch (if_type) { |
| 10504 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10505 | case LPFC_SLI_INTF_IF_TYPE_2: |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10506 | phba->sli4_hba.sli4_eq_clr_intr = lpfc_sli4_eq_clr_intr; |
James Smart | 32517fc | 2019-01-28 11:14:33 -0800 | [diff] [blame] | 10507 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_write_eq_db; |
| 10508 | phba->sli4_hba.sli4_write_cq_db = lpfc_sli4_write_cq_db; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10509 | break; |
| 10510 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10511 | 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] | 10512 | phba->sli4_hba.sli4_write_eq_db = lpfc_sli4_if6_write_eq_db; |
| 10513 | 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] | 10514 | break; |
| 10515 | default: |
| 10516 | break; |
James Smart | b71413d | 2018-02-22 08:18:40 -0800 | [diff] [blame] | 10517 | } |
| 10518 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10519 | return 0; |
| 10520 | |
| 10521 | out_iounmap_all: |
| 10522 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10523 | out_iounmap_ctrl: |
| 10524 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10525 | out_iounmap_conf: |
| 10526 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
Dan Carpenter | 3a487ff | 2019-03-07 08:33:44 +0300 | [diff] [blame] | 10527 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10528 | return error; |
| 10529 | } |
| 10530 | |
| 10531 | /** |
| 10532 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. |
| 10533 | * @phba: pointer to lpfc hba data structure. |
| 10534 | * |
| 10535 | * This routine is invoked to unset the PCI device memory space for device |
| 10536 | * with SLI-4 interface spec. |
| 10537 | **/ |
| 10538 | static void |
| 10539 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) |
| 10540 | { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10541 | uint32_t if_type; |
| 10542 | 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] | 10543 | |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10544 | switch (if_type) { |
| 10545 | case LPFC_SLI_INTF_IF_TYPE_0: |
| 10546 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10547 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); |
| 10548 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10549 | break; |
| 10550 | case LPFC_SLI_INTF_IF_TYPE_2: |
| 10551 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
| 10552 | break; |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10553 | case LPFC_SLI_INTF_IF_TYPE_6: |
| 10554 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); |
| 10555 | iounmap(phba->sli4_hba.conf_regs_memmap_p); |
James Smart | 0b43919 | 2019-12-18 15:58:05 -0800 | [diff] [blame] | 10556 | if (phba->sli4_hba.dpp_regs_memmap_p) |
| 10557 | iounmap(phba->sli4_hba.dpp_regs_memmap_p); |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 10558 | break; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 10559 | case LPFC_SLI_INTF_IF_TYPE_1: |
| 10560 | default: |
| 10561 | dev_printk(KERN_ERR, &phba->pcidev->dev, |
| 10562 | "FATAL - unsupported SLI4 interface type - %d\n", |
| 10563 | if_type); |
| 10564 | break; |
| 10565 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 10566 | } |
| 10567 | |
| 10568 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10569 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device |
| 10570 | * @phba: pointer to lpfc hba data structure. |
| 10571 | * |
| 10572 | * 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] | 10573 | * with SLI-3 interface specs. |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10574 | * |
| 10575 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10576 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10577 | * other values - error |
| 10578 | **/ |
| 10579 | static int |
| 10580 | lpfc_sli_enable_msix(struct lpfc_hba *phba) |
| 10581 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10582 | int rc; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10583 | LPFC_MBOXQ_t *pmb; |
| 10584 | |
| 10585 | /* Set up MSI-X multi-message vectors */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10586 | rc = pci_alloc_irq_vectors(phba->pcidev, |
| 10587 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); |
| 10588 | if (rc < 0) { |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10589 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10590 | "0420 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10591 | goto vec_fail_out; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10592 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10593 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10594 | /* |
| 10595 | * Assign MSI-X vectors to interrupt handlers |
| 10596 | */ |
| 10597 | |
| 10598 | /* vector-0 is associated to slow-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10599 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10600 | &lpfc_sli_sp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10601 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 10602 | if (rc) { |
| 10603 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10604 | "0421 MSI-X slow-path request_irq failed " |
| 10605 | "(%d)\n", rc); |
| 10606 | goto msi_fail_out; |
| 10607 | } |
| 10608 | |
| 10609 | /* vector-1 is associated to fast-path handler */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10610 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10611 | &lpfc_sli_fp_intr_handler, 0, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10612 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 10613 | |
| 10614 | if (rc) { |
| 10615 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10616 | "0429 MSI-X fast-path request_irq failed " |
| 10617 | "(%d)\n", rc); |
| 10618 | goto irq_fail_out; |
| 10619 | } |
| 10620 | |
| 10621 | /* |
| 10622 | * Configure HBA MSI-X attention conditions to messages |
| 10623 | */ |
| 10624 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 10625 | |
| 10626 | if (!pmb) { |
| 10627 | rc = -ENOMEM; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 10628 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10629 | "0474 Unable to allocate memory for issuing " |
| 10630 | "MBOX_CONFIG_MSI command\n"); |
| 10631 | goto mem_fail_out; |
| 10632 | } |
| 10633 | rc = lpfc_config_msi(phba, pmb); |
| 10634 | if (rc) |
| 10635 | goto mbx_fail_out; |
| 10636 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 10637 | if (rc != MBX_SUCCESS) { |
| 10638 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 10639 | "0351 Config MSI mailbox command failed, " |
| 10640 | "mbxCmd x%x, mbxStatus x%x\n", |
| 10641 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); |
| 10642 | goto mbx_fail_out; |
| 10643 | } |
| 10644 | |
| 10645 | /* Free memory allocated for mailbox command */ |
| 10646 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10647 | return rc; |
| 10648 | |
| 10649 | mbx_fail_out: |
| 10650 | /* Free memory allocated for mailbox command */ |
| 10651 | mempool_free(pmb, phba->mbox_mem_pool); |
| 10652 | |
| 10653 | mem_fail_out: |
| 10654 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10655 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10656 | |
| 10657 | irq_fail_out: |
| 10658 | /* free the irq already requested */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10659 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10660 | |
| 10661 | msi_fail_out: |
| 10662 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10663 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 10664 | |
| 10665 | vec_fail_out: |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10666 | return rc; |
| 10667 | } |
| 10668 | |
| 10669 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10670 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. |
| 10671 | * @phba: pointer to lpfc hba data structure. |
| 10672 | * |
| 10673 | * This routine is invoked to enable the MSI interrupt mode to device with |
| 10674 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to |
| 10675 | * enable the MSI vector. The device driver is responsible for calling the |
| 10676 | * request_irq() to register MSI vector with a interrupt the handler, which |
| 10677 | * is done in this function. |
| 10678 | * |
| 10679 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10680 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10681 | * other values - error |
| 10682 | */ |
| 10683 | static int |
| 10684 | lpfc_sli_enable_msi(struct lpfc_hba *phba) |
| 10685 | { |
| 10686 | int rc; |
| 10687 | |
| 10688 | rc = pci_enable_msi(phba->pcidev); |
| 10689 | if (!rc) |
| 10690 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10691 | "0462 PCI enable MSI mode success.\n"); |
| 10692 | else { |
| 10693 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10694 | "0471 PCI enable MSI mode failed (%d)\n", rc); |
| 10695 | return rc; |
| 10696 | } |
| 10697 | |
| 10698 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 10699 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10700 | if (rc) { |
| 10701 | pci_disable_msi(phba->pcidev); |
| 10702 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 10703 | "0478 MSI request_irq failed (%d)\n", rc); |
| 10704 | } |
| 10705 | return rc; |
| 10706 | } |
| 10707 | |
| 10708 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10709 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. |
| 10710 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 10711 | * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X). |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10712 | * |
| 10713 | * This routine is invoked to enable device interrupt and associate driver's |
| 10714 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface |
| 10715 | * spec. Depends on the interrupt mode configured to the driver, the driver |
| 10716 | * will try to fallback from the configured interrupt mode to an interrupt |
| 10717 | * mode which is supported by the platform, kernel, and device in the order |
| 10718 | * of: |
| 10719 | * MSI-X -> MSI -> IRQ. |
| 10720 | * |
| 10721 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 10722 | * 0 - successful |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10723 | * other values - error |
| 10724 | **/ |
| 10725 | static uint32_t |
| 10726 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 10727 | { |
| 10728 | uint32_t intr_mode = LPFC_INTR_ERROR; |
| 10729 | int retval; |
| 10730 | |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame^] | 10731 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 10732 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); |
| 10733 | if (retval) |
| 10734 | return intr_mode; |
| 10735 | phba->hba_flag &= ~HBA_NEEDS_CFG_PORT; |
| 10736 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10737 | if (cfg_mode == 2) { |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame^] | 10738 | /* Now, try to enable MSI-X interrupt mode */ |
| 10739 | retval = lpfc_sli_enable_msix(phba); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10740 | if (!retval) { |
James Smart | d2f2547 | 2021-01-04 10:02:27 -0800 | [diff] [blame^] | 10741 | /* Indicate initialization to MSI-X mode */ |
| 10742 | phba->intr_type = MSIX; |
| 10743 | intr_mode = 2; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10744 | } |
| 10745 | } |
| 10746 | |
| 10747 | /* Fallback to MSI if MSI-X initialization failed */ |
| 10748 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 10749 | retval = lpfc_sli_enable_msi(phba); |
| 10750 | if (!retval) { |
| 10751 | /* Indicate initialization to MSI mode */ |
| 10752 | phba->intr_type = MSI; |
| 10753 | intr_mode = 1; |
| 10754 | } |
| 10755 | } |
| 10756 | |
| 10757 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 10758 | if (phba->intr_type == NONE) { |
| 10759 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, |
| 10760 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 10761 | if (!retval) { |
| 10762 | /* Indicate initialization to INTx mode */ |
| 10763 | phba->intr_type = INTx; |
| 10764 | intr_mode = 0; |
| 10765 | } |
| 10766 | } |
| 10767 | return intr_mode; |
| 10768 | } |
| 10769 | |
| 10770 | /** |
| 10771 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. |
| 10772 | * @phba: pointer to lpfc hba data structure. |
| 10773 | * |
| 10774 | * This routine is invoked to disable device interrupt and disassociate the |
| 10775 | * driver's interrupt handler(s) from interrupt vector(s) to device with |
| 10776 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will |
| 10777 | * release the interrupt vector(s) for the message signaled interrupt. |
| 10778 | **/ |
| 10779 | static void |
| 10780 | lpfc_sli_disable_intr(struct lpfc_hba *phba) |
| 10781 | { |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10782 | int nr_irqs, i; |
| 10783 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10784 | if (phba->intr_type == MSIX) |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 10785 | nr_irqs = LPFC_MSIX_VECTORS; |
| 10786 | else |
| 10787 | nr_irqs = 1; |
| 10788 | |
| 10789 | for (i = 0; i < nr_irqs; i++) |
| 10790 | free_irq(pci_irq_vector(phba->pcidev, i), phba); |
| 10791 | pci_free_irq_vectors(phba->pcidev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10792 | |
| 10793 | /* Reset interrupt management states */ |
| 10794 | phba->intr_type = NONE; |
| 10795 | phba->sli.slistat.sli_intr = 0; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 10796 | } |
| 10797 | |
| 10798 | /** |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10799 | * 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] | 10800 | * @phba: pointer to lpfc hba data structure. |
| 10801 | * @id: EQ vector index or Hardware Queue index |
| 10802 | * @match: LPFC_FIND_BY_EQ = match by EQ |
| 10803 | * LPFC_FIND_BY_HDWQ = match by Hardware Queue |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10804 | * Return the CPU that matches the selection criteria |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10805 | */ |
| 10806 | static uint16_t |
| 10807 | lpfc_find_cpu_handle(struct lpfc_hba *phba, uint16_t id, int match) |
| 10808 | { |
| 10809 | struct lpfc_vector_map_info *cpup; |
| 10810 | int cpu; |
| 10811 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10812 | /* Loop through all CPUs */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10813 | for_each_present_cpu(cpu) { |
| 10814 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10815 | |
| 10816 | /* If we are matching by EQ, there may be multiple CPUs using |
| 10817 | * using the same vector, so select the one with |
| 10818 | * LPFC_CPU_FIRST_IRQ set. |
| 10819 | */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10820 | if ((match == LPFC_FIND_BY_EQ) && |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10821 | (cpup->flag & LPFC_CPU_FIRST_IRQ) && |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10822 | (cpup->eq == id)) |
| 10823 | return cpu; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10824 | |
| 10825 | /* If matching by HDWQ, select the first CPU that matches */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10826 | if ((match == LPFC_FIND_BY_HDWQ) && (cpup->hdwq == id)) |
| 10827 | return cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10828 | } |
| 10829 | return 0; |
| 10830 | } |
| 10831 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10832 | #ifdef CONFIG_X86 |
| 10833 | /** |
| 10834 | * lpfc_find_hyper - Determine if the CPU map entry is hyper-threaded |
| 10835 | * @phba: pointer to lpfc hba data structure. |
| 10836 | * @cpu: CPU map index |
| 10837 | * @phys_id: CPU package physical id |
| 10838 | * @core_id: CPU core id |
| 10839 | */ |
| 10840 | static int |
| 10841 | lpfc_find_hyper(struct lpfc_hba *phba, int cpu, |
| 10842 | uint16_t phys_id, uint16_t core_id) |
| 10843 | { |
| 10844 | struct lpfc_vector_map_info *cpup; |
| 10845 | int idx; |
| 10846 | |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10847 | for_each_present_cpu(idx) { |
| 10848 | cpup = &phba->sli4_hba.cpu_map[idx]; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10849 | /* Does the cpup match the one we are looking for */ |
| 10850 | if ((cpup->phys_id == phys_id) && |
| 10851 | (cpup->core_id == core_id) && |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10852 | (cpu != idx)) |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10853 | return 1; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10854 | } |
| 10855 | return 0; |
| 10856 | } |
| 10857 | #endif |
| 10858 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 10859 | /* |
| 10860 | * lpfc_assign_eq_map_info - Assigns eq for vector_map structure |
| 10861 | * @phba: pointer to lpfc hba data structure. |
| 10862 | * @eqidx: index for eq and irq vector |
| 10863 | * @flag: flags to set for vector_map structure |
| 10864 | * @cpu: cpu used to index vector_map structure |
| 10865 | * |
| 10866 | * The routine assigns eq info into vector_map structure |
| 10867 | */ |
| 10868 | static inline void |
| 10869 | lpfc_assign_eq_map_info(struct lpfc_hba *phba, uint16_t eqidx, uint16_t flag, |
| 10870 | unsigned int cpu) |
| 10871 | { |
| 10872 | struct lpfc_vector_map_info *cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10873 | struct lpfc_hba_eq_hdl *eqhdl = lpfc_get_eq_hdl(eqidx); |
| 10874 | |
| 10875 | cpup->eq = eqidx; |
| 10876 | cpup->flag |= flag; |
| 10877 | |
| 10878 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 10879 | "3336 Set Affinity: CPU %d irq %d eq %d flag x%x\n", |
| 10880 | cpu, eqhdl->irq, cpup->eq, cpup->flag); |
| 10881 | } |
| 10882 | |
| 10883 | /** |
| 10884 | * lpfc_cpu_map_array_init - Initialize cpu_map structure |
| 10885 | * @phba: pointer to lpfc hba data structure. |
| 10886 | * |
| 10887 | * The routine initializes the cpu_map array structure |
| 10888 | */ |
| 10889 | static void |
| 10890 | lpfc_cpu_map_array_init(struct lpfc_hba *phba) |
| 10891 | { |
| 10892 | struct lpfc_vector_map_info *cpup; |
| 10893 | struct lpfc_eq_intr_info *eqi; |
| 10894 | int cpu; |
| 10895 | |
| 10896 | for_each_possible_cpu(cpu) { |
| 10897 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10898 | cpup->phys_id = LPFC_VECTOR_MAP_EMPTY; |
| 10899 | cpup->core_id = LPFC_VECTOR_MAP_EMPTY; |
| 10900 | cpup->hdwq = LPFC_VECTOR_MAP_EMPTY; |
| 10901 | cpup->eq = LPFC_VECTOR_MAP_EMPTY; |
| 10902 | cpup->flag = 0; |
| 10903 | eqi = per_cpu_ptr(phba->sli4_hba.eq_info, cpu); |
| 10904 | INIT_LIST_HEAD(&eqi->list); |
| 10905 | eqi->icnt = 0; |
| 10906 | } |
| 10907 | } |
| 10908 | |
| 10909 | /** |
| 10910 | * lpfc_hba_eq_hdl_array_init - Initialize hba_eq_hdl structure |
| 10911 | * @phba: pointer to lpfc hba data structure. |
| 10912 | * |
| 10913 | * The routine initializes the hba_eq_hdl array structure |
| 10914 | */ |
| 10915 | static void |
| 10916 | lpfc_hba_eq_hdl_array_init(struct lpfc_hba *phba) |
| 10917 | { |
| 10918 | struct lpfc_hba_eq_hdl *eqhdl; |
| 10919 | int i; |
| 10920 | |
| 10921 | for (i = 0; i < phba->cfg_irq_chann; i++) { |
| 10922 | eqhdl = lpfc_get_eq_hdl(i); |
| 10923 | eqhdl->irq = LPFC_VECTOR_MAP_EMPTY; |
| 10924 | eqhdl->phba = phba; |
| 10925 | } |
| 10926 | } |
| 10927 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10928 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10929 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10930 | * @phba: pointer to lpfc hba data structure. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10931 | * @vectors: number of msix vectors allocated. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10932 | * |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10933 | * The routine will figure out the CPU affinity assignment for every |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10934 | * MSI-X vector allocated for the HBA. |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10935 | * In addition, the CPU to IO channel mapping will be calculated |
| 10936 | * and the phba->sli4_hba.cpu_map array will reflect this. |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10937 | */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 10938 | static void |
| 10939 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10940 | { |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 10941 | int i, cpu, idx, next_idx, new_cpu, start_cpu, first_cpu; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10942 | int max_phys_id, min_phys_id; |
| 10943 | int max_core_id, min_core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10944 | struct lpfc_vector_map_info *cpup; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10945 | struct lpfc_vector_map_info *new_cpup; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10946 | #ifdef CONFIG_X86 |
| 10947 | struct cpuinfo_x86 *cpuinfo; |
| 10948 | #endif |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 10949 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 10950 | struct lpfc_hdwq_stat *c_stat; |
| 10951 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10952 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10953 | max_phys_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10954 | min_phys_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10955 | max_core_id = 0; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10956 | min_core_id = LPFC_VECTOR_MAP_EMPTY; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10957 | |
| 10958 | /* Update CPU map with physical id and core id of each CPU */ |
James Smart | 222e923 | 2019-01-28 11:14:35 -0800 | [diff] [blame] | 10959 | for_each_present_cpu(cpu) { |
| 10960 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10961 | #ifdef CONFIG_X86 |
| 10962 | cpuinfo = &cpu_data(cpu); |
| 10963 | cpup->phys_id = cpuinfo->phys_proc_id; |
| 10964 | cpup->core_id = cpuinfo->cpu_core_id; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10965 | if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) |
| 10966 | cpup->flag |= LPFC_CPU_MAP_HYPER; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10967 | #else |
| 10968 | /* No distinction between CPUs for other platforms */ |
| 10969 | cpup->phys_id = 0; |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10970 | cpup->core_id = cpu; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10971 | #endif |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10972 | |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10973 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 10974 | "3328 CPU %d physid %d coreid %d flag x%x\n", |
| 10975 | cpu, cpup->phys_id, cpup->core_id, cpup->flag); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 10976 | |
| 10977 | if (cpup->phys_id > max_phys_id) |
| 10978 | max_phys_id = cpup->phys_id; |
| 10979 | if (cpup->phys_id < min_phys_id) |
| 10980 | min_phys_id = cpup->phys_id; |
| 10981 | |
| 10982 | if (cpup->core_id > max_core_id) |
| 10983 | max_core_id = cpup->core_id; |
| 10984 | if (cpup->core_id < min_core_id) |
| 10985 | min_core_id = cpup->core_id; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 10986 | } |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 10987 | |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10988 | /* After looking at each irq vector assigned to this pcidev, its |
| 10989 | * possible to see that not ALL CPUs have been accounted for. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 10990 | * Next we will set any unassigned (unaffinitized) cpu map |
| 10991 | * entries to a IRQ on the same phys_id. |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 10992 | */ |
| 10993 | first_cpu = cpumask_first(cpu_present_mask); |
| 10994 | start_cpu = first_cpu; |
| 10995 | |
| 10996 | for_each_present_cpu(cpu) { |
| 10997 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 10998 | |
| 10999 | /* Is this CPU entry unassigned */ |
| 11000 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 11001 | /* Mark CPU as IRQ not assigned by the kernel */ |
| 11002 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 11003 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11004 | /* If so, find a new_cpup thats on the the SAME |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11005 | * phys_id as cpup. start_cpu will start where we |
| 11006 | * left off so all unassigned entries don't get assgined |
| 11007 | * the IRQ of the first entry. |
| 11008 | */ |
| 11009 | new_cpu = start_cpu; |
| 11010 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11011 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11012 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11013 | (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY) && |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11014 | (new_cpup->phys_id == cpup->phys_id)) |
| 11015 | goto found_same; |
| 11016 | new_cpu = cpumask_next( |
| 11017 | new_cpu, cpu_present_mask); |
| 11018 | if (new_cpu == nr_cpumask_bits) |
| 11019 | new_cpu = first_cpu; |
| 11020 | } |
| 11021 | /* At this point, we leave the CPU as unassigned */ |
| 11022 | continue; |
| 11023 | found_same: |
| 11024 | /* We found a matching phys_id, so copy the IRQ info */ |
| 11025 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11026 | |
| 11027 | /* Bump start_cpu to the next slot to minmize the |
| 11028 | * chance of having multiple unassigned CPU entries |
| 11029 | * selecting the same IRQ. |
| 11030 | */ |
| 11031 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11032 | if (start_cpu == nr_cpumask_bits) |
| 11033 | start_cpu = first_cpu; |
| 11034 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11035 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11036 | "3337 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11037 | "eq %d from peer cpu %d same " |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11038 | "phys_id (%d)\n", |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11039 | cpu, cpup->eq, new_cpu, |
| 11040 | cpup->phys_id); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11041 | } |
| 11042 | } |
| 11043 | |
| 11044 | /* Set any unassigned cpu map entries to a IRQ on any phys_id */ |
| 11045 | start_cpu = first_cpu; |
| 11046 | |
| 11047 | for_each_present_cpu(cpu) { |
| 11048 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11049 | |
| 11050 | /* Is this entry unassigned */ |
| 11051 | if (cpup->eq == LPFC_VECTOR_MAP_EMPTY) { |
| 11052 | /* Mark it as IRQ not assigned by the kernel */ |
| 11053 | cpup->flag |= LPFC_CPU_MAP_UNASSIGN; |
| 11054 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11055 | /* If so, find a new_cpup thats on ANY phys_id |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11056 | * as the cpup. start_cpu will start where we |
| 11057 | * left off so all unassigned entries don't get |
| 11058 | * assigned the IRQ of the first entry. |
| 11059 | */ |
| 11060 | new_cpu = start_cpu; |
| 11061 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11062 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11063 | if (!(new_cpup->flag & LPFC_CPU_MAP_UNASSIGN) && |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11064 | (new_cpup->eq != LPFC_VECTOR_MAP_EMPTY)) |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11065 | goto found_any; |
| 11066 | new_cpu = cpumask_next( |
| 11067 | new_cpu, cpu_present_mask); |
| 11068 | if (new_cpu == nr_cpumask_bits) |
| 11069 | new_cpu = first_cpu; |
| 11070 | } |
| 11071 | /* We should never leave an entry unassigned */ |
| 11072 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 11073 | "3339 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11074 | "eq %d UNASSIGNED\n", |
| 11075 | cpup->hdwq, cpup->eq); |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11076 | continue; |
| 11077 | found_any: |
| 11078 | /* We found an available entry, copy the IRQ info */ |
| 11079 | cpup->eq = new_cpup->eq; |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11080 | |
| 11081 | /* Bump start_cpu to the next slot to minmize the |
| 11082 | * chance of having multiple unassigned CPU entries |
| 11083 | * selecting the same IRQ. |
| 11084 | */ |
| 11085 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11086 | if (start_cpu == nr_cpumask_bits) |
| 11087 | start_cpu = first_cpu; |
| 11088 | |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11089 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11090 | "3338 Set Affinity: CPU %d " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11091 | "eq %d from peer cpu %d (%d/%d)\n", |
| 11092 | cpu, cpup->eq, new_cpu, |
James Smart | d9954a2 | 2019-05-21 17:49:05 -0700 | [diff] [blame] | 11093 | new_cpup->phys_id, new_cpup->core_id); |
| 11094 | } |
| 11095 | } |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11096 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11097 | /* Assign hdwq indices that are unique across all cpus in the map |
| 11098 | * that are also FIRST_CPUs. |
| 11099 | */ |
| 11100 | idx = 0; |
| 11101 | for_each_present_cpu(cpu) { |
| 11102 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11103 | |
| 11104 | /* Only FIRST IRQs get a hdwq index assignment. */ |
| 11105 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 11106 | continue; |
| 11107 | |
| 11108 | /* 1 to 1, the first LPFC_CPU_FIRST_IRQ cpus to a unique hdwq */ |
| 11109 | cpup->hdwq = idx; |
| 11110 | idx++; |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 11111 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11112 | "3333 Set Affinity: CPU %d (phys %d core %d): " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11113 | "hdwq %d eq %d flg x%x\n", |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11114 | cpu, cpup->phys_id, cpup->core_id, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11115 | cpup->hdwq, cpup->eq, cpup->flag); |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11116 | } |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11117 | /* Associate a hdwq with each cpu_map entry |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11118 | * This will be 1 to 1 - hdwq to cpu, unless there are less |
| 11119 | * hardware queues then CPUs. For that case we will just round-robin |
| 11120 | * the available hardware queues as they get assigned to CPUs. |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11121 | * The next_idx is the idx from the FIRST_CPU loop above to account |
| 11122 | * for irq_chann < hdwq. The idx is used for round-robin assignments |
| 11123 | * and needs to start at 0. |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11124 | */ |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11125 | next_idx = idx; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11126 | start_cpu = 0; |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11127 | idx = 0; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11128 | for_each_present_cpu(cpu) { |
| 11129 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11130 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11131 | /* FIRST cpus are already mapped. */ |
| 11132 | if (cpup->flag & LPFC_CPU_FIRST_IRQ) |
| 11133 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11134 | |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11135 | /* If the cfg_irq_chann < cfg_hdw_queue, set the hdwq |
| 11136 | * of the unassigned cpus to the next idx so that all |
| 11137 | * hdw queues are fully utilized. |
| 11138 | */ |
| 11139 | if (next_idx < phba->cfg_hdw_queue) { |
| 11140 | cpup->hdwq = next_idx; |
| 11141 | next_idx++; |
| 11142 | continue; |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11143 | } |
James Smart | 3ad348d | 2019-08-14 16:56:43 -0700 | [diff] [blame] | 11144 | |
| 11145 | /* Not a First CPU and all hdw_queues are used. Reuse a |
| 11146 | * Hardware Queue for another CPU, so be smart about it |
| 11147 | * and pick one that has its IRQ/EQ mapped to the same phys_id |
| 11148 | * (CPU package) and core_id. |
| 11149 | */ |
| 11150 | new_cpu = start_cpu; |
| 11151 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11152 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11153 | if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && |
| 11154 | new_cpup->phys_id == cpup->phys_id && |
| 11155 | new_cpup->core_id == cpup->core_id) { |
| 11156 | goto found_hdwq; |
| 11157 | } |
| 11158 | new_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11159 | if (new_cpu == nr_cpumask_bits) |
| 11160 | new_cpu = first_cpu; |
| 11161 | } |
| 11162 | |
| 11163 | /* If we can't match both phys_id and core_id, |
| 11164 | * settle for just a phys_id match. |
| 11165 | */ |
| 11166 | new_cpu = start_cpu; |
| 11167 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { |
| 11168 | new_cpup = &phba->sli4_hba.cpu_map[new_cpu]; |
| 11169 | if (new_cpup->hdwq != LPFC_VECTOR_MAP_EMPTY && |
| 11170 | new_cpup->phys_id == cpup->phys_id) |
| 11171 | goto found_hdwq; |
| 11172 | |
| 11173 | new_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11174 | if (new_cpu == nr_cpumask_bits) |
| 11175 | new_cpu = first_cpu; |
| 11176 | } |
| 11177 | |
| 11178 | /* Otherwise just round robin on cfg_hdw_queue */ |
| 11179 | cpup->hdwq = idx % phba->cfg_hdw_queue; |
| 11180 | idx++; |
| 11181 | goto logit; |
| 11182 | found_hdwq: |
| 11183 | /* We found an available entry, copy the IRQ info */ |
| 11184 | start_cpu = cpumask_next(new_cpu, cpu_present_mask); |
| 11185 | if (start_cpu == nr_cpumask_bits) |
| 11186 | start_cpu = first_cpu; |
| 11187 | cpup->hdwq = new_cpup->hdwq; |
| 11188 | logit: |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 11189 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11190 | "3335 Set Affinity: CPU %d (phys %d core %d): " |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11191 | "hdwq %d eq %d flg x%x\n", |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11192 | cpu, cpup->phys_id, cpup->core_id, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11193 | cpup->hdwq, cpup->eq, cpup->flag); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11194 | } |
| 11195 | |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11196 | /* |
| 11197 | * Initialize the cpu_map slots for not-present cpus in case |
| 11198 | * a cpu is hot-added. Perform a simple hdwq round robin assignment. |
| 11199 | */ |
| 11200 | idx = 0; |
| 11201 | for_each_possible_cpu(cpu) { |
| 11202 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 11203 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 11204 | c_stat = per_cpu_ptr(phba->sli4_hba.c_stat, cpu); |
| 11205 | c_stat->hdwq_no = cpup->hdwq; |
| 11206 | #endif |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11207 | if (cpup->hdwq != LPFC_VECTOR_MAP_EMPTY) |
| 11208 | continue; |
| 11209 | |
| 11210 | cpup->hdwq = idx++ % phba->cfg_hdw_queue; |
James Smart | 840eda9 | 2020-03-22 11:13:00 -0700 | [diff] [blame] | 11211 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 11212 | c_stat->hdwq_no = cpup->hdwq; |
| 11213 | #endif |
James Smart | bc227dd | 2019-11-11 15:03:59 -0800 | [diff] [blame] | 11214 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11215 | "3340 Set Affinity: not present " |
| 11216 | "CPU %d hdwq %d\n", |
| 11217 | cpu, cpup->hdwq); |
James Smart | 657add4 | 2019-05-21 17:49:06 -0700 | [diff] [blame] | 11218 | } |
| 11219 | |
| 11220 | /* The cpu_map array will be used later during initialization |
| 11221 | * when EQ / CQ / WQs are allocated and configured. |
| 11222 | */ |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11223 | return; |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11224 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11225 | |
| 11226 | /** |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11227 | * lpfc_cpuhp_get_eq |
| 11228 | * |
| 11229 | * @phba: pointer to lpfc hba data structure. |
| 11230 | * @cpu: cpu going offline |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 11231 | * @eqlist: eq list to append to |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11232 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11233 | static int |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11234 | lpfc_cpuhp_get_eq(struct lpfc_hba *phba, unsigned int cpu, |
| 11235 | struct list_head *eqlist) |
| 11236 | { |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11237 | const struct cpumask *maskp; |
| 11238 | struct lpfc_queue *eq; |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11239 | struct cpumask *tmp; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11240 | u16 idx; |
| 11241 | |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11242 | tmp = kzalloc(cpumask_size(), GFP_KERNEL); |
| 11243 | if (!tmp) |
| 11244 | return -ENOMEM; |
| 11245 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11246 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 11247 | maskp = pci_irq_get_affinity(phba->pcidev, idx); |
| 11248 | if (!maskp) |
| 11249 | continue; |
| 11250 | /* |
| 11251 | * if irq is not affinitized to the cpu going |
| 11252 | * then we don't need to poll the eq attached |
| 11253 | * to it. |
| 11254 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11255 | if (!cpumask_and(tmp, maskp, cpumask_of(cpu))) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11256 | continue; |
| 11257 | /* get the cpus that are online and are affini- |
| 11258 | * tized to this irq vector. If the count is |
| 11259 | * more than 1 then cpuhp is not going to shut- |
| 11260 | * down this vector. Since this cpu has not |
| 11261 | * gone offline yet, we need >1. |
| 11262 | */ |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11263 | cpumask_and(tmp, maskp, cpu_online_mask); |
| 11264 | if (cpumask_weight(tmp) > 1) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11265 | continue; |
| 11266 | |
| 11267 | /* Now that we have an irq to shutdown, get the eq |
| 11268 | * mapped to this irq. Note: multiple hdwq's in |
| 11269 | * the software can share an eq, but eventually |
| 11270 | * only eq will be mapped to this vector |
| 11271 | */ |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11272 | eq = phba->sli4_hba.hba_eq_hdl[idx].eq; |
| 11273 | list_add(&eq->_poll_list, eqlist); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11274 | } |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11275 | kfree(tmp); |
| 11276 | return 0; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11277 | } |
| 11278 | |
| 11279 | static void __lpfc_cpuhp_remove(struct lpfc_hba *phba) |
| 11280 | { |
| 11281 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 11282 | return; |
| 11283 | |
| 11284 | cpuhp_state_remove_instance_nocalls(lpfc_cpuhp_state, |
| 11285 | &phba->cpuhp); |
| 11286 | /* |
| 11287 | * unregistering the instance doesn't stop the polling |
| 11288 | * timer. Wait for the poll timer to retire. |
| 11289 | */ |
| 11290 | synchronize_rcu(); |
| 11291 | del_timer_sync(&phba->cpuhp_poll_timer); |
| 11292 | } |
| 11293 | |
| 11294 | static void lpfc_cpuhp_remove(struct lpfc_hba *phba) |
| 11295 | { |
| 11296 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
| 11297 | return; |
| 11298 | |
| 11299 | __lpfc_cpuhp_remove(phba); |
| 11300 | } |
| 11301 | |
| 11302 | static void lpfc_cpuhp_add(struct lpfc_hba *phba) |
| 11303 | { |
| 11304 | if (phba->sli_rev != LPFC_SLI_REV4) |
| 11305 | return; |
| 11306 | |
| 11307 | rcu_read_lock(); |
| 11308 | |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 11309 | if (!list_empty(&phba->poll_list)) |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11310 | mod_timer(&phba->cpuhp_poll_timer, |
| 11311 | jiffies + msecs_to_jiffies(LPFC_POLL_HB)); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11312 | |
| 11313 | rcu_read_unlock(); |
| 11314 | |
| 11315 | cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, |
| 11316 | &phba->cpuhp); |
| 11317 | } |
| 11318 | |
| 11319 | static int __lpfc_cpuhp_checks(struct lpfc_hba *phba, int *retval) |
| 11320 | { |
| 11321 | if (phba->pport->load_flag & FC_UNLOADING) { |
| 11322 | *retval = -EAGAIN; |
| 11323 | return true; |
| 11324 | } |
| 11325 | |
| 11326 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 11327 | *retval = 0; |
| 11328 | return true; |
| 11329 | } |
| 11330 | |
| 11331 | /* proceed with the hotplug */ |
| 11332 | return false; |
| 11333 | } |
| 11334 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11335 | /** |
| 11336 | * lpfc_irq_set_aff - set IRQ affinity |
| 11337 | * @eqhdl: EQ handle |
| 11338 | * @cpu: cpu to set affinity |
| 11339 | * |
| 11340 | **/ |
| 11341 | static inline void |
| 11342 | lpfc_irq_set_aff(struct lpfc_hba_eq_hdl *eqhdl, unsigned int cpu) |
| 11343 | { |
| 11344 | cpumask_clear(&eqhdl->aff_mask); |
| 11345 | cpumask_set_cpu(cpu, &eqhdl->aff_mask); |
| 11346 | irq_set_status_flags(eqhdl->irq, IRQ_NO_BALANCING); |
| 11347 | irq_set_affinity_hint(eqhdl->irq, &eqhdl->aff_mask); |
| 11348 | } |
| 11349 | |
| 11350 | /** |
| 11351 | * lpfc_irq_clear_aff - clear IRQ affinity |
| 11352 | * @eqhdl: EQ handle |
| 11353 | * |
| 11354 | **/ |
| 11355 | static inline void |
| 11356 | lpfc_irq_clear_aff(struct lpfc_hba_eq_hdl *eqhdl) |
| 11357 | { |
| 11358 | cpumask_clear(&eqhdl->aff_mask); |
| 11359 | irq_clear_status_flags(eqhdl->irq, IRQ_NO_BALANCING); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11360 | } |
| 11361 | |
| 11362 | /** |
| 11363 | * lpfc_irq_rebalance - rebalances IRQ affinity according to cpuhp event |
| 11364 | * @phba: pointer to HBA context object. |
| 11365 | * @cpu: cpu going offline/online |
| 11366 | * @offline: true, cpu is going offline. false, cpu is coming online. |
| 11367 | * |
| 11368 | * 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] | 11369 | * online cpu on the phba's original_mask and migrate all offlining IRQ |
| 11370 | * affinities. |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11371 | * |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11372 | * 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] | 11373 | * |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11374 | * 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] | 11375 | * PCI_IRQ_AFFINITY to auto-manage IRQ affinity. |
| 11376 | * |
| 11377 | **/ |
| 11378 | static void |
| 11379 | lpfc_irq_rebalance(struct lpfc_hba *phba, unsigned int cpu, bool offline) |
| 11380 | { |
| 11381 | struct lpfc_vector_map_info *cpup; |
| 11382 | struct cpumask *aff_mask; |
| 11383 | unsigned int cpu_select, cpu_next, idx; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11384 | const struct cpumask *orig_mask; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11385 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11386 | if (phba->irq_chann_mode == NORMAL_MODE) |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11387 | return; |
| 11388 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11389 | orig_mask = &phba->sli4_hba.irq_aff_mask; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11390 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11391 | if (!cpumask_test_cpu(cpu, orig_mask)) |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11392 | return; |
| 11393 | |
| 11394 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11395 | |
| 11396 | if (!(cpup->flag & LPFC_CPU_FIRST_IRQ)) |
| 11397 | return; |
| 11398 | |
| 11399 | if (offline) { |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11400 | /* Find next online CPU on original mask */ |
| 11401 | cpu_next = cpumask_next_wrap(cpu, orig_mask, cpu, true); |
| 11402 | cpu_select = lpfc_next_online_cpu(orig_mask, cpu_next); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11403 | |
| 11404 | /* Found a valid CPU */ |
| 11405 | if ((cpu_select < nr_cpu_ids) && (cpu_select != cpu)) { |
| 11406 | /* Go through each eqhdl and ensure offlining |
| 11407 | * cpu aff_mask is migrated |
| 11408 | */ |
| 11409 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
| 11410 | aff_mask = lpfc_get_aff_mask(idx); |
| 11411 | |
| 11412 | /* Migrate affinity */ |
| 11413 | if (cpumask_test_cpu(cpu, aff_mask)) |
| 11414 | lpfc_irq_set_aff(lpfc_get_eq_hdl(idx), |
| 11415 | cpu_select); |
| 11416 | } |
| 11417 | } else { |
| 11418 | /* Rely on irqbalance if no online CPUs left on NUMA */ |
| 11419 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) |
| 11420 | lpfc_irq_clear_aff(lpfc_get_eq_hdl(idx)); |
| 11421 | } |
| 11422 | } else { |
| 11423 | /* Migrate affinity back to this CPU */ |
| 11424 | lpfc_irq_set_aff(lpfc_get_eq_hdl(cpup->eq), cpu); |
| 11425 | } |
| 11426 | } |
| 11427 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11428 | static int lpfc_cpu_offline(unsigned int cpu, struct hlist_node *node) |
| 11429 | { |
| 11430 | struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp); |
| 11431 | struct lpfc_queue *eq, *next; |
| 11432 | LIST_HEAD(eqlist); |
| 11433 | int retval; |
| 11434 | |
| 11435 | if (!phba) { |
| 11436 | WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id()); |
| 11437 | return 0; |
| 11438 | } |
| 11439 | |
| 11440 | if (__lpfc_cpuhp_checks(phba, &retval)) |
| 11441 | return retval; |
| 11442 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11443 | lpfc_irq_rebalance(phba, cpu, true); |
| 11444 | |
James Smart | a99c807 | 2020-01-27 16:23:06 -0800 | [diff] [blame] | 11445 | retval = lpfc_cpuhp_get_eq(phba, cpu, &eqlist); |
| 11446 | if (retval) |
| 11447 | return retval; |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11448 | |
| 11449 | /* start polling on these eq's */ |
| 11450 | list_for_each_entry_safe(eq, next, &eqlist, _poll_list) { |
| 11451 | list_del_init(&eq->_poll_list); |
| 11452 | lpfc_sli4_start_polling(eq); |
| 11453 | } |
| 11454 | |
| 11455 | return 0; |
| 11456 | } |
| 11457 | |
| 11458 | static int lpfc_cpu_online(unsigned int cpu, struct hlist_node *node) |
| 11459 | { |
| 11460 | struct lpfc_hba *phba = hlist_entry_safe(node, struct lpfc_hba, cpuhp); |
| 11461 | struct lpfc_queue *eq, *next; |
| 11462 | unsigned int n; |
| 11463 | int retval; |
| 11464 | |
| 11465 | if (!phba) { |
| 11466 | WARN_ONCE(!phba, "cpu: %u. phba:NULL", raw_smp_processor_id()); |
| 11467 | return 0; |
| 11468 | } |
| 11469 | |
| 11470 | if (__lpfc_cpuhp_checks(phba, &retval)) |
| 11471 | return retval; |
| 11472 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11473 | lpfc_irq_rebalance(phba, cpu, false); |
| 11474 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11475 | list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list) { |
| 11476 | n = lpfc_find_cpu_handle(phba, eq->hdwq, LPFC_FIND_BY_HDWQ); |
| 11477 | if (n == cpu) |
| 11478 | lpfc_sli4_stop_polling(eq); |
| 11479 | } |
| 11480 | |
| 11481 | return 0; |
| 11482 | } |
| 11483 | |
| 11484 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11485 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device |
| 11486 | * @phba: pointer to lpfc hba data structure. |
| 11487 | * |
| 11488 | * 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] | 11489 | * with SLI-4 interface spec. It also allocates MSI-X vectors and maps them |
| 11490 | * to cpus on the system. |
| 11491 | * |
| 11492 | * When cfg_irq_numa is enabled, the adapter will only allocate vectors for |
| 11493 | * the number of cpus on the same numa node as this adapter. The vectors are |
| 11494 | * allocated without requesting OS affinity mapping. A vector will be |
| 11495 | * allocated and assigned to each online and offline cpu. If the cpu is |
| 11496 | * online, then affinity will be set to that cpu. If the cpu is offline, then |
| 11497 | * affinity will be set to the nearest peer cpu within the numa node that is |
| 11498 | * online. If there are no online cpus within the numa node, affinity is not |
| 11499 | * assigned and the OS may do as it pleases. Note: cpu vector affinity mapping |
| 11500 | * is consistent with the way cpu online/offline is handled when cfg_irq_numa is |
| 11501 | * configured. |
| 11502 | * |
| 11503 | * If numa mode is not enabled and there is more than 1 vector allocated, then |
| 11504 | * the driver relies on the managed irq interface where the OS assigns vector to |
| 11505 | * cpu affinity. The driver will then use that affinity mapping to setup its |
| 11506 | * cpu mapping table. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11507 | * |
| 11508 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11509 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11510 | * other values - error |
| 11511 | **/ |
| 11512 | static int |
| 11513 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) |
| 11514 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11515 | int vectors, rc, index; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11516 | char *name; |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11517 | const struct cpumask *aff_mask = NULL; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11518 | unsigned int cpu = 0, cpu_cnt = 0, cpu_select = nr_cpu_ids; |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11519 | struct lpfc_vector_map_info *cpup; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11520 | struct lpfc_hba_eq_hdl *eqhdl; |
| 11521 | const struct cpumask *maskp; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11522 | unsigned int flags = PCI_IRQ_MSIX; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11523 | |
| 11524 | /* Set up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11525 | vectors = phba->cfg_irq_chann; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11526 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11527 | if (phba->irq_chann_mode != NORMAL_MODE) |
| 11528 | aff_mask = &phba->sli4_hba.irq_aff_mask; |
| 11529 | |
| 11530 | if (aff_mask) { |
| 11531 | cpu_cnt = cpumask_weight(aff_mask); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11532 | vectors = min(phba->cfg_irq_chann, cpu_cnt); |
| 11533 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11534 | /* cpu: iterates over aff_mask including offline or online |
| 11535 | * cpu_select: iterates over online aff_mask to set affinity |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11536 | */ |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11537 | cpu = cpumask_first(aff_mask); |
| 11538 | cpu_select = lpfc_next_online_cpu(aff_mask, cpu); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11539 | } else { |
| 11540 | flags |= PCI_IRQ_AFFINITY; |
| 11541 | } |
| 11542 | |
| 11543 | rc = pci_alloc_irq_vectors(phba->pcidev, 1, vectors, flags); |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11544 | if (rc < 0) { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11545 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11546 | "0484 PCI enable MSI-X failed (%d)\n", rc); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11547 | goto vec_fail_out; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11548 | } |
Alexander Gordeev | 4f871e1 | 2014-09-03 12:56:29 -0400 | [diff] [blame] | 11549 | vectors = rc; |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11550 | |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11551 | /* Assign MSI-X vectors to interrupt handlers */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 11552 | for (index = 0; index < vectors; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11553 | eqhdl = lpfc_get_eq_hdl(index); |
| 11554 | name = eqhdl->handler_name; |
James Smart | b83d005 | 2017-06-01 21:07:05 -0700 | [diff] [blame] | 11555 | memset(name, 0, LPFC_SLI4_HANDLER_NAME_SZ); |
| 11556 | snprintf(name, LPFC_SLI4_HANDLER_NAME_SZ, |
James Smart | 4305f18 | 2012-08-03 12:36:33 -0400 | [diff] [blame] | 11557 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11558 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11559 | eqhdl->idx = index; |
James Smart | 7370d10 | 2019-01-28 11:14:20 -0800 | [diff] [blame] | 11560 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
| 11561 | &lpfc_sli4_hba_intr_handler, 0, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11562 | name, eqhdl); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11563 | if (rc) { |
| 11564 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11565 | "0486 MSI-X fast-path (%d) " |
| 11566 | "request_irq failed (%d)\n", index, rc); |
| 11567 | goto cfg_fail_out; |
| 11568 | } |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11569 | |
| 11570 | eqhdl->irq = pci_irq_vector(phba->pcidev, index); |
| 11571 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11572 | if (aff_mask) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11573 | /* If found a neighboring online cpu, set affinity */ |
| 11574 | if (cpu_select < nr_cpu_ids) |
| 11575 | lpfc_irq_set_aff(eqhdl, cpu_select); |
| 11576 | |
| 11577 | /* Assign EQ to cpu_map */ |
| 11578 | lpfc_assign_eq_map_info(phba, index, |
| 11579 | LPFC_CPU_FIRST_IRQ, |
| 11580 | cpu); |
| 11581 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11582 | /* Iterate to next offline or online cpu in aff_mask */ |
| 11583 | cpu = cpumask_next(cpu, aff_mask); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11584 | |
Dick Kennedy | 3048e3e | 2020-05-01 14:43:06 -0700 | [diff] [blame] | 11585 | /* Find next online cpu in aff_mask to set affinity */ |
| 11586 | cpu_select = lpfc_next_online_cpu(aff_mask, cpu); |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11587 | } else if (vectors == 1) { |
| 11588 | cpu = cpumask_first(cpu_present_mask); |
| 11589 | lpfc_assign_eq_map_info(phba, index, LPFC_CPU_FIRST_IRQ, |
| 11590 | cpu); |
| 11591 | } else { |
| 11592 | maskp = pci_irq_get_affinity(phba->pcidev, index); |
| 11593 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11594 | /* Loop through all CPUs associated with vector index */ |
| 11595 | for_each_cpu_and(cpu, maskp, cpu_present_mask) { |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11596 | cpup = &phba->sli4_hba.cpu_map[cpu]; |
| 11597 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11598 | /* If this is the first CPU thats assigned to |
| 11599 | * this vector, set LPFC_CPU_FIRST_IRQ. |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11600 | * |
| 11601 | * With certain platforms its possible that irq |
| 11602 | * vectors are affinitized to all the cpu's. |
| 11603 | * This can result in each cpu_map.eq to be set |
| 11604 | * to the last vector, resulting in overwrite |
| 11605 | * of all the previous cpu_map.eq. Ensure that |
| 11606 | * each vector receives a place in cpu_map. |
| 11607 | * Later call to lpfc_cpu_affinity_check will |
| 11608 | * ensure we are nicely balanced out. |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11609 | */ |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11610 | if (cpup->eq != LPFC_VECTOR_MAP_EMPTY) |
| 11611 | continue; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11612 | lpfc_assign_eq_map_info(phba, index, |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11613 | LPFC_CPU_FIRST_IRQ, |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11614 | cpu); |
Dick Kennedy | 17105d9 | 2020-07-06 13:42:30 -0700 | [diff] [blame] | 11615 | break; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11616 | } |
| 11617 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11618 | } |
| 11619 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11620 | if (vectors != phba->cfg_irq_chann) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11621 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11622 | "3238 Reducing IO channels to match number of " |
| 11623 | "MSI-X vectors, requested %d got %d\n", |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11624 | phba->cfg_irq_chann, vectors); |
| 11625 | if (phba->cfg_irq_chann > vectors) |
| 11626 | phba->cfg_irq_chann = vectors; |
James Smart | 82c3e9b | 2012-09-29 11:29:50 -0400 | [diff] [blame] | 11627 | } |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 11628 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11629 | return rc; |
| 11630 | |
| 11631 | cfg_fail_out: |
| 11632 | /* free the irq already requested */ |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11633 | for (--index; index >= 0; index--) { |
| 11634 | eqhdl = lpfc_get_eq_hdl(index); |
| 11635 | lpfc_irq_clear_aff(eqhdl); |
| 11636 | irq_set_affinity_hint(eqhdl->irq, NULL); |
| 11637 | free_irq(eqhdl->irq, eqhdl); |
| 11638 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11639 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11640 | /* Unconfigure MSI-X capability structure */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11641 | pci_free_irq_vectors(phba->pcidev); |
Alexander Gordeev | 029165a | 2014-07-16 20:05:15 +0200 | [diff] [blame] | 11642 | |
| 11643 | vec_fail_out: |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11644 | return rc; |
| 11645 | } |
| 11646 | |
| 11647 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11648 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device |
| 11649 | * @phba: pointer to lpfc hba data structure. |
| 11650 | * |
| 11651 | * 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] | 11652 | * SLI-4 interface spec. The kernel function pci_alloc_irq_vectors() is |
| 11653 | * called to enable the MSI vector. The device driver is responsible for |
| 11654 | * calling the request_irq() to register MSI vector with a interrupt the |
| 11655 | * handler, which is done in this function. |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11656 | * |
| 11657 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11658 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11659 | * other values - error |
| 11660 | **/ |
| 11661 | static int |
| 11662 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) |
| 11663 | { |
| 11664 | int rc, index; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11665 | unsigned int cpu; |
| 11666 | struct lpfc_hba_eq_hdl *eqhdl; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11667 | |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11668 | rc = pci_alloc_irq_vectors(phba->pcidev, 1, 1, |
| 11669 | PCI_IRQ_MSI | PCI_IRQ_AFFINITY); |
| 11670 | if (rc > 0) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11671 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11672 | "0487 PCI enable MSI mode success.\n"); |
| 11673 | else { |
| 11674 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 11675 | "0488 PCI enable MSI mode failed (%d)\n", rc); |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11676 | return rc ? rc : -1; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11677 | } |
| 11678 | |
| 11679 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
James Smart | ed243d3 | 2015-05-21 13:55:25 -0400 | [diff] [blame] | 11680 | 0, LPFC_DRIVER_NAME, phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11681 | if (rc) { |
James Smart | 07b1b91 | 2019-08-14 16:56:58 -0700 | [diff] [blame] | 11682 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11683 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
| 11684 | "0490 MSI request_irq failed (%d)\n", rc); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11685 | return rc; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11686 | } |
| 11687 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11688 | eqhdl = lpfc_get_eq_hdl(0); |
| 11689 | eqhdl->irq = pci_irq_vector(phba->pcidev, 0); |
| 11690 | |
| 11691 | cpu = cpumask_first(cpu_present_mask); |
| 11692 | lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, cpu); |
| 11693 | |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11694 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11695 | eqhdl = lpfc_get_eq_hdl(index); |
| 11696 | eqhdl->idx = index; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11697 | } |
| 11698 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 11699 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11700 | } |
| 11701 | |
| 11702 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11703 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device |
| 11704 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 11705 | * @cfg_mode: Interrupt configuration mode (INTx, MSI or MSI-X). |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11706 | * |
| 11707 | * This routine is invoked to enable device interrupt and associate driver's |
| 11708 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 |
| 11709 | * interface spec. Depends on the interrupt mode configured to the driver, |
| 11710 | * the driver will try to fallback from the configured interrupt mode to an |
| 11711 | * interrupt mode which is supported by the platform, kernel, and device in |
| 11712 | * the order of: |
| 11713 | * MSI-X -> MSI -> IRQ. |
| 11714 | * |
| 11715 | * Return codes |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 11716 | * 0 - successful |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11717 | * other values - error |
| 11718 | **/ |
| 11719 | static uint32_t |
| 11720 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) |
| 11721 | { |
| 11722 | uint32_t intr_mode = LPFC_INTR_ERROR; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11723 | int retval, idx; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11724 | |
| 11725 | if (cfg_mode == 2) { |
| 11726 | /* Preparation before conf_msi mbox cmd */ |
| 11727 | retval = 0; |
| 11728 | if (!retval) { |
| 11729 | /* Now, try to enable MSI-X interrupt mode */ |
| 11730 | retval = lpfc_sli4_enable_msix(phba); |
| 11731 | if (!retval) { |
| 11732 | /* Indicate initialization to MSI-X mode */ |
| 11733 | phba->intr_type = MSIX; |
| 11734 | intr_mode = 2; |
| 11735 | } |
| 11736 | } |
| 11737 | } |
| 11738 | |
| 11739 | /* Fallback to MSI if MSI-X initialization failed */ |
| 11740 | if (cfg_mode >= 1 && phba->intr_type == NONE) { |
| 11741 | retval = lpfc_sli4_enable_msi(phba); |
| 11742 | if (!retval) { |
| 11743 | /* Indicate initialization to MSI mode */ |
| 11744 | phba->intr_type = MSI; |
| 11745 | intr_mode = 1; |
| 11746 | } |
| 11747 | } |
| 11748 | |
| 11749 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ |
| 11750 | if (phba->intr_type == NONE) { |
| 11751 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, |
| 11752 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 11753 | if (!retval) { |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11754 | struct lpfc_hba_eq_hdl *eqhdl; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11755 | unsigned int cpu; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11756 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11757 | /* Indicate initialization to INTx mode */ |
| 11758 | phba->intr_type = INTx; |
| 11759 | intr_mode = 0; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11760 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11761 | eqhdl = lpfc_get_eq_hdl(0); |
| 11762 | eqhdl->irq = pci_irq_vector(phba->pcidev, 0); |
| 11763 | |
| 11764 | cpu = cpumask_first(cpu_present_mask); |
| 11765 | lpfc_assign_eq_map_info(phba, 0, LPFC_CPU_FIRST_IRQ, |
| 11766 | cpu); |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11767 | for (idx = 0; idx < phba->cfg_irq_chann; idx++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11768 | eqhdl = lpfc_get_eq_hdl(idx); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11769 | eqhdl->idx = idx; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 11770 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11771 | } |
| 11772 | } |
| 11773 | return intr_mode; |
| 11774 | } |
| 11775 | |
| 11776 | /** |
| 11777 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device |
| 11778 | * @phba: pointer to lpfc hba data structure. |
| 11779 | * |
| 11780 | * This routine is invoked to disable device interrupt and disassociate |
| 11781 | * the driver's interrupt handler(s) from interrupt vector(s) to device |
| 11782 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver |
| 11783 | * will release the interrupt vector(s) for the message signaled interrupt. |
| 11784 | **/ |
| 11785 | static void |
| 11786 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) |
| 11787 | { |
| 11788 | /* Disable the currently initialized interrupt mode */ |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11789 | if (phba->intr_type == MSIX) { |
| 11790 | int index; |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11791 | struct lpfc_hba_eq_hdl *eqhdl; |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11792 | |
| 11793 | /* Free up MSI-X multi-message vectors */ |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 11794 | for (index = 0; index < phba->cfg_irq_chann; index++) { |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 11795 | eqhdl = lpfc_get_eq_hdl(index); |
| 11796 | lpfc_irq_clear_aff(eqhdl); |
| 11797 | irq_set_affinity_hint(eqhdl->irq, NULL); |
| 11798 | free_irq(eqhdl->irq, eqhdl); |
James Smart | b3295c2 | 2019-01-28 11:14:30 -0800 | [diff] [blame] | 11799 | } |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11800 | } else { |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11801 | free_irq(phba->pcidev->irq, phba); |
Christoph Hellwig | 45ffac1 | 2017-02-12 13:52:26 -0800 | [diff] [blame] | 11802 | } |
| 11803 | |
| 11804 | pci_free_irq_vectors(phba->pcidev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11805 | |
| 11806 | /* Reset interrupt management states */ |
| 11807 | phba->intr_type = NONE; |
| 11808 | phba->sli.slistat.sli_intr = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11809 | } |
| 11810 | |
| 11811 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11812 | * lpfc_unset_hba - Unset SLI3 hba device initialization |
| 11813 | * @phba: pointer to lpfc hba data structure. |
| 11814 | * |
| 11815 | * This routine is invoked to unset the HBA device initialization steps to |
| 11816 | * a device with SLI-3 interface spec. |
| 11817 | **/ |
| 11818 | static void |
| 11819 | lpfc_unset_hba(struct lpfc_hba *phba) |
| 11820 | { |
| 11821 | struct lpfc_vport *vport = phba->pport; |
| 11822 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 11823 | |
| 11824 | spin_lock_irq(shost->host_lock); |
| 11825 | vport->load_flag |= FC_UNLOADING; |
| 11826 | spin_unlock_irq(shost->host_lock); |
| 11827 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 11828 | kfree(phba->vpi_bmask); |
| 11829 | kfree(phba->vpi_ids); |
| 11830 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 11831 | lpfc_stop_hba_timers(phba); |
| 11832 | |
| 11833 | phba->pport->work_port_events = 0; |
| 11834 | |
| 11835 | lpfc_sli_hba_down(phba); |
| 11836 | |
| 11837 | lpfc_sli_brdrestart(phba); |
| 11838 | |
| 11839 | lpfc_sli_disable_intr(phba); |
| 11840 | |
| 11841 | return; |
| 11842 | } |
| 11843 | |
| 11844 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11845 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy |
| 11846 | * @phba: Pointer to HBA context object. |
| 11847 | * |
| 11848 | * This function is called in the SLI4 code path to wait for completion |
| 11849 | * of device's XRIs exchange busy. It will check the XRI exchange busy |
| 11850 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after |
| 11851 | * that, it will check the XRI exchange busy on outstanding FCP and ELS |
| 11852 | * I/Os every 30 seconds, log error message, and wait forever. Only when |
| 11853 | * all XRI exchange busy complete, the driver unload shall proceed with |
| 11854 | * invoking the function reset ioctl mailbox command to the CNA and the |
| 11855 | * the rest of the driver unload resource release. |
| 11856 | **/ |
| 11857 | static void |
| 11858 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) |
| 11859 | { |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11860 | struct lpfc_sli4_hdw_queue *qp; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11861 | int idx, ccnt; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11862 | int wait_time = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11863 | int io_xri_cmpl = 1; |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11864 | int nvmet_xri_cmpl = 1; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11865 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
| 11866 | |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 11867 | /* Driver just aborted IOs during the hba_unset process. Pause |
| 11868 | * here to give the HBA time to complete the IO and get entries |
| 11869 | * into the abts lists. |
| 11870 | */ |
| 11871 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1 * 5); |
| 11872 | |
| 11873 | /* Wait for NVME pending IO to flush back to transport. */ |
| 11874 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
| 11875 | lpfc_nvme_wait_for_io_drain(phba); |
| 11876 | |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11877 | ccnt = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11878 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11879 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11880 | io_xri_cmpl = list_empty(&qp->lpfc_abts_io_buf_list); |
| 11881 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11882 | ccnt++; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11883 | } |
| 11884 | if (ccnt) |
| 11885 | io_xri_cmpl = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11886 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11887 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11888 | nvmet_xri_cmpl = |
| 11889 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11890 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 11891 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11892 | while (!els_xri_cmpl || !io_xri_cmpl || !nvmet_xri_cmpl) { |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11893 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 11894 | if (!nvmet_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11895 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 68c9b55 | 2018-06-26 08:24:25 -0700 | [diff] [blame] | 11896 | "6424 NVMET XRI exchange busy " |
| 11897 | "wait time: %d seconds.\n", |
| 11898 | wait_time/1000); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11899 | if (!io_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11900 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11901 | "6100 IO XRI exchange busy " |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11902 | "wait time: %d seconds.\n", |
| 11903 | wait_time/1000); |
| 11904 | if (!els_xri_cmpl) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 11905 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11906 | "2878 ELS XRI exchange busy " |
| 11907 | "wait time: %d seconds.\n", |
| 11908 | wait_time/1000); |
| 11909 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); |
| 11910 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; |
| 11911 | } else { |
| 11912 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); |
| 11913 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; |
| 11914 | } |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11915 | |
| 11916 | ccnt = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11917 | for (idx = 0; idx < phba->cfg_hdw_queue; idx++) { |
| 11918 | qp = &phba->sli4_hba.hdwq[idx]; |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 11919 | io_xri_cmpl = list_empty( |
| 11920 | &qp->lpfc_abts_io_buf_list); |
| 11921 | if (!io_xri_cmpl) /* if list is NOT empty */ |
| 11922 | ccnt++; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11923 | } |
| 11924 | if (ccnt) |
| 11925 | io_xri_cmpl = 0; |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 11926 | |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11927 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 86c6737 | 2017-04-21 16:05:04 -0700 | [diff] [blame] | 11928 | nvmet_xri_cmpl = list_empty( |
| 11929 | &phba->sli4_hba.lpfc_abts_nvmet_ctx_list); |
| 11930 | } |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11931 | els_xri_cmpl = |
| 11932 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 11933 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11934 | } |
| 11935 | } |
| 11936 | |
| 11937 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11938 | * lpfc_sli4_hba_unset - Unset the fcoe hba |
| 11939 | * @phba: Pointer to HBA context object. |
| 11940 | * |
| 11941 | * This function is called in the SLI4 code path to reset the HBA's FCoE |
| 11942 | * function. The caller is not required to hold any lock. This routine |
| 11943 | * issues PCI function reset mailbox command to reset the FCoE function. |
| 11944 | * At the end of the function, it calls lpfc_hba_down_post function to |
| 11945 | * free any pending commands. |
| 11946 | **/ |
| 11947 | static void |
| 11948 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) |
| 11949 | { |
| 11950 | int wait_cnt = 0; |
| 11951 | LPFC_MBOXQ_t *mboxq; |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11952 | struct pci_dev *pdev = phba->pcidev; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11953 | |
| 11954 | lpfc_stop_hba_timers(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 11955 | if (phba->pport) |
| 11956 | phba->sli4_hba.intr_enable = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11957 | |
| 11958 | /* |
| 11959 | * Gracefully wait out the potential current outstanding asynchronous |
| 11960 | * mailbox command. |
| 11961 | */ |
| 11962 | |
| 11963 | /* First, block any pending async mailbox command from posted */ |
| 11964 | spin_lock_irq(&phba->hbalock); |
| 11965 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; |
| 11966 | spin_unlock_irq(&phba->hbalock); |
| 11967 | /* Now, trying to wait it out if we can */ |
| 11968 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11969 | msleep(10); |
| 11970 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) |
| 11971 | break; |
| 11972 | } |
| 11973 | /* Forcefully release the outstanding mailbox command if timed out */ |
| 11974 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { |
| 11975 | spin_lock_irq(&phba->hbalock); |
| 11976 | mboxq = phba->sli.mbox_active; |
| 11977 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; |
| 11978 | __lpfc_mbox_cmpl_put(phba, mboxq); |
| 11979 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
| 11980 | phba->sli.mbox_active = NULL; |
| 11981 | spin_unlock_irq(&phba->hbalock); |
| 11982 | } |
| 11983 | |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 11984 | /* Abort all iocbs associated with the hba */ |
| 11985 | lpfc_sli_hba_iocb_abort(phba); |
| 11986 | |
| 11987 | /* Wait for completion of device XRI exchange busy */ |
| 11988 | lpfc_sli4_xri_exchange_busy_wait(phba); |
| 11989 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11990 | /* per-phba callback de-registration for hotplug event */ |
SeongJae Park | 46da547 | 2020-06-23 10:41:22 +0200 | [diff] [blame] | 11991 | if (phba->pport) |
| 11992 | lpfc_cpuhp_remove(phba); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 11993 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 11994 | /* Disable PCI subsystem interrupt */ |
| 11995 | lpfc_sli4_disable_intr(phba); |
| 11996 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 11997 | /* Disable SR-IOV if enabled */ |
| 11998 | if (phba->cfg_sriov_nr_virtfn) |
| 11999 | pci_disable_sriov(pdev); |
| 12000 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12001 | /* Stop kthread signal shall trigger work_done one more time */ |
| 12002 | kthread_stop(phba->worker_thread); |
| 12003 | |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12004 | /* Disable FW logging to host memory */ |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 12005 | lpfc_ras_stop_fwlog(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12006 | |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 12007 | /* Unset the queues shared with the hardware then release all |
| 12008 | * allocated resources. |
| 12009 | */ |
| 12010 | lpfc_sli4_queue_unset(phba); |
| 12011 | lpfc_sli4_queue_destroy(phba); |
| 12012 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 12013 | /* Reset SLI4 HBA FCoE function */ |
| 12014 | lpfc_pci_function_reset(phba); |
| 12015 | |
James Smart | 1165a5c | 2018-11-29 16:09:39 -0800 | [diff] [blame] | 12016 | /* Free RAS DMA memory */ |
| 12017 | if (phba->ras_fwlog.ras_enabled) |
| 12018 | lpfc_sli4_ras_dma_free(phba); |
| 12019 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12020 | /* Stop the SLI4 device port */ |
James Smart | 1ffdd2c | 2019-03-04 15:27:51 -0800 | [diff] [blame] | 12021 | if (phba->pport) |
| 12022 | phba->pport->work_port_events = 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12023 | } |
| 12024 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 12025 | /** |
| 12026 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. |
| 12027 | * @phba: Pointer to HBA context object. |
| 12028 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 12029 | * |
| 12030 | * This function is called in the SLI4 code path to read the port's |
| 12031 | * sli4 capabilities. |
| 12032 | * |
| 12033 | * This function may be be called from any context that can block-wait |
| 12034 | * for the completion. The expectation is that this routine is called |
| 12035 | * typically from probe_one or from the online routine. |
| 12036 | **/ |
| 12037 | int |
| 12038 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 12039 | { |
| 12040 | int rc; |
| 12041 | struct lpfc_mqe *mqe; |
| 12042 | struct lpfc_pc_sli4_params *sli4_params; |
| 12043 | uint32_t mbox_tmo; |
| 12044 | |
| 12045 | rc = 0; |
| 12046 | mqe = &mboxq->u.mqe; |
| 12047 | |
| 12048 | /* Read the port's SLI4 Parameters port capabilities */ |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12049 | lpfc_pc_sli4_params(mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 12050 | if (!phba->sli4_hba.intr_enable) |
| 12051 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
| 12052 | else { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12053 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 12054 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 12055 | } |
| 12056 | |
| 12057 | if (unlikely(rc)) |
| 12058 | return 1; |
| 12059 | |
| 12060 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 12061 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); |
| 12062 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); |
| 12063 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); |
| 12064 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, |
| 12065 | &mqe->un.sli4_params); |
| 12066 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, |
| 12067 | &mqe->un.sli4_params); |
| 12068 | sli4_params->proto_types = mqe->un.sli4_params.word3; |
| 12069 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; |
| 12070 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); |
| 12071 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); |
| 12072 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); |
| 12073 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); |
| 12074 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); |
| 12075 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); |
| 12076 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); |
| 12077 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); |
| 12078 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); |
| 12079 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); |
| 12080 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); |
| 12081 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); |
| 12082 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); |
| 12083 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); |
| 12084 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); |
| 12085 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); |
| 12086 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); |
| 12087 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); |
| 12088 | sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params); |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12089 | |
| 12090 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 12091 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 12092 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 12093 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 12094 | return rc; |
| 12095 | } |
| 12096 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12097 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12098 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. |
| 12099 | * @phba: Pointer to HBA context object. |
| 12100 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. |
| 12101 | * |
| 12102 | * This function is called in the SLI4 code path to read the port's |
| 12103 | * sli4 capabilities. |
| 12104 | * |
| 12105 | * This function may be be called from any context that can block-wait |
| 12106 | * for the completion. The expectation is that this routine is called |
| 12107 | * typically from probe_one or from the online routine. |
| 12108 | **/ |
| 12109 | int |
| 12110 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 12111 | { |
| 12112 | int rc; |
| 12113 | struct lpfc_mqe *mqe = &mboxq->u.mqe; |
| 12114 | struct lpfc_pc_sli4_params *sli4_params; |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12115 | uint32_t mbox_tmo; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12116 | int length; |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12117 | bool exp_wqcq_pages = true; |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12118 | struct lpfc_sli4_parameters *mbx_sli4_parameters; |
| 12119 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 12120 | /* |
| 12121 | * By default, the driver assumes the SLI4 port requires RPI |
| 12122 | * header postings. The SLI4_PARAM response will correct this |
| 12123 | * assumption. |
| 12124 | */ |
| 12125 | phba->sli4_hba.rpi_hdrs_in_use = 1; |
| 12126 | |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12127 | /* Read the port's SLI4 Config Parameters */ |
| 12128 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - |
| 12129 | sizeof(struct lpfc_sli4_cfg_mhdr)); |
| 12130 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
| 12131 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, |
| 12132 | length, LPFC_SLI4_MBX_EMBED); |
| 12133 | if (!phba->sli4_hba.intr_enable) |
| 12134 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 12135 | else { |
| 12136 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
| 12137 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
| 12138 | } |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12139 | if (unlikely(rc)) |
| 12140 | return rc; |
| 12141 | sli4_params = &phba->sli4_hba.pc_sli4_params; |
| 12142 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; |
| 12143 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); |
| 12144 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); |
| 12145 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); |
| 12146 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, |
| 12147 | mbx_sli4_parameters); |
| 12148 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, |
| 12149 | mbx_sli4_parameters); |
| 12150 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) |
| 12151 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; |
| 12152 | else |
| 12153 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; |
| 12154 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; |
| 12155 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 12156 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12157 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
| 12158 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); |
| 12159 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); |
| 12160 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); |
James Smart | 7365f6f | 2018-02-22 08:18:46 -0800 | [diff] [blame] | 12161 | sli4_params->eqav = bf_get(cfg_eqav, mbx_sli4_parameters); |
| 12162 | sli4_params->cqav = bf_get(cfg_cqav, mbx_sli4_parameters); |
James Smart | 0c65187 | 2013-07-15 18:33:23 -0400 | [diff] [blame] | 12163 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
James Smart | 66e9e6b | 2018-06-26 08:24:27 -0700 | [diff] [blame] | 12164 | sli4_params->bv1s = bf_get(cfg_bv1s, mbx_sli4_parameters); |
James Smart | 83c6cb1 | 2019-10-18 14:18:30 -0700 | [diff] [blame] | 12165 | sli4_params->pls = bf_get(cfg_pvl, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12166 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
| 12167 | mbx_sli4_parameters); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12168 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12169 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
| 12170 | mbx_sli4_parameters); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 12171 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
| 12172 | 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] | 12173 | |
James Smart | d79c9e9 | 2019-08-14 16:57:09 -0700 | [diff] [blame] | 12174 | /* Check for Extended Pre-Registered SGL support */ |
| 12175 | phba->cfg_xpsgl = bf_get(cfg_xpsgl, mbx_sli4_parameters); |
| 12176 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12177 | /* Check for firmware nvme support */ |
| 12178 | rc = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
| 12179 | bf_get(cfg_xib, mbx_sli4_parameters)); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12180 | |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12181 | if (rc) { |
| 12182 | /* Save this to indicate the Firmware supports NVME */ |
| 12183 | sli4_params->nvme = 1; |
| 12184 | |
| 12185 | /* Firmware NVME support, check driver FC4 NVME support */ |
| 12186 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) { |
| 12187 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
| 12188 | "6133 Disabling NVME support: " |
| 12189 | "FC4 type not supported: x%x\n", |
| 12190 | phba->cfg_enable_fc4_type); |
| 12191 | goto fcponly; |
| 12192 | } |
| 12193 | } else { |
| 12194 | /* No firmware NVME support, check driver FC4 NVME support */ |
| 12195 | sli4_params->nvme = 0; |
| 12196 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 12197 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, |
| 12198 | "6101 Disabling NVME support: Not " |
| 12199 | "supported by firmware (%d %d) x%x\n", |
| 12200 | bf_get(cfg_nvme, mbx_sli4_parameters), |
| 12201 | bf_get(cfg_xib, mbx_sli4_parameters), |
| 12202 | phba->cfg_enable_fc4_type); |
| 12203 | fcponly: |
| 12204 | phba->nvme_support = 0; |
| 12205 | phba->nvmet_support = 0; |
| 12206 | phba->cfg_nvmet_mrq = 0; |
James Smart | 6a224b4 | 2019-08-14 16:56:57 -0700 | [diff] [blame] | 12207 | phba->cfg_nvme_seg_cnt = 0; |
James Smart | c15e070 | 2019-05-21 17:49:02 -0700 | [diff] [blame] | 12208 | |
| 12209 | /* If no FC4 type support, move to just SCSI support */ |
| 12210 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
| 12211 | return -ENODEV; |
| 12212 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; |
| 12213 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12214 | } |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12215 | |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12216 | /* 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] | 12217 | * accommodate 512K and 1M IOs in a single nvme buf. |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12218 | */ |
James Smart | a5f7337 | 2019-09-21 20:58:50 -0700 | [diff] [blame] | 12219 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12220 | phba->cfg_sg_seg_cnt = LPFC_MAX_NVME_SEG_CNT; |
James Smart | c26c265 | 2019-08-14 16:56:49 -0700 | [diff] [blame] | 12221 | |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12222 | /* Only embed PBDE for if_type 6, PBDE support requires xib be set */ |
| 12223 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != |
| 12224 | LPFC_SLI_INTF_IF_TYPE_6) || (!bf_get(cfg_xib, mbx_sli4_parameters))) |
| 12225 | phba->cfg_enable_pbde = 0; |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12226 | |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 12227 | /* |
| 12228 | * To support Suppress Response feature we must satisfy 3 conditions. |
| 12229 | * lpfc_suppress_rsp module parameter must be set (default). |
| 12230 | * In SLI4-Parameters Descriptor: |
| 12231 | * Extended Inline Buffers (XIB) must be supported. |
| 12232 | * Suppress Response IU Not Supported (SRIUNS) must NOT be supported |
| 12233 | * (double negative). |
| 12234 | */ |
| 12235 | if (phba->cfg_suppress_rsp && bf_get(cfg_xib, mbx_sli4_parameters) && |
| 12236 | !(bf_get(cfg_nosr, mbx_sli4_parameters))) |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12237 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; |
James Smart | 20aefac | 2018-01-30 15:58:58 -0800 | [diff] [blame] | 12238 | else |
| 12239 | phba->cfg_suppress_rsp = 0; |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12240 | |
James Smart | 0cf07f84 | 2017-06-01 21:07:10 -0700 | [diff] [blame] | 12241 | if (bf_get(cfg_eqdr, mbx_sli4_parameters)) |
| 12242 | phba->sli.sli_flag |= LPFC_SLI_USE_EQDR; |
| 12243 | |
James Smart | 0558056 | 2011-05-24 11:40:48 -0400 | [diff] [blame] | 12244 | /* Make sure that sge_supp_len can be handled by the driver */ |
| 12245 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) |
| 12246 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; |
| 12247 | |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 12248 | /* |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12249 | * Check whether the adapter supports an embedded copy of the |
| 12250 | * FCP CMD IU within the WQE for FCP_Ixxx commands. In order |
| 12251 | * to use this option, 128-byte WQEs must be used. |
James Smart | b5c5395 | 2016-03-31 14:12:30 -0700 | [diff] [blame] | 12252 | */ |
| 12253 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) |
| 12254 | phba->fcp_embed_io = 1; |
| 12255 | else |
| 12256 | phba->fcp_embed_io = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 12257 | |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12258 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_NVME, |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12259 | "6422 XIB %d PBDE %d: FCP %d NVME %d %d %d\n", |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12260 | bf_get(cfg_xib, mbx_sli4_parameters), |
James Smart | 414abe0 | 2018-06-26 08:24:26 -0700 | [diff] [blame] | 12261 | phba->cfg_enable_pbde, |
| 12262 | phba->fcp_embed_io, phba->nvme_support, |
James Smart | 4e565cf | 2018-02-22 08:18:50 -0800 | [diff] [blame] | 12263 | phba->cfg_nvme_embed_cmd, phba->cfg_suppress_rsp); |
James Smart | 0bc2b7c | 2018-02-22 08:18:48 -0800 | [diff] [blame] | 12264 | |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12265 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
| 12266 | LPFC_SLI_INTF_IF_TYPE_2) && |
| 12267 | (bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf) == |
James Smart | c221768 | 2018-05-24 21:09:00 -0700 | [diff] [blame] | 12268 | LPFC_SLI_INTF_FAMILY_LNCR_A0)) |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12269 | exp_wqcq_pages = false; |
| 12270 | |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12271 | if ((bf_get(cfg_cqpsize, mbx_sli4_parameters) & LPFC_CQ_16K_PAGE_SZ) && |
| 12272 | (bf_get(cfg_wqpsize, mbx_sli4_parameters) & LPFC_WQ_16K_PAGE_SZ) && |
James Smart | bf316c7 | 2018-04-09 14:24:28 -0700 | [diff] [blame] | 12273 | exp_wqcq_pages && |
James Smart | c176ffa | 2018-01-30 15:58:46 -0800 | [diff] [blame] | 12274 | (sli4_params->wqsize & LPFC_WQ_SZ128_SUPPORT)) |
| 12275 | phba->enab_exp_wqcq_pages = 1; |
| 12276 | else |
| 12277 | phba->enab_exp_wqcq_pages = 0; |
James Smart | 7bdedb3 | 2016-07-06 12:36:00 -0700 | [diff] [blame] | 12278 | /* |
| 12279 | * Check if the SLI port supports MDS Diagnostics |
| 12280 | */ |
| 12281 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) |
| 12282 | phba->mds_diags_support = 1; |
| 12283 | else |
| 12284 | phba->mds_diags_support = 0; |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 12285 | |
James Smart | 0d8af09 | 2019-08-14 16:57:10 -0700 | [diff] [blame] | 12286 | /* |
| 12287 | * Check if the SLI port supports NSLER |
| 12288 | */ |
| 12289 | if (bf_get(cfg_nsler, mbx_sli4_parameters)) |
| 12290 | phba->nsler = 1; |
| 12291 | else |
| 12292 | phba->nsler = 0; |
| 12293 | |
James Smart | 8aaa7bc | 2020-10-20 13:27:17 -0700 | [diff] [blame] | 12294 | /* Save PB info for use during HBA setup */ |
| 12295 | sli4_params->mi_ver = bf_get(cfg_mi_ver, mbx_sli4_parameters); |
| 12296 | sli4_params->mib_bde_cnt = bf_get(cfg_mib_bde_cnt, mbx_sli4_parameters); |
| 12297 | sli4_params->mib_size = mbx_sli4_parameters->mib_size; |
| 12298 | sli4_params->mi_value = LPFC_DFLT_MIB_VAL; |
| 12299 | |
| 12300 | /* Next we check for Vendor MIB support */ |
| 12301 | if (sli4_params->mi_ver && phba->cfg_enable_mi) |
| 12302 | phba->cfg_fdmi_on = LPFC_FDMI_SUPPORT; |
| 12303 | |
| 12304 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12305 | "6461 MIB attr %d enable %d FDMI %d buf %d:%d\n", |
| 12306 | sli4_params->mi_ver, phba->cfg_enable_mi, |
| 12307 | sli4_params->mi_value, sli4_params->mib_bde_cnt, |
| 12308 | sli4_params->mib_size); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 12309 | return 0; |
| 12310 | } |
| 12311 | |
| 12312 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12313 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. |
| 12314 | * @pdev: pointer to PCI device |
| 12315 | * @pid: pointer to PCI device identifier |
| 12316 | * |
| 12317 | * This routine is to be called to attach a device with SLI-3 interface spec |
| 12318 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 12319 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 12320 | * information of the device and driver to see if the driver state that it can |
| 12321 | * support this kind of device. If the match is successful, the driver core |
| 12322 | * invokes this routine. If this routine determines it can claim the HBA, it |
| 12323 | * does all the initialization that it needs to do to handle the HBA properly. |
| 12324 | * |
| 12325 | * Return code |
| 12326 | * 0 - driver can claim the device |
| 12327 | * negative value - driver can not claim the device |
| 12328 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12329 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12330 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 12331 | { |
| 12332 | struct lpfc_hba *phba; |
| 12333 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12334 | struct Scsi_Host *shost = NULL; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12335 | int error; |
| 12336 | uint32_t cfg_mode, intr_mode; |
| 12337 | |
| 12338 | /* Allocate memory for HBA structure */ |
| 12339 | phba = lpfc_hba_alloc(pdev); |
| 12340 | if (!phba) |
| 12341 | return -ENOMEM; |
| 12342 | |
| 12343 | /* Perform generic PCI device enabling operation */ |
| 12344 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12345 | if (error) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12346 | goto out_free_phba; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12347 | |
| 12348 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ |
| 12349 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); |
| 12350 | if (error) |
| 12351 | goto out_disable_pci_dev; |
| 12352 | |
| 12353 | /* Set up SLI-3 specific device PCI memory space */ |
| 12354 | error = lpfc_sli_pci_mem_setup(phba); |
| 12355 | if (error) { |
| 12356 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12357 | "1402 Failed to set up pci memory space.\n"); |
| 12358 | goto out_disable_pci_dev; |
| 12359 | } |
| 12360 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12361 | /* Set up SLI-3 specific device driver resources */ |
| 12362 | error = lpfc_sli_driver_resource_setup(phba); |
| 12363 | if (error) { |
| 12364 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12365 | "1404 Failed to set up driver resource.\n"); |
| 12366 | goto out_unset_pci_mem_s3; |
| 12367 | } |
| 12368 | |
| 12369 | /* Initialize and populate the iocb list per host */ |
James Smart | d1f525a | 2017-04-21 16:04:55 -0700 | [diff] [blame] | 12370 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12371 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); |
| 12372 | if (error) { |
| 12373 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12374 | "1405 Failed to initialize iocb list.\n"); |
| 12375 | goto out_unset_driver_resource_s3; |
| 12376 | } |
| 12377 | |
| 12378 | /* Set up common device driver resources */ |
| 12379 | error = lpfc_setup_driver_resource_phase2(phba); |
| 12380 | if (error) { |
| 12381 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12382 | "1406 Failed to set up driver resource.\n"); |
| 12383 | goto out_free_iocb_list; |
| 12384 | } |
| 12385 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 12386 | /* Get the default values for Model Name and Description */ |
| 12387 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 12388 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12389 | /* Create SCSI host to the physical port */ |
| 12390 | error = lpfc_create_shost(phba); |
| 12391 | if (error) { |
| 12392 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12393 | "1407 Failed to create scsi host.\n"); |
| 12394 | goto out_unset_driver_resource; |
| 12395 | } |
| 12396 | |
| 12397 | /* Configure sysfs attributes */ |
| 12398 | vport = phba->pport; |
| 12399 | error = lpfc_alloc_sysfs_attr(vport); |
| 12400 | if (error) { |
| 12401 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12402 | "1476 Failed to allocate sysfs attr\n"); |
| 12403 | goto out_destroy_shost; |
| 12404 | } |
| 12405 | |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12406 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12407 | /* Now, trying to enable interrupt and bring up the device */ |
| 12408 | cfg_mode = phba->cfg_use_msi; |
| 12409 | while (true) { |
| 12410 | /* Put device to a known state before enabling interrupt */ |
| 12411 | lpfc_stop_port(phba); |
| 12412 | /* Configure and enable interrupt */ |
| 12413 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); |
| 12414 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12415 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12416 | "0431 Failed to enable interrupt.\n"); |
| 12417 | error = -ENODEV; |
| 12418 | goto out_free_sysfs_attr; |
| 12419 | } |
| 12420 | /* SLI-3 HBA setup */ |
| 12421 | if (lpfc_sli_hba_setup(phba)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12422 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12423 | "1477 Failed to set up hba\n"); |
| 12424 | error = -ENODEV; |
| 12425 | goto out_remove_device; |
| 12426 | } |
| 12427 | |
| 12428 | /* Wait 50ms for the interrupts of previous mailbox commands */ |
| 12429 | msleep(50); |
| 12430 | /* Check active interrupts on message signaled interrupts */ |
| 12431 | if (intr_mode == 0 || |
| 12432 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { |
| 12433 | /* Log the current active interrupt mode */ |
| 12434 | phba->intr_mode = intr_mode; |
| 12435 | lpfc_log_intr_mode(phba, intr_mode); |
| 12436 | break; |
| 12437 | } else { |
| 12438 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12439 | "0447 Configure interrupt mode (%d) " |
| 12440 | "failed active interrupt test.\n", |
| 12441 | intr_mode); |
| 12442 | /* Disable the current interrupt mode */ |
| 12443 | lpfc_sli_disable_intr(phba); |
| 12444 | /* Try next level of interrupt mode */ |
| 12445 | cfg_mode = --intr_mode; |
| 12446 | } |
| 12447 | } |
| 12448 | |
| 12449 | /* Perform post initialization setup */ |
| 12450 | lpfc_post_init_setup(phba); |
| 12451 | |
| 12452 | /* Check if there are static vports to be created. */ |
| 12453 | lpfc_create_static_vport(phba); |
| 12454 | |
| 12455 | return 0; |
| 12456 | |
| 12457 | out_remove_device: |
| 12458 | lpfc_unset_hba(phba); |
| 12459 | out_free_sysfs_attr: |
| 12460 | lpfc_free_sysfs_attr(vport); |
| 12461 | out_destroy_shost: |
| 12462 | lpfc_destroy_shost(phba); |
| 12463 | out_unset_driver_resource: |
| 12464 | lpfc_unset_driver_resource_phase2(phba); |
| 12465 | out_free_iocb_list: |
| 12466 | lpfc_free_iocb_list(phba); |
| 12467 | out_unset_driver_resource_s3: |
| 12468 | lpfc_sli_driver_resource_unset(phba); |
| 12469 | out_unset_pci_mem_s3: |
| 12470 | lpfc_sli_pci_mem_unset(phba); |
| 12471 | out_disable_pci_dev: |
| 12472 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 12473 | if (shost) |
| 12474 | scsi_host_put(shost); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12475 | out_free_phba: |
| 12476 | lpfc_hba_free(phba); |
| 12477 | return error; |
| 12478 | } |
| 12479 | |
| 12480 | /** |
| 12481 | * 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] | 12482 | * @pdev: pointer to PCI device |
| 12483 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12484 | * This routine is to be called to disattach a device with SLI-3 interface |
| 12485 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is |
| 12486 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 12487 | * device to be removed from the PCI subsystem properly. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12488 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 12489 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12490 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12491 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12492 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12493 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12494 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12495 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12496 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 12497 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 12498 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12499 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 12500 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12501 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12502 | lpfc_free_sysfs_attr(vport); |
| 12503 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12504 | /* Release all the vports against this physical port */ |
| 12505 | vports = lpfc_create_vport_work_array(phba); |
| 12506 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12507 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 12508 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 12509 | continue; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12510 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 12511 | } |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 12512 | lpfc_destroy_vport_work_array(phba, vports); |
| 12513 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 12514 | /* Remove FC host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12515 | fc_remove_host(shost); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 12516 | scsi_remove_host(shost); |
James Smart | d613b6a | 2017-02-12 13:52:37 -0800 | [diff] [blame] | 12517 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 12518 | /* Clean up all nodes, mailboxes and IOs. */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 12519 | lpfc_cleanup(vport); |
| 12520 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12521 | /* |
| 12522 | * Bring down the SLI Layer. This step disable all interrupts, |
| 12523 | * clears the rings, discards all mailbox commands, and resets |
| 12524 | * the HBA. |
| 12525 | */ |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12526 | |
Justin P. Mattock | 48e34d0 | 2010-12-30 15:07:58 -0800 | [diff] [blame] | 12527 | /* HBA interrupt will be disabled after this call */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12528 | lpfc_sli_hba_down(phba); |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 12529 | /* Stop kthread signal shall trigger work_done one more time */ |
| 12530 | kthread_stop(phba->worker_thread); |
| 12531 | /* Final cleanup of txcmplq and reset the HBA */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12532 | lpfc_sli_brdrestart(phba); |
| 12533 | |
James Smart | 7285990 | 2012-01-18 16:25:38 -0500 | [diff] [blame] | 12534 | kfree(phba->vpi_bmask); |
| 12535 | kfree(phba->vpi_ids); |
| 12536 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12537 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12538 | spin_lock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12539 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 12540 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12541 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12542 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12543 | |
James Smart | 912e3ac | 2011-05-24 11:42:11 -0400 | [diff] [blame] | 12544 | /* Disable SR-IOV if enabled */ |
| 12545 | if (phba->cfg_sriov_nr_virtfn) |
| 12546 | pci_disable_sriov(pdev); |
| 12547 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12548 | /* Disable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12549 | lpfc_sli_disable_intr(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12550 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 12551 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12552 | |
| 12553 | /* |
| 12554 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 12555 | * corresponding pools here. |
| 12556 | */ |
| 12557 | lpfc_scsi_free(phba); |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 12558 | lpfc_free_iocb_list(phba); |
| 12559 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12560 | lpfc_mem_free_all(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12561 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12562 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 12563 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 12564 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12565 | /* Free resources associated with SLI2 interface */ |
| 12566 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 12567 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12568 | |
| 12569 | /* unmap adapter SLIM and Control Registers */ |
| 12570 | iounmap(phba->ctrl_regs_memmap_p); |
| 12571 | iounmap(phba->slim_memmap_p); |
| 12572 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12573 | lpfc_hba_free(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12574 | |
Johannes Thumshirn | e0c0483 | 2016-06-07 09:44:03 +0200 | [diff] [blame] | 12575 | pci_release_mem_regions(pdev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 12576 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 12577 | } |
| 12578 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12579 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12580 | * 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] | 12581 | * @dev_d: pointer to device |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12582 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12583 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12584 | * system Power Management (PM) to device with SLI-3 interface spec. When |
| 12585 | * PM invokes this method, it quiesces the device by stopping the driver's |
| 12586 | * worker thread for the device, turning off device's interrupt and DMA, |
| 12587 | * and bring the device offline. Note that as the driver implements the |
| 12588 | * minimum PM requirements to a power-aware driver's PM support for the |
| 12589 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 12590 | * to the suspend() method call will be treated as SUSPEND and the driver will |
| 12591 | * fully reinitialize its device during resume() method call, the driver will |
| 12592 | * set device to PCI_D3hot state in PCI config space instead of setting it |
| 12593 | * according to the @msg provided by the PM. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12594 | * |
| 12595 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12596 | * 0 - driver suspended the device |
| 12597 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12598 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12599 | static int __maybe_unused |
| 12600 | lpfc_pci_suspend_one_s3(struct device *dev_d) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12601 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12602 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12603 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 12604 | |
| 12605 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12606 | "0473 PCI device Power Management suspend.\n"); |
| 12607 | |
| 12608 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12609 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12610 | lpfc_offline(phba); |
| 12611 | kthread_stop(phba->worker_thread); |
| 12612 | |
| 12613 | /* Disable interrupt from device */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12614 | lpfc_sli_disable_intr(phba); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12615 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12616 | return 0; |
| 12617 | } |
| 12618 | |
| 12619 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12620 | * 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] | 12621 | * @dev_d: pointer to device |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12622 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12623 | * This routine is to be called from the kernel's PCI subsystem to support |
| 12624 | * system Power Management (PM) to device with SLI-3 interface spec. When PM |
| 12625 | * invokes this method, it restores the device's PCI config space state and |
| 12626 | * fully reinitializes the device and brings it online. Note that as the |
| 12627 | * driver implements the minimum PM requirements to a power-aware driver's |
| 12628 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, |
| 12629 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the |
| 12630 | * driver will fully reinitialize its device during resume() method call, |
| 12631 | * the device will be set to PCI_D0 directly in PCI config space before |
| 12632 | * restoring the state. |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12633 | * |
| 12634 | * Return code |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12635 | * 0 - driver suspended the device |
| 12636 | * Error otherwise |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12637 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12638 | static int __maybe_unused |
| 12639 | lpfc_pci_resume_one_s3(struct device *dev_d) |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12640 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 12641 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12642 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12643 | uint32_t intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12644 | int error; |
| 12645 | |
| 12646 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 12647 | "0452 PCI device Power Management resume.\n"); |
| 12648 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12649 | /* Startup the kernel thread for this host adapter. */ |
| 12650 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 12651 | "lpfc_worker_%d", phba->brd_no); |
| 12652 | if (IS_ERR(phba->worker_thread)) { |
| 12653 | error = PTR_ERR(phba->worker_thread); |
| 12654 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 12655 | "0434 PM resume failed to start worker " |
| 12656 | "thread: error=x%x.\n", error); |
| 12657 | return error; |
| 12658 | } |
| 12659 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12660 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12661 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12662 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12663 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12664 | "0430 PM resume Failed to enable interrupt\n"); |
| 12665 | return -EIO; |
| 12666 | } else |
| 12667 | phba->intr_mode = intr_mode; |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12668 | |
| 12669 | /* Restart HBA and bring it online */ |
| 12670 | lpfc_sli_brdrestart(phba); |
| 12671 | lpfc_online(phba); |
| 12672 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12673 | /* Log the current active interrupt mode */ |
| 12674 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12675 | |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 12676 | return 0; |
| 12677 | } |
| 12678 | |
| 12679 | /** |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12680 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover |
| 12681 | * @phba: pointer to lpfc hba data structure. |
| 12682 | * |
| 12683 | * 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] | 12684 | * aborts all the outstanding SCSI I/Os to the pci device. |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12685 | **/ |
| 12686 | static void |
| 12687 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) |
| 12688 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12689 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12690 | "2723 PCI channel I/O abort preparing for recovery\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12691 | |
| 12692 | /* |
| 12693 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 12694 | * and let the SCSI mid-layer to retry them to recover. |
| 12695 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 12696 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12697 | } |
| 12698 | |
| 12699 | /** |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12700 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset |
| 12701 | * @phba: pointer to lpfc hba data structure. |
| 12702 | * |
| 12703 | * This routine is called to prepare the SLI3 device for PCI slot reset. It |
| 12704 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 12705 | * pending I/Os. |
| 12706 | **/ |
| 12707 | static void |
| 12708 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) |
| 12709 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12710 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12711 | "2710 PCI channel disable preparing for reset\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12712 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12713 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12714 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12715 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12716 | /* Block all SCSI devices' I/Os on the host */ |
| 12717 | lpfc_scsi_dev_block(phba); |
| 12718 | |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12719 | /* 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] | 12720 | lpfc_sli_flush_io_rings(phba); |
James Smart | ea714f3 | 2013-04-17 20:18:47 -0400 | [diff] [blame] | 12721 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12722 | /* stop all timers */ |
| 12723 | lpfc_stop_hba_timers(phba); |
| 12724 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12725 | /* Disable interrupt and pci device */ |
| 12726 | lpfc_sli_disable_intr(phba); |
| 12727 | pci_disable_device(phba->pcidev); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12728 | } |
| 12729 | |
| 12730 | /** |
| 12731 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable |
| 12732 | * @phba: pointer to lpfc hba data structure. |
| 12733 | * |
| 12734 | * This routine is called to prepare the SLI3 device for PCI slot permanently |
| 12735 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 12736 | * pending I/Os. |
| 12737 | **/ |
| 12738 | static void |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12739 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12740 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12741 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12742 | "2711 PCI channel permanent disable for failure\n"); |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12743 | /* Block all SCSI devices' I/Os on the host */ |
| 12744 | lpfc_scsi_dev_block(phba); |
| 12745 | |
| 12746 | /* stop all timers */ |
| 12747 | lpfc_stop_hba_timers(phba); |
| 12748 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12749 | /* Clean up all driver's outstanding SCSI I/Os */ |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 12750 | lpfc_sli_flush_io_rings(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12751 | } |
| 12752 | |
| 12753 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12754 | * 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] | 12755 | * @pdev: pointer to PCI device. |
| 12756 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12757 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12758 | * This routine is called from the PCI subsystem for I/O error handling to |
| 12759 | * device with SLI-3 interface spec. This function is called by the PCI |
| 12760 | * subsystem after a PCI bus error affecting this device has been detected. |
| 12761 | * When this function is invoked, it will need to stop all the I/Os and |
| 12762 | * interrupt(s) to the device. Once that is done, it will return |
| 12763 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery |
| 12764 | * as desired. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12765 | * |
| 12766 | * Return codes |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12767 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12768 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 12769 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12770 | **/ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12771 | static pci_ers_result_t |
| 12772 | 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] | 12773 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12774 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12775 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12776 | |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12777 | switch (state) { |
| 12778 | case pci_channel_io_normal: |
James Smart | 891478a | 2009-11-18 15:40:23 -0500 | [diff] [blame] | 12779 | /* Non-fatal error, prepare for recovery */ |
| 12780 | lpfc_sli_prep_dev_for_recover(phba); |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12781 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 12782 | case pci_channel_io_frozen: |
| 12783 | /* Fatal error, prepare for slot reset */ |
| 12784 | lpfc_sli_prep_dev_for_reset(phba); |
| 12785 | return PCI_ERS_RESULT_NEED_RESET; |
| 12786 | case pci_channel_io_perm_failure: |
| 12787 | /* Permanent failure, prepare for device down */ |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12788 | lpfc_sli_prep_dev_for_perm_failure(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12789 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12790 | default: |
| 12791 | /* Unknown state, prepare and request slot reset */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12792 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0d87841 | 2009-10-02 15:16:56 -0400 | [diff] [blame] | 12793 | "0472 Unknown PCI error state: x%x\n", state); |
| 12794 | lpfc_sli_prep_dev_for_reset(phba); |
| 12795 | return PCI_ERS_RESULT_NEED_RESET; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 12796 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12797 | } |
| 12798 | |
| 12799 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12800 | * 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] | 12801 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12802 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12803 | * This routine is called from the PCI subsystem for error handling to |
| 12804 | * device with SLI-3 interface spec. This is called after PCI bus has been |
| 12805 | * reset to restart the PCI card from scratch, as if from a cold-boot. |
| 12806 | * During the PCI subsystem error recovery, after driver returns |
| 12807 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 12808 | * recovery and then call this routine before calling the .resume method |
| 12809 | * to recover the device. This function will initialize the HBA device, |
| 12810 | * enable the interrupt, but it will just put the HBA to offline state |
| 12811 | * without passing any I/O traffic. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 12812 | * |
| 12813 | * Return codes |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12814 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 12815 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12816 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12817 | static pci_ers_result_t |
| 12818 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12819 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12820 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12821 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12822 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12823 | uint32_t intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12824 | |
| 12825 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 12826 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12827 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 12828 | "PCI device after reset.\n"); |
| 12829 | return PCI_ERS_RESULT_DISCONNECT; |
| 12830 | } |
| 12831 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12832 | pci_restore_state(pdev); |
James Smart | 1dfb5a4 | 2010-02-12 14:40:50 -0500 | [diff] [blame] | 12833 | |
| 12834 | /* |
| 12835 | * As the new kernel behavior of pci_restore_state() API call clears |
| 12836 | * device saved_state flag, need to save the restored state again. |
| 12837 | */ |
| 12838 | pci_save_state(pdev); |
| 12839 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 12840 | if (pdev->is_busmaster) |
| 12841 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12842 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12843 | spin_lock_irq(&phba->hbalock); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12844 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 12845 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12846 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12847 | /* Configure and enable interrupt */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12848 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12849 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12850 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12851 | "0427 Cannot re-enable interrupt after " |
| 12852 | "slot reset.\n"); |
| 12853 | return PCI_ERS_RESULT_DISCONNECT; |
| 12854 | } else |
| 12855 | phba->intr_mode = intr_mode; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12856 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 12857 | /* Take device offline, it will perform cleanup */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 12858 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12859 | lpfc_offline(phba); |
| 12860 | lpfc_sli_brdrestart(phba); |
| 12861 | |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 12862 | /* Log the current active interrupt mode */ |
| 12863 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 12864 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12865 | return PCI_ERS_RESULT_RECOVERED; |
| 12866 | } |
| 12867 | |
| 12868 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12869 | * 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] | 12870 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12871 | * |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12872 | * This routine is called from the PCI subsystem for error handling to device |
| 12873 | * with SLI-3 interface spec. It is called when kernel error recovery tells |
| 12874 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 12875 | * error recovery. After this call, traffic can start to flow from this device |
| 12876 | * again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12877 | */ |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12878 | static void |
| 12879 | lpfc_io_resume_s3(struct pci_dev *pdev) |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12880 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 12881 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 12882 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12883 | |
James Smart | e2af0d2 | 2010-03-15 11:25:32 -0400 | [diff] [blame] | 12884 | /* 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] | 12885 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 12886 | } |
| 12887 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 12888 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12889 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve |
| 12890 | * @phba: pointer to lpfc hba data structure. |
| 12891 | * |
| 12892 | * returns the number of ELS/CT IOCBs to reserve |
| 12893 | **/ |
| 12894 | int |
| 12895 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) |
| 12896 | { |
| 12897 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; |
| 12898 | |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12899 | if (phba->sli_rev == LPFC_SLI_REV4) { |
| 12900 | if (max_xri <= 100) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12901 | return 10; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12902 | else if (max_xri <= 256) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12903 | return 25; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12904 | else if (max_xri <= 512) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12905 | return 50; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12906 | else if (max_xri <= 1024) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12907 | return 100; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12908 | else if (max_xri <= 1536) |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 12909 | return 150; |
James Smart | 8a9d2e8 | 2012-05-09 21:16:12 -0400 | [diff] [blame] | 12910 | else if (max_xri <= 2048) |
| 12911 | return 200; |
| 12912 | else |
| 12913 | return 250; |
James Smart | f112668 | 2009-06-10 17:22:44 -0400 | [diff] [blame] | 12914 | } else |
| 12915 | return 0; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 12916 | } |
| 12917 | |
| 12918 | /** |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12919 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve |
| 12920 | * @phba: pointer to lpfc hba data structure. |
| 12921 | * |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12922 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12923 | **/ |
| 12924 | int |
| 12925 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) |
| 12926 | { |
| 12927 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); |
| 12928 | |
James Smart | f358dd0 | 2017-02-12 13:52:34 -0800 | [diff] [blame] | 12929 | if (phba->nvmet_support) |
| 12930 | max_xri += LPFC_NVMET_BUF_POST; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12931 | return max_xri; |
| 12932 | } |
| 12933 | |
| 12934 | |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12935 | static int |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12936 | lpfc_log_write_firmware_error(struct lpfc_hba *phba, uint32_t offset, |
| 12937 | uint32_t magic_number, uint32_t ftype, uint32_t fid, uint32_t fsize, |
| 12938 | const struct firmware *fw) |
| 12939 | { |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12940 | int rc; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12941 | |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12942 | /* Three cases: (1) FW was not supported on the detected adapter. |
| 12943 | * (2) FW update has been locked out administratively. |
| 12944 | * (3) Some other error during FW update. |
| 12945 | * In each case, an unmaskable message is written to the console |
| 12946 | * for admin diagnosis. |
| 12947 | */ |
| 12948 | if (offset == ADD_STATUS_FW_NOT_SUPPORTED || |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12949 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
James Smart | 5792a0e | 2019-10-25 11:43:42 -0700 | [diff] [blame] | 12950 | magic_number != MAGIC_NUMBER_G6) || |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12951 | (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC && |
James Smart | 5792a0e | 2019-10-25 11:43:42 -0700 | [diff] [blame] | 12952 | magic_number != MAGIC_NUMBER_G7)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12953 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12954 | "3030 This firmware version is not supported on" |
| 12955 | " this HBA model. Device:%x Magic:%x Type:%x " |
| 12956 | "ID:%x Size %d %zd\n", |
| 12957 | phba->pcidev->device, magic_number, ftype, fid, |
| 12958 | fsize, fw->size); |
| 12959 | rc = -EINVAL; |
| 12960 | } else if (offset == ADD_STATUS_FW_DOWNLOAD_HW_DISABLED) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12961 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12962 | "3021 Firmware downloads have been prohibited " |
| 12963 | "by a system configuration setting on " |
| 12964 | "Device:%x Magic:%x Type:%x ID:%x Size %d " |
| 12965 | "%zd\n", |
| 12966 | phba->pcidev->device, magic_number, ftype, fid, |
| 12967 | fsize, fw->size); |
| 12968 | rc = -EACCES; |
| 12969 | } else { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 12970 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12971 | "3022 FW Download failed. Add Status x%x " |
| 12972 | "Device:%x Magic:%x Type:%x ID:%x Size %d " |
| 12973 | "%zd\n", |
| 12974 | offset, phba->pcidev->device, magic_number, |
| 12975 | ftype, fid, fsize, fw->size); |
| 12976 | rc = -EIO; |
| 12977 | } |
| 12978 | return rc; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12979 | } |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 12980 | |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 12981 | /** |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12982 | * lpfc_write_firmware - attempt to write a firmware image to the port |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12983 | * @fw: pointer to firmware image returned from request_firmware. |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 12984 | * @context: pointer to firmware image returned from request_firmware. |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12985 | * |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12986 | **/ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12987 | static void |
| 12988 | lpfc_write_firmware(const struct firmware *fw, void *context) |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12989 | { |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12990 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
James Smart | 6b5151f | 2012-01-18 16:24:06 -0500 | [diff] [blame] | 12991 | char fwrev[FW_REV_STR_SIZE]; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 12992 | struct lpfc_grp_hdr *image; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12993 | struct list_head dma_buffer_list; |
| 12994 | int i, rc = 0; |
| 12995 | struct lpfc_dmabuf *dmabuf, *next; |
| 12996 | uint32_t offset = 0, temp_offset = 0; |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 12997 | uint32_t magic_number, ftype, fid, fsize; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 12998 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 12999 | /* It can be null in no-wait mode, sanity check */ |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13000 | if (!fw) { |
| 13001 | rc = -ENXIO; |
| 13002 | goto out; |
| 13003 | } |
| 13004 | image = (struct lpfc_grp_hdr *)fw->data; |
| 13005 | |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 13006 | magic_number = be32_to_cpu(image->magic_number); |
| 13007 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13008 | fid = bf_get_be32(lpfc_grp_hdr_id, image); |
James Smart | 6b6ef5d | 2016-10-13 15:06:17 -0700 | [diff] [blame] | 13009 | fsize = be32_to_cpu(image->size); |
| 13010 | |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13011 | INIT_LIST_HEAD(&dma_buffer_list); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13012 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13013 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13014 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13015 | "3023 Updating Firmware, Current Version:%s " |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13016 | "New Version:%s\n", |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13017 | fwrev, image->revision); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13018 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
| 13019 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), |
| 13020 | GFP_KERNEL); |
| 13021 | if (!dmabuf) { |
| 13022 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13023 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13024 | } |
| 13025 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 13026 | SLI4_PAGE_SIZE, |
| 13027 | &dmabuf->phys, |
| 13028 | GFP_KERNEL); |
| 13029 | if (!dmabuf->virt) { |
| 13030 | kfree(dmabuf); |
| 13031 | rc = -ENOMEM; |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13032 | goto release_out; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13033 | } |
| 13034 | list_add_tail(&dmabuf->list, &dma_buffer_list); |
| 13035 | } |
| 13036 | while (offset < fw->size) { |
| 13037 | temp_offset = offset; |
| 13038 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13039 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13040 | memcpy(dmabuf->virt, |
| 13041 | fw->data + temp_offset, |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13042 | fw->size - temp_offset); |
| 13043 | temp_offset = fw->size; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13044 | break; |
| 13045 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13046 | memcpy(dmabuf->virt, fw->data + temp_offset, |
| 13047 | SLI4_PAGE_SIZE); |
James Smart | 88a2cfb | 2011-07-22 18:36:33 -0400 | [diff] [blame] | 13048 | temp_offset += SLI4_PAGE_SIZE; |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13049 | } |
| 13050 | rc = lpfc_wr_object(phba, &dma_buffer_list, |
| 13051 | (fw->size - offset), &offset); |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13052 | if (rc) { |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13053 | rc = lpfc_log_write_firmware_error(phba, offset, |
| 13054 | magic_number, |
| 13055 | ftype, |
| 13056 | fid, |
| 13057 | fsize, |
| 13058 | fw); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13059 | goto release_out; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13060 | } |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13061 | } |
| 13062 | rc = offset; |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13063 | } else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13064 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 1feb820 | 2018-02-22 08:18:47 -0800 | [diff] [blame] | 13065 | "3029 Skipped Firmware update, Current " |
| 13066 | "Version:%s New Version:%s\n", |
| 13067 | fwrev, image->revision); |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13068 | |
| 13069 | release_out: |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13070 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
| 13071 | list_del(&dmabuf->list); |
| 13072 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
| 13073 | dmabuf->virt, dmabuf->phys); |
| 13074 | kfree(dmabuf); |
| 13075 | } |
James Smart | ce39628 | 2012-09-29 11:30:56 -0400 | [diff] [blame] | 13076 | release_firmware(fw); |
| 13077 | out: |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13078 | if (rc < 0) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13079 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13080 | "3062 Firmware update error, status %d.\n", rc); |
| 13081 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13082 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0a5ce73 | 2019-10-18 14:18:18 -0700 | [diff] [blame] | 13083 | "3024 Firmware update success: size %d.\n", rc); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13084 | } |
| 13085 | |
| 13086 | /** |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13087 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade |
| 13088 | * @phba: pointer to lpfc hba data structure. |
Lee Jones | fe614ac | 2020-07-23 13:24:22 +0100 | [diff] [blame] | 13089 | * @fw_upgrade: which firmware to update. |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13090 | * |
| 13091 | * This routine is called to perform Linux generic firmware upgrade on device |
| 13092 | * that supports such feature. |
| 13093 | **/ |
| 13094 | int |
| 13095 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) |
| 13096 | { |
| 13097 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; |
| 13098 | int ret; |
| 13099 | const struct firmware *fw; |
| 13100 | |
| 13101 | /* Only supported on SLI4 interface type 2 for now */ |
James Smart | 27d6ac0 | 2018-02-22 08:18:42 -0800 | [diff] [blame] | 13102 | 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] | 13103 | LPFC_SLI_INTF_IF_TYPE_2) |
| 13104 | return -EPERM; |
| 13105 | |
| 13106 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); |
| 13107 | |
| 13108 | if (fw_upgrade == INT_FW_UPGRADE) { |
| 13109 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 13110 | file_name, &phba->pcidev->dev, |
| 13111 | GFP_KERNEL, (void *)phba, |
| 13112 | lpfc_write_firmware); |
| 13113 | } else if (fw_upgrade == RUN_FW_UPGRADE) { |
| 13114 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); |
| 13115 | if (!ret) |
| 13116 | lpfc_write_firmware(fw, (void *)phba); |
| 13117 | } else { |
| 13118 | ret = -EINVAL; |
| 13119 | } |
| 13120 | |
| 13121 | return ret; |
| 13122 | } |
| 13123 | |
| 13124 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13125 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
| 13126 | * @pdev: pointer to PCI device |
| 13127 | * @pid: pointer to PCI device identifier |
| 13128 | * |
| 13129 | * This routine is called from the kernel's PCI subsystem to device with |
| 13130 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 13131 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
| 13132 | * information of the device and driver to see if the driver state that it |
| 13133 | * can support this kind of device. If the match is successful, the driver |
| 13134 | * core invokes this routine. If this routine determines it can claim the HBA, |
| 13135 | * it does all the initialization that it needs to do to handle the HBA |
| 13136 | * properly. |
| 13137 | * |
| 13138 | * Return code |
| 13139 | * 0 - driver can claim the device |
| 13140 | * negative value - driver can not claim the device |
| 13141 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13142 | static int |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13143 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13144 | { |
| 13145 | struct lpfc_hba *phba; |
| 13146 | struct lpfc_vport *vport = NULL; |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13147 | struct Scsi_Host *shost = NULL; |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 13148 | int error; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13149 | uint32_t cfg_mode, intr_mode; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13150 | |
| 13151 | /* Allocate memory for HBA structure */ |
| 13152 | phba = lpfc_hba_alloc(pdev); |
| 13153 | if (!phba) |
| 13154 | return -ENOMEM; |
| 13155 | |
| 13156 | /* Perform generic PCI device enabling operation */ |
| 13157 | error = lpfc_enable_pci_dev(phba); |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13158 | if (error) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13159 | goto out_free_phba; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13160 | |
| 13161 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
| 13162 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); |
| 13163 | if (error) |
| 13164 | goto out_disable_pci_dev; |
| 13165 | |
| 13166 | /* Set up SLI-4 specific device PCI memory space */ |
| 13167 | error = lpfc_sli4_pci_mem_setup(phba); |
| 13168 | if (error) { |
| 13169 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13170 | "1410 Failed to set up pci memory space.\n"); |
| 13171 | goto out_disable_pci_dev; |
| 13172 | } |
| 13173 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13174 | /* Set up SLI-4 Specific device driver resources */ |
| 13175 | error = lpfc_sli4_driver_resource_setup(phba); |
| 13176 | if (error) { |
| 13177 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13178 | "1412 Failed to set up driver resource.\n"); |
| 13179 | goto out_unset_pci_mem_s4; |
| 13180 | } |
| 13181 | |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 13182 | INIT_LIST_HEAD(&phba->active_rrq_list); |
James Smart | 7d791df | 2011-07-22 18:37:52 -0400 | [diff] [blame] | 13183 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
James Smart | 19ca760 | 2010-11-20 23:11:55 -0500 | [diff] [blame] | 13184 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13185 | /* Set up common device driver resources */ |
| 13186 | error = lpfc_setup_driver_resource_phase2(phba); |
| 13187 | if (error) { |
| 13188 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13189 | "1414 Failed to set up driver resource.\n"); |
James Smart | 6c621a2 | 2017-05-15 15:20:45 -0700 | [diff] [blame] | 13190 | goto out_unset_driver_resource_s4; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13191 | } |
| 13192 | |
James Smart | 079b5c9 | 2011-08-21 21:48:49 -0400 | [diff] [blame] | 13193 | /* Get the default values for Model Name and Description */ |
| 13194 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 13195 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13196 | /* Now, trying to enable interrupt and bring up the device */ |
| 13197 | cfg_mode = phba->cfg_use_msi; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13198 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13199 | /* Put device to a known state before enabling interrupt */ |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13200 | phba->pport = NULL; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13201 | lpfc_stop_port(phba); |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13202 | |
James Smart | dcaa213 | 2019-11-04 16:57:06 -0800 | [diff] [blame] | 13203 | /* Init cpu_map array */ |
| 13204 | lpfc_cpu_map_array_init(phba); |
| 13205 | |
| 13206 | /* Init hba_eq_hdl array */ |
| 13207 | lpfc_hba_eq_hdl_array_init(phba); |
| 13208 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13209 | /* Configure and enable interrupt */ |
| 13210 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
| 13211 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13212 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13213 | "0426 Failed to enable interrupt.\n"); |
| 13214 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13215 | goto out_unset_driver_resource; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13216 | } |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13217 | /* Default to single EQ for non-MSI-X */ |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13218 | if (phba->intr_type != MSIX) { |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13219 | phba->cfg_irq_chann = 1; |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13220 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
James Smart | 2d7dbc4 | 2017-02-12 13:52:35 -0800 | [diff] [blame] | 13221 | if (phba->nvmet_support) |
| 13222 | phba->cfg_nvmet_mrq = 1; |
| 13223 | } |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13224 | } |
James Smart | 6a828b0 | 2019-01-28 11:14:31 -0800 | [diff] [blame] | 13225 | lpfc_cpu_affinity_check(phba, phba->cfg_irq_chann); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13226 | |
| 13227 | /* Create SCSI host to the physical port */ |
| 13228 | error = lpfc_create_shost(phba); |
| 13229 | if (error) { |
| 13230 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13231 | "1415 Failed to create scsi host.\n"); |
| 13232 | goto out_disable_intr; |
| 13233 | } |
| 13234 | vport = phba->pport; |
| 13235 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
| 13236 | |
| 13237 | /* Configure sysfs attributes */ |
| 13238 | error = lpfc_alloc_sysfs_attr(vport); |
| 13239 | if (error) { |
| 13240 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13241 | "1416 Failed to allocate sysfs attr\n"); |
| 13242 | goto out_destroy_shost; |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13243 | } |
| 13244 | |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13245 | /* Set up SLI-4 HBA */ |
| 13246 | if (lpfc_sli4_hba_setup(phba)) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13247 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13248 | "1421 Failed to set up hba\n"); |
| 13249 | error = -ENODEV; |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13250 | goto out_free_sysfs_attr; |
James Smart | 7b15db3 | 2013-01-03 15:43:29 -0500 | [diff] [blame] | 13251 | } |
| 13252 | |
| 13253 | /* Log the current active interrupt mode */ |
| 13254 | phba->intr_mode = intr_mode; |
| 13255 | lpfc_log_intr_mode(phba, intr_mode); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13256 | |
| 13257 | /* Perform post initialization setup */ |
| 13258 | lpfc_post_init_setup(phba); |
| 13259 | |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13260 | /* NVME support in FW earlier in the driver load corrects the |
| 13261 | * FC4 type making a check for nvme_support unnecessary. |
| 13262 | */ |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 13263 | if (phba->nvmet_support == 0) { |
| 13264 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { |
| 13265 | /* Create NVME binding with nvme_fc_transport. This |
| 13266 | * ensures the vport is initialized. If the localport |
| 13267 | * create fails, it should not unload the driver to |
| 13268 | * support field issues. |
| 13269 | */ |
| 13270 | error = lpfc_nvme_create_localport(vport); |
| 13271 | if (error) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13272 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 0794d60 | 2019-01-28 11:14:19 -0800 | [diff] [blame] | 13273 | "6004 NVME registration " |
| 13274 | "failed, error x%x\n", |
| 13275 | error); |
| 13276 | } |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13277 | } |
| 13278 | } |
James Smart | 895427b | 2017-02-12 13:52:30 -0800 | [diff] [blame] | 13279 | |
James Smart | c71ab86 | 2012-10-31 14:44:33 -0400 | [diff] [blame] | 13280 | /* check for firmware upgrade or downgrade */ |
| 13281 | if (phba->cfg_request_firmware_upgrade) |
Sebastian Herbszt | db6f1c2 | 2015-08-31 16:48:14 -0400 | [diff] [blame] | 13282 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
James Smart | 52d5244 | 2011-05-24 11:42:45 -0400 | [diff] [blame] | 13283 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 13284 | /* Check if there are static vports to be created. */ |
| 13285 | lpfc_create_static_vport(phba); |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13286 | |
| 13287 | /* Enable RAS FW log support */ |
| 13288 | lpfc_sli4_ras_setup(phba); |
| 13289 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13290 | INIT_LIST_HEAD(&phba->poll_list); |
James Smart | f861f59 | 2020-03-22 11:12:54 -0700 | [diff] [blame] | 13291 | timer_setup(&phba->cpuhp_poll_timer, lpfc_sli4_poll_hbtimer, 0); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 13292 | cpuhp_state_add_instance_nocalls(lpfc_cpuhp_state, &phba->cpuhp); |
| 13293 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13294 | return 0; |
| 13295 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13296 | out_free_sysfs_attr: |
| 13297 | lpfc_free_sysfs_attr(vport); |
| 13298 | out_destroy_shost: |
| 13299 | lpfc_destroy_shost(phba); |
James Smart | cdb42be | 2019-01-28 11:14:21 -0800 | [diff] [blame] | 13300 | out_disable_intr: |
| 13301 | lpfc_sli4_disable_intr(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13302 | out_unset_driver_resource: |
| 13303 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13304 | out_unset_driver_resource_s4: |
| 13305 | lpfc_sli4_driver_resource_unset(phba); |
| 13306 | out_unset_pci_mem_s4: |
| 13307 | lpfc_sli4_pci_mem_unset(phba); |
| 13308 | out_disable_pci_dev: |
| 13309 | lpfc_disable_pci_dev(phba); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 13310 | if (shost) |
| 13311 | scsi_host_put(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13312 | out_free_phba: |
| 13313 | lpfc_hba_free(phba); |
| 13314 | return error; |
| 13315 | } |
| 13316 | |
| 13317 | /** |
| 13318 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
| 13319 | * @pdev: pointer to PCI device |
| 13320 | * |
| 13321 | * This routine is called from the kernel's PCI subsystem to device with |
| 13322 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is |
| 13323 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
| 13324 | * device to be removed from the PCI subsystem properly. |
| 13325 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13326 | static void |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13327 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
| 13328 | { |
| 13329 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13330 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 13331 | struct lpfc_vport **vports; |
| 13332 | struct lpfc_hba *phba = vport->phba; |
| 13333 | int i; |
| 13334 | |
| 13335 | /* Mark the device unloading flag */ |
| 13336 | spin_lock_irq(&phba->hbalock); |
| 13337 | vport->load_flag |= FC_UNLOADING; |
| 13338 | spin_unlock_irq(&phba->hbalock); |
| 13339 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13340 | lpfc_free_sysfs_attr(vport); |
| 13341 | |
| 13342 | /* Release all the vports against this physical port */ |
| 13343 | vports = lpfc_create_vport_work_array(phba); |
| 13344 | if (vports != NULL) |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 13345 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
| 13346 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) |
| 13347 | continue; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13348 | fc_vport_terminate(vports[i]->fc_vport); |
James Smart | 587a37f | 2012-05-09 21:16:03 -0400 | [diff] [blame] | 13349 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13350 | lpfc_destroy_vport_work_array(phba, vports); |
| 13351 | |
James Smart | 95f0ef8 | 2020-11-15 11:26:32 -0800 | [diff] [blame] | 13352 | /* Remove FC host with the physical port */ |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13353 | fc_remove_host(shost); |
James Smart | e9b1108 | 2020-11-15 11:26:33 -0800 | [diff] [blame] | 13354 | scsi_remove_host(shost); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13355 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13356 | /* Perform ndlp cleanup on the physical port. The nvme and nvmet |
| 13357 | * localports are destroyed after to cleanup all transport memory. |
| 13358 | */ |
| 13359 | lpfc_cleanup(vport); |
| 13360 | lpfc_nvmet_destroy_targetport(phba); |
| 13361 | lpfc_nvme_destroy_localport(vport); |
| 13362 | |
James Smart | c490850 | 2019-01-28 11:14:28 -0800 | [diff] [blame] | 13363 | /* De-allocate multi-XRI pools */ |
| 13364 | if (phba->cfg_xri_rebalancing) |
| 13365 | lpfc_destroy_multixri_pools(phba); |
| 13366 | |
James Smart | 281d619 | 2018-01-30 15:58:47 -0800 | [diff] [blame] | 13367 | /* |
| 13368 | * Bring down the SLI Layer. This step disables all interrupts, |
| 13369 | * clears the rings, discards all mailbox commands, and resets |
| 13370 | * the HBA FCoE function. |
| 13371 | */ |
| 13372 | lpfc_debugfs_terminate(vport); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13373 | |
Dick Kennedy | 1901762 | 2017-09-29 17:34:27 -0700 | [diff] [blame] | 13374 | lpfc_stop_hba_timers(phba); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13375 | spin_lock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13376 | list_del_init(&vport->listentry); |
James Smart | 523128e | 2018-09-10 10:30:46 -0700 | [diff] [blame] | 13377 | spin_unlock_irq(&phba->port_list_lock); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13378 | |
James Smart | 3677a3a | 2010-09-29 11:19:14 -0400 | [diff] [blame] | 13379 | /* Perform scsi free before driver resource_unset since scsi |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13380 | * buffers are released to their corresponding pools here. |
| 13381 | */ |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13382 | lpfc_io_free(phba); |
James Smart | 0164956 | 2017-02-12 13:52:32 -0800 | [diff] [blame] | 13383 | lpfc_free_iocb_list(phba); |
James Smart | 5e5b511 | 2019-01-28 11:14:22 -0800 | [diff] [blame] | 13384 | lpfc_sli4_hba_unset(phba); |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 13385 | |
James Smart | 0cdb84e | 2018-04-09 14:24:26 -0700 | [diff] [blame] | 13386 | lpfc_unset_driver_resource_phase2(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13387 | lpfc_sli4_driver_resource_unset(phba); |
| 13388 | |
| 13389 | /* Unmap adapter Control and Doorbell registers */ |
| 13390 | lpfc_sli4_pci_mem_unset(phba); |
| 13391 | |
| 13392 | /* Release PCI resources and disable device's PCI function */ |
| 13393 | scsi_host_put(shost); |
| 13394 | lpfc_disable_pci_dev(phba); |
| 13395 | |
| 13396 | /* Finally, free the driver's device data structure */ |
| 13397 | lpfc_hba_free(phba); |
| 13398 | |
| 13399 | return; |
| 13400 | } |
| 13401 | |
| 13402 | /** |
| 13403 | * 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] | 13404 | * @dev_d: pointer to device |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13405 | * |
| 13406 | * This routine is called from the kernel's PCI subsystem to support system |
| 13407 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes |
| 13408 | * this method, it quiesces the device by stopping the driver's worker |
| 13409 | * thread for the device, turning off device's interrupt and DMA, and bring |
| 13410 | * the device offline. Note that as the driver implements the minimum PM |
| 13411 | * requirements to a power-aware driver's PM support for suspend/resume -- all |
| 13412 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 13413 | * method call will be treated as SUSPEND and the driver will fully |
| 13414 | * reinitialize its device during resume() method call, the driver will set |
| 13415 | * device to PCI_D3hot state in PCI config space instead of setting it |
| 13416 | * according to the @msg provided by the PM. |
| 13417 | * |
| 13418 | * Return code |
| 13419 | * 0 - driver suspended the device |
| 13420 | * Error otherwise |
| 13421 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13422 | static int __maybe_unused |
| 13423 | lpfc_pci_suspend_one_s4(struct device *dev_d) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13424 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13425 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13426 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13427 | |
| 13428 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13429 | "2843 PCI device Power Management suspend.\n"); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13430 | |
| 13431 | /* Bring down the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13432 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13433 | lpfc_offline(phba); |
| 13434 | kthread_stop(phba->worker_thread); |
| 13435 | |
| 13436 | /* Disable interrupt from device */ |
| 13437 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13438 | lpfc_sli4_queue_destroy(phba); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13439 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13440 | return 0; |
| 13441 | } |
| 13442 | |
| 13443 | /** |
| 13444 | * 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] | 13445 | * @dev_d: pointer to device |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13446 | * |
| 13447 | * This routine is called from the kernel's PCI subsystem to support system |
| 13448 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes |
| 13449 | * this method, it restores the device's PCI config space state and fully |
| 13450 | * reinitializes the device and brings it online. Note that as the driver |
| 13451 | * implements the minimum PM requirements to a power-aware driver's PM for |
| 13452 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) |
| 13453 | * to the suspend() method call will be treated as SUSPEND and the driver |
| 13454 | * will fully reinitialize its device during resume() method call, the device |
| 13455 | * will be set to PCI_D0 directly in PCI config space before restoring the |
| 13456 | * state. |
| 13457 | * |
| 13458 | * Return code |
| 13459 | * 0 - driver suspended the device |
| 13460 | * Error otherwise |
| 13461 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13462 | static int __maybe_unused |
| 13463 | lpfc_pci_resume_one_s4(struct device *dev_d) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13464 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13465 | struct Scsi_Host *shost = dev_get_drvdata(dev_d); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13466 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13467 | uint32_t intr_mode; |
| 13468 | int error; |
| 13469 | |
| 13470 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 13471 | "0292 PCI device Power Management resume.\n"); |
| 13472 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13473 | /* Startup the kernel thread for this host adapter. */ |
| 13474 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 13475 | "lpfc_worker_%d", phba->brd_no); |
| 13476 | if (IS_ERR(phba->worker_thread)) { |
| 13477 | error = PTR_ERR(phba->worker_thread); |
| 13478 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 13479 | "0293 PM resume failed to start worker " |
| 13480 | "thread: error=x%x.\n", error); |
| 13481 | return error; |
| 13482 | } |
| 13483 | |
| 13484 | /* Configure and enable interrupt */ |
| 13485 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13486 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13487 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13488 | "0294 PM resume Failed to enable interrupt\n"); |
| 13489 | return -EIO; |
| 13490 | } else |
| 13491 | phba->intr_mode = intr_mode; |
| 13492 | |
| 13493 | /* Restart HBA and bring it online */ |
| 13494 | lpfc_sli_brdrestart(phba); |
| 13495 | lpfc_online(phba); |
| 13496 | |
| 13497 | /* Log the current active interrupt mode */ |
| 13498 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13499 | |
| 13500 | return 0; |
| 13501 | } |
| 13502 | |
| 13503 | /** |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13504 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover |
| 13505 | * @phba: pointer to lpfc hba data structure. |
| 13506 | * |
| 13507 | * This routine is called to prepare the SLI4 device for PCI slot recover. It |
| 13508 | * aborts all the outstanding SCSI I/Os to the pci device. |
| 13509 | **/ |
| 13510 | static void |
| 13511 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) |
| 13512 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13513 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13514 | "2828 PCI channel I/O abort preparing for recovery\n"); |
| 13515 | /* |
| 13516 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq |
| 13517 | * and let the SCSI mid-layer to retry them to recover. |
| 13518 | */ |
James Smart | db55fba | 2014-04-04 13:52:02 -0400 | [diff] [blame] | 13519 | lpfc_sli_abort_fcp_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13520 | } |
| 13521 | |
| 13522 | /** |
| 13523 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset |
| 13524 | * @phba: pointer to lpfc hba data structure. |
| 13525 | * |
| 13526 | * This routine is called to prepare the SLI4 device for PCI slot reset. It |
| 13527 | * disables the device interrupt and pci device, and aborts the internal FCP |
| 13528 | * pending I/Os. |
| 13529 | **/ |
| 13530 | static void |
| 13531 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) |
| 13532 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13533 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13534 | "2826 PCI channel disable preparing for reset\n"); |
| 13535 | |
| 13536 | /* Block any management I/Os to the device */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13537 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13538 | |
| 13539 | /* Block all SCSI devices' I/Os on the host */ |
| 13540 | lpfc_scsi_dev_block(phba); |
| 13541 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13542 | /* Flush all driver's outstanding I/Os as we are to reset */ |
| 13543 | lpfc_sli_flush_io_rings(phba); |
James Smart | c3725bd | 2017-11-20 16:00:42 -0800 | [diff] [blame] | 13544 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13545 | /* stop all timers */ |
| 13546 | lpfc_stop_hba_timers(phba); |
| 13547 | |
| 13548 | /* Disable interrupt and pci device */ |
| 13549 | lpfc_sli4_disable_intr(phba); |
James Smart | 5350d87 | 2011-10-10 21:33:49 -0400 | [diff] [blame] | 13550 | lpfc_sli4_queue_destroy(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13551 | pci_disable_device(phba->pcidev); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13552 | } |
| 13553 | |
| 13554 | /** |
| 13555 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable |
| 13556 | * @phba: pointer to lpfc hba data structure. |
| 13557 | * |
| 13558 | * This routine is called to prepare the SLI4 device for PCI slot permanently |
| 13559 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP |
| 13560 | * pending I/Os. |
| 13561 | **/ |
| 13562 | static void |
| 13563 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
| 13564 | { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13565 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13566 | "2827 PCI channel permanent disable for failure\n"); |
| 13567 | |
| 13568 | /* Block all SCSI devices' I/Os on the host */ |
| 13569 | lpfc_scsi_dev_block(phba); |
| 13570 | |
| 13571 | /* stop all timers */ |
| 13572 | lpfc_stop_hba_timers(phba); |
| 13573 | |
James Smart | c00f62e | 2019-08-14 16:57:11 -0700 | [diff] [blame] | 13574 | /* Clean up all driver's outstanding I/Os */ |
| 13575 | lpfc_sli_flush_io_rings(phba); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13576 | } |
| 13577 | |
| 13578 | /** |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13579 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
| 13580 | * @pdev: pointer to PCI device. |
| 13581 | * @state: the current PCI connection state. |
| 13582 | * |
| 13583 | * This routine is called from the PCI subsystem for error handling to device |
| 13584 | * with SLI-4 interface spec. This function is called by the PCI subsystem |
| 13585 | * after a PCI bus error affecting this device has been detected. When this |
| 13586 | * function is invoked, it will need to stop all the I/Os and interrupt(s) |
| 13587 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET |
| 13588 | * for the PCI subsystem to perform proper recovery as desired. |
| 13589 | * |
| 13590 | * Return codes |
| 13591 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13592 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13593 | **/ |
| 13594 | static pci_ers_result_t |
| 13595 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
| 13596 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13597 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13598 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13599 | |
| 13600 | switch (state) { |
| 13601 | case pci_channel_io_normal: |
| 13602 | /* Non-fatal error, prepare for recovery */ |
| 13603 | lpfc_sli4_prep_dev_for_recover(phba); |
| 13604 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 13605 | case pci_channel_io_frozen: |
| 13606 | /* Fatal error, prepare for slot reset */ |
| 13607 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13608 | return PCI_ERS_RESULT_NEED_RESET; |
| 13609 | case pci_channel_io_perm_failure: |
| 13610 | /* Permanent failure, prepare for device down */ |
| 13611 | lpfc_sli4_prep_dev_for_perm_failure(phba); |
| 13612 | return PCI_ERS_RESULT_DISCONNECT; |
| 13613 | default: |
| 13614 | /* Unknown state, prepare and request slot reset */ |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13615 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13616 | "2825 Unknown PCI error state: x%x\n", state); |
| 13617 | lpfc_sli4_prep_dev_for_reset(phba); |
| 13618 | return PCI_ERS_RESULT_NEED_RESET; |
| 13619 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13620 | } |
| 13621 | |
| 13622 | /** |
| 13623 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
| 13624 | * @pdev: pointer to PCI device. |
| 13625 | * |
| 13626 | * This routine is called from the PCI subsystem for error handling to device |
| 13627 | * with SLI-4 interface spec. It is called after PCI bus has been reset to |
| 13628 | * restart the PCI card from scratch, as if from a cold-boot. During the |
| 13629 | * PCI subsystem error recovery, after the driver returns |
| 13630 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
| 13631 | * recovery and then call this routine before calling the .resume method to |
| 13632 | * recover the device. This function will initialize the HBA device, enable |
| 13633 | * the interrupt, but it will just put the HBA to offline state without |
| 13634 | * passing any I/O traffic. |
| 13635 | * |
| 13636 | * Return codes |
| 13637 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13638 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13639 | */ |
| 13640 | static pci_ers_result_t |
| 13641 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
| 13642 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13643 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13644 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13645 | struct lpfc_sli *psli = &phba->sli; |
| 13646 | uint32_t intr_mode; |
| 13647 | |
| 13648 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
| 13649 | if (pci_enable_device_mem(pdev)) { |
| 13650 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 13651 | "PCI device after reset.\n"); |
| 13652 | return PCI_ERS_RESULT_DISCONNECT; |
| 13653 | } |
| 13654 | |
| 13655 | pci_restore_state(pdev); |
James Smart | 0a96e97 | 2011-07-22 18:37:28 -0400 | [diff] [blame] | 13656 | |
| 13657 | /* |
| 13658 | * As the new kernel behavior of pci_restore_state() API call clears |
| 13659 | * device saved_state flag, need to save the restored state again. |
| 13660 | */ |
| 13661 | pci_save_state(pdev); |
| 13662 | |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13663 | if (pdev->is_busmaster) |
| 13664 | pci_set_master(pdev); |
| 13665 | |
| 13666 | spin_lock_irq(&phba->hbalock); |
| 13667 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
| 13668 | spin_unlock_irq(&phba->hbalock); |
| 13669 | |
| 13670 | /* Configure and enable interrupt */ |
| 13671 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
| 13672 | if (intr_mode == LPFC_INTR_ERROR) { |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13673 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13674 | "2824 Cannot re-enable interrupt after " |
| 13675 | "slot reset.\n"); |
| 13676 | return PCI_ERS_RESULT_DISCONNECT; |
| 13677 | } else |
| 13678 | phba->intr_mode = intr_mode; |
| 13679 | |
| 13680 | /* Log the current active interrupt mode */ |
| 13681 | lpfc_log_intr_mode(phba, phba->intr_mode); |
| 13682 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13683 | return PCI_ERS_RESULT_RECOVERED; |
| 13684 | } |
| 13685 | |
| 13686 | /** |
| 13687 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
| 13688 | * @pdev: pointer to PCI device |
| 13689 | * |
| 13690 | * This routine is called from the PCI subsystem for error handling to device |
| 13691 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
| 13692 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
| 13693 | * error recovery. After this call, traffic can start to flow from this device |
| 13694 | * again. |
| 13695 | **/ |
| 13696 | static void |
| 13697 | lpfc_io_resume_s4(struct pci_dev *pdev) |
| 13698 | { |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13699 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13700 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13701 | |
| 13702 | /* |
| 13703 | * In case of slot reset, as function reset is performed through |
| 13704 | * mailbox command which needs DMA to be enabled, this operation |
| 13705 | * has to be moved to the io resume phase. Taking device offline |
| 13706 | * will perform the necessary cleanup. |
| 13707 | */ |
| 13708 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { |
| 13709 | /* Perform device reset */ |
James Smart | 618a523 | 2012-06-12 13:54:36 -0400 | [diff] [blame] | 13710 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
James Smart | 75baf69 | 2010-06-08 18:31:21 -0400 | [diff] [blame] | 13711 | lpfc_offline(phba); |
| 13712 | lpfc_sli_brdrestart(phba); |
| 13713 | /* Bring the device back online */ |
| 13714 | lpfc_online(phba); |
| 13715 | } |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13716 | } |
| 13717 | |
| 13718 | /** |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13719 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem |
| 13720 | * @pdev: pointer to PCI device |
| 13721 | * @pid: pointer to PCI device identifier |
| 13722 | * |
| 13723 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13724 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks |
| 13725 | * at PCI device-specific information of the device and driver to see if the |
| 13726 | * driver state that it can support this kind of device. If the match is |
| 13727 | * successful, the driver core invokes this routine. This routine dispatches |
| 13728 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will |
| 13729 | * do all the initialization that it needs to do to handle the HBA device |
| 13730 | * properly. |
| 13731 | * |
| 13732 | * Return code |
| 13733 | * 0 - driver can claim the device |
| 13734 | * negative value - driver can not claim the device |
| 13735 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13736 | static int |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13737 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 13738 | { |
| 13739 | int rc; |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13740 | struct lpfc_sli_intf intf; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13741 | |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13742 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13743 | return -ENODEV; |
| 13744 | |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13745 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 13746 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13747 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13748 | else |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13749 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 13750 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13751 | return rc; |
| 13752 | } |
| 13753 | |
| 13754 | /** |
| 13755 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem |
| 13756 | * @pdev: pointer to PCI device |
| 13757 | * |
| 13758 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 13759 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. |
| 13760 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device |
| 13761 | * remove routine, which will perform all the necessary cleanup for the |
| 13762 | * device to be removed from the PCI subsystem properly. |
| 13763 | **/ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 13764 | static void |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13765 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 13766 | { |
| 13767 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13768 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13769 | |
| 13770 | switch (phba->pci_dev_grp) { |
| 13771 | case LPFC_PCI_DEV_LP: |
| 13772 | lpfc_pci_remove_one_s3(pdev); |
| 13773 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13774 | case LPFC_PCI_DEV_OC: |
| 13775 | lpfc_pci_remove_one_s4(pdev); |
| 13776 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13777 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13778 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13779 | "1424 Invalid PCI device group: 0x%x\n", |
| 13780 | phba->pci_dev_grp); |
| 13781 | break; |
| 13782 | } |
| 13783 | return; |
| 13784 | } |
| 13785 | |
| 13786 | /** |
| 13787 | * 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] | 13788 | * @dev: pointer to device |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13789 | * |
| 13790 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13791 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13792 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will |
| 13793 | * suspend the device. |
| 13794 | * |
| 13795 | * Return code |
| 13796 | * 0 - driver suspended the device |
| 13797 | * Error otherwise |
| 13798 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13799 | static int __maybe_unused |
| 13800 | lpfc_pci_suspend_one(struct device *dev) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13801 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13802 | struct Scsi_Host *shost = dev_get_drvdata(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13803 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13804 | int rc = -ENODEV; |
| 13805 | |
| 13806 | switch (phba->pci_dev_grp) { |
| 13807 | case LPFC_PCI_DEV_LP: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13808 | rc = lpfc_pci_suspend_one_s3(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13809 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13810 | case LPFC_PCI_DEV_OC: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13811 | rc = lpfc_pci_suspend_one_s4(dev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13812 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13813 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13814 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13815 | "1425 Invalid PCI device group: 0x%x\n", |
| 13816 | phba->pci_dev_grp); |
| 13817 | break; |
| 13818 | } |
| 13819 | return rc; |
| 13820 | } |
| 13821 | |
| 13822 | /** |
| 13823 | * 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] | 13824 | * @dev: pointer to device |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13825 | * |
| 13826 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 13827 | * system Power Management (PM). When PM invokes this method, it dispatches |
| 13828 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will |
| 13829 | * resume the device. |
| 13830 | * |
| 13831 | * Return code |
| 13832 | * 0 - driver suspended the device |
| 13833 | * Error otherwise |
| 13834 | **/ |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13835 | static int __maybe_unused |
| 13836 | lpfc_pci_resume_one(struct device *dev) |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13837 | { |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13838 | struct Scsi_Host *shost = dev_get_drvdata(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13839 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13840 | int rc = -ENODEV; |
| 13841 | |
| 13842 | switch (phba->pci_dev_grp) { |
| 13843 | case LPFC_PCI_DEV_LP: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13844 | rc = lpfc_pci_resume_one_s3(dev); |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13845 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13846 | case LPFC_PCI_DEV_OC: |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 13847 | rc = lpfc_pci_resume_one_s4(dev); |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13848 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13849 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13850 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13851 | "1426 Invalid PCI device group: 0x%x\n", |
| 13852 | phba->pci_dev_grp); |
| 13853 | break; |
| 13854 | } |
| 13855 | return rc; |
| 13856 | } |
| 13857 | |
| 13858 | /** |
| 13859 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error |
| 13860 | * @pdev: pointer to PCI device. |
| 13861 | * @state: the current PCI connection state. |
| 13862 | * |
| 13863 | * This routine is registered to the PCI subsystem for error handling. This |
| 13864 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 13865 | * this device has been detected. When this routine is invoked, it dispatches |
| 13866 | * the action to the proper SLI-3 or SLI-4 device error detected handling |
| 13867 | * routine, which will perform the proper error detected operation. |
| 13868 | * |
| 13869 | * Return codes |
| 13870 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 13871 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13872 | **/ |
| 13873 | static pci_ers_result_t |
| 13874 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 13875 | { |
| 13876 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13877 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13878 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13879 | |
| 13880 | switch (phba->pci_dev_grp) { |
| 13881 | case LPFC_PCI_DEV_LP: |
| 13882 | rc = lpfc_io_error_detected_s3(pdev, state); |
| 13883 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13884 | case LPFC_PCI_DEV_OC: |
| 13885 | rc = lpfc_io_error_detected_s4(pdev, state); |
| 13886 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13887 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13888 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13889 | "1427 Invalid PCI device group: 0x%x\n", |
| 13890 | phba->pci_dev_grp); |
| 13891 | break; |
| 13892 | } |
| 13893 | return rc; |
| 13894 | } |
| 13895 | |
| 13896 | /** |
| 13897 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch |
| 13898 | * @pdev: pointer to PCI device. |
| 13899 | * |
| 13900 | * This routine is registered to the PCI subsystem for error handling. This |
| 13901 | * function is called after PCI bus has been reset to restart the PCI card |
| 13902 | * from scratch, as if from a cold-boot. When this routine is invoked, it |
| 13903 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling |
| 13904 | * routine, which will perform the proper device reset. |
| 13905 | * |
| 13906 | * Return codes |
| 13907 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 13908 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 13909 | **/ |
| 13910 | static pci_ers_result_t |
| 13911 | lpfc_io_slot_reset(struct pci_dev *pdev) |
| 13912 | { |
| 13913 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13914 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13915 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; |
| 13916 | |
| 13917 | switch (phba->pci_dev_grp) { |
| 13918 | case LPFC_PCI_DEV_LP: |
| 13919 | rc = lpfc_io_slot_reset_s3(pdev); |
| 13920 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13921 | case LPFC_PCI_DEV_OC: |
| 13922 | rc = lpfc_io_slot_reset_s4(pdev); |
| 13923 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13924 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13925 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13926 | "1428 Invalid PCI device group: 0x%x\n", |
| 13927 | phba->pci_dev_grp); |
| 13928 | break; |
| 13929 | } |
| 13930 | return rc; |
| 13931 | } |
| 13932 | |
| 13933 | /** |
| 13934 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation |
| 13935 | * @pdev: pointer to PCI device |
| 13936 | * |
| 13937 | * This routine is registered to the PCI subsystem for error handling. It |
| 13938 | * is called when kernel error recovery tells the lpfc driver that it is |
| 13939 | * OK to resume normal PCI operation after PCI bus error recovery. When |
| 13940 | * this routine is invoked, it dispatches the action to the proper SLI-3 |
| 13941 | * or SLI-4 device io_resume routine, which will resume the device operation. |
| 13942 | **/ |
| 13943 | static void |
| 13944 | lpfc_io_resume(struct pci_dev *pdev) |
| 13945 | { |
| 13946 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 13947 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 13948 | |
| 13949 | switch (phba->pci_dev_grp) { |
| 13950 | case LPFC_PCI_DEV_LP: |
| 13951 | lpfc_io_resume_s3(pdev); |
| 13952 | break; |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 13953 | case LPFC_PCI_DEV_OC: |
| 13954 | lpfc_io_resume_s4(pdev); |
| 13955 | break; |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13956 | default: |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 13957 | lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 13958 | "1429 Invalid PCI device group: 0x%x\n", |
| 13959 | phba->pci_dev_grp); |
| 13960 | break; |
| 13961 | } |
| 13962 | return; |
| 13963 | } |
| 13964 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13965 | /** |
| 13966 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter |
| 13967 | * @phba: pointer to lpfc hba data structure. |
| 13968 | * |
| 13969 | * This routine checks to see if OAS is supported for this adapter. If |
| 13970 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, |
| 13971 | * the enable oas flag is cleared and the pool created for OAS device data |
| 13972 | * is destroyed. |
| 13973 | * |
| 13974 | **/ |
YueHaibing | c709297 | 2019-04-17 23:05:54 +0800 | [diff] [blame] | 13975 | static void |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13976 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) |
| 13977 | { |
| 13978 | |
| 13979 | if (!phba->cfg_EnableXLane) |
| 13980 | return; |
| 13981 | |
| 13982 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { |
| 13983 | phba->cfg_fof = 1; |
| 13984 | } else { |
James Smart | f38fa0b | 2014-04-04 13:52:21 -0400 | [diff] [blame] | 13985 | phba->cfg_fof = 0; |
Saurav Girepunje | c3e5aac | 2019-10-27 01:17:17 +0530 | [diff] [blame] | 13986 | mempool_destroy(phba->device_data_mem_pool); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 13987 | phba->device_data_mem_pool = NULL; |
| 13988 | } |
| 13989 | |
| 13990 | return; |
| 13991 | } |
| 13992 | |
| 13993 | /** |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 13994 | * lpfc_sli4_ras_init - Verify RAS-FW log is supported by this adapter |
| 13995 | * @phba: pointer to lpfc hba data structure. |
| 13996 | * |
| 13997 | * This routine checks to see if RAS is supported by the adapter. Check the |
| 13998 | * function through which RAS support enablement is to be done. |
| 13999 | **/ |
| 14000 | void |
| 14001 | lpfc_sli4_ras_init(struct lpfc_hba *phba) |
| 14002 | { |
| 14003 | switch (phba->pcidev->device) { |
| 14004 | case PCI_DEVICE_ID_LANCER_G6_FC: |
| 14005 | case PCI_DEVICE_ID_LANCER_G7_FC: |
| 14006 | phba->ras_fwlog.ras_hwsupport = true; |
James Smart | cb34990 | 2018-11-29 16:09:27 -0800 | [diff] [blame] | 14007 | if (phba->cfg_ras_fwlog_func == PCI_FUNC(phba->pcidev->devfn) && |
| 14008 | phba->cfg_ras_fwlog_buffsize) |
James Smart | d2cc9bc | 2018-09-10 10:30:50 -0700 | [diff] [blame] | 14009 | phba->ras_fwlog.ras_enabled = true; |
| 14010 | else |
| 14011 | phba->ras_fwlog.ras_enabled = false; |
| 14012 | break; |
| 14013 | default: |
| 14014 | phba->ras_fwlog.ras_hwsupport = false; |
| 14015 | } |
| 14016 | } |
| 14017 | |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 14018 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14019 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 14020 | |
Stephen Hemminger | a55b2d2 | 2012-09-07 09:33:16 -0700 | [diff] [blame] | 14021 | static const struct pci_error_handlers lpfc_err_handler = { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 14022 | .error_detected = lpfc_io_error_detected, |
| 14023 | .slot_reset = lpfc_io_slot_reset, |
| 14024 | .resume = lpfc_io_resume, |
| 14025 | }; |
| 14026 | |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14027 | static SIMPLE_DEV_PM_OPS(lpfc_pci_pm_ops_one, |
| 14028 | lpfc_pci_suspend_one, |
| 14029 | lpfc_pci_resume_one); |
| 14030 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14031 | static struct pci_driver lpfc_driver = { |
| 14032 | .name = LPFC_DRIVER_NAME, |
| 14033 | .id_table = lpfc_id_table, |
| 14034 | .probe = lpfc_pci_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 14035 | .remove = lpfc_pci_remove_one, |
Anton Blanchard | 85e8a23 | 2017-02-13 08:49:20 +1100 | [diff] [blame] | 14036 | .shutdown = lpfc_pci_remove_one, |
Vaibhav Gupta | ef6fa16 | 2020-11-02 22:17:18 +0530 | [diff] [blame] | 14037 | .driver.pm = &lpfc_pci_pm_ops_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 14038 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14039 | }; |
| 14040 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14041 | static const struct file_operations lpfc_mgmt_fop = { |
Al Viro | 858feac | 2013-04-14 22:39:37 -0400 | [diff] [blame] | 14042 | .owner = THIS_MODULE, |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14043 | }; |
| 14044 | |
| 14045 | static struct miscdevice lpfc_mgmt_dev = { |
| 14046 | .minor = MISC_DYNAMIC_MINOR, |
| 14047 | .name = "lpfcmgmt", |
| 14048 | .fops = &lpfc_mgmt_fop, |
| 14049 | }; |
| 14050 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14051 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 14052 | * lpfc_init - lpfc module initialization routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14053 | * |
| 14054 | * This routine is to be invoked when the lpfc module is loaded into the |
| 14055 | * kernel. The special kernel macro module_init() is used to indicate the |
| 14056 | * role of this routine to the kernel as lpfc module entry point. |
| 14057 | * |
| 14058 | * Return codes |
| 14059 | * 0 - successful |
| 14060 | * -ENOMEM - FC attach transport failed |
| 14061 | * all others - failed |
| 14062 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14063 | static int __init |
| 14064 | lpfc_init(void) |
| 14065 | { |
| 14066 | int error = 0; |
| 14067 | |
Anton Blanchard | bc2736e | 2020-07-13 18:39:08 +1000 | [diff] [blame] | 14068 | pr_info(LPFC_MODULE_DESC "\n"); |
| 14069 | pr_info(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14070 | |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14071 | error = misc_register(&lpfc_mgmt_dev); |
| 14072 | if (error) |
| 14073 | printk(KERN_ERR "Could not register lpfcmgmt device, " |
| 14074 | "misc_register returned with status %d", error); |
| 14075 | |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14076 | error = -ENOMEM; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 14077 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 14078 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14079 | lpfc_transport_template = |
| 14080 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 14081 | if (lpfc_transport_template == NULL) |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14082 | goto unregister; |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 14083 | lpfc_vport_transport_template = |
| 14084 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 14085 | if (lpfc_vport_transport_template == NULL) { |
| 14086 | fc_release_transport(lpfc_transport_template); |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14087 | goto unregister; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 14088 | } |
James Smart | 840a470 | 2020-11-15 11:26:40 -0800 | [diff] [blame] | 14089 | lpfc_wqe_cmd_template(); |
James Smart | bd3061b | 2018-03-05 12:04:05 -0800 | [diff] [blame] | 14090 | lpfc_nvmet_cmd_template(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 14091 | |
| 14092 | /* Initialize in case vector mapping is needed */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 14093 | lpfc_present_cpu = num_present_cpus(); |
James Smart | 7bb03bb | 2013-04-17 20:19:16 -0400 | [diff] [blame] | 14094 | |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14095 | error = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, |
| 14096 | "lpfc/sli4:online", |
| 14097 | lpfc_cpu_online, lpfc_cpu_offline); |
| 14098 | if (error < 0) |
| 14099 | goto cpuhp_failure; |
| 14100 | lpfc_cpuhp_state = error; |
| 14101 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14102 | error = pci_register_driver(&lpfc_driver); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14103 | if (error) |
| 14104 | goto unwind; |
| 14105 | |
| 14106 | return error; |
| 14107 | |
| 14108 | unwind: |
| 14109 | cpuhp_remove_multi_state(lpfc_cpuhp_state); |
| 14110 | cpuhp_failure: |
| 14111 | fc_release_transport(lpfc_transport_template); |
| 14112 | fc_release_transport(lpfc_vport_transport_template); |
Jing Xiangfeng | 1eaff53 | 2020-07-31 14:56:39 +0800 | [diff] [blame] | 14113 | unregister: |
| 14114 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14115 | |
| 14116 | return error; |
| 14117 | } |
| 14118 | |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14119 | void lpfc_dmp_dbg(struct lpfc_hba *phba) |
| 14120 | { |
| 14121 | unsigned int start_idx; |
| 14122 | unsigned int dbg_cnt; |
| 14123 | unsigned int temp_idx; |
| 14124 | int i; |
| 14125 | int j = 0; |
| 14126 | unsigned long rem_nsec; |
| 14127 | |
| 14128 | if (phba->cfg_log_verbose) |
| 14129 | return; |
| 14130 | |
| 14131 | if (atomic_cmpxchg(&phba->dbg_log_dmping, 0, 1) != 0) |
| 14132 | return; |
| 14133 | |
| 14134 | start_idx = (unsigned int)atomic_read(&phba->dbg_log_idx) % DBG_LOG_SZ; |
| 14135 | dbg_cnt = (unsigned int)atomic_read(&phba->dbg_log_cnt); |
| 14136 | temp_idx = start_idx; |
| 14137 | if (dbg_cnt >= DBG_LOG_SZ) { |
| 14138 | dbg_cnt = DBG_LOG_SZ; |
| 14139 | temp_idx -= 1; |
| 14140 | } else { |
| 14141 | if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) { |
| 14142 | temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ; |
| 14143 | } else { |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 14144 | if (start_idx < dbg_cnt) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14145 | start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx); |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 14146 | else |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14147 | start_idx -= dbg_cnt; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14148 | } |
| 14149 | } |
| 14150 | dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n", |
| 14151 | start_idx, temp_idx, dbg_cnt); |
| 14152 | |
| 14153 | for (i = 0; i < dbg_cnt; i++) { |
| 14154 | if ((start_idx + i) < DBG_LOG_SZ) |
Dick Kennedy | 77dd7d7 | 2020-07-06 13:42:46 -0700 | [diff] [blame] | 14155 | temp_idx = (start_idx + i) % DBG_LOG_SZ; |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14156 | else |
| 14157 | temp_idx = j++; |
| 14158 | rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC); |
| 14159 | dev_info(&phba->pcidev->dev, "%d: [%5lu.%06lu] %s", |
| 14160 | temp_idx, |
| 14161 | (unsigned long)phba->dbg_log[temp_idx].t_ns, |
| 14162 | rem_nsec / 1000, |
| 14163 | phba->dbg_log[temp_idx].log); |
| 14164 | } |
| 14165 | atomic_set(&phba->dbg_log_cnt, 0); |
| 14166 | atomic_set(&phba->dbg_log_dmping, 0); |
| 14167 | } |
| 14168 | |
Lee Jones | 7fa03c7 | 2020-07-23 13:24:21 +0100 | [diff] [blame] | 14169 | __printf(2, 3) |
Dick Kennedy | 372c187 | 2020-06-30 14:50:00 -0700 | [diff] [blame] | 14170 | void lpfc_dbg_print(struct lpfc_hba *phba, const char *fmt, ...) |
| 14171 | { |
| 14172 | unsigned int idx; |
| 14173 | va_list args; |
| 14174 | int dbg_dmping = atomic_read(&phba->dbg_log_dmping); |
| 14175 | struct va_format vaf; |
| 14176 | |
| 14177 | |
| 14178 | va_start(args, fmt); |
| 14179 | if (unlikely(dbg_dmping)) { |
| 14180 | vaf.fmt = fmt; |
| 14181 | vaf.va = &args; |
| 14182 | dev_info(&phba->pcidev->dev, "%pV", &vaf); |
| 14183 | va_end(args); |
| 14184 | return; |
| 14185 | } |
| 14186 | idx = (unsigned int)atomic_fetch_add(1, &phba->dbg_log_idx) % |
| 14187 | DBG_LOG_SZ; |
| 14188 | |
| 14189 | atomic_inc(&phba->dbg_log_cnt); |
| 14190 | |
| 14191 | vscnprintf(phba->dbg_log[idx].log, |
| 14192 | sizeof(phba->dbg_log[idx].log), fmt, args); |
| 14193 | va_end(args); |
| 14194 | |
| 14195 | phba->dbg_log[idx].t_ns = local_clock(); |
| 14196 | } |
| 14197 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14198 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 14199 | * lpfc_exit - lpfc module removal routine |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 14200 | * |
| 14201 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 14202 | * The special kernel macro module_exit() is used to indicate the role of |
| 14203 | * this routine to the kernel as lpfc module exit point. |
| 14204 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14205 | static void __exit |
| 14206 | lpfc_exit(void) |
| 14207 | { |
James Smart | 3ef6d24 | 2012-01-18 16:23:48 -0500 | [diff] [blame] | 14208 | misc_deregister(&lpfc_mgmt_dev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14209 | pci_unregister_driver(&lpfc_driver); |
James Smart | 93a4d6f | 2019-11-04 16:57:05 -0800 | [diff] [blame] | 14210 | cpuhp_remove_multi_state(lpfc_cpuhp_state); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14211 | fc_release_transport(lpfc_transport_template); |
James Smart | 458c083 | 2016-07-06 12:36:07 -0700 | [diff] [blame] | 14212 | fc_release_transport(lpfc_vport_transport_template); |
Johannes Thumshirn | 7973967 | 2015-08-31 16:48:11 -0400 | [diff] [blame] | 14213 | idr_destroy(&lpfc_hba_index); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14214 | } |
| 14215 | |
| 14216 | module_init(lpfc_init); |
| 14217 | module_exit(lpfc_exit); |
| 14218 | MODULE_LICENSE("GPL"); |
| 14219 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
James Smart | d080abe | 2017-02-12 13:52:39 -0800 | [diff] [blame] | 14220 | MODULE_AUTHOR("Broadcom"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 14221 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |